home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e002 / 1.ddi / WKSHEET.CN_ / WKSHEET.CN
Encoding:
Text File  |  1993-11-15  |  11.3 KB  |  436 lines

  1. /* We also want to add commands to the worksheet menu */
  2.  
  3. menu -Worksheet
  4.     /* switch to the worksheet menu */
  5.  
  6. menu 1.12 /* move to the file:Import menu */
  7.  
  8.  
  9. def FilterImport {
  10.     GetFileName *.%1;
  11.     open -WF %A
  12. }
  13.  
  14. def FormatFilterImport {
  15.     GetFileName *.%2;
  16.     open -WE %1 %A
  17. }
  18. menu /* separator */
  19. menu "&Lotus(WKS).." (FilterImport WKS)
  20. menu "Lotus(WK1).." (FilterImport WK1)
  21. menu "Lotus(WK3).." (FilterImport WK3)
  22. menu "&Quattro(WKQ).." (FilterImport WKQ)
  23. menu "&Excel (XLS).." (FormatFilterImport ?XLS XLS)
  24. menu
  25. menu "&Dbase (DBF).." (FormatFilterImport ?DBF DBF)
  26. menu "&Symphony (WR1).." (FormatFilterImport ?WR WR1)
  27. menu "&Paradox (PXT).."    (FilterImport PXT)
  28. menu "D&IF.."        (FilterImport DIF)
  29.  
  30.  
  31. menu 5 /* move to the data menu on the worksheet, no new menu is added */
  32.  
  33. menu -i 6 (&Worksheet Script..) {
  34.     worksheet -Edit Script;/* i will contain button hit, 0 = Update, 1 = Doit */
  35.     if(i==0) (type -b Script updated for %H. To run the script, you need to click the Do It button.);
  36.  
  37.     if(i==1) (worksheet -Rpun);
  38.     /* run the script, the p switch postpond the execution
  39.      * until all windows messages are processed 
  40.      */
  41. }
  42.     
  43. /* The macro below test whether the user
  44.  * had selected a worksheet column
  45.  */
  46. def TestColSel {
  47.     if (exist(%C)!=1 || SelC2 > SelC1)
  48.     {    /* exist return 1 if %C is a data set name */
  49. type -b "This command requires a single column selection.\
  50.  Please select a column by clicking on its heading first.";break 1;
  51.      }
  52. }
  53.  
  54. menu
  55. /* this is changed in v3.0 */
  56. menu "Statistics on &Columns" {
  57.     if (selc1==selc2 && selc1==0) {
  58.         type -b "This command requires a selection range.";
  59.         break 1;
  60.     };
  61.     %W = %H; /* save worksheet name */
  62.     win -T Wks ColStat;
  63.     statcbut.run();
  64. #Descriptive statistics on the selected columns. Results in new worksheet.
  65. }
  66.  
  67.  
  68. menu "Statistics on &Rows" {
  69.     if(SelC2-SelC1 < 1) {
  70.         type -b "You must select at least two columns for this operation";
  71.         break 1;
  72.     };
  73.     bModifiedRange=0;
  74.     if(selr1>0) {/* a range is selected */
  75.         bModifiedRange=1;
  76.         set wcol(selc1) -bs Mks1;
  77.         set wcol(selc1) -es Mks2;
  78.     };
  79.     sum(%H,selc1,selc2);
  80.     /* stat results in 
  81.      * _MEAN, _SD, _MAX, _MIN, _RANGE, _NPTS
  82.      */
  83.     if(bModifiedRange) {
  84.         set wcol(selc1) -e;/* reset to wks range */
  85.     };
  86.     del -v bModifiedRange;
  87.  
  88.     worksheet -i selc2 mean;
  89.     wcol(selc2+1) = _Mean;
  90.     
  91.     /* next add standard err */
  92.     worksheet -i (selc2+1) se;
  93.     wcol(selc2+2) = _SD;
  94.     wcol(selc2+2) /= sqrt(_NPTS);
  95.     work -t $(selc2+2) 3;/* set as error bar */
  96.     
  97.     /* next add sd */
  98.     worksheet -i (selc2+1) sd;
  99.     wcol(selc2+2) = _SD;
  100.     work -t $(selc2+2) 3;/* set as error bar */
  101.     
  102.     queue (x1=x1);/* force worksheet redraw */
  103. #Descriptive statistics across rows of the selected columns. Results in new columns.
  104. }
  105.  
  106. menu
  107.  
  108. menu     "&Sort..." {
  109.     if (exist(%C)!=1) {
  110.         type -b "This command requires a selection.";
  111.         break 1;
  112.     };
  113.     %A="Ascending Decending";
  114.     checkVar Sort.Order 1;
  115.     if(Sort.Order < 1 || Sort.Order>2) (Sort.Order=1);
  116.  
  117.     if(SelC1 == SelC2) /* single column */ {
  118.         Getn Sort Sort.Order:A "Sort all columns in the worksheet using values in column col(%(%H,@C,selc1))";
  119.         if(Sort.Order==1) {
  120.             sort -w %H %C;
  121.         } else {
  122.             sort -wd %H %C;
  123.         }
  124.     }
  125.     else {
  126.         Getn Sort Sort.Order:A "Sort selected region in the worksheet using values in column col(%(%H,@C,selc1))";
  127.         if(Sort.Order==1) {
  128.             sort -c SelC1 SelC2 %C;
  129.         } else {
  130.             sort -cd SelC1 SelC2 %C;
  131.         }
  132.     }
  133. }
  134.  
  135. menu "&Frequency Count.." {
  136.     TestColSel;/* see above */
  137.     /* we will contiune if %C is OK. Remember %C is the data set name
  138.      * of the selected column
  139.      */
  140.     sum(%C);/* We need to find the maximum and minimum */
  141.  
  142.     /* we may also print the statistics on the script window */
  143.     type -a "mean\tsd\tsize";/* -a opens the script window if needed */
  144.     type "$(sum.mean)\t$(sum.sd)\t$(sum.n)";
  145.     
  146.     if (sum.n < 200) {/* don't do this if too many points */
  147.     /* To find the median, we sort the data and find the mid point */
  148.     w1=sort(%C);
  149.     get w1 -b i1;get w1 -e i2;/* i1 and i2 now contains begin and end index */
  150.     i=int((i2-i1+1)/2);
  151.     type "median= $(mod(i2-i1,2)==0?w1[i+1]:0.5*(w1[i+1]+w1[i]))";
  152.                 /* notice the C notation? */
  153.     del w1;/* we are done with w1 for the time being */
  154.     };
  155.  
  156.     i = nint(sqrt(sum.N));
  157.     if(i < 2) {
  158.         type -b Not enough points for histogram;
  159.         break 1;
  160.     };
  161.  
  162.     limit -r sum.min sum.max i inc;/* round these numbers */
  163.     
  164.     GetNumber (From Minimum) sum.min (To Maximum) sum.max (Step Size) inc (Count %C);
  165.         /* the three variables inc, sum.min, sum.max will contain user choices. */
  166.     w1=histogram(%C,inc,sum.min, sum.max);
  167.         /* put temperary result in a scratch data set w1 */
  168.     window -T Data Count;
  169.         /* open a worksheet template called Count */
  170.     col(2)=w1;del w1;
  171.         /* put the contents of the scratch data into column 2 
  172.          * then delete the scratch data.
  173.          */
  174.     col(1)=data(sum.min+0.5*inc,sum.max+0.5*inc,inc);
  175.         /*  X column for the new worksheet. Note that this must
  176.          *  be done before the sum function is called again.
  177.          *  Also, this actually may create one more point than
  178.          * is needed.
  179.          */
  180.  
  181.     col(3)=col(1);col(3)+=0.5*inc;
  182.         /* this is the X column for the cumulative sum, it needs to be
  183.          * offseted for inbetween bins
  184.          */
  185.     col(4)=sum(col(2));
  186.         /* col 4 contains cumulative counts. sum.max, min etc are modified. */
  187.     
  188.     set %H -e sum.n;
  189.         /* to make sure all columns have the same size */
  190. #Count frequency for histogram
  191. }
  192.  
  193. menu "&Normalize.." {
  194.     TestColSel;/* see above */
  195.     /* we will contiune if %C is OK. Remember %C is the data set name
  196.      * of the selected column
  197.      */
  198.     sum(%C);/* We need to find the maximum and minimum */
  199.     divider=1;
  200.     
  201.     GetNumber -s "Current limits:
  202. Max = $(sum.max)
  203. Min = $(sum.min)
  204. Divide data by:" divider
  205. "Normalizing %C";
  206.  
  207.     /* divide %C by divider
  208.      * may need to check for zero here
  209.      */
  210.     
  211.     %C/divider;
  212.     
  213. #Enter a factor to normalize %C
  214. }
  215.  
  216. menu
  217.     /* the following macro
  218.      * assum real and imaginary data
  219.      * in tmpreal and tmpimag.
  220.      * Result of FFT in a new worksheet
  221.      * and plotted in new window
  222.      * doFFT RFFT
  223.      * doFFT CFFT
  224.      */
  225. def doFFT {
  226.     get tmpreal -i FFT.dT;
  227.     /* copy into tmp buffers and check for
  228.      * 2^n relation
  229.      * -i get data increment
  230.      */
  231.     copy -z tmpreal tmpimag tmpfft;
  232.         /* Zip the real and imaginary data into
  233.          * a single array
  234.          */
  235.     FFT.npts = copy.n/2;/* save the num of points info */
  236.     dll orgmath fft -C tmpfft;
  237.     
  238.     /* normalize the amplitude */
  239.     tmpfft /= 0.5 * FFT.npts;
  240.     /* the DC term is shared, so we need to divide that
  241.      * one more time, see Numerical Recipes, page 411
  242.      */
  243.     tmpfft[1]/=2;
  244.     tmpfft[2]/=2;
  245.     
  246.     if("%1" == "CFFT") {
  247.         copy -mvunzip tmpfft tmpreal tmpimag;
  248.     }
  249.     else {
  250.         copy -uhalf tmpfft tmpreal tmpimag;
  251.     };
  252.     
  253.     /* result now in tmpreal and tmpimag
  254.      * so we can remove tmpfft 
  255.      */
  256.     del tmpfft;
  257.     
  258.     GetEnumWKS FFT;set %H -e copy.n;
  259.     /* copy.n: number of points during the copy
  260.      * FFT is a worksheet template,
  261.      * assumned to contain four columns
  262.      * Real Imag r phi
  263.      */
  264.     col(Real)=tmpreal;col(Imag)=tmpimag;
  265.  
  266.     /* convert real and imaginary part into
  267.      * r and phi, and put into worksheet columns
  268.      * assume angular unit is radiant.
  269.      */
  270.     col(phi) = angle(tmpreal,tmpimag);
  271.     col(phi) *= (180/pi);/* convert into degrees */
  272.     
  273.     /* the code below does
  274.      *
  275.     col(r)= sqrt(tmpreal*tmpreal + tmpimag*tmpimag);
  276.      * but much faster
  277.      */
  278.     tmpreal^=2;tmpimag^=2;tmpreal+=tmpimag;
  279.     col(r)= sqrt(tmpreal);
  280.     del tmpreal;del tmpimag;
  281.     /* they are modified and no longer needed */
  282.     
  283.     set %H -i 1/(FFT.npts * FFT.dT);/* X increment */
  284.     if("%1" == "CFFT") {
  285.         set %H -f (-1/(2*FFT.dT));/* first X value */
  286.     }
  287.     else {
  288.         set %H -f 0;
  289.     };
  290.     
  291.     %A=%H;/* save woksheet winodw name */
  292.     win -T Plot %1 %H.Plot;
  293.     layer -S 2;layer -i %A_phi;rescale;
  294.     layer -S 1;layer -i %A_r;rescale;
  295. }
  296.  
  297. menu "Complex FFT" {
  298.     if(selc2-selc1 != 1 || %(%H,@T,selc1) != 1 || %(%H,@T,selc2) != 1) {
  299.         ty -b "Please select two Y columns first.
  300. 1st column = Real
  301. 2nd column = Imaginary.";
  302.         break 1
  303.     }
  304.     ty -C "Complex FFT on
  305.       Real: col(%(%H,@C,selc1))
  306. Imaginary : col(%(%H,@C,selc2))";
  307.     copy -s (-2) %(%H,@Data,selc1) tmpreal;
  308.     copy -s (-2) %(%H,@Data,selc2) tmpimag;
  309.     
  310.     doFFT CFFT;/* see definition above */
  311.     
  312. #FFT. Highlight a Y (imaginary) column 1st. X column is assumed real.
  313. }
  314.  
  315. Menu (Real FFT..) {
  316.     if(selc2-selc1 != 0 || %(%H,@T,selc1) != 1) {
  317.         ty -b "Please select one Y columns first.";
  318.         break 1
  319.     }
  320.     ty -C "FFT on col(%(%H,@C,selc1))
  321. Imaginary part assumed zero.";
  322.     copy -s (-2) %(%H,@Data,selc1) tmpreal;
  323.     copy tmpReal tmpImag;/* create a comparable data set */
  324.     tmpImag*0;/* put zero into the imaginary part */
  325.     
  326.     doFFT RFFT;/* see definition above */
  327. #FFT on %C, assume zero for imaginary part
  328. }
  329.  
  330.  
  331. menu 3 /* the plot menu */
  332.  
  333. menu /* a separator */
  334.  
  335. DLL -Draw OrgPie 225;
  336. /* initialize the Pie DLL
  337.  * the name of the DLL is OrgPie
  338.  * the ID for the DLL is 225
  339.  * nothing is done if already init
  340.  */
  341. Menu -L (Pie Chart) /* start drop down */
  342.  
  343. menu (Pie Chart) {
  344.     worksheet -Plot 225 Pie;
  345. /* plot with ID 225 and load the Pie template
  346.  */
  347. #Create a pie chart for the selected column
  348. }
  349.  
  350. menu (Piece % Pie Chart) {
  351.     if ( %(%H,@Y#,2) < 2 ) {
  352.         ty -b You must select at least two Y columns for a Piece Percent Pie Chart;
  353.         break 1;
  354.     }
  355.     worksheet -Plot 225 Pie;
  356.     set %C -g 1;/* set group as one plot */
  357. #1st Y column as Pie % and the 2nd Y column as Piece %
  358. }
  359. menu -L /* end Pie Chart drop down */
  360.  
  361. menu (&Polar Plot) {
  362.     worksheet -P ? Polar;Legend;
  363. #Plot selected region as polar graph
  364. }
  365.  
  366. menu
  367.  
  368. Menu "Double Y (Line/Symbol)" {
  369.     if( %(%H,@Y#,2) < 2 ) {
  370.         ty -b You must select at least two Y columns for a double Y chart;
  371.         break 1;
  372.     }
  373.     i = %(%H,@Y-,selc2);/* the last Y column before,include end of sel */
  374.  
  375.     v1=wks.c1;v2=wks.r1;v3=wks.c2;v4=wks.r2;
  376.  
  377.     %W = %H;/* save the worksheet name */
  378.     win -t plot doubleY;/* load template */
  379.  
  380.     /* layer 2 is the active layer when the template is loaded */
  381.  
  382.     layer -w %W i v2 v3 v4 ?;legend;
  383.         /* ? to use template graph type */
  384.     layer -S 1;/* select the first layer */
  385.  
  386.     layer -w %W v1 v2 (i-1) v4 ?;legend;
  387.  
  388.     X1=X1;/* to force link axes update */
  389. #Create a double Y line chart by putting the last selected Y column into the 2nd layer
  390. }
  391.  
  392. menu (&Water Fall (X Y offset)) {
  393.     worksheet -P ? Waterfal;
  394. #Plot the selected columns as a water fall line graph
  395. }
  396.  
  397. menu (&Line Series Chart) {
  398.     NumYs =  %(%H,@Y#,2);/* num of Y columns */
  399.     if ( NumYs< 2 || NumYs > 3 ) {
  400.         ty -b You must selectt two or three Y columns for this chart;
  401.         break 1;
  402.     };
  403.     worksheet -i selc2 Values;
  404.     worksheet -i selc2 Series;/* contains 1,2,1,2 etc. */
  405.     worksheet -t $(selc2+1) 4;/* set the series column as X */
  406.     get wcol(selc2) -b i1;
  407.     get wcol(selc2) -e i2;
  408.     break -b Constructing new columns;
  409.     break -r i1 i2;/* set progress range */
  410.     for(j=i1,i=i1;i<=i2;i+=1) {
  411.         break -p i;
  412.         for(x=1,k=selc1;k<=selc2;x+=1,k+=1,j+=1) {
  413.             wcol(selc2+1)[j]=x;
  414.             wcol(selc2+2)[j]=wcol(k)[i];
  415.         };
  416.     };
  417.     break -end;/* close progress dialog */
  418.     worksheet -s (selc2+1) 0 (selc2+2) 0;
  419.     worksheet -P ? LSer$(NumYs);/* we have LSer2 and Lser3 */
  420. #Plot the selected columns as dots and lines connecting them
  421. }
  422.  
  423. menu 1 /* return to the File menu */
  424.  
  425. menu -i 15 "&Print.." {
  426.     print -a;/* ask */
  427. #Print the worksheet %H
  428. }
  429.  
  430. menu -i 16 "Print &Setup.." {
  431.     print -setup;
  432. #Opens the Print Setup dialog box
  433. }
  434.  
  435. menu -i 17 /* add a separator */
  436.