home *** CD-ROM | disk | FTP | other *** search
- /* We also want to add commands to the worksheet menu */
-
- menu -Worksheet
- /* switch to the worksheet menu */
-
- menu 1.12 /* move to the file:Import menu */
-
-
- def FilterImport {
- GetFileName *.%1;
- open -WF %A
- }
-
- def FormatFilterImport {
- GetFileName *.%2;
- open -WE %1 %A
- }
- menu /* separator */
- menu "&Lotus(WKS).." (FilterImport WKS)
- menu "Lotus(WK1).." (FilterImport WK1)
- menu "Lotus(WK3).." (FilterImport WK3)
- menu "&Quattro(WKQ).." (FilterImport WKQ)
- menu "&Excel (XLS).." (FormatFilterImport ?XLS XLS)
- menu
- menu "&Dbase (DBF).." (FormatFilterImport ?DBF DBF)
- menu "&Symphony (WR1).." (FormatFilterImport ?WR WR1)
- menu "&Paradox (PXT).." (FilterImport PXT)
- menu "D&IF.." (FilterImport DIF)
-
-
- menu 5 /* move to the data menu on the worksheet, no new menu is added */
-
- menu -i 6 (&Worksheet Script..) {
- worksheet -Edit Script;/* i will contain button hit, 0 = Update, 1 = Doit */
- if(i==0) (type -b Script updated for %H. To run the script, you need to click the Do It button.);
-
- if(i==1) (worksheet -Rpun);
- /* run the script, the p switch postpond the execution
- * until all windows messages are processed
- */
- }
-
- /* The macro below test whether the user
- * had selected a worksheet column
- */
- def TestColSel {
- if (exist(%C)!=1 || SelC2 > SelC1)
- { /* exist return 1 if %C is a data set name */
- type -b "This command requires a single column selection.\
- Please select a column by clicking on its heading first.";break 1;
- }
- }
-
- menu
- /* this is changed in v3.0 */
- menu "Statistics on &Columns" {
- if (selc1==selc2 && selc1==0) {
- type -b "This command requires a selection range.";
- break 1;
- };
- %W = %H; /* save worksheet name */
- win -T Wks ColStat;
- statcbut.run();
- #Descriptive statistics on the selected columns. Results in new worksheet.
- }
-
-
- menu "Statistics on &Rows" {
- if(SelC2-SelC1 < 1) {
- type -b "You must select at least two columns for this operation";
- break 1;
- };
- bModifiedRange=0;
- if(selr1>0) {/* a range is selected */
- bModifiedRange=1;
- set wcol(selc1) -bs Mks1;
- set wcol(selc1) -es Mks2;
- };
- sum(%H,selc1,selc2);
- /* stat results in
- * _MEAN, _SD, _MAX, _MIN, _RANGE, _NPTS
- */
- if(bModifiedRange) {
- set wcol(selc1) -e;/* reset to wks range */
- };
- del -v bModifiedRange;
-
- worksheet -i selc2 mean;
- wcol(selc2+1) = _Mean;
-
- /* next add standard err */
- worksheet -i (selc2+1) se;
- wcol(selc2+2) = _SD;
- wcol(selc2+2) /= sqrt(_NPTS);
- work -t $(selc2+2) 3;/* set as error bar */
-
- /* next add sd */
- worksheet -i (selc2+1) sd;
- wcol(selc2+2) = _SD;
- work -t $(selc2+2) 3;/* set as error bar */
-
- queue (x1=x1);/* force worksheet redraw */
- #Descriptive statistics across rows of the selected columns. Results in new columns.
- }
-
- menu
-
- menu "&Sort..." {
- if (exist(%C)!=1) {
- type -b "This command requires a selection.";
- break 1;
- };
- %A="Ascending Decending";
- checkVar Sort.Order 1;
- if(Sort.Order < 1 || Sort.Order>2) (Sort.Order=1);
-
- if(SelC1 == SelC2) /* single column */ {
- Getn Sort Sort.Order:A "Sort all columns in the worksheet using values in column col(%(%H,@C,selc1))";
- if(Sort.Order==1) {
- sort -w %H %C;
- } else {
- sort -wd %H %C;
- }
- }
- else {
- Getn Sort Sort.Order:A "Sort selected region in the worksheet using values in column col(%(%H,@C,selc1))";
- if(Sort.Order==1) {
- sort -c SelC1 SelC2 %C;
- } else {
- sort -cd SelC1 SelC2 %C;
- }
- }
- }
-
- menu "&Frequency Count.." {
- TestColSel;/* see above */
- /* we will contiune if %C is OK. Remember %C is the data set name
- * of the selected column
- */
- sum(%C);/* We need to find the maximum and minimum */
-
- /* we may also print the statistics on the script window */
- type -a "mean\tsd\tsize";/* -a opens the script window if needed */
- type "$(sum.mean)\t$(sum.sd)\t$(sum.n)";
-
- if (sum.n < 200) {/* don't do this if too many points */
- /* To find the median, we sort the data and find the mid point */
- w1=sort(%C);
- get w1 -b i1;get w1 -e i2;/* i1 and i2 now contains begin and end index */
- i=int((i2-i1+1)/2);
- type "median= $(mod(i2-i1,2)==0?w1[i+1]:0.5*(w1[i+1]+w1[i]))";
- /* notice the C notation? */
- del w1;/* we are done with w1 for the time being */
- };
-
- i = nint(sqrt(sum.N));
- if(i < 2) {
- type -b Not enough points for histogram;
- break 1;
- };
-
- limit -r sum.min sum.max i inc;/* round these numbers */
-
- GetNumber (From Minimum) sum.min (To Maximum) sum.max (Step Size) inc (Count %C);
- /* the three variables inc, sum.min, sum.max will contain user choices. */
- w1=histogram(%C,inc,sum.min, sum.max);
- /* put temperary result in a scratch data set w1 */
- window -T Data Count;
- /* open a worksheet template called Count */
- col(2)=w1;del w1;
- /* put the contents of the scratch data into column 2
- * then delete the scratch data.
- */
- col(1)=data(sum.min+0.5*inc,sum.max+0.5*inc,inc);
- /* X column for the new worksheet. Note that this must
- * be done before the sum function is called again.
- * Also, this actually may create one more point than
- * is needed.
- */
-
- col(3)=col(1);col(3)+=0.5*inc;
- /* this is the X column for the cumulative sum, it needs to be
- * offseted for inbetween bins
- */
- col(4)=sum(col(2));
- /* col 4 contains cumulative counts. sum.max, min etc are modified. */
-
- set %H -e sum.n;
- /* to make sure all columns have the same size */
- #Count frequency for histogram
- }
-
- menu "&Normalize.." {
- TestColSel;/* see above */
- /* we will contiune if %C is OK. Remember %C is the data set name
- * of the selected column
- */
- sum(%C);/* We need to find the maximum and minimum */
- divider=1;
-
- GetNumber -s "Current limits:
- Max = $(sum.max)
- Min = $(sum.min)
- Divide data by:" divider
- "Normalizing %C";
-
- /* divide %C by divider
- * may need to check for zero here
- */
-
- %C/divider;
-
- #Enter a factor to normalize %C
- }
-
- menu
- /* the following macro
- * assum real and imaginary data
- * in tmpreal and tmpimag.
- * Result of FFT in a new worksheet
- * and plotted in new window
- * doFFT RFFT
- * doFFT CFFT
- */
- def doFFT {
- get tmpreal -i FFT.dT;
- /* copy into tmp buffers and check for
- * 2^n relation
- * -i get data increment
- */
- copy -z tmpreal tmpimag tmpfft;
- /* Zip the real and imaginary data into
- * a single array
- */
- FFT.npts = copy.n/2;/* save the num of points info */
- dll orgmath fft -C tmpfft;
-
- /* normalize the amplitude */
- tmpfft /= 0.5 * FFT.npts;
- /* the DC term is shared, so we need to divide that
- * one more time, see Numerical Recipes, page 411
- */
- tmpfft[1]/=2;
- tmpfft[2]/=2;
-
- if("%1" == "CFFT") {
- copy -mvunzip tmpfft tmpreal tmpimag;
- }
- else {
- copy -uhalf tmpfft tmpreal tmpimag;
- };
-
- /* result now in tmpreal and tmpimag
- * so we can remove tmpfft
- */
- del tmpfft;
-
- GetEnumWKS FFT;set %H -e copy.n;
- /* copy.n: number of points during the copy
- * FFT is a worksheet template,
- * assumned to contain four columns
- * Real Imag r phi
- */
- col(Real)=tmpreal;col(Imag)=tmpimag;
-
- /* convert real and imaginary part into
- * r and phi, and put into worksheet columns
- * assume angular unit is radiant.
- */
- col(phi) = angle(tmpreal,tmpimag);
- col(phi) *= (180/pi);/* convert into degrees */
-
- /* the code below does
- *
- col(r)= sqrt(tmpreal*tmpreal + tmpimag*tmpimag);
- * but much faster
- */
- tmpreal^=2;tmpimag^=2;tmpreal+=tmpimag;
- col(r)= sqrt(tmpreal);
- del tmpreal;del tmpimag;
- /* they are modified and no longer needed */
-
- set %H -i 1/(FFT.npts * FFT.dT);/* X increment */
- if("%1" == "CFFT") {
- set %H -f (-1/(2*FFT.dT));/* first X value */
- }
- else {
- set %H -f 0;
- };
-
- %A=%H;/* save woksheet winodw name */
- win -T Plot %1 %H.Plot;
- layer -S 2;layer -i %A_phi;rescale;
- layer -S 1;layer -i %A_r;rescale;
- }
-
- menu "Complex FFT" {
- if(selc2-selc1 != 1 || %(%H,@T,selc1) != 1 || %(%H,@T,selc2) != 1) {
- ty -b "Please select two Y columns first.
- 1st column = Real
- 2nd column = Imaginary.";
- break 1
- }
- ty -C "Complex FFT on
- Real: col(%(%H,@C,selc1))
- Imaginary : col(%(%H,@C,selc2))";
- copy -s (-2) %(%H,@Data,selc1) tmpreal;
- copy -s (-2) %(%H,@Data,selc2) tmpimag;
-
- doFFT CFFT;/* see definition above */
-
- #FFT. Highlight a Y (imaginary) column 1st. X column is assumed real.
- }
-
- Menu (Real FFT..) {
- if(selc2-selc1 != 0 || %(%H,@T,selc1) != 1) {
- ty -b "Please select one Y columns first.";
- break 1
- }
- ty -C "FFT on col(%(%H,@C,selc1))
- Imaginary part assumed zero.";
- copy -s (-2) %(%H,@Data,selc1) tmpreal;
- copy tmpReal tmpImag;/* create a comparable data set */
- tmpImag*0;/* put zero into the imaginary part */
-
- doFFT RFFT;/* see definition above */
- #FFT on %C, assume zero for imaginary part
- }
-
-
- menu 3 /* the plot menu */
-
- menu /* a separator */
-
- DLL -Draw OrgPie 225;
- /* initialize the Pie DLL
- * the name of the DLL is OrgPie
- * the ID for the DLL is 225
- * nothing is done if already init
- */
- Menu -L (Pie Chart) /* start drop down */
-
- menu (Pie Chart) {
- worksheet -Plot 225 Pie;
- /* plot with ID 225 and load the Pie template
- */
- #Create a pie chart for the selected column
- }
-
- menu (Piece % Pie Chart) {
- if ( %(%H,@Y#,2) < 2 ) {
- ty -b You must select at least two Y columns for a Piece Percent Pie Chart;
- break 1;
- }
- worksheet -Plot 225 Pie;
- set %C -g 1;/* set group as one plot */
- #1st Y column as Pie % and the 2nd Y column as Piece %
- }
- menu -L /* end Pie Chart drop down */
-
- menu (&Polar Plot) {
- worksheet -P ? Polar;Legend;
- #Plot selected region as polar graph
- }
-
- menu
-
- Menu "Double Y (Line/Symbol)" {
- if( %(%H,@Y#,2) < 2 ) {
- ty -b You must select at least two Y columns for a double Y chart;
- break 1;
- }
- i = %(%H,@Y-,selc2);/* the last Y column before,include end of sel */
-
- v1=wks.c1;v2=wks.r1;v3=wks.c2;v4=wks.r2;
-
- %W = %H;/* save the worksheet name */
- win -t plot doubleY;/* load template */
-
- /* layer 2 is the active layer when the template is loaded */
-
- layer -w %W i v2 v3 v4 ?;legend;
- /* ? to use template graph type */
- layer -S 1;/* select the first layer */
-
- layer -w %W v1 v2 (i-1) v4 ?;legend;
-
- X1=X1;/* to force link axes update */
- #Create a double Y line chart by putting the last selected Y column into the 2nd layer
- }
-
- menu (&Water Fall (X Y offset)) {
- worksheet -P ? Waterfal;
- #Plot the selected columns as a water fall line graph
- }
-
- menu (&Line Series Chart) {
- NumYs = %(%H,@Y#,2);/* num of Y columns */
- if ( NumYs< 2 || NumYs > 3 ) {
- ty -b You must selectt two or three Y columns for this chart;
- break 1;
- };
- worksheet -i selc2 Values;
- worksheet -i selc2 Series;/* contains 1,2,1,2 etc. */
- worksheet -t $(selc2+1) 4;/* set the series column as X */
- get wcol(selc2) -b i1;
- get wcol(selc2) -e i2;
- break -b Constructing new columns;
- break -r i1 i2;/* set progress range */
- for(j=i1,i=i1;i<=i2;i+=1) {
- break -p i;
- for(x=1,k=selc1;k<=selc2;x+=1,k+=1,j+=1) {
- wcol(selc2+1)[j]=x;
- wcol(selc2+2)[j]=wcol(k)[i];
- };
- };
- break -end;/* close progress dialog */
- worksheet -s (selc2+1) 0 (selc2+2) 0;
- worksheet -P ? LSer$(NumYs);/* we have LSer2 and Lser3 */
- #Plot the selected columns as dots and lines connecting them
- }
-
- menu 1 /* return to the File menu */
-
- menu -i 15 "&Print.." {
- print -a;/* ask */
- #Print the worksheet %H
- }
-
- menu -i 16 "Print &Setup.." {
- print -setup;
- #Opens the Print Setup dialog box
- }
-
- menu -i 17 /* add a separator */
-