home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e002 / 1.ddi / MATH.CN_ / MATH.CN
Encoding:
Text File  |  1993-12-06  |  6.6 KB  |  294 lines

  1. menu -plot /* make sure plot window menu */
  2.  
  3. menu 7 &Math    
  4.     /* install the math menu */     
  5.  
  6. Menu "Simple &Math.." {/* begins a block */
  7.     Math %C %C;    /*the ';' is needed to separate two commands in the same line*/
  8.     #Basic arithmetic such as Data+2 via a dialog box
  9. }/* end of block */
  10.  
  11.  
  12. /*********************************************
  13.  *  
  14.  * The '#' after the ';' above starts the help text that appears
  15.  * in the status bar when the command is highlighted.
  16.  * 
  17.  *********************************************/
  18.  
  19. Menu
  20. def AskSmooth {
  21.     if (MKS1>=0) {
  22.         data.selected=1;
  23.         %B = %C;
  24.         type -C "Replace the selected section of %C with %1 values?";
  25.     }
  26.     else {
  27.         data.selected=0;
  28.         %B=%C.%2;
  29.         if(%[%B]>24) {
  30.             type -B "Worksheet name too long or column name too long. Rename worksheet or column first.";
  31.             break 1;
  32.         };
  33.         copy %C %B;
  34.         type -C "%1 %C and put the result into %B?";
  35.     };
  36. }
  37.  
  38. Menu "&Smoothing.." {
  39.     if ( smdegree < 5) {smdegree=5};
  40.     if ( smdegree > 13) {smdegree=13};
  41.     
  42.     GetNumber -s
  43.         [Degree of smoothing
  44. (# of pts: 5,7,9,11,13)]
  45.         smdegree
  46.         [Smoothing %C];
  47.  
  48.     if ( smdegree < 5 || smdegree > 13 ) {
  49.         ty -b "$(smdegree) is illegal for smoothing.";
  50.         break 1;
  51.     };
  52.     
  53.     AskSmooth Smooth sm$(smdegree);
  54.     
  55.     i=int(smdegree/2);/* save for setting color */
  56.     dll orgmath smooth $(1+2*i) 0 %B;
  57.     
  58.     if (data.selected == 0) {
  59.         graph %B;
  60.         set %B -color i;/* see above */
  61.     };
  62. #Smooth %C by Savitzky-Golay method.
  63. }
  64.  
  65. Menu "&Adjacent Averaging.. " {
  66.     CheckVar AveStep 2;
  67.     GetNumber -s
  68.         [# of pts in either side 
  69. to be averaged (1,2,3..)] 
  70.         AveStep 
  71.         [Adjacent Averaging %C];
  72.         
  73.     AskSmooth Average av$(AveStep);
  74.  
  75.     if ( AveStep < 1) {
  76.         ty -b "$(smdegree) is illegal for averaging.";
  77.         break 1;
  78.     };
  79.  
  80.     Ave -n AveStep %B;
  81.     
  82.     if (data.selected == 0) {
  83.         graph %B;
  84.         set %B -c (1+AveStep);
  85.     };
  86.     /* assign different color to the result depending on AveStep */
  87. #Smooth %C by averaging adjacent points (Running Averaging).
  88. }
  89.  
  90. Menu  (FFT Filter Smoothing..) {
  91.     CheckVar ftsmsize 5;
  92.     
  93.     if (MkS1>=0) (i1=MkS1;i2=MkS2)
  94.     else (get %C -b i1;get %C -e i2);
  95.     
  96.     npts = int((i2-i1)/2);
  97.     if ( ftsmsize > npts ) {ftsmsize = npts};
  98.  
  99.     GetNumber -s
  100.     [FFT filter window
  101. (# of pts: 5)] ftsmsize;
  102.  
  103.      if ( ftsmsize > npts) {ftsmsize = npts};
  104.     AskSmooth FTSmooth ftsm$(ftsmsize);
  105.     i=int(ftsmsize/2);
  106.     dll orgmath smooft $(ftsmsize) %B;
  107.     if (data.selected == 0) {
  108.         graph %B;
  109.         set %B -color i;
  110.     };
  111. }
  112.  
  113. Menu
  114.  
  115. Menu &Differentiate {
  116.     copy %C %C';/* copy %C into a new data set %C' */
  117.     deriv %C';/* take a derivative with default settings */
  118.     %B=%C';/* save the name in %B */
  119.     GetNamedWin Deriv;/* Open the template called Deriv */
  120.     graph %B;
  121.     rescale;
  122. #Take the derivative of %C and put the result into a new window
  123. }
  124.  
  125. Menu "Diff/Smooth.." {
  126. CheckVar smdegree 5;
  127. CheckVar dorder 1;
  128. GetNumber -s
  129. [Order of Derivatives
  130. ( 1 or 2 )]
  131. dorder
  132. [Taking Derivatives on %C];
  133.         
  134.     if (dorder<1 || dorder>2) {
  135.         type -b "First or Second Order Derivatives only.";
  136.         break 1;
  137.     };
  138.     
  139. GetNumber -s
  140. [Degree of smoothing
  141. (# of pts: 5,7,9,11,13)]
  142. smdegree
  143. [Smoothing Applied];
  144.         
  145.     %B=%C$(dorder).$(smdegree);
  146.     copy %C %B;
  147.     
  148.     i=int(smdegree/2);/* save for setting color */
  149.     dll orgmath smooth $(1+2*i) $(dorder) %B;
  150.     GetNamedWin Deriv;/* Open the template called Deriv */
  151.     graph %B;
  152.     rescale;
  153. #1st or 2nd Derivatives of %C by Savitzky-Golay smoothing.
  154. }
  155.  
  156.  
  157. Menu &Integrate {
  158.     integ %C;
  159.     if (MkS1>=0) (i1=MkS1;i2=MkS2)
  160.         /* MkS1 and MkS2 are the Data Markers,
  161.          * MkS1 = -1 if no markers are selected
  162.          */
  163.     else (get %C -b i1;get %C -e i2);
  164.     
  165.     ty -a Integ of %C from zero;
  166.         /* type -a; bring up the Script window */
  167.         
  168.     ty "i = $(i1) --> $(i2)";
  169.     ty "x = $(integ.x1) --> $(integ.x2)";
  170.     ty "Area    Peak at    Width    Height";
  171.     ty "$(integ.area)    $(integ.x0)    $(integ.dx)    $(integ.y0)";
  172. #Integrate %C (from zero)
  173. }
  174.  
  175.  
  176. Menu /* No argument, appears as a separator in the menu */
  177.  
  178.  
  179.  
  180. Menu "Subtract &Ref Data.." {
  181.     math -o -;
  182.         /* Start the math 
  183.          * dialog and set the operator to minus
  184.      */
  185.     rescale;/* reset both axes to show the data */
  186. #Subtract one data set from another
  187. }
  188.  
  189.  
  190.  
  191. Menu "Subtract Straight &Line" {
  192.     create _line -M 3;set _line -l 1;
  193.     def EndToolbox (;%C --O _Line;del _line;rescale);
  194.     
  195.     GetPts -n _line 2 /* to be continue..  */
  196.     [Double-click to set straight line begin..]
  197.     [Double-click to set straight line end..];/* end of GetPts */
  198.     
  199. #Pick two screen pts and subtract %C from the line formed
  200. }
  201.  
  202. Menu
  203.  
  204. Menu "&Y Translate" {
  205.     def EndToolbox
  206.     {        /* after a double-click, cursor location 
  207.              * is in variables x and y
  208.              */
  209.         y_last=y;;
  210.             /* double ';' to make scripts follow to be executed
  211.              * after all Windows messages are processed.
  212.              */
  213.         def EndToolbox [y-y_last;%C + y;];
  214.         
  215.         GetPts -Y 1 
  216.         (Move cursor to new location, hit ENTER)
  217.     };
  218.     Pick1pt;
  219. #Pick one pt as ref and move curve to a new pt vertically.
  220. }
  221.  
  222.  
  223.  
  224. Menu "&X Translate" {
  225.     def EndToolbox
  226.     {
  227.         x_last = x;;
  228.         def EndToolbox {
  229.             x - x_last;
  230.             if (hasx(%C)) [xof(%C)=xof(%C)+x;x=0];
  231.             /* the following is not necessary if %C has X
  232.              * but we do it for both case so as to
  233.              * update generate the update message.
  234.              */
  235.             get %C -f v1;v1+x;set %C -f v1;
  236.         };
  237.         GetPts -X 1
  238.         (Move cursor to a new location, hit Enter)
  239.     };
  240.     Pick1pt;
  241. #Pick one pt as ref and move curve to a new pt horizontally.
  242. }
  243.  
  244. Menu
  245.  
  246. Menu (Averaging &Multiple Curves..) {
  247.     layer -c;
  248.     if(count < 2) {
  249.         type -b You need to have at least two curves.
  250.         return;
  251.     };
  252.     %B = Ave.$(count);
  253.     copy -x %(1,@D) %B_mean;
  254.     for(i = 2;i <= count; i+=1) {
  255.         %B_mean+%(i,@D);
  256.     };
  257.     %B_mean/=count;
  258.     layer -i %B_mean;
  259.     set %B_mean -c count;
  260.  
  261. #Creates averaged data by summing up all of \
  262. the data in the current layer.
  263. }
  264.  
  265. Menu (Inter/extrapolate..) {
  266.     limit %C;fitx1=limit.xmin;fitx2=limit.xmax;
  267.     layer -c %C;/* Position of %C in the layer, result in count */
  268.     GetCuvName cuv;/* result in %B */
  269.  
  270.     GetNumber
  271.     [Make Curve Xmin] fitx1
  272.     [Make Curve Xmax] fitx2
  273.     [Make Curve # pts] fitnpts
  274.     [Make Curve Name] %%B
  275.     [Make Interpolated Curve from %C];
  276.     /* user can cancel, otherwise we will continue */
  277.  
  278.     del %B;/* incase it already exists, remove it first */
  279.     (%B)=data(0,0,fitnpts);
  280.     /* (%B) instead of %B, otherwise just the content of %B
  281.      * will be set instead of the name in %B be assigned 
  282.      */
  283.     SetDataRange %B;/* use fitx1, fitx2 and fitnpts */
  284.     %B +-O %C;/* %B is all zeros, add %C and extrapolate if outside */
  285.     graph %B;/* show it in the current layer */
  286.     set %B -c 2;/* color red */
  287. #Interpolate or extrapolate %C into a new curve,\
  288.  depending on %C's line connection type.
  289. }
  290.  
  291. /* end of Math menu */
  292.  
  293.  
  294.