home *** CD-ROM | disk | FTP | other *** search
- menu -plot /* make sure plot window menu */
-
- menu 7 &Math
- /* install the math menu */
-
- Menu "Simple &Math.." {/* begins a block */
- 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
- def AskSmooth {
- if (MKS1>=0) {
- data.selected=1;
- %B = %C;
- type -C "Replace the selected section of %C with %1 values?";
- }
- else {
- data.selected=0;
- %B=%C.%2;
- if(%[%B]>24) {
- type -B "Worksheet name too long or column name too long. Rename worksheet or column first.";
- break 1;
- };
- copy %C %B;
- type -C "%1 %C and put the result into %B?";
- };
- }
-
- Menu "&Smoothing.." {
- if ( smdegree < 5) {smdegree=5};
- if ( smdegree > 13) {smdegree=13};
-
- GetNumber -s
- [Degree of smoothing
- (# of pts: 5,7,9,11,13)]
- smdegree
- [Smoothing %C];
-
- if ( smdegree < 5 || smdegree > 13 ) {
- ty -b "$(smdegree) is illegal for smoothing.";
- break 1;
- };
-
- AskSmooth Smooth sm$(smdegree);
-
- i=int(smdegree/2);/* save for setting color */
- dll orgmath smooth $(1+2*i) 0 %B;
-
- if (data.selected == 0) {
- graph %B;
- set %B -color i;/* see above */
- };
- #Smooth %C by Savitzky-Golay method.
- }
-
- Menu "&Adjacent Averaging.. " {
- CheckVar AveStep 2;
- GetNumber -s
- [# of pts in either side
- to be averaged (1,2,3..)]
- AveStep
- [Adjacent Averaging %C];
-
- AskSmooth Average av$(AveStep);
-
- if ( AveStep < 1) {
- ty -b "$(smdegree) is illegal for averaging.";
- break 1;
- };
-
- Ave -n AveStep %B;
-
- if (data.selected == 0) {
- graph %B;
- set %B -c (1+AveStep);
- };
- /* assign different color to the result depending on AveStep */
- #Smooth %C by averaging adjacent points (Running Averaging).
- }
-
- Menu (FFT Filter Smoothing..) {
- CheckVar ftsmsize 5;
-
- if (MkS1>=0) (i1=MkS1;i2=MkS2)
- else (get %C -b i1;get %C -e i2);
-
- npts = int((i2-i1)/2);
- if ( ftsmsize > npts ) {ftsmsize = npts};
-
- GetNumber -s
- [FFT filter window
- (# of pts: 5)] ftsmsize;
-
- if ( ftsmsize > npts) {ftsmsize = npts};
- AskSmooth FTSmooth ftsm$(ftsmsize);
- i=int(ftsmsize/2);
- dll orgmath smooft $(ftsmsize) %B;
- if (data.selected == 0) {
- graph %B;
- set %B -color i;
- };
- }
-
- Menu
-
- Menu &Differentiate {
- copy %C %C';/* copy %C into a new data set %C' */
- deriv %C';/* take a derivative with default settings */
- %B=%C';/* save the name in %B */
- GetNamedWin Deriv;/* Open the template called Deriv */
- graph %B;
- rescale;
- #Take the derivative of %C and put the result into a new window
- }
-
- Menu "Diff/Smooth.." {
- CheckVar smdegree 5;
- CheckVar dorder 1;
- GetNumber -s
- [Order of Derivatives
- ( 1 or 2 )]
- dorder
- [Taking Derivatives on %C];
-
- if (dorder<1 || dorder>2) {
- type -b "First or Second Order Derivatives only.";
- break 1;
- };
-
- GetNumber -s
- [Degree of smoothing
- (# of pts: 5,7,9,11,13)]
- smdegree
- [Smoothing Applied];
-
- %B=%C$(dorder).$(smdegree);
- copy %C %B;
-
- i=int(smdegree/2);/* save for setting color */
- dll orgmath smooth $(1+2*i) $(dorder) %B;
- GetNamedWin Deriv;/* Open the template called Deriv */
- graph %B;
- rescale;
- #1st or 2nd Derivatives of %C by Savitzky-Golay smoothing.
- }
-
-
- Menu &Integrate {
- integ %C;
- 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 zero;
- /* type -a; bring up the Script window */
-
- ty "i = $(i1) --> $(i2)";
- ty "x = $(integ.x1) --> $(integ.x2)";
- ty "Area Peak at Width Height";
- ty "$(integ.area) $(integ.x0) $(integ.dx) $(integ.y0)";
- #Integrate %C (from zero)
- }
-
-
- 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
- */
- rescale;/* 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;rescale);
-
- GetPts -n _line 2 /* 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
-
- 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 -Y 1
- (Move cursor to new location, hit ENTER)
- };
- Pick1pt;
- #Pick one pt as ref and move curve to a new pt vertically.
- }
-
-
-
- Menu "&X Translate" {
- def EndToolbox
- {
- x_last = x;;
- def EndToolbox {
- x - x_last;
- if (hasx(%C)) [xof(%C)=xof(%C)+x;x=0];
- /* the following is not necessary if %C has X
- * but we do it for both case so as to
- * update generate the update message.
- */
- get %C -f v1;v1+x;set %C -f v1;
- };
- GetPts -X 1
- (Move cursor to a new location, hit Enter)
- };
- Pick1pt;
- #Pick one pt as ref and move curve to a new pt horizontally.
- }
-
- Menu
-
- Menu (Averaging &Multiple Curves..) {
- layer -c;
- if(count < 2) {
- type -b You need to have at least two curves.
- return;
- };
- %B = Ave.$(count);
- copy -x %(1,@D) %B_mean;
- for(i = 2;i <= count; i+=1) {
- %B_mean+%(i,@D);
- };
- %B_mean/=count;
- layer -i %B_mean;
- set %B_mean -c count;
-
- #Creates averaged data by summing up all of \
- the data in the current layer.
- }
-
- Menu (Inter/extrapolate..) {
- limit %C;fitx1=limit.xmin;fitx2=limit.xmax;
- layer -c %C;/* Position of %C in the layer, result in count */
- GetCuvName cuv;/* result in %B */
-
- GetNumber
- [Make Curve Xmin] fitx1
- [Make Curve Xmax] fitx2
- [Make Curve # pts] fitnpts
- [Make Curve Name] %%B
- [Make Interpolated Curve from %C];
- /* user can cancel, otherwise we will continue */
-
- del %B;/* incase it already exists, remove it first */
- (%B)=data(0,0,fitnpts);
- /* (%B) instead of %B, otherwise just the content of %B
- * will be set instead of the name in %B be assigned
- */
- SetDataRange %B;/* use fitx1, fitx2 and fitnpts */
- %B +-O %C;/* %B is all zeros, add %C and extrapolate if outside */
- graph %B;/* show it in the current layer */
- set %B -c 2;/* color red */
- #Interpolate or extrapolate %C into a new curve,\
- depending on %C's line connection type.
- }
-
- /* end of Math menu */
-
-
-