/* Origin Initial Configuration File The following LabTalk scripts are read into ORIGIN whenever a new Origin document is created. Origin uses these scripts to create menus, toolbox tools, and a variety of macros. The scripts (and thus the menus, tools, and macros) are user-definable. By editing the scripts as described below, you can customize Origin's initiial configuration. This script file is executed whenever a new Origin document is created. This includes: 1. Each time you launch Origin. 2. Each time you select File:New:Document. When you open an existing Origin document (an .ORG file), this script file is not executed. This script file is parsed line by line. The '\' character is used to indicate line continuation into the next line: This is considered to\ be a single line. Use the ';' character to separate multiple commands in a single line. A 'block' of text enclosed by '{ }' is considered a single line. End-of-line characters between the parentheses are ignored. For example: {This is a single line.} { So is this. } This { is also a single line. } But {this is the next line} Two different types of comments are used to annotate the script file. The C-like comment (enclosed by '/' and '*' characters) is ignored when the script file is parsed. These comments are not visible when this file is opened from within Origin. The '#' character starts a comment that extends to the end of a line, and is ignored only in script execution. These comments are visible whenever you open the script file. All LabTalk commands, as well as their arguments, are case insensitive. Any command can be abbreviated to two characters. For example: Type hello World #is the same as ty hello World For more information about the ORIGIN LabTalk Scripting language, please refer to the separate LabTalk manual */ /* In this section of the configuration file, * the user-definable menus are created. * The existing menus are as follows: * 1. File * 2. Edit * 3. Options * 4. Page * 5. Plot * 6. Data * <----- Add your menus here. * 7. Window * 8. Help * The Window and Help menus are standard and * should not be changed. The Data and Options menu * should also be preserved. You are advised to add * your menus between the Data and Window menus. */ /***************************************************** * * The following command adds a popup menu 'Math' between * 'Data' and 'Window'. The '7' indicates that this is to be the * seventh menu on the menu display bar. The '&' makes the * following character the keyboard equivalent for this menu command. * ******************************************************/ menu 7 &Math /* * The following are the commands for the Math * menu we just created. The Menu function alway * takes two words as arguments. A word is considered * to be any text between {} or [] or "" ("" is used only * in the simplest cases). The first word below (Simple &Math) * is the text to be displayed in the pull-down menu for this * command. The second word (everything between * the first '{' and the last '}' to come after 'Menu") is the script that * determines what this menu command does. * Seven menu commands are defined below: * Simple Math * Smoothing * Differentiate * Integrate * Subtract Ref Data * Subtract Straight Line * Y Translate *****************************************/ { /* the '{' character indicates the start of a 'block' */ Menu "Simple &Math.." { Math %C %C; /*the ';' is needed to separate two commands in the same line*/ #Basic arithmetic such as Data+2 via a dialog box } } /* end of block */ /********************************************* * * The '#' after the ';' above starts the help text that appears * in the status bar when the command is highlighted. * *********************************************/ { Menu &Smoothing.. ( GetNum [Pts to ave %C on both side] AveStep; Ave -n AveStep %C; ) } Menu &Averaging { /* this is another way to introduce a block */ Ave -a %C;#Create an averaged data \ curve by summing up all of the data in the current layer} Menu &Differentiate { copy %C %C';/* copy %C into a new data set %C' */ deriv %C';/* take a derivative with default settings */ win -D %C' Derivatives;/* Display %C' in a window named Derivatives */ #Take the derivative of %C and put the result into a new window } Menu &Integrate { ty -a;integ %C;EndInteg 0; #Integ %C from i=$(MkS1) to $(MkS2) }/* type -a; bring up the Script window */ Menu /* No argument, appears as a separator in the menu */ Menu "Subtract &Ref Data.." { math -o -; /* Start the math * dialog and set the operator to minus */ frame -all;/* reset both axes to show the data */ #Subtract one data set from another } Menu "Subtract Straight &Line" { create _line -M 3;set _line -l 1; def EndToolbox (;%C --O _Line;del _line;fr -a); GetPts -n 2 _line /* to be continue.. */ [Double-click to set straight line begin..] [Double-click to set straight line end..];/* end of GetPts */ #Pick two screen pts and subtract %C from the line formed } Menu "Y &Translate" { def EndToolbox { /* after a double-click, cursor location * is in variables x and y */ y_last=y;; /* double ';' to make scripts follow to be executed * after all Windows messages are processed. */ def EndToolbox [y-y_last;%C + y;]; GetPts -v 1 (Move cursor to new location, hit ENTER) }; Pick1pt;#Pick one pt as ref and move curve to a new pt. } /* end of Math menu */ /********************************************** * * Next we create a new menu, called 'Fit', that appears after 'Math' in the menu bar * * **********************************************/ menu 8 F&it Menu "Sta&ndard Linear" { del %C.LINE;x1=0;y1=0; LR -s %C;set %C.LINE -b 0;; type -a Standard fit to %C:; type "slope = $(LR.B)"; #Zero Y-intercept linear fit to %C } menu (&Linear Regression) { del %C.LINE;/* resulting curve of LR is in %C.LINE */ LR %C; /* linear Regression */ type -a; /* open the script window is it is not */ type Linear Regression for %C:; type "Y = A + B * X"; /* no need to have "" except if there is '=' involved */ type "A = $(LR.A) +- $(LR.sdA)"; type "B = $(LR.B) +- $(LR.sdB)"; type "SD = $(LR.sd), R= $(LR.r), N = $(LR.N)"; } Menu Menu "Single &Exponential" { nlsf -f Kinetic; /* params: A,t0,x0,y0. Must define function first */ limit %C; /* find max/min in both X and Y for the data */ y0 = limit.ymin;x0=0;/* y0 if Y offset */ A = limit.ymax-limit.ymin;/* amplitude */ LR -B %C; /* Linear Regression to begin of data,slope in LR.B */ t0=-0.8*A/LR.B; pv3=0;/* Hold the 3rd parameter (x0) to its current value */ lsqfit;/* the generic fitting macro */ queue { ty -a Fit y0+Ae^(-x/t) to %C; ty "y0=$(y0), A=$(A), t=$(t0)"; };#Fit y0+Ae^(-x/t) to %C } Menu &Power { nlsf -f Power; p4=%C(0); /* the DataSet(x) notation * interpolate and get the * y value at the given X */ limit %C; p1 = %C(limit.xmax) - p4; integ %C; /* get area */ LR -E %C; /* get derivative(LR.B) at the end of the curve */ p2 = limit.xmax * sqrt(LR.B/integ.Area); /* p2 is the power */ p1=p1/limit.xmax^p2; /* p1 was the y value at xmax less offset */ p3=0;pv3=0; /* assume no x offset, and hold it fixed during fitting */ lsqfit; /* the generic fitting macro */ queue { ty -a Fit B*(x-x0)^p + y0 to %C; ty "B=$(p1), p=$(p2), x0=$(p3), y0 = $(p4)" };#Fit B*(x-x0)^p + y0 to %C } /* The Fit1Peak macro is used for both Gaussian and * Lorentzian fit. The macro does not need to be defined * before the menu, but it is clearer to put them * together. */ def Fit1Peak { integ %C;nlsf -f %1; /* %1 is the argument passed to the macro */ Get %C -b i;if (MkS1>=0) (i=MkS1); /* get the beginning index, which is in the * variable MKS1 is the data is selected */ y0=%C[i]; /* assuming the beginning data point is closed to * the baseline */ x0=integ.x0;A=integ.Area; dx=integ.dx; /* parameter initialization from the * integration result(integ.x0,integ.area,integ.dx). */ lsqfit; /* the generic macro for iterating 10 times */ queue { ty -a %1 fit to %C; ty "Area\tCenter\tWidth\tOffset"; ty "$(A)\t$(x0)\t$(dx)\t$(y0)" }; /* using a queue command will * ensure proper windows updating. */ } Menu &Gaussian { Fit1Peak Gaussian;#Gaussian fit to %C } Menu &Lorentzian { Fit1Peak Lorentz;#Lorentzian fit to %C } Menu Menu "&Select Fitting Function.." { nlsf -f; #Select one of the built-in \ fitting functions, or enter your own. } Menu "Start &Fitting Session.." { nlsf %C; #Start the user control \ non-linear least square fitting session } Menu "&Parameters/Simulate.." { fitX1=X1;fitX2=X2; nlsf -e; #Open the Fitting Function dialog box } /* End of Fit menu */ /***************************************************************** * * The following section contains a number of user-definable macros. * * *****************************************************************/ /* * UserTool: The last tool in the left * column of the Toolbox is user definable. * The UserTool defined below does free hand * drawing of a data set by double-clicking. */ FirstTry=0 /* An explanation message will display when the * user click the UserTool the first time. * Please note that if a new document is opened, the macro will stay but * variables will not, so that we need to test the existance of this * variable at the begining of the macro. * A document carries variables and data, but not macros. */ def UserTool { doTool 0;/* return to the PointerTool first */ if (exist(FirstTry)!=4 || FirstTry==0) { /* exist(name) returns 4 if name is a variable */ type -C This tool is currently defined to use the ScreenReader\ to "DRAW" data. Move the cursor to the plot and double-click to "Add" new\ data points. Click any tool to end.;FirstTry=1; }; doc -cs DRAW;create DRAW.$(count+1) -curve 50; getpts -new 50 DRAW.$(count+1) (Double-click to add new pt,click any tool to quit) } def NotReady { ty -c This operation is not available at the current version... } def EndToolbox [ ] /* Do nothing */ def new {create %1 -n %2;set %1 -e %2} /* example: new test 100 * create a default data set with 100 elements */ def ErrorProc [ ] /* Do nothing */ def wait {seconds -w %1}/* wait seconds */ def watch {seconds;type "Elapsed time = $(time) sec."} /* example: second;{do something here };watch * will display the time to take to do something */ def layer frame /* alias layer to be the same as frame */ /********************************************** * At the end of integration, Origin executes the * following macro (EndInteg), which is currently * defined to display the results of the integration * in the Script window. **********************************************/ def EndInteg { if (MkS1>=0) (i1=MkS1;i2=MkS2) /* MkS1 and MkS2 are the Data Markers, * MkS1 = -1 if no markers are selected */ else (get %C -b i1;get %C -e i2); ty -a Integ of %C from %1; ty "i = $(i1) --> $(i2)"; ty "x = $(integ.x1) --> $(integ.x2)"; ty "Area\tPeak at\tWdith\tHeight"; ty "$(integ.area)\t$(integ.x0)\t$(integ.dx)\t$(integ.y0)"; } def FitWindow { } /* This macro is used if Origin is used * as a DDE server. The command * DDE -init * must also be used to enable the DDE */ def DDEBegin { if (exist(%1) == 2) (win -a %1;ClearWorksheet %1) else if (exist(%2%3) == 2) (win -a %2%3;ClearWorksheet %2%3;win -rename %2%3 %1) /* exist(name) returns 1=Data, 2 = woksheet, 3 = Plot. * %2 = DSC %3 = 1, %2%3 = DSC1 */ else (win -T Data %2 %1) } DDE -init def EndCreateWorksheet { } /********************************************* * Variables Definition: * You may define any variables that you * would like below, using the syntax * Key = Value, * where key is the variable name, and Value is the value. * ********************************************/ pi = 3.1415926 /* The following variables are used by Origin, and are * necessary for the proper operation of the program. */ fitnpts = 60 fitx1 = 1 fitx2 = 10 TimerCycle=5; #User installed timer period AcceptFit=0.05; #Norm of Chi^2 to terminate fitting initNfitPts=30; #Number of data pts used in least square fitting #The initial step size = NumPtsInData/initNfitPts AveStep=3; #Number of points used in smoothing /* * Baseline related variables */ MV_BASELINE_PTS=12 /* Number of data points used in cursor move baseline */ /* LR -B DataSet command uses the * following variables */ Chk_Linear_R=400 /* Sets the amount of tolerance in the automatic * determination of linear segments from the data */ MAX_L_RANGE=40 /* percentage of the entire data range to * be examined by the find linear segment routine */