source: sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/WorkFileUtils.ipf @ 206

Last change on this file since 206 was 206, checked in by srkline, 15 years ago

Three changes:

(1) in WorkfileUtils? - DetCorr?() now includes the correction to the detector efficiency at large angles as was described in John's memo of 3/20/2007. A small correction, increasing the measured intensity by at most a few percent at the largest scattering angles.

(2) Tweaks to the ascii output for Grasp, still untested.

(3) Changed beamstop x-tolerance to -8 cm to account for the 3" BS malfunction on NG3. Only affected recognition of transmission files, and easily worked around by resetting the BS position (NG1 Files to Trans function)

File size: 39.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//*******************
6// Vers 1.2 100901
7//
8//*******************
9// Utility procedures for handling of workfiles (each is housed in a separate datafolder)
10//
11// - adding data to a workfile
12// - copying workfiles to another folder
13//
14// - absolute scaling
15// - DIV detector sensitivity corrections
16//
17// - the WorkFile Math panel for simple image math
18// -
19// - adding work.drk data without normalizing to monitor counts
20//***************************
21
22
23//testing procedure, not called anymore
24Proc Add_to_Workfile(type, add)
25        String type,add
26        Prompt type,"WORK data type",popup,"SAM;EMP;BGD"
27        Prompt add,"Add to current WORK contents?",popup,"No;Yes"
28       
29        //macro will take whatever is in RAW folder and "ADD" it to the folder specified
30        //in the popup menu
31       
32        //"add" = yes/no, don't add to previous runs
33        //switch here - two separate functions to avoid (my) confusion
34        Variable err
35        if(cmpstr(add,"No")==0)
36                //don't add to prev work contents, copy RAW contents to work and convert
37                err = Raw_to_work(type)
38        else
39                //yes, add RAW to the current work folder contents
40                err = Add_raw_to_work(type)
41        endif
42       
43        String newTitle = "WORK_"+type
44        DoWindow/F SANS_Data
45        DoWindow/T SANS_Data, newTitle
46        KillStrings/Z newTitle
47       
48        //need to update the display with "data" from the correct dataFolder
49        fRawWindowHook()
50       
51End
52
53//will "ADD" the current contents of the RAW folder to the newType work folder
54//and will ADD the RAW contents to the existing content of the newType folder
55// - used when adding multiple runs together
56//(the function Raw_to_work(type) makes a fresh workfile)
57//
58//the current display type is updated to newType (global)
59Function Add_raw_to_work(newType)
60        String newType
61               
62        String destPath=""
63       
64        // if the desired workfile doesn't exist, let the user know, and just make a new one
65        destPath = "root:"+newType + ":data"
66        if(WaveExists($destpath) == 0)
67                Print "There is no old work file to add to - a new one will be created"
68                //call Raw_to_work(), then return from this function
69                Raw_to_Work(newType)
70                Return(0)               //does not generate an error - a single file was converted to work.newtype
71        Endif
72       
73        //now make references to data in newType folder
74        DestPath="root:"+newType       
75        WAVE data=$(destPath +":data")                  // these wave references point to the EXISTING work data
76        WAVE/T textread=$(destPath + ":textread")
77        WAVE integersread=$(destPath + ":integersread")
78        WAVE realsread=$(destPath + ":realsread")
79       
80        Variable deadTime,defmon,total_mon,total_det,total_trn,total_numruns,total_rtime
81        Variable ii,jj,itim,cntrate,dscale,scale,uscale,wrk_beamx,wrk_beamy,xshift,yshift
82
83// 08/01 detector constants are now returned from a function, based on the detector type and beamline
84//      dt_ornl = 3.4e-6                //deadtime of Ordella detectors as of 30-AUG-99
85//      dt_ill=3.0e-6                   //Cerca detector deadtime constant as of 30-AUG-99
86
87        defmon=1e8                      //default monitor counts
88       
89        //Yes, add to previous run(s) in work, that does exist
90        //use the actual monitor count run.savmon rather than the normalized monitor count
91        //in run.moncnt and unscale the work data
92       
93        total_mon = realsread[1]        //saved monitor count
94        uscale = total_mon/defmon               //unscaling factor
95        total_det = uscale*realsread[2]         //unscaled detector count
96        total_trn = uscale*realsread[39]        //unscaled trans det count
97        total_numruns = integersread[3] //number of runs in workfile
98        total_rtime = integersread[2]           //total counting time in workfile
99        //retrieve workfile beamcenter
100        wrk_beamx = realsread[16]
101        wrk_beamy = realsread[17]
102        //unscale the workfile data in "newType"
103        //
104        //check for log-scaling and adjust if necessary
105        ConvertFolderToLinearScale(newType)
106        //
107        //then unscale the data array
108        data *= uscale
109       
110        //DetCorr() has not been applied to the data in RAW , do it now in a local reference to the raw data
111        WAVE raw_data = $"root:RAW:data"
112        WAVE raw_reals =  $"root:RAW:realsread"
113        WAVE/T raw_text = $"root:RAW:textread"
114        WAVE raw_ints = $"root:RAW:integersread"
115       
116        //check for log-scaling of the raw data - make sure it's linear
117        ConvertFolderToLinearScale("RAW")
118       
119        DetCorr(raw_data,raw_reals)     //applies correction to raw_data, and overwrites it
120       
121        //if RAW data is ILL type detector, correct raw_data for same counts being written to 4 pixels
122        if(cmpstr(raw_text[9], "ILL   ") == 0 )         //text field in header is 6 characters "ILL---"
123                raw_data /= 4
124        endif
125       
126        //deadtime corrections to raw data
127        deadTime = DetectorDeadtime(raw_text[3],raw_text[9])            //pick the correct detector deadtime
128        itim = raw_ints[2]
129        cntrate = sum(raw_data,-inf,inf)/itim           //080802 use data sum, rather than scaler value
130        dscale = 1/(1-deadTime*cntrate)
131
132        //update totals by adding RAW values to the local ones (write to work header at end of function)
133        total_mon += raw_reals[0]
134        total_det += dscale*raw_reals[2]
135        total_trn += raw_reals[39]
136        total_rtime += raw_ints[2]
137        total_numruns +=1
138       
139        //do the beamcenter shifting if there is a mismatch
140        //and then add the two data sets together, changing "data" since it is the workfile data
141        xshift = raw_reals[16] - wrk_beamx
142        yshift = raw_reals[17] - wrk_beamy
143       
144        If((xshift != 0) || (yshift != 0))
145                DoAlert 1,"Do you want to ignore the beam center mismatch?"
146                if(V_flag==1)
147                        xshift=0
148                        yshift=0
149                endif
150        endif
151       
152        NVAR pixelsX = root:myGlobals:gNPixelsX
153        NVAR pixelsY = root:myGlobals:gNPixelsY
154       
155        If((xshift == 0) && (yshift == 0))              //no shift, just add them
156                data += dscale*raw_data         //do the deadtime correction on RAW here
157        else
158                //shift the beamcenter, then add
159                Make/O/N=1 $(destPath + ":noadd")               //needed to get noadd condition back from ShiftSum()
160                WAVE noadd = $(destPath + ":noadd")
161                Variable sh_sum                 //returned value
162                Print "BEAM CENTER MISMATCH - - BEAM CENTER WILL BE SHIFTED TO THIS FILE'S VALUE"
163                //ii,jj are just indices here, not physical locations - so [0,127] is fine
164                ii=0
165                do
166                        jj=0
167                        do
168                                //get the contribution of shifted data
169                                sh_sum = ShiftSum(data,ii,jj,xshift,yshift,noadd)
170                                if(noadd[0])
171                                        //don't do anything to data[][]
172                                else
173                                        //add the raw_data + shifted sum (and do the deadtime correction on both)
174                                        data[ii][jj] += dscale*(raw_data[ii][jj]+sh_sum)                //do the deadtime correction on RAW here
175                                Endif
176                                jj+=1
177                        while(jj<pixelsY)
178                        ii+=1
179                while(ii<pixelsX)
180        Endif
181       
182        //scale the data to the default montor counts
183        scale = defmon/total_mon
184        data *= scale
185       
186        //all is done, except for the bookkeeping of updating the header info in the work folder
187        textread[1] = date() + " " + time()             //date + time stamp
188        integersread[3] = total_numruns                                         //numruns = more than one
189        realsread[1] = total_mon                        //save the true monitor count
190        realsread[0] = defmon                                   //monitor ct = defmon
191        integersread[2] = total_rtime                   // total counting time
192        realsread[2] = scale*total_det                  //scaled detector counts
193        realsread[39] = scale*total_trn                 //scaled transmission counts
194       
195        //Add the added raw filename to the list of files in the workfile
196        String newfile = ";" + raw_text[0]
197        SVAR oldList = $(destPath + ":fileList")
198        String/G $(destPath + ":fileList") = oldList + newfile
199       
200        //reset the current displaytype to "newtype"
201        String/G root:myGlobals:gDataDisplayType=newType
202       
203        //return to root folder (redundant)
204        SetDataFolder root:
205       
206        Return(0)
207End
208
209//will copy the current contents of the RAW folder to the newType work folder
210//and do the geometric corrections and normalization to monitor counts
211//(the function Add_Raw_to_work(type) adds multiple runs together)
212//
213//the current display type is updated to newType (global)
214//
215Function Raw_to_work(newType)
216        String newType
217       
218        Variable deadTime,defmon,total_mon,total_det,total_trn,total_numruns,total_rtime
219        Variable ii,jj,itim,cntrate,dscale,scale,uscale,wrk_beamx,wrk_beamy
220        String destPath
221       
222// 08/01 detector constants are now returned from a function, based on the detector type and beamline
223//      dt_ornl = 3.4e-6                //deadtime of Ordella detectors as of 30-AUG-99
224//      dt_ill=3.0e-6                   //Cerca detector deadtime constant as of 30-AUG-99
225        defmon=1e8                      //default monitor counts
226       
227        //initialize values before normalization
228        total_mon=0
229        total_det=0
230        total_trn=0
231        total_numruns=0
232        total_rtime=0
233       
234        //Not adding multiple runs, so wipe out the old contents of the work folder and
235        // replace with the contents of raw
236
237        destPath = "root:" + newType
238       
239        //check for log-scaling of the RAW data and adjust if necessary
240        ConvertFolderToLinearScale("RAW")
241        //then continue
242
243        //copy from current dir (RAW) to work, defined by destpath
244        DestPath = "root:"+newType
245        Duplicate/O $"root:RAW:data",$(destPath + ":data")
246//      Duplicate/O $"root:RAW:vlegend",$(destPath + ":vlegend")
247        Duplicate/O $"root:RAW:textread",$(destPath + ":textread")
248        Duplicate/O $"root:RAW:integersread",$(destPath + ":integersread")
249        Duplicate/O $"root:RAW:realsread",$(destPath + ":realsread")
250        Variable/G $(destPath + ":gIsLogscale")=0                       //overwite flag in newType folder, data converted (above) to linear scale
251       
252        WAVE data=$(destPath + ":data")                         // these wave references point to the data in work
253        WAVE/T textread=$(destPath + ":textread")                       //that are to be directly operated on
254        WAVE integersread=$(destPath + ":integersread")
255        WAVE realsread=$(destPath + ":realsread")
256        String/G $(destPath + ":fileList") = textread[0]                        //a list of names of the files in the work file (1)
257       
258        //apply nonlinear, Jacobian corrections ---
259        DetCorr(data,realsread)         //the parameters are waves, and will be changed by the function
260       
261        //if ILL type detector, correct for same counts being written to 4 pixels
262        if(cmpstr(textread[9], "ILL   ") == 0 )         //text field in header is 6 characters "ILL---"
263                data /= 4
264        endif
265       
266        //deadtime corrections
267        itim = integersread[2]
268        cntrate = sum(data,-inf,inf)/itim               //use sum of detector counts rather than scaler value
269        deadtime = DetectorDeadtime(textread[3],textread[9])    //pick the correct deadtime
270        dscale = 1/(1-deadTime*cntrate)
271       
272        //update totals to put in the work header (at the end of the function)
273        total_mon += realsread[0]
274        total_det += dscale*realsread[2]
275        total_trn += realsread[39]
276        total_rtime += integersread[2]
277        total_numruns +=1
278       
279        // NO xcenter,ycenter shifting is done - this is the first (and only) file in the work folder
280       
281        //only ONE data file- no addition of multiple runs in this function, so data is
282        //just simply corrected for deadtime.
283        data *= dscale          //deadtime correction
284       
285        //scale the data to the default montor counts
286        scale = defmon/total_mon
287        data *= scale
288       
289        //all is done, except for the bookkeeping, updating the header information in the work folder
290        textread[1] = date() + " " + time()             //date + time stamp
291        integersread[3] = total_numruns                                         //numruns = 1
292        realsread[1] = total_mon                        //save the true monitor count
293        realsread[0] = defmon                                   //monitor ct = defmon
294        integersread[2] = total_rtime                   // total counting time
295        realsread[2] = scale*total_det                  //scaled detector counts
296        realsread[39] = scale*total_trn                 //scaled transmission counts
297       
298        //reset the current displaytype to "newtype"
299        String/G root:myGlobals:gDataDisplayType=newType
300       
301        //return to root folder (redundant)
302        SetDataFolder root:
303       
304        Return(0)
305End
306
307//used for adding DRK (beam shutter CLOSED) data to a workfile
308//force the monitor count to 1, since it's irrelevant
309// run data through normal "add" step, then unscale default monitor counts
310//to get the data back on a simple time basis
311//
312Function Raw_to_Work_NoNorm(type)
313        String type
314       
315        WAVE reals=$("root:RAW:realsread")
316        reals[1]=1              //true monitor counts, still in raw
317        Raw_to_work(type)
318        //data is now in "type" folder
319        WAVE data=$("root:"+type+":data")
320        WAVE new_reals=$("root:"+type+":realsread")
321       
322        Variable norm_mon,tot_mon,scale
323       
324        norm_mon = new_reals[0]         //should be 1e8
325        tot_mon = new_reals[1]          //should be 1
326        scale= norm_mon/tot_mon
327       
328        data /= scale           //unscale the data
329       
330        return(0)
331End
332
333//used for adding DRK (beam shutter CLOSED) data to a workfile
334//force the monitor count to 1, since it's irrelevant
335// run data through normal "add" step, then unscale default monitor counts
336//to get the data back on a simple time basis
337//
338Function Add_Raw_to_Work_NoNorm(type)
339        String type
340       
341        WAVE reals=$("root:RAW:realsread")
342        reals[1]=1              //true monitor counts, still in raw
343        Add_Raw_to_work(type)
344        //data is now in "type" folder
345        WAVE data=$("root:"+type+":data")
346        WAVE new_reals=$("root:"+type+":realsread")
347       
348        Variable norm_mon,tot_mon,scale
349       
350        norm_mon = new_reals[0]         //should be 1e8
351        tot_mon = new_reals[1]          //should be equal to the number of runs (1 count per run)
352        scale= norm_mon/tot_mon
353       
354        data /= scale           //unscale the data
355       
356        return(0)
357End
358
359//performs solid angle and non-linear detector corrections to raw data as it is "added" to a work folder
360//function is called by Raw_to_work() and Add_raw_to_work() functions
361//works on the actual data array, assumes that is is already on LINEAR scale
362//
363Function DetCorr(data,realsread)
364        Wave data,realsread
365       
366        Variable xcenter,ycenter,x0,y0,sx,sx3,sy,sy3,xx0,yy0
367        Variable ii,jj,dtdist,dtdis2
368        Variable xi,xd,yd,rad,ratio,domega,xy
369        Variable lambda
370       
371//      Print "...doing jacobian and non-linear corrections"
372        NVAR pixelsX = root:myGlobals:gNPixelsX
373        NVAR pixelsY = root:myGlobals:gNPixelsY
374       
375        //set up values to send to auxiliary trig functions
376        xcenter = pixelsX/2 + 0.5               // == 64.5 for 128x128 Ordela
377        ycenter = pixelsY/2 + 0.5               // == 64.5 for 128x128 Ordela
378
379        x0 = realsread[16]
380        y0 = realsread[17]
381        sx = realsread[10]
382        sx3 = realsread[11]
383        sy = realsread[13]
384        sy3 = realsread[14]
385       
386        dtdist = 1000*realsread[18]     //sdd in mm
387        dtdis2 = dtdist^2
388       
389        lambda = realsRead[26]
390       
391        xx0 = dc_fx(x0,sx,sx3,xcenter)
392        yy0 = dc_fy(y0,sy,sy3,ycenter)
393       
394
395        //waves to contain repeated function calls
396        Make/O/N=(pixelsX) fyy,xx,yy            //Assumes square detector !!!
397        ii=0
398        do
399                xi = ii
400                fyy[ii] = dc_fy(ii+1,sy,sy3,ycenter)
401                xx[ii] = dc_fxn(ii+1,sx,sx3,xcenter)
402                yy[ii] = dc_fym(ii+1,sy,sy3,ycenter)
403                ii+=1
404        while(ii<pixelsX)
405       
406//      Make/O/N=(pixelsX,pixelsX) SolidAngle           // testing only
407       
408        ii=0
409        do
410                xi = ii
411                xd = dc_fx(ii+1,sx,sx3,xcenter)-xx0
412                jj=0
413                do
414                        yd = fyy[jj]-yy0
415                        //rad is the distance of pixel ij from the sample
416                        //domega is the ratio of the solid angle of pixel ij versus center pixel
417                        rad = sqrt(dtdis2 + xd^2 + yd^2)
418                        domega = rad/dtdist
419                        ratio = domega^3
420//                      solidAngle[ii][jj] = ratio              //testing only 
421                        xy = xx[ii]*yy[jj]
422                        data[ii][jj] *= xy*ratio
423                       
424                        // multiplicative correction for detector efficiency JBG memo det_eff_cor2.doc 3/20/07
425                        // correction inserted 11/2007 SRK
426                       
427                        data[ii][jj] *= DetEffCorr(lambda,dtdist,xd,yd)
428                       
429//                      solidAngle[ii][jj] = DetEffCorr(lambda,dtdist,xd,yd)            //testing only
430                       
431                        jj+=1
432                while(jj<pixelsX)
433                ii+=1
434        while(ii<pixelsX)
435       
436        //clean up waves
437//      Killwaves/Z fyy,xx,yy
438       
439        Return(0)
440End
441
442//trig function used by DetCorr()
443Function dc_fx(x,sx,sx3,xcenter)
444        Variable x,sx,sx3,xcenter
445       
446        Variable result
447       
448        result = sx3*tan((x-xcenter)*sx/sx3)
449        Return(result)
450End
451
452//trig function used by DetCorr()
453Function dc_fy(y,sy,sy3,ycenter)
454        Variable y,sy,sy3,ycenter
455       
456        Variable result
457       
458        result = sy3*tan((y-ycenter)*sy/sy3)
459        Return(result)
460End
461
462//trig function used by DetCorr()
463Function dc_fxn(x,sx,sx3,xcenter)
464        Variable x,sx,sx3,xcenter
465       
466        Variable result
467       
468        result = (cos((x-xcenter)*sx/sx3))^2
469        Return(result)
470End
471
472//trig function used by DetCorr()
473Function dc_fym(y,sy,sy3,ycenter)
474        Variable y,sy,sy3,ycenter
475       
476        Variable result
477       
478        result = (cos((y-ycenter)*sy/sy3))^2
479        Return(result)
480End
481
482//distances passed in are in mm
483// dtdist is SDD
484// xd and yd are distances from the beam center to the current pixel
485//
486Function DetEffCorr(lambda,dtdist,xd,yd)
487        Variable lambda,dtdist,xd,yd
488       
489        Variable theta,cosT,ff,stAl,stHe
490       
491        theta = atan( (sqrt(xd^2 + yd^2))/dtdist )
492        cosT = cos(theta)
493       
494        stAl = 0.00967*lambda*0.8               //dimensionless, constants from JGB memo
495        stHe = 0.146*lambda*2.5
496       
497        ff = exp(-stAl/cosT)*(1-exp(-stHe/cosT)) / ( exp(-stAl)*(1-exp(-stHe)) )
498               
499        return(ff)
500End
501//******************
502//direct port of the FORTRAN code for calculating the weighted
503//shifted element to add when beam centers in data headers do not match
504//(indices updated to [0,n-1] indexing rather than (1,n) of fortran
505//
506// as of IGOR 4.0, could be rewritten to pass-by-reference noadd, rather than wave, but the function
507// is so little used, it's not worth the time
508Function ShiftSum(DATA,ip,jp,XSHIFT,YSHIFT,noadd)
509        Wave data
510        Variable ip,jp,xshift,yshift
511        Wave noadd
512//
513//       COMPUTE WEIGHTED OFFSET ELEMENT SUM FOR USE IN SANS DATA
514//       ANALYSIS MODULES.
515//
516// "data" wave passed in is the current contents of the work file
517// sum_val is the return value of the function
518// "noadd" is passed back to the calling function as a one-point wave
519
520        Variable XDELTA,YDELTA,kk,II,JJ,ISHIFT,JSHIFT,sum_val
521        Make/O/N=4 iii,jjj,a
522
523//       -----------------------------------------------------------------
524
525        ISHIFT = trunc(XSHIFT)          // INTEGER PART, trunc gives int closest in dierction of zero
526        XDELTA = XSHIFT - ISHIFT        //FRACTIONAL PART.
527        JSHIFT = trunc(YSHIFT)
528        YDELTA = YSHIFT - JSHIFT
529        II = ip + ISHIFT
530        JJ = jp + JSHIFT
531
532//       SHIFT IS DEFINED AS A VECTOR ANCHORED AT THE STATIONARY CENTER
533//       AND POINTING TO THE MOVABLE CENTER.  THE MOVABLE FIELD IS THUS
534//       ACTUALLY MOVED BY -SHIFT.
535//
536        IF ((XDELTA>= 0) && (YDELTA >= 0))              // CASE I ---- "%&" is "and"
537                III[0] = II
538                JJJ[0] = JJ
539                III[1] = II + 1
540                JJJ[1] = JJ
541                III[2] = II + 1
542                JJJ[2] = JJ + 1
543                III[3] = II
544                JJJ[3] = JJ + 1
545                A[0] = (1. - XDELTA)*(1. - YDELTA)
546                A[1] = XDELTA*(1. - YDELTA)
547                A[2] = XDELTA*YDELTA
548                A[3] = (1. - XDELTA)*YDELTA
549        Endif
550        IF ((XDELTA >= 0) && (YDELTA < 0))              // CASE II.
551                III[0] = II
552                JJJ[0] = JJ
553                III[1] = II
554                JJJ[1] = JJ - 1
555                III[2] = II + 1
556                JJJ[2] = JJ - 1
557                III[3] = II + 1
558                JJJ[3] = JJ
559                A[0] = (1. - XDELTA)*(1. + YDELTA)
560                A[1] = (1. - XDELTA)*(-YDELTA)
561                A[2] = XDELTA*(-YDELTA)
562                A[3] = XDELTA*(1. + YDELTA)
563        Endif
564        IF ((XDELTA < 0) && (YDELTA >= 0))              // CASE III.
565                III[0] = II
566                JJJ[0] = JJ
567                III[1] = II
568                JJJ[1] = JJ + 1
569                III[2] = II - 1
570                JJJ[2] = JJ + 1
571                III[3] = II - 1
572                JJJ[3] = JJ
573                A[0] = (1. + XDELTA)*(1 - YDELTA)
574                A[1] = (1. + XDELTA)*YDELTA
575                A[2] = -XDELTA*YDELTA
576                A[3] = -XDELTA*(1. - YDELTA)
577        Endif
578        IF ((XDELTA < 0) && (YDELTA < 0))               //CASE IV.
579                III[0] = II
580                JJJ[0] = JJ
581                III[1] = II - 1
582                JJJ[1] = JJ
583                III[2] = II - 1
584                JJJ[2] = JJ - 1
585                III[3] = II
586                JJJ[3] = JJ - 1
587                A[0] = (1. + XDELTA)*(1. + YDELTA)
588                A[1] = -XDELTA*(1. + YDELTA)
589                A[2] = (-XDELTA)*(-YDELTA)
590                A[3] = (1. + XDELTA)*(-YDELTA)
591        Endif
592
593        NVAR pixelsX = root:myGlobals:gNPixelsX
594        NVAR pixelsY = root:myGlobals:gNPixelsY
595//check to see if iii[0],jjj[0] are valid detector elements, in [0,127]
596//if not set noadd[0] to 1, to let calling routine know NOT to add
597//        CALL TESTIJ(III(1),JJJ(1),OKIJ)
598        NOADD[0] = 0
599        if( (iii[0]<0) || (iii[0]>(pixelsX-1)) )
600                noadd[0] = 1
601        endif
602        if((jjj[0]<0) || (jjj[0]>(pixelsY-1)) )
603                noadd[0] = 1
604        endif
605       
606
607       
608        sum_val = 0.
609        kk = 0
610        Do
611                IF(JJJ[kk] == pixelsX)
612                        //do nothing
613                else
614                        sum_val += A[kk]*DATA[III[kk]][JJJ[kk]]
615                endif
616                kk+=1
617        while(kk<4)
618       
619        //clean up waves
620        KillWaves/z iii,jjj,a
621       
622        RETURN (sum_val)
623       
624End             //function ShiftSum
625
626//************************
627//unused testing procedure, may not be up-to-date with other procedures
628//check before re-implementing
629//
630Proc DIV_a_Workfile(type)
631        String type
632        Prompt type,"WORK data type",popup,"COR;SAM;EMP;BGD"
633       
634        //macro will take whatever is in SELECTED folder and DIVide it by the current
635        //contents of the DIV folder - the function will check for existence
636        //before proceeding
637       
638        Variable err
639        err = Divide_work(type)         //returns err = 1 if data doesn't exist in specified folders
640       
641        if(err)
642                Abort "error in Divide_work"
643        endif
644       
645        //contents are always dumped to CAL
646        type = "CAL"
647       
648        String newTitle = "WORK_"+type
649        DoWindow/F SANS_Data
650        DoWindow/T SANS_Data, newTitle
651        KillStrings/Z newTitle
652       
653        //need to update the display with "data" from the correct dataFolder
654        //reset the current displaytype to "type"
655        String/G root:myGlobals:gDataDisplayType=Type
656       
657        fRawWindowHook()
658       
659End
660
661//function will divide the contents of "type" folder with the contents of
662//the DIV folder
663// all data is converted to linear scale for the calculation
664//
665Function Divide_work(type)
666        String type
667       
668        //check for existence of data in type and DIV
669        // if the desired workfile doesn't exist, let the user know, and abort
670        String destPath=""
671        destPath = "root:"+Type + ":data"
672        if(WaveExists($destpath) == 0)
673                Print "There is no work file in "+type+"--Aborting"
674                Return(1)               //error condition
675        Endif
676        //check for DIV
677        // if the DIV workfile doesn't exist, let the user know,and abort
678        destPath = "root:DIV:data"
679        if(WaveExists($destpath) == 0)
680                Print "There is no work file in DIV --Aborting"
681                Return(1)               //error condition
682        Endif
683        //files exist, proceed
684       
685        //check for log-scaling of the "DIV" data and adjust if necessary
686        ConvertFolderToLinearScale("DIV")
687       
688        //copy type information to CAL, wiping out the old contents of the CAL folder first
689       
690        //destPath = "root:CAL"
691        //SetDataFolder destPath
692        //KillWaves/A/Z                 //get rid of the old data in CAL folder
693
694        //check for log-scaling of the "type" data and adjust if necessary
695        ConvertFolderToLinearScale(type)
696        //then continue
697
698        //copy from current dir (type)=destPath to CAL, overwriting CAL contents
699        destPath = "root:" + type
700        Duplicate/O $(destPath + ":data"),$"root:CAL:data"
701//      Duplicate/O $(destPath + ":vlegend"),$"root:CAL:vlegend"
702        Duplicate/O $(destPath + ":textread"),$"root:CAL:textread"
703        Duplicate/O $(destPath + ":integersread"),$"root:CAL:integersread"
704        Duplicate/O $(destPath + ":realsread"),$"root:CAL:realsread"
705        //need to save a copy of filelist string too (from the current type folder)
706        SVAR oldFileList = $(destPath + ":fileList")
707
708        //now switch to reference waves in CAL folder
709        destPath = "root:CAL"
710        //make appropriate wave references
711        Wave data=$(destPath + ":data")                                 // these wave references point to the data in CAL
712        Wave/t textread=$(destPath + ":textread")                       //that are to be directly operated on
713        Wave integersread=$(destPath + ":integersread")
714        Wave realsread=$(destPath + ":realsread")
715        Variable/G $(destPath + ":gIsLogScale")=0                       //make new flag in CAL folder, data is linear scale
716        //need to copy filelist string too
717        String/G $(destPath + ":fileList") = oldFileList
718
719        Wave div_data = $"root:DIV:data"                //hard-wired in....
720        //do the division, changing data in CAL
721        data /= div_data
722       
723        //update CAL header
724        textread[1] = date() + " " + time()             //date + time stamp
725       
726        Return(0)
727End
728
729//test procedure, not called anymore
730Proc AbsoluteScaling(type,c0,c1,c2,c3,c4,c5)
731        String type
732        Variable c0=1,c1=0.1,c2=0.95,c3=0.1,c4=1,c5=32.0
733        Prompt type,"WORK data type",popup,"CAL;COR;SAM"
734        Prompt c0, "Sample Transmission"
735        Prompt c1, "Sample Thickness (cm)"
736        Prompt c2, "Standard Transmission"
737        Prompt c3, "Standard Thickness (cm)"
738        Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)"
739        Prompt c5, "Standard Cross-Section (cm-1)"
740
741        Variable err
742        //call the function to do the math
743        //data from "type" will be scaled and deposited in ABS
744        err = Absolute_Scale(type,c0,c1,c2,c3,c4,c5)
745       
746        if(err)
747                Abort "Error in Absolute_Scale()"
748        endif
749       
750        //contents are always dumped to ABS
751        type = "ABS"
752       
753        String newTitle = "WORK_"+type
754        DoWindow/F SANS_Data
755        DoWindow/T SANS_Data, newTitle
756        KillStrings/Z newTitle
757       
758        //need to update the display with "data" from the correct dataFolder
759        //reset the current displaytype to "type"
760        String/G root:myGlobals:gDataDisplayType=Type
761       
762        fRawWindowHook()
763       
764End
765
766//s_ is the standard
767//w_ is the "work" file
768//both are work files and should already be normalized to 10^8 monitor counts
769Function Absolute_Scale(type,w_trans,w_thick,s_trans,s_thick,s_izero,s_cross)
770        String type
771        Variable w_trans,w_thick,s_trans,s_thick,s_izero,s_cross
772       
773        //convert the "type" data to absolute scale using the given standard information
774        //copying the "type" waves to ABS
775       
776        //check for existence of data, rescale to linear if needed
777        String destPath
778        //check for "type"
779        destPath = "root:"+Type + ":data"
780        if(WaveExists($destpath) == 0)
781                Print "There is no work file in "+type+"--Aborting"
782                Return(1)               //error condition
783        Endif
784        //check for log-scaling of the "type" data and adjust if necessary
785        destPath = "root:"+Type
786        NVAR gIsLogScale = $(destPath + ":gIsLogScale")
787        if(gIsLogScale)
788                Duplicate/O $(destPath + ":linear_data") $(destPath + ":data")//back to linear scale
789                Variable/G $(destPath + ":gIsLogScale")=0       //the "type" data is not logscale anymore
790        endif
791       
792        //copy "oldtype" information to ABS
793        //overwriting out the old contents of the ABS folder (/O option in Duplicate)
794        //copy over the waves data,vlegend,text,integers,reals(read)
795
796        String oldType= "root:"+type            //this is where the data to be absoluted is
797        //copy from current dir (type) to ABS, defined by destPath
798        Duplicate/O $(oldType + ":data"),$"root:ABS:data"
799//      Duplicate/O $(oldType + ":vlegend"),$"root:ABS:vlegend"
800        Duplicate/O $(oldType + ":textread"),$"root:ABS:textread"
801        Duplicate/O $(oldType + ":integersread"),$"root:ABS:integersread"
802        Duplicate/O $(oldType + ":realsread"),$"root:ABS:realsread"
803        //need to save a copy of filelist string too (from the current type folder)
804        SVAR oldFileList = $(oldType + ":fileList")
805        //need to copy filelist string too
806        String/G $"root:ABS:fileList" = oldFileList
807       
808        //now switch to ABS folder
809        //make appropriate wave references
810        WAVE data=$"root:ABS:data"                                      // these wave references point to the "type" data in ABS
811        WAVE/T textread=$"root:ABS:textread"                    //that are to be directly operated on
812        WAVE integersread=$"root:ABS:integersread"
813        WAVE realsread=$"root:ABS:realsread"
814        Variable/G $"root:ABS:gIsLogscale"=0                    //make new flag in ABS folder, data is linear scale
815       
816        //do the actual absolute scaling here, modifying the data in ABS
817        Variable defmon = 1e8,w_moncount,s1,s2,s3,s4
818       
819        w_moncount = realsread[0]               //monitor count in "type"
820        if(w_moncount == 0)
821                //zero monitor counts will give divide by zero ---
822                DoAlert 0,"Total monitor count in data file is zero. No rescaling of data"
823                Return(1)               //report error
824        Endif
825       
826        //calculate scale factor
827        s1 = defmon/realsread[0]                //[0] is monitor count (s1 should be 1)
828        s2 = s_thick/w_thick
829        s3 = s_trans/w_trans
830        s4 = s_cross/s_izero
831       
832        data *= s1*s2*s3*s4
833       
834        //********* 15APR02
835        // DO NOt correct for atenuators here - the COR step already does this, putting all of the data one equal
836        // footing (zero atten) before doing the subtraction.
837        //
838        //Print "ABS data multiplied by  ",s1*s2*s3*s4/attenFactor
839       
840        //update the ABS header information
841        textread[1] = date() + " " + time()             //date + time stamp
842       
843        Return (0) //no error
844End
845
846//*************
847// start of section of functions used for workfile math panel
848//*************
849
850
851//function will copy the contents of oldtype folder to newtype folder
852//converted to linear scale before copying
853//******data in newtype is overwritten********
854//
855Function CopyWorkContents(oldtype,newtype)
856        String oldtype,newtype
857       
858        //check for existence of data in oldtype
859        // if the desired workfile doesn't exist, let the user know, and abort
860        String destPath=""
861        destPath = "root:"+oldType + ":data"
862        if(WaveExists($destpath) == 0)
863                Print "There is no work file in "+oldtype+"--Aborting"
864                Return(1)               //error condition
865        Endif
866       
867        //check for log-scaling of the "type" data and adjust if necessary
868        ConvertFolderToLinearScale(oldtype)
869        Fix_LogLinButtonState(0)                //make sure the button reflects the new linear scaling
870        //then continue
871
872        //copy from current dir (type)=destPath to newtype, overwriting newtype contents
873        destPath = "root:" + oldtype
874        Duplicate/O $(destPath + ":data"),$("root:"+newtype+":data")
875        Duplicate/O $(destPath + ":textread"),$("root:"+newtype+":textread")
876        Duplicate/O $(destPath + ":integersread"),$("root:"+newtype+":integersread")
877        Duplicate/O $(destPath + ":realsread"),$("root:"+newtype+":realsread")
878        //need to save a copy of filelist string too (from the current type folder)
879        SVAR oldFileList = $(destPath + ":fileList")
880
881        //now switch to reference waves in newtype folder
882        destPath = "root:"+newtype
883        Variable/G $(destPath + ":gIsLogScale")=0                       //make new flag in newtype folder, data is linear scale
884        //need to copy filelist string too
885        String/G $(destPath + ":fileList") = oldFileList
886
887        Return(0)
888End
889
890//Entry procedure from main panel
891//
892Proc CopyWorkFolder(oldType,newType)
893        String oldType,newType
894        Prompt oldType,"Source WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;"
895        Prompt newType,"Destination WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;"
896//      Prompt oldType,"Source WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;"
897//      Prompt newType,"Destination WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;"
898
899        // data folder "old" will be copied to "new" (and will overwrite)
900        CopyWorkContents(oldtype,newtype)
901End
902
903//initializes datafolder and constants necessary for the workfilemath panel
904//
905Proc Init_WorkMath()
906        //create the data folder
907        //String str = "AAA;BBB;CCC;DDD;EEE;FFF;GGG;"
908        String str = "File_1;File_2;Result;"
909        NewDataFolder/O/S root:myGlobals:WorkMath
910        String/G gFolderList=str
911        Variable ii=0,num=itemsinlist(str)
912        do
913                Execute "NewDataFolder/O "+StringFromList(ii, str ,";")
914                ii+=1
915        while(ii<num)
916        Variable/G const1=1,const2=1
917       
918        SetDataFolder root:
919End
920
921//entry procedure to invoke the workfilemath panel, initializes if needed
922//
923Proc Show_WorkMath_Panel()
924        DoWindow/F WorkFileMath
925        if(V_flag==0)
926                Init_WorkMath()
927                WorkFileMath()
928        Endif
929End
930
931//attempts to perform the selected math operation based on the selections in the panel
932// aborts with an error condition if operation can't be completed
933// or puts the final answer in the Result folder, and displays the selected data
934//
935Function WorkMath_DoIt_ButtonProc(ctrlName) : ButtonControl
936        String ctrlName
937
938        String str1,str2,oper,dest = "Result"
939        String pathStr,workMathStr="myGlobals:WorkMath:"
940       
941        //get the panel selections (these are the names of the files on disk)
942        PathInfo catPathName
943        pathStr=S_Path
944        ControlInfo popup0
945        str1=S_Value
946        ControlInfo popup1
947        str2=S_Value
948        ControlInfo popup2
949        oper=S_Value
950       
951        //check that something has been selected for operation and destination
952        if(cmpstr(oper,"Operation")==0)
953                Abort "Select a math operand from the popup"
954        Endif
955
956        //constants from globals
957        NVAR const1=root:myGlobals:WorkMath:const1
958        NVAR const2=root:myGlobals:WorkMath:const2
959        Printf "(%g)%s %s (%g)%s = %s\r", const1,str1,oper,const2,str2,dest
960        //check for proper folders (all 3 must be different)
961       
962        //load the data in here...
963        //set #1
964        Load_NamedASC_File(pathStr+str1,workMathStr+"File_1")
965       
966        NVAR pixelsX = root:myGlobals:gNPixelsX
967        NVAR pixelsY = root:myGlobals:gNPixelsY
968       
969        WAVE/Z data1=$("root:"+workMathStr+"File_1:data")
970        If(cmpstr(str2,"UNIT MATRIX")==0)
971                Make/O/N=(pixelsX,pixelsY) root:myGlobals:WorkMath:data         //don't put in File_2 folder
972                Wave/Z data2 =  root:myGlobals:WorkMath:data                    //it's not real data!
973                data2=1
974        else
975                //Load set #2
976                Load_NamedASC_File(pathStr+str2,workMathStr+"File_2")
977                WAVE/Z data2=$("root:"+workMathStr+"File_2:data")
978        Endif
979
980        ///////
981       
982        //now that we know that data exists, convert each of the operands to linear scale
983        ConvertFolderToLinearScale(workMathStr+"File_1")
984        If(cmpstr(str2,"UNIT MATRIX")!=0)
985                ConvertFolderToLinearScale(workMathStr+"File_2")                //don't need to convert unit matrix to linear
986        endif
987        //copy contents of str1 folder to dest and create the wave ref (it will exist)
988        CopyWorkContents(workMathStr+"File_1",workMathStr+dest)
989        WAVE/Z destData=$("root:"+workMathStr+dest+":data")
990       
991        //dispatch
992        strswitch(oper)
993                case "*":               //multiplication
994                        destData = const1*data1 * const2*data2
995                        break   
996                case "_":               //subtraction
997                        destData = const1*data1 - const2*data2
998                        break
999                case "/":               //division
1000                        destData = (const1*data1) / (const2*data2)
1001                        break
1002                case "+":               //addition
1003                        destData = const1*data1 + const2*data2
1004                        break                   
1005        endswitch
1006       
1007        //show the result
1008        WorkMath_Display_PopMenuProc("",0,"Result")
1009End
1010
1011// closes the panel and kills the data folder when done
1012//
1013Function WorkMath_Done_ButtonProc(ctrlName) : ButtonControl
1014        String ctrlName
1015       
1016        DoAlert 1,"Closing the panel will kill all of the data you have loaded into memory. Do you want to continue?"
1017        If(V_Flag==2)
1018                return(0)               //don't do anything
1019        Endif
1020        //kill the panel
1021        DoWindow/K WorkFileMath
1022        //wipe out the data folder of globals
1023        SVAR dataType=root:myGlobals:gDataDisplayType
1024        if(strsearch(dataType, "myGlobals", 0 ) != -1)          //kill the SANS_Data graph if needed
1025                DoWindow/K SANS_Data
1026        Endif
1027        KillDataFolder root:myGlobals:WorkMath
1028End
1029
1030// loads data into the specified folder
1031//
1032// currently unused since button has been removed from panel
1033//
1034Function WorkMath_Load_ButtonProc(ctrlName) : ButtonControl
1035        String ctrlName
1036       
1037        String destStr=""
1038        SVAR folderList=root:myGlobals:WorkMath:gFolderList
1039        Prompt destStr,"Select the destination folder",popup,folderList
1040        DoPrompt "Folder for ASC Load",destStr
1041       
1042        if(V_flag==1)
1043                return(1)               //user abort, do nothing
1044        Endif
1045       
1046        String destFolder = "myGlobals:WorkMath:"+destStr
1047       
1048        Load_ASC_File("Pick the ASC file",destFolder)
1049End
1050
1051// changes the display of the SANS_Data window based on popped data type
1052// first loads in the data from the File1 or File2 popup as needed
1053// then displays the selcted dataset, if it exists
1054// makes use of procedure from DisplayUtils
1055//
1056// - Always replaces File1 or File2 with fresh data from disk
1057//
1058Function WorkMath_Display_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
1059        String ctrlName
1060        Variable popNum
1061        String popStr
1062       
1063        String folder="myGlobals:WorkMath:",pathStr,str1
1064
1065        PathInfo catPathName
1066        pathStr=S_Path
1067       
1068        //if display result, just do it and return
1069        if(cmpstr(popStr,"Result")==0)
1070                Execute "ChangeDisplay(\""+folder+popstr+"\")"
1071                return(0)
1072        endif
1073        // if file1 or file2, load in the data and display
1074        if(cmpstr(popStr,"File_1")==0)
1075                ControlInfo popup0
1076                str1 = S_Value
1077        Endif
1078        if(cmpstr(popStr,"File_2")==0)
1079                ControlInfo popup1
1080                str1 = S_Value
1081        Endif
1082        //don't load or display the unit matrix
1083        Print str1
1084        if(cmpstr(str1,"UNIT MATRIX")!=0)
1085                Load_NamedASC_File(pathStr+str1,folder+popStr)
1086                //change the display
1087                Execute "ChangeDisplay(\""+folder+popstr+"\")"
1088        endif
1089        return(0)       
1090End
1091
1092//simple panel to do workfile arithmetic
1093//
1094Proc WorkFileMath()
1095        PauseUpdate; Silent 1           // building window...
1096        NewPanel /W=(610,211,880,490)/K=2 as "Work File Math"           // replace /K=2 flag
1097        DoWindow/C WorkFileMath
1098        ModifyPanel cbRGB=(47802,54484,6682)
1099        ModifyPanel fixedSize=1
1100        SetDrawLayer UserBack
1101        DrawLine 6,166,214,166
1102        SetDrawEnv fstyle= 4
1103        DrawText 10,34,"File #1:"
1104        SetDrawEnv fstyle= 4
1105        DrawText 13,129,"File #2:"
1106        DrawText 78,186,"= Result"
1107        Button button0,pos={28,245},size={50,20},proc=WorkMath_DoIt_ButtonProc,title="Do It"
1108        Button button0,help={"Performs the specified arithmetic"}
1109        Button button1,pos={183,245},size={50,20},proc=WorkMath_Done_ButtonProc,title="Done"
1110        Button button1,help={"Closes the panel"}
1111//      Button button2,pos={30,8},size={110,20},proc=WorkMath_Load_ButtonProc,title="Load ASC Data"
1112//      Button button2,help={"Loads ASC data files into the specified folder"}
1113        Button button3,pos={205,8},size={25,20},proc=ShowWorkMathHelp,title="?"
1114        Button button3,help={"Show help file for math operations on 2-D data sets"}
1115        SetVariable setvar0,pos={9,46},size={70,15},title=" "
1116        SetVariable setvar0,limits={-Inf,Inf,0},value= root:myGlobals:WorkMath:const1
1117        SetVariable setvar0,help={"Multiplicative constant for the first dataset"}
1118        PopupMenu popup0,pos={89,44},size={84,20},title="X  "
1119        PopupMenu popup0,mode=1,popvalue="1st Set",value= ASC_FileList()
1120        PopupMenu popup0,help={"Selects the first dataset for the operation"}
1121        PopupMenu popup1,pos={93,136},size={89,20},title="X  "
1122        PopupMenu popup1,mode=1,popvalue="2nd Set",value= "UNIT MATRIX;"+ASC_FileList()
1123        PopupMenu popup1,help={"Selects the second dataset for the operation"}
1124        PopupMenu popup2,pos={50,82},size={70,20},title="Operator  "
1125        PopupMenu popup2,mode=3,popvalue="Operation",value= #"\"+;_;*;/;\""
1126        PopupMenu popup2,help={"Selects the mathematical operator"}
1127        SetVariable setvar1,pos={13,139},size={70,15},title=" "
1128        SetVariable setvar1,limits={-Inf,Inf,0},value= root:myGlobals:WorkMath:const2
1129        SetVariable setvar1,help={"Multiplicative constant for the second dataset"}
1130//      PopupMenu popup3,pos={27,167},size={124,20},title=" = Destination"
1131//      PopupMenu popup3,mode=1,popvalue="Destination",value= root:myGlobals:WorkMath:gFolderList
1132//      PopupMenu popup3,help={"Selects the destination folder"}
1133        PopupMenu popup4,pos={55,204},size={103,20},proc=WorkMath_Display_PopMenuProc,title="Display"
1134        PopupMenu popup4,mode=3,value= "File_1;File_2;Result;"
1135        PopupMenu popup4,help={"Displays the data in the specified folder"}
1136EndMacro
1137
1138//jump to the help topic
1139Function ShowWorkMathHelp(ctrlName) : ButtonControl
1140        String ctrlName
1141        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[2-D Work File Arithmetic]"
1142End
1143
1144//utility function to clear the contents of a data folder
1145//won't clear data that is in use -
1146//
1147Function ClearDataFolder(type)
1148        String type
1149       
1150        SetDataFolder $("root:"+type)
1151        KillWaves/a/z
1152        KillStrings/a/z
1153        KillVariables/a/z
1154        SetDataFolder root:
1155End
1156
1157
1158
1159//fileStr must be the FULL path and filename on disk
1160//destFolder is the path to the Igor folder where the data is to be deposited
1161// - "myGlobals:WorkMath:File_1" for example, compatible with SANS_Data display type
1162//
1163Function Load_NamedASC_File(fileStr,destFolder)
1164        String fileStr,destFolder
1165
1166        Variable refnum
1167       
1168        //read in the data
1169        ReadASCData(fileStr,destFolder)
1170
1171        //the calling macro must change the display type
1172        String/G root:myGlobals:gDataDisplayType=destFolder
1173       
1174        FillFakeHeader_ASC(destFolder)          //uses info on the panel, if available
1175
1176        //data is displayed here, and needs header info
1177       
1178        fRawWindowHook()
1179       
1180        return(0)
1181End
1182
1183
1184//function called by the main entry procedure (the load button)
1185//loads data into the specified folder, and wipes out what was there
1186//
1187//aborts if no file was selected
1188//
1189// reads the data in if all is OK
1190//
1191// currently unused, as load button has been replaced
1192//
1193Function Load_ASC_File(msgStr,destFolder)
1194        String msgStr,destFolder
1195
1196        String filename="",pathStr=""
1197        Variable refnum
1198
1199        //check for the path
1200        PathInfo catPathName
1201        If(V_Flag==1)           //      /D does not open the file
1202                Open/D/R/T="????"/M=(msgStr)/P=catPathName refNum
1203        else
1204                Open/D/R/T="????"/M=(msgStr) refNum
1205        endif
1206        filename = S_FileName           //get the filename, or null if canceled from dialog
1207        if(strlen(filename)==0)
1208                //user cancelled, abort
1209                SetDataFolder root:
1210                Abort "No file selected, action aborted"
1211        Endif
1212       
1213        //read in the data
1214        ReadASCData(filename,destFolder)
1215
1216        //the calling macro must change the display type
1217        String/G root:myGlobals:gDataDisplayType=destFolder
1218       
1219        FillFakeHeader_ASC(destFolder)          //uses info on the panel, if available
1220
1221        //data is displayed here, and needs header info
1222       
1223        fRawWindowHook()
1224       
1225        return(0)
1226End
1227
1228
1229
1230//function called by the popups to get a file list of data that can be sorted
1231// this procedure simply removes the raw data files from the string - there
1232//can be lots of other junk present, but this is very fast...
1233//
1234Function/S ASC_FileList()
1235
1236        String list="",newList="",item=""
1237        Variable num,ii
1238       
1239        //check for the path
1240        PathInfo catPathName
1241        if(V_Flag==0)
1242                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
1243                Return("")
1244        Endif
1245       
1246        list = IndexedFile(catpathName,-1,"????")
1247        num=ItemsInList(list,";")
1248        //print "num = ",num
1249        for(ii=(num-1);ii>=0;ii-=1)
1250                item = StringFromList(ii, list  ,";")
1251                //simply remove all that are not raw data files (SA1 SA2 SA3)
1252                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
1253                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
1254                                if(!stringmatch(item,"*.AVE") && !stringmatch(item,"*.ABS"))
1255                                        newlist += item + ";"
1256                                endif
1257                        endif
1258                endif
1259        endfor
1260        //remove VAX version numbers
1261        newList = RemoveVersNumsFromList(newList)
1262        //sort
1263        newList = SortList(newList,";",0)
1264
1265        return newlist
1266End
Note: See TracBrowser for help on using the repository browser.