source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_Utils.ipf @ 430

Last change on this file since 430 was 412, checked in by ajj, 14 years ago

More reorg.

File size: 39.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.0
4
5// this file contains globals and functions that are specific to a
6// particular facility or data file format
7// branched out 29MAR07 - SRK
8//
9// functions are either labeled with the procedure file that calls them,
10// or noted that they are local to this file
11
12
13// initializes globals that are specific to a particular facility
14// - number of XY pixels
15// - pixexl resolution [cm]
16// - detector deadtime constant [s]
17//
18// called by Initialize.ipf
19//
20Function InitFacilityGlobals()
21
22        //Detector -specific globals
23        Variable/G root:myGlobals:gNPixelsX=128
24        Variable/G root:myGlobals:gNPixelsY=128
25       
26        // as of Jan2008, detector pixel sizes are read directly from the file header, so they MUST
27        // be set correctly in instr.cfg
28        Variable/G root:myGlobals:PixelResNG3_ILL = 1.0         //pixel resolution in cm
29        Variable/G root:myGlobals:PixelResNG5_ILL = 1.0
30        Variable/G root:myGlobals:PixelResNG7_ILL = 1.0
31        Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5
32        Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5
33        Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5
34        Variable/G root:myGlobals:PixelResDefault = 0.5
35       
36        Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6              //deadtime in seconds
37        Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6
38        Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6
39        Variable/G root:myGlobals:DeadtimeNG3_ORNL = 3.4e-6
40        Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6             //as of 9 MAY 2002
41        Variable/G root:myGlobals:DeadtimeNG7_ORNL = 3.4e-6
42        Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6
43       
44        //new 11APR07
45        Variable/G root:myGlobals:BeamstopXTol = -8                     // (cm) is BS Xpos is -5 cm or less, it's a trans measurement
46        // sample aperture offset is NOT stored in the VAX header, but it should be
47        // - when it is, remove the global and write an accessor AND make a place for
48        // it in the RealsRead
49        Variable/G root:myGlobals:apOff = 5.0                           // (cm) distance from sample aperture to sample position
50
51End
52
53
54//**********************
55// Resolution calculation - used by the averaging routines
56// to calculate the resolution function at each q-value
57// - the return value is not used
58//
59// equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR
60// Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114
61//
62// - 21 MAR 07 uses projected BS diameter on the detector
63// - APR 07 still need to add resolution with lenses. currently there is no flag in the
64//          raw data header to indicate the presence of lenses.
65//
66// - Aug 07 - added input to switch calculation based on lenses (==1 if in)
67//
68// - called by CircSectAvg.ipf and RectAnnulAvg.ipf
69//
70// passed values are read from RealsRead
71// except DDet and apOff, which are set from globals before passing
72//
73//
74Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,SigmaQ,QBar,fSubS)
75        Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses
76        Variable &fSubS, &QBar, &SigmaQ         //these are the output quantities at the input Q value
77       
78        //lots of calculation variables
79        Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g
80        Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r
81
82        //Constants
83        Variable vz_1 = 3.956e5         //velocity [cm/s] of 1 A neutron
84        Variable g = 981.0                              //gravity acceleration [cm/s^2]
85
86        String results
87        results ="Failure"
88
89        S1 *= 0.5*0.1                   //convert to radius and [cm]
90        S2 *= 0.5*0.1
91
92        L1 *= 100.0                     // [cm]
93        L1 -= apOff                             //correct the distance
94
95        L2 *= 100.0
96        L2 += apOff
97        del_r *= 0.1                            //width of annulus, convert mm to [cm]
98       
99        BS *= 0.5*0.1                   //nominal BS diameter passed in, convert to radius and [cm]
100        // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture
101        Variable LB
102        LB = 20.1 + 1.61*BS                     //distance in cm from beamstop to anode plane (empirical)
103        BS = bs + bs*lb/(l2-lb)         //adjusted diameter of shadow from parallax
104       
105        //Start resolution calculation
106        a2 = S1*L2/L1 + S2*(L1+L2)/L1
107        q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2)
108        lp = 1.0/( 1.0/L1 + 1.0/L2)
109
110        v_lambda = lambdaWidth^2/6.0
111       
112//      if(usingLenses==1)                      //SRK 2007
113        if(usingLenses != 0)                    //SRK 2008 allows for the possibility of different numbers of lenses in header
114                v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2         //correction to 2nd term
115        else
116                v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2              //original form
117        endif
118       
119        v_d = (DDet/2.3548)^2 + del_r^2/12.0
120        vz = vz_1 / lambda
121        yg = 0.5*g*L2*(L1+L2)/vz^2
122        v_g = 2.0*(2.0*yg^2*v_lambda)                                   //factor of 2 correction, B. Hammouda, 2007
123
124        r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) ))
125        delta = 0.5*(BS - r0)^2/v_d
126
127        if (r0 < BS)
128                inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta))
129        else
130                inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta))
131        endif
132
133        fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) )
134        if (fSubS <= 0.0)
135                fSubS = 1.e-10
136        endif
137        fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi))
138        fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d
139
140        rmd = fr*r0
141        v_r1 = v_b + fv*v_d +v_g
142
143        rm = rmd + 0.5*v_r1/rmd
144        v_r = v_r1 - 0.5*(v_r1/rmd)^2
145        if (v_r < 0.0)
146                v_r = 0.0
147        endif
148        QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2))
149        SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda)
150
151        results = "success"
152        Return results
153End
154
155
156//Utility function that returns the detector resolution (in cm)
157//Global values are set in the Initialize procedure
158//
159//
160// - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf
161//
162// fileStr is passed as TextRead[3]
163// detStr is passed as TextRead[9]
164//
165// *** as of Jan 2008, depricated. Now detector pixel sizes are read from the file header
166// rw[10] = x size (mm); rw[13] = y size (mm)
167//
168Function xDetectorPixelResolution(fileStr,detStr)
169        String fileStr,detStr
170       
171        Variable DDet
172        String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)
173       
174        NVAR PixelResNG3_ILL = root:myGlobals:PixelResNG3_ILL           //pixel resolution in cm
175        NVAR PixelResNG5_ILL = root:myGlobals:PixelResNG5_ILL
176        NVAR PixelResNG7_ILL = root:myGlobals:PixelResNG7_ILL
177        NVAR PixelResNG3_ORNL = root:myGlobals:PixelResNG3_ORNL
178        NVAR PixelResNG5_ORNL = root:myGlobals:PixelResNG5_ORNL
179        NVAR PixelResNG7_ORNL = root:myGlobals:PixelResNG7_ORNL
180        NVAR PixelResDefault = root:myGlobals:PixelResDefault
181       
182        strswitch(instr)
183                case "NG3":
184                        if(cmpstr(detStr, "ILL   ") == 0 )
185                                DDet= PixelResNG3_ILL
186                        else
187                                DDet = PixelResNG3_ORNL //detector is ordella-type
188                        endif
189                        break
190                case "NG5":
191                        if(cmpstr(detStr, "ILL   ") == 0 )
192                                DDet= PixelResNG5_ILL
193                        else
194                                DDet = PixelResNG5_ORNL //detector is ordella-type
195                        endif
196                        break
197                case "NG7":
198                        if(cmpstr(detStr, "ILL   ") == 0 )
199                                DDet= PixelResNG7_ILL
200                        else
201                                DDet = PixelResNG7_ORNL //detector is ordella-type
202                        endif
203                        break
204                default:                                                       
205                        //return error?
206                        DDet = PixelResDefault  //0.5 cm, typical for new ORNL detectors
207        endswitch
208       
209        return(DDet)
210End
211
212//Utility function that returns the detector deadtime (in seconds)
213//Global values are set in the Initialize procedure
214//
215// - called by WorkFileUtils.ipf
216//
217// fileStr is passed as TextRead[3]
218// detStr is passed as TextRead[9]
219//
220Function DetectorDeadtime(fileStr,detStr)
221        String fileStr,detStr
222       
223        Variable deadtime
224        String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)
225       
226        NVAR DeadtimeNG3_ILL = root:myGlobals:DeadtimeNG3_ILL           //pixel resolution in cm
227        NVAR DeadtimeNG5_ILL = root:myGlobals:DeadtimeNG5_ILL
228        NVAR DeadtimeNG7_ILL = root:myGlobals:DeadtimeNG7_ILL
229        NVAR DeadtimeNG3_ORNL = root:myGlobals:DeadtimeNG3_ORNL
230        NVAR DeadtimeNG5_ORNL = root:myGlobals:DeadtimeNG5_ORNL
231        NVAR DeadtimeNG7_ORNL = root:myGlobals:DeadtimeNG7_ORNL
232        NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault
233       
234        strswitch(instr)
235                case "NG3":
236                        if(cmpstr(detStr, "ILL   ") == 0 )
237                                deadtime= DeadtimeNG3_ILL
238                        else
239                                deadtime = DeadtimeNG3_ORNL     //detector is ordella-type
240                        endif
241                        break
242                case "NG5":
243                        if(cmpstr(detStr, "ILL   ") == 0 )
244                                deadtime= DeadtimeNG5_ILL
245                        else
246                                deadtime = DeadtimeNG5_ORNL     //detector is ordella-type
247                        endif
248                        break
249                case "NG7":
250                        if(cmpstr(detStr, "ILL   ") == 0 )
251                                deadtime= DeadtimeNG7_ILL
252                        else
253                                deadtime = DeadtimeNG7_ORNL     //detector is ordella-type
254                        endif
255                        break
256                default:                                                       
257                        //return error?
258                        deadtime = DeadtimeDefault      //1e-6 seconds, typical for new ORNL detectors
259        endswitch
260       
261        return(deadtime)
262End
263
264
265/////VAX filename/Run number parsing utilities
266//
267// a collection of uilities for processing vax filenames
268//and processing lists (especially for display in popup menus)
269//
270//required to correctly account for VAX supplied version numbers, which
271//may or may not be removed by the ftp utility
272//
273// - parses lists of run numbers into real filenames
274// - selects proper detector constants
275//
276//**************************
277//
278//given a filename of a SANS data filename of the form
279//TTTTTnnn.SAn_TTT_Txxx
280//returns the run number "nnn" as a number
281//returns -1 as an invalid file number
282//
283// called by several ipfs
284//
285//
286Function GetRunNumFromFile(item)
287        String item
288        Variable invalid = -1   //negative numbers are invalid
289        Variable num=-1
290       
291        //find the "dot"
292        String runStr=""
293        Variable pos = strsearch(item,".",0)
294        if(pos == -1)
295                //"dot" not found
296                return (invalid)
297        else
298                //found, get the three characters preceeding it
299                if (pos <=2)
300                        //not enough characters
301                        return (invalid)
302                else
303                        runStr = item[pos-3,pos-1]
304                        //convert to a number
305                        num = str2num(runStr)
306                        //if valid, return it
307                        if (num == NaN)
308                                //3 characters were not a number
309                                return (invalid)
310                        else
311                                //run was OK
312                                return (num)
313                        Endif
314                Endif
315        Endif
316End
317
318//given a filename of a SANS data filename of the form
319//TTTTTnnn.SAn_TTT_Txxx
320//returns the run number "nnn" as a STRING of THREE characters
321//returns "ABC" as an invalid file number
322//
323// local function to aid in locating files by run number
324//
325Function/S GetRunNumStrFromFile(item)
326        String item
327        String invalid = "ABC"  //"ABC" is not a valid run number, since it's text
328        Variable num=-1
329       
330        //find the "dot"
331        String runStr=""
332        Variable pos = strsearch(item,".",0)
333        if(pos == -1)
334                //"dot" not found
335                return (invalid)
336        else
337                //found, get the three characters preceeding it
338                if (pos <=2)
339                        //not enough characters
340                        return (invalid)
341                else
342                        runStr = item[pos-3,pos-1]
343                        return (runStr)
344                Endif
345        Endif
346End
347
348//returns a string containing the full path to the file containing the
349//run number "num". The null string is returned if no valid file can be found
350//the path "catPathName" used and is hard-wired, will abort if this path does not exist
351//the file returned will be a RAW SANS data file, other types of files are
352//filtered out.
353//
354// called by Buttons.ipf and Transmission.ipf, and locally by parsing routines
355//
356Function/S FindFileFromRunNumber(num)
357        Variable num
358       
359        String fullName="",partialName="",item=""
360        //get list of raw data files in folder that match "num" (add leading zeros)
361        if( (num>999) || (num<=0) )
362                //Print "error in  FindFileFromRunNumber(num), file number too large or too small"
363                Return ("")
364        Endif
365        //make a three character string of the run number
366        String numStr=""
367        if(num<10)
368                numStr = "00"+num2str(num)
369        else
370                if(num<100)
371                        numStr = "0"+num2str(num)
372                else
373                        numStr = num2str(num)
374                Endif
375        Endif
376        //Print "numstr = ",numstr
377       
378        //make sure that path exists
379        PathInfo catPathName
380        String path = S_path
381        if (V_flag == 0)
382                Abort "folder path does not exist - use Pick Path button"
383        Endif
384        String list="",newList="",testStr=""
385       
386        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
387        //find (the) one with the number in the run # location in the name
388        Variable numItems,ii,runFound,isRAW
389        numItems = ItemsInList(list,";")                //get the new number of items in the list
390        ii=0
391        do
392                //parse through the list in this order:
393                // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy"
394                // 2 - exclude by isRaw? (to minimize disk access)
395                item = StringFromList(ii, list  ,";" )
396                if(strlen(item) != 0)
397                        //find the run number, if it exists as a three character string
398                        testStr = GetRunNumStrFromFile(item)
399                        runFound= cmpstr(numStr,testStr)        //compare the three character strings, 0 if equal
400                        if(runFound == 0)
401                                //the run Number was found
402                                //build valid filename
403                                partialName = FindValidFileName(item)
404                                if(strlen(partialName) != 0)            //non-null return from FindValidFileName()
405                                        fullName = path + partialName
406                                        //check if RAW, if so,this must be the file!
407                                        isRAW = CheckIfRawData(fullName)
408                                        if(isRaw)
409                                                //stop here
410                                                return(fullname)
411                                        Endif
412                                Endif
413                        Endif
414                Endif
415                ii+=1
416        while(ii<numItems)              //process all items in list
417        Return ("")     //null return if file not found in list
418End
419
420//function to test a binary file to see if it is a RAW binary SANS file
421//first checks the total bytes in the file (which for raw data is 33316 bytes)
422//**note that the "DIV" file will also show up as a raw file by the run field
423//should be listed in CAT/SHORT and in patch windows
424//
425//Function then checks the file fname (full path:file) for "RAW" run.type field
426//if not found, the data is not raw data and zero is returned
427//
428// called by many procedures (both external and local)
429//
430Function CheckIfRawData(fname)
431        String fname
432       
433        Variable refnum,totalBytes
434        String testStr=""
435       
436        Open/R/T="????TEXT" refNum as fname
437        //get the total number of bytes in the file
438        FStatus refNum
439        totalBytes = V_logEOF
440        //Print totalBytes
441        if(totalBytes < 100)
442                Close refNum
443                return(0)               //not a raw file
444        endif
445        FSetPos refNum,75
446        FReadLine/N=3 refNum,testStr
447        Close refNum
448       
449        if(totalBytes == 33316 && cmpstr(testStr,"RAW")==0)
450                //true, is raw data file
451                Return(1)
452        else
453                //some other file
454                Return(0)
455        Endif
456End
457
458//function to check the header of a raw data file (full path specified by fname)
459//checks the field of the x-position of the beamstop during data collection
460//if the x-position is more negative (farther to the left) than xTol(input)
461//the the beamstop is "out" and the file is a transmission run and not a scattering run
462//xtol typically set at -5 (cm) - trans runs have bs(x) at -10 to -15 cm
463// function returns 1 if beamstop is out, 0 if beamstop is in
464//
465// tolerance is set as a global value "root:myGlobals:BeamstopXTol"
466//
467// called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf
468//
469Function isTransFile(fName)
470        String fname
471       
472        Variable refnum,xpos
473        NVAR xTol = root:myGlobals:BeamstopXTol
474       
475        //pos = 369, read one real value
476       
477        SetDataFolder root:
478        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
479        String strToExecute=""
480        // 1 R*4 value
481        strToExecute = GBLoadStr + "/S=368/U=1" + "\"" + fname + "\""
482        Execute strToExecute
483        Wave w=$"root:tempGBWave0"
484        xPos = w[0]
485        KillWaves/Z w
486        //Print "xPos = ",xpos
487       
488        if(xpos<=xTol)
489                //xpos is farther left (more negative) than xtol (currently -5 cm)
490                Return(1)
491        else
492                //some other file
493                Return(0)
494        Endif
495End
496
497
498//function to remove all spaces from names when searching for filenames
499//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
500//but the text field in the header WILL, if less than 3 characters were used for the
501//user's initials, and can have leading spaces if prefix was less than 5 characters
502//
503//returns a string identical to the original string, except with the interior spaces removed
504//
505// local function for file name manipulation
506//
507Function/S RemoveAllSpaces(str)
508        String str
509       
510        String tempstr = str
511        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
512        ii=0
513        do
514                len = strlen(tempStr)
515                spc = strsearch(tempStr," ",0)          //is the last character a space?
516                if (spc == -1)
517                        break           //no more spaces found, get out
518                endif
519                str = tempstr
520                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
521        While(1)        //should never be more than 2 or 3
522       
523        If(strlen(tempStr) < 1)
524                tempStr = ""            //be sure to return a null string if problem found
525        Endif
526       
527        //Print strlen(tempstr)
528       
529        Return(tempStr)
530               
531End
532
533
534//Function attempts to find valid filename from partial name by checking for
535// the existence of the file on disk.
536// - checks as is
537// - adds ";vers" for possible VAX files
538// - strips spaces
539// - permutations of upper/lowercase
540//
541// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
542// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
543// upper/lowercase letters, while the filename on the server (should) be all caps
544// now makes repeated calls to ValidFileString()
545//
546// returns a valid filename (No path prepended) or a null string
547//
548// called by any functions, both external and local
549//
550Function/S FindValidFilename(partialName)
551        String PartialName
552       
553        String retStr=""
554       
555        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
556        retStr = ValidFileString(partialName)
557        if(cmpstr(retStr,"") !=0)
558                //non-null return
559                return(retStr)
560        Endif
561       
562        //if the partial name is derived from the file header, there can be spaces at the beginning
563        //or in the middle of the filename - depending on the prefix and initials used
564        //
565        //remove any leading spaces from the name before starting
566        partialName = RemoveAllSpaces(partialName)
567       
568        //try name with no spaces
569        retStr = ValidFileString(partialName)
570        if(cmpstr(retStr,"") !=0)
571                //non-null return
572                return(retStr)
573        Endif
574       
575        //try all UPPERCASE
576        partialName = UpperStr(partialName)
577        retStr = ValidFileString(partialName)
578        if(cmpstr(retStr,"") !=0)
579                //non-null return
580                return(retStr)
581        Endif
582       
583        //try all lowercase (ret null if failure)
584        partialName = LowerStr(partialName)
585        retStr = ValidFileString(partialName)
586        if(cmpstr(retStr,"") !=0)
587                //non-null return
588                return(retStr)
589        else
590                return(retStr)
591        Endif
592End
593
594// Function checks for the existence of a file
595// partialName;vers (to account for VAX filenaming conventions)
596// The partial name is tried first with no version number
597//
598// *** the PATH is hard-wired to catPathName (which is assumed to exist)
599// version numers up to ;10 are tried
600// only the "name;vers" is returned if successful. The path is not prepended
601//
602// local function
603//
604Function/S ValidFileString(partialName)
605        String partialName
606       
607        String tempName = "",msg=""
608        Variable ii,refnum
609       
610        ii=0
611        do
612                if(ii==0)
613                        //first pass, try the partialName
614                        tempName = partialName
615                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
616                        if(V_flag == 0)
617                                //file exists
618                                Close refnum            //YES needed,
619                                break
620                        endif
621                else
622                        tempName = partialName + ";" + num2str(ii)
623                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
624                        if(V_flag == 0)
625                                //file exists
626                                Close refnum
627                                break
628                        endif
629                Endif
630                ii+=1
631                //print "ii=",ii
632        while(ii<11)
633        //go get the selected bits of information, using tempName, which exists
634        if(ii>=11)
635                //msg = partialName + " not found. is version number > 11?"
636                //DoAlert 0, msg
637                //PathInfo catPathName
638                //Print S_Path
639                Return ("")             //use null string as error condition
640        Endif
641       
642        Return (tempName)
643End
644
645//returns a string containing filename (WITHOUT the ;vers)
646//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
647//with the folders separated by colons
648//
649// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf
650//
651Function/S GetFileNameFromPathNoSemi(fullPath)
652        String fullPath
653       
654        Variable offset1,offset2
655        String filename=""
656        //String PartialPath
657        offset1 = 0
658        do
659                offset2 = StrSearch(fullPath, ":", offset1)
660                if (offset2 == -1)                              // no more colons ?
661                        fileName = FullPath[offset1,strlen(FullPath) ]
662                        //PartialPath = FullPath[0, offset1-1]
663                        break
664                endif
665                offset1 = offset2+1
666        while (1)
667       
668        //remove version number from name, if it's there - format should be: filename;N
669        filename =  StringFromList(0,filename,";")              //returns null if error
670       
671        Return filename
672End
673
674//returns a string containing filename (INCLUDING the ;vers)
675//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
676//with the folders separated by colons
677//
678// local, currently unused
679//
680Function/S GetFileNameFromPathKeepSemi(fullPath)
681        String fullPath
682       
683        Variable offset1,offset2
684        String filename
685        //String PartialPath
686        offset1 = 0
687        do
688                offset2 = StrSearch(fullPath, ":", offset1)
689                if (offset2 == -1)                              // no more colons ?
690                        fileName = FullPath[offset1,strlen(FullPath) ]
691                        //PartialPath = FullPath[0, offset1-1]
692                        break
693                endif
694                offset1 = offset2+1
695        while (1)
696       
697        //keep version number from name, if it's there - format should be: filename;N
698       
699        Return filename
700End
701
702//given the full path and filename (fullPath), strips the data path
703//(Mac-style, separated by colons) and returns this path
704//this partial path is the same string that would be returned from PathInfo, for example
705//
706// - allows the user to save to a different path than catPathName
707//
708// called by WriteQIS.ipf
709//
710Function/S GetPathStrFromfullName(fullPath)
711        String fullPath
712       
713        Variable offset1,offset2
714        //String filename
715        String PartialPath
716        offset1 = 0
717        do
718                offset2 = StrSearch(fullPath, ":", offset1)
719                if (offset2 == -1)                              // no more colons ?
720                        //fileName = FullPath[offset1,strlen(FullPath) ]
721                        PartialPath = FullPath[0, offset1-1]
722                        break
723                endif
724                offset1 = offset2+1
725        while (1)
726       
727        Return PartialPath
728End
729
730//given the VAX filename, pull off the first 8 characters to make a valid
731//file string that can be used for naming averaged 1-d files
732//
733// called by ProtocolAsPanel.ipf and Tile_2D.ipf
734//
735Function/S GetNameFromHeader(fullName)
736        String fullName
737        String temp, newName = ""
738        Variable spc,ii=0
739       
740        //filename is 20 characters NNNNNxxx.SAn_NNN_NNN
741        //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning
742        //NNNNN was entered as less than 5 characters
743        //returns a null string if no name can be found
744        do
745                temp = fullname[ii,7]           //characters ii,7 of the name
746                spc = strsearch(temp," ",0)
747                if (spc == -1)
748                        break           //no more spaces found
749                endif
750                ii+=1
751        While(ii<8)
752       
753        If(strlen(temp) < 1)
754                newName = ""            //be sure to return a null string if problem found
755        else
756                newName = temp
757        Endif
758       
759        Return(newName)
760End
761
762//list (input) is a list, typically returned from IndexedFile()
763//which is semicolon-delimited, and may contain filenames from the VAX
764//that contain version numbers, where the version number appears as a separate list item
765//(and also as a non-existent file)
766//these numbers must be purged from the list, especially for display in a popup
767//or list processing of filenames
768//the function returns the list, cleaned of version numbers (up to 11)
769//raw data files will typically never have a version number other than 1.
770//
771// if there are no version numbers in the list, the input list is returned
772//
773// called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf
774//
775Function/S RemoveVersNumsFromList(list)
776        String list
777       
778        //get rid of version numbers first (up to 11)
779        Variable ii,num
780        String item
781        num = ItemsInList(list,";")
782        ii=1
783        do
784                item = num2str(ii)
785                list = RemoveFromList(item, list ,";" )
786                ii+=1
787        while(ii<12)
788       
789        return (list)
790End
791
792//input is a list of run numbers, and output is a list of filenames (not the full path)
793//*** input list must be COMMA delimited***
794//output is equivalent to selecting from the CAT table
795//if some or all of the list items are valid filenames, keep them...
796//if an error is encountered, notify of the offending element and return a null list
797//
798//output is COMMA delimited
799//
800// this routine is expecting that the "ask", "none" special cases are handled elsewhere
801//and not passed here
802//
803// called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf
804//
805Function/S ParseRunNumberList(list)
806        String list
807       
808        String newList="",item="",tempStr=""
809        Variable num,ii,runNum
810       
811        //expand number ranges, if any
812        list = ExpandNumRanges(list)
813       
814        num=itemsinlist(list,",")
815       
816        for(ii=0;ii<num;ii+=1)
817                //get the item
818                item = StringFromList(ii,list,",")
819                //is it already a valid filename?
820                tempStr=FindValidFilename(item) //returns filename if good, null if error
821                if(strlen(tempstr)!=0)
822                        //valid name, add to list
823                        //Print "it's a file"
824                        newList += tempStr + ","
825                else
826                        //not a valid name
827                        //is it a number?
828                        runNum=str2num(item)
829                        //print runnum
830                        if(numtype(runNum) != 0)
831                                //not a number -  maybe an error                       
832                                DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename."
833                                return("")
834                        else
835                                //a run number or an error
836                                tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) )
837                                if(strlen(tempstr)==0)
838                                        //file not found, error
839                                        DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number."
840                                        return("")
841                                else
842                                        newList += tempStr + ","
843                                endif
844                        endif
845                endif
846        endfor          //loop over all items in list
847       
848        return(newList)
849End
850
851//takes a comma delimited list that MAY contain number range, and
852//expands any range of run numbers into a comma-delimited list...
853//and returns the new list - if not a range, return unchanged
854//
855// local function
856//
857Function/S ExpandNumRanges(list)
858        String list
859       
860        String newList="",dash="-",item,str
861        Variable num,ii,hasDash
862       
863        num=itemsinlist(list,",")
864//      print num
865        for(ii=0;ii<num;ii+=1)
866                //get the item
867                item = StringFromList(ii,list,",")
868                //does it contain a dash?
869                hasDash = strsearch(item,dash,0)                //-1 if no dash found
870                if(hasDash == -1)
871                        //not a range, keep it in the list
872                        newList += item + ","
873                else
874                        //has a dash (so it's a range), expand (or add null)
875                        newList += ListFromDash(item)           
876                endif
877        endfor
878       
879        return newList
880End
881
882//be sure to add a trailing comma to the return string...
883//
884// local function
885//
886Function/S ListFromDash(item)
887        String item
888       
889        String numList="",loStr="",hiStr=""
890        Variable lo,hi,ii
891       
892        loStr=StringFromList(0,item,"-")        //treat the range as a list
893        hiStr=StringFromList(1,item,"-")
894        lo=str2num(loStr)
895        hi=str2num(hiStr)
896        if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) )
897                numList=""
898                return numList
899        endif
900        for(ii=lo;ii<=hi;ii+=1)
901                numList += num2str(ii) + ","
902        endfor
903       
904        Return numList
905End
906
907
908////////Transmission
909//******************
910//lookup tables for attenuator transmissions
911//NG3 and NG7 attenuators are physically different, so the transmissions are slightly different
912//NG1 - (8m SANS) is not supported
913//
914// new calibration done June 2007, John Barker
915//
916Proc MakeNG3AttenTable()
917
918        NewDataFolder/O root:myGlobals:Attenuators
919        //do explicitly to avoid data folder problems, redundant, but it must work without fail
920        Variable num=10         //10 needed for tables after June 2007
921
922        Make/O/N=(num) root:myGlobals:Attenuators:ng3att0
923        Make/O/N=(num) root:myGlobals:Attenuators:ng3att1
924        Make/O/N=(num) root:myGlobals:Attenuators:ng3att2
925        Make/O/N=(num) root:myGlobals:Attenuators:ng3att3
926        Make/O/N=(num) root:myGlobals:Attenuators:ng3att4
927        Make/O/N=(num) root:myGlobals:Attenuators:ng3att5
928        Make/O/N=(num) root:myGlobals:Attenuators:ng3att6
929        Make/O/N=(num) root:myGlobals:Attenuators:ng3att7
930        Make/O/N=(num) root:myGlobals:Attenuators:ng3att8
931        Make/O/N=(num) root:myGlobals:Attenuators:ng3att9
932        Make/O/N=(num) root:myGlobals:Attenuators:ng3att10
933       
934        //each wave has 10 elements, the transmission of att# at the wavelengths
935        //lambda = 4,5,6,7,8,10,12,14,17,20 (4 A and 20 A are extrapolated values)
936        Make/O/N=(num) root:myGlobals:Attenuators:ng3lambda={4,5,6,7,8,10,12,14,17,20}
937       
938        // new calibration done June 2007, John Barker
939        root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
940        root:myGlobals:Attenuators:ng3att1 = {0.444784,0.419,0.3935,0.3682,0.3492,0.3132,0.2936,0.2767,0.2477,0.22404}
941        root:myGlobals:Attenuators:ng3att2 = {0.207506,0.1848,0.1629,0.1447,0.1292,0.1056,0.09263,0.08171,0.06656,0.0546552}
942        root:myGlobals:Attenuators:ng3att3 = {0.092412,0.07746,0.06422,0.05379,0.04512,0.03321,0.02707,0.02237,0.01643,0.0121969}
943        root:myGlobals:Attenuators:ng3att4 = {0.0417722,0.03302,0.02567,0.02036,0.01604,0.01067,0.00812,0.006316,0.00419,0.00282411}
944        root:myGlobals:Attenuators:ng3att5 = {0.0187129,0.01397,0.01017,0.007591,0.005668,0.003377,0.002423,0.001771,0.001064,0.000651257}
945        root:myGlobals:Attenuators:ng3att6 = {0.00851048,0.005984,0.004104,0.002888,0.002029,0.001098,0.0007419,0.0005141,0.000272833,0.000150624}
946        root:myGlobals:Attenuators:ng3att7 = {0.00170757,0.001084,0.0006469,0.0004142,0.0002607,0.0001201,7.664e-05,4.06624e-05,1.77379e-05,7.30624e-06}
947        root:myGlobals:Attenuators:ng3att8 = {0.000320057,0.0001918,0.0001025,6.085e-05,3.681e-05,1.835e-05,6.74002e-06,3.25288e-06,1.15321e-06,3.98173e-07}
948        root:myGlobals:Attenuators:ng3att9 = {6.27682e-05,3.69e-05,1.908e-05,1.196e-05,8.738e-06,6.996e-06,6.2901e-07,2.60221e-07,7.49748e-08,2.08029e-08}
949        root:myGlobals:Attenuators:ng3att10 = {1.40323e-05,8.51e-06,5.161e-06,4.4e-06,4.273e-06,1.88799e-07,5.87021e-08,2.08169e-08,4.8744e-09,1.08687e-09}
950 
951  //old tables, pre-June 2007
952//      Make/O/N=9 root:myGlobals:Attenuators:ng3lambda={5,6,7,8,10,12,14,17,20}
953//      root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1,1 }
954//      root:myGlobals:Attenuators:ng3att1 = {0.421, 0.394, 0.371, 0.349, 0.316, 0.293, 0.274, 0.245,0.220}
955//      root:myGlobals:Attenuators:ng3att2 = {0.187, 0.164, 0.145, 0.130, 0.106, 0.0916, 0.0808, 0.0651,0.0531}
956//      root:myGlobals:Attenuators:ng3att3 = {0.0777, 0.0636, 0.0534, 0.0446, 0.0330, 0.0262, 0.0217, 0.0157 ,0.0116}
957//      root:myGlobals:Attenuators:ng3att4 = {0.0328, 0.0252, 0.0195, 0.0156, 0.0104, 7.68e-3, 5.98e-3, 3.91e-3,0.00262}
958//      root:myGlobals:Attenuators:ng3att5 = {0.0139, 9.94e-3, 7.34e-3, 5.44e-3, 3.29e-3, 2.25e-3, 1.66e-3, 9.95e-4, 6.12e-4}
959//      root:myGlobals:Attenuators:ng3att6 = {5.95e-3, 3.97e-3, 2.77e-3, 1.95e-3, 1.06e-3, 6.81e-4, 4.71e-4, 2.59e-4 , 1.45e-4}
960//      root:myGlobals:Attenuators:ng3att7 = {1.07e-3, 6.24e-4, 3.90e-4, 2.44e-4, 1.14e-4, 6.55e-5, 4.10e-5, 1.64e-5 , 7.26e-6}
961//      root:myGlobals:Attenuators:ng3att8 = {1.90e-4, 9.84e-5, 5.60e-5, 3.25e-5, 1.55e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7}
962//      root:myGlobals:Attenuators:ng3att9 = {3.61e-5, 1.74e-5, 9.90e-6, 6.45e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8}
963//      root:myGlobals:Attenuators:ng3att10 = {7.60e-6, 3.99e-6, 2.96e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9 , 8.60e-10}
964
965End
966
967// new calibration done June 2007, John Barker
968Proc MakeNG7AttenTable()
969
970        NewDataFolder/O root:myGlobals:Attenuators
971       
972        Variable num=10         //10 needed for tables after June 2007
973       
974        Make/O/N=(num) root:myGlobals:Attenuators:ng7att0
975        Make/O/N=(num) root:myGlobals:Attenuators:ng7att1
976        Make/O/N=(num) root:myGlobals:Attenuators:ng7att2
977        Make/O/N=(num) root:myGlobals:Attenuators:ng7att3
978        Make/O/N=(num) root:myGlobals:Attenuators:ng7att4
979        Make/O/N=(num) root:myGlobals:Attenuators:ng7att5
980        Make/O/N=(num) root:myGlobals:Attenuators:ng7att6
981        Make/O/N=(num) root:myGlobals:Attenuators:ng7att7
982        Make/O/N=(num) root:myGlobals:Attenuators:ng7att8
983        Make/O/N=(num) root:myGlobals:Attenuators:ng7att9
984        Make/O/N=(num) root:myGlobals:Attenuators:ng7att10
985       
986        //NG7 wave has 10 elements, the transmission of att# at the wavelengths
987        //lambda =4, 5,6,7,8,10,12,14,17,20
988        // note that some of the higher attenuations and ALL of the 4 A and 20A data is interpolated
989        // none of these values are expected to be used in reality since the flux would be too low in practice
990        Make/O/N=(num) root:myGlobals:Attenuators:ng7lambda={4,5,6,7,8,10,12,14,17,20}
991
992// New calibration, June 2007, John Barker
993        root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1,1}     
994        root:myGlobals:Attenuators:ng7att1 = {0.448656,0.4192,0.3925,0.3661,0.3458,0.3098,0.2922,0.2738,0.2544,0.251352}
995        root:myGlobals:Attenuators:ng7att2 = {0.217193,0.1898,0.1682,0.148,0.1321,0.1076,0.0957,0.08485,0.07479,0.0735965}
996        root:myGlobals:Attenuators:ng7att3 = {0.098019,0.07877,0.06611,0.05429,0.04548,0.03318,0.02798,0.0234,0.02004,0.0202492}
997        root:myGlobals:Attenuators:ng7att4 = {0.0426904,0.03302,0.02617,0.02026,0.0158,0.01052,0.008327,0.006665,0.005745,0.00524807}
998        root:myGlobals:Attenuators:ng7att5 = {0.0194353,0.01398,0.01037,0.0075496,0.005542,0.003339,0.002505,0.001936,0.001765,0.00165959}
999        root:myGlobals:Attenuators:ng7att6 = {0.00971666,0.005979,0.004136,0.002848,0.001946,0.001079,0.0007717,0.000588,0.000487337,0.000447713}
1000        root:myGlobals:Attenuators:ng7att7 = {0.00207332,0.001054,0.0006462,0.0003957,0.0002368,0.0001111,7.642e-05,4.83076e-05,3.99401e-05,3.54814e-05}
1001        root:myGlobals:Attenuators:ng7att8 = {0.000397173,0.0001911,0.0001044,5.844e-05,3.236e-05,1.471e-05,6.88523e-06,4.06541e-06,3.27333e-06,2.81838e-06}
1002        root:myGlobals:Attenuators:ng7att9 = {9.43625e-05,3.557e-05,1.833e-05,1.014e-05,6.153e-06,1.64816e-06,6.42353e-07,3.42132e-07,2.68269e-07,2.2182e-07}
1003        root:myGlobals:Attenuators:ng7att10 = {2.1607e-05,7.521e-06,2.91221e-06,1.45252e-06,7.93451e-07,1.92309e-07,5.99279e-08,2.87928e-08,2.19862e-08,1.7559e-08}
1004
1005// Pre-June 2007 calibration values - do not use these anymore 
1006////    root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1}
1007////    root:myGlobals:Attenuators:ng7att1 = {0.418, 0.393, 0.369, 0.347, 0.313, 0.291, 0.271, 0.244, 0.219 }
1008////    root:myGlobals:Attenuators:ng7att2 = {0.189, 0.167, 0.148, 0.132, 0.109, 0.0945, 0.0830, 0.0681, 0.0560}
1009////    root:myGlobals:Attenuators:ng7att3 = {0.0784, 0.0651, 0.0541, 0.0456, 0.0340, 0.0273, 0.0223, 0.0164 , 0.0121}
1010////    root:myGlobals:Attenuators:ng7att4 = {0.0328, 0.0256, 0.0200, 0.0159, 0.0107, 7.98e-3, 6.14e-3, 4.09e-3 , 0.00274}
1011////    root:myGlobals:Attenuators:ng7att5 = {0.0139, 0.0101, 7.43e-3, 5.58e-3, 3.42e-3, 2.36e-3, 1.70e-3, 1.03e-3 , 6.27e-4}
1012////    root:myGlobals:Attenuators:ng7att6 = {5.90e-3, 4.07e-3, 2.79e-3, 1.99e-3, 1.11e-3, 7.13e-4, 4.91e-4, 2.59e-4 , 1.42e-4}
1013////    root:myGlobals:Attenuators:ng7att7 = {1.04e-3, 6.37e-4, 3.85e-4, 2.46e-4, 1.16e-4, 6.86e-5, 4.10e-5, 1.64e-5 ,7.02e-6}
1014////    root:myGlobals:Attenuators:ng7att8 = {1.90e-4, 1.03e-4, 5.71e-5, 3.44e-5, 1.65e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7}
1015////    root:myGlobals:Attenuators:ng7att9 = {3.58e-5, 1.87e-5, 1.05e-5, 7.00e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8}
1016////    root:myGlobals:Attenuators:ng7att10 = {7.76e-6, 4.56e-6, 3.25e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9, 8.60e-10}
1017End
1018
1019//returns the transmission of the attenuator (at NG3) given the attenuator number
1020//which must be an integer(to select the wave) and given the wavelength.
1021//the wavelength may be any value between 4 and 20 (A), and is interpolated
1022//between calibrated wavelengths for a given attenuator
1023//
1024//
1025Function LookupAttenNG3(lambda,attenNo)
1026        Variable lambda, attenNo
1027       
1028        Variable trans
1029        String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(attenNo))
1030        String lamStr = "root:myGlobals:Attenuators:ng3lambda"
1031       
1032        if(attenNo == 0)
1033                return (1)              //no attenuation, return trans == 1
1034        endif
1035       
1036        if( (lambda < 4) || (lambda > 20 ) )
1037                Abort "Wavelength out of calibration range (4,20). You must manually enter the absolute parameters"
1038        Endif
1039       
1040        if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )
1041                Execute "MakeNG3AttenTable()"
1042        Endif
1043        //just in case creating the tables fails....
1044        if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )
1045                Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters"
1046        Endif
1047       
1048        //lookup the value by interpolating the wavelength
1049        //the attenuator must always be an integer
1050        Wave att = $attStr
1051        Wave lam = $lamstr
1052        trans = interp(lambda,lam,att)
1053       
1054//      Print "trans = ",trans
1055       
1056        return trans
1057End
1058
1059//returns the transmission of the attenuator (at NG7) given the attenuator number
1060//which must be an integer(to select the wave) and given the wavelength.
1061//the wavelength may be any value between 4 and 20 (A), and is interpolated
1062//between calibrated wavelengths for a given attenuator
1063//
1064// this set of tables is also used for NG5 (NG1) SANS instrument - as the attenuator has never been calibrated
1065//
1066// local function
1067//
1068Function LookupAttenNG7(lambda,attenNo)
1069        Variable lambda, attenNo
1070       
1071        Variable trans
1072        String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(attenNo))
1073        String lamStr = "root:myGlobals:Attenuators:ng7lambda"
1074       
1075        if(attenNo == 0)
1076                return (1)              //no attenuation, return trans == 1
1077        endif
1078       
1079        if( (lambda < 4) || (lambda > 20 ) )
1080                Abort "Wavelength out of calibration range (4,20). You must manually enter the absolute parameters"
1081        Endif
1082       
1083        if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )
1084                Execute "MakeNG7AttenTable()"
1085        Endif
1086        //just in case creating the tables fails....
1087        if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )
1088                Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters"
1089        Endif
1090       
1091        //lookup the value by interpolating the wavelength
1092        //the attenuator must always be an integer
1093        Wave att = $attStr
1094        Wave lam = $lamstr
1095        trans = interp(lambda,lam,att)
1096       
1097        //Print "trans = ",trans
1098       
1099        return trans
1100
1101End
1102
1103//returns the proper attenuation factor based on the instrument (NG3, NG5, or NG7)
1104//NG5 values are taken from the NG7 tables (there is very little difference in the
1105//values, and NG5 attenuators have not been calibrated (as of 8/01)
1106//
1107// filestr is passed from TextRead[3] = the default directory
1108// lam is passed from RealsRead[26]
1109// AttenNo is passed from ReaslRead[3]
1110//
1111// Attenuation factor as defined here is <= 1
1112//
1113// ORNL can pass ("",1,attenuationFactor) and have this function simply
1114// spit back the attenuationFactor (that was read into rw[3])
1115//
1116// called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf
1117//
1118Function AttenuationFactor(fileStr,lam,attenNo)
1119        String fileStr
1120        Variable lam,attenNo
1121       
1122        Variable attenFactor=1,loc
1123        String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)
1124       
1125        strswitch(instr)
1126                case "NG3":
1127                        attenFactor = LookupAttenNG3(lam,attenNo)
1128                        break
1129                case "NG5":
1130                        //using NG7 lookup Table
1131                        attenFactor = LookupAttenNG7(lam,attenNo)
1132                        break
1133                case "NG7":
1134                        attenFactor = LookupAttenNG7(lam,attenNo)
1135                        break
1136                default:                                                       
1137                        //return error?
1138                        attenFactor=1
1139        endswitch
1140//      print "instr, lambda, attenNo,attenFactor = ",instr,lam,attenNo,attenFactor
1141        return(attenFactor)
1142End
1143
1144//function called by the popups to get a file list of data that can be sorted
1145// this procedure simply removes the raw data files from the string - there
1146//can be lots of other junk present, but this is very fast...
1147//
1148// could also use the alternate procedure of keeping only file with the proper extension
1149//
1150// another possibility is to get a listing of the text files, but is unreliable on
1151// Windows, where the data file must be .txt (and possibly OSX)
1152//
1153// called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf
1154//
1155Function/S ReducedDataFileList(ctrlName)
1156        String ctrlName
1157
1158        String list="",newList="",item=""
1159        Variable num,ii
1160       
1161        //check for the path
1162        PathInfo catPathName
1163        if(V_Flag==0)
1164                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
1165                Return("")
1166        Endif
1167       
1168        list = IndexedFile(catpathName,-1,"????")
1169        num=ItemsInList(list,";")
1170        //print "num = ",num
1171        for(ii=(num-1);ii>=0;ii-=1)
1172                item = StringFromList(ii, list  ,";")
1173                //simply remove all that are not raw data files (SA1 SA2 SA3)
1174                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
1175                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
1176                                newlist += item + ";"
1177                        endif
1178                endif
1179        endfor
1180        //remove VAX version numbers
1181        newList = RemoveVersNumsFromList(newList)
1182        //sort
1183        newList = SortList(newList,";",0)
1184
1185        return newlist
1186End
1187
1188// returns a list of raw data files in the catPathName directory on disk
1189// - list is SEMICOLON-delimited
1190//
1191// does it the "cheap" way, simply finding the ".SAn" in the file name
1192// = does not check for proper byte length.
1193//
1194// called by PatchFiles.ipf, Tile_2D.ipf
1195//
1196Function/S GetRawDataFileList()
1197       
1198        //make sure that path exists
1199        PathInfo catPathName
1200        if (V_flag == 0)
1201                Abort "Folder path does not exist - use Pick Path button on Main Panel"
1202        Endif
1203       
1204        String list=IndexedFile(catPathName,-1,"????")
1205        String newList="",item=""
1206        Variable num=ItemsInList(list,";"),ii
1207        for(ii=0;ii<num;ii+=1)
1208                item = StringFromList(ii, list  ,";")
1209                if( stringmatch(item,"*.sa1*") )
1210                        newlist += item + ";"
1211                endif
1212                if( stringmatch(item,"*.sa2*") )
1213                        newlist += item + ";"
1214                endif
1215                if( stringmatch(item,"*.sa3*") )
1216                        newlist += item + ";"
1217                endif
1218                //print "ii=",ii
1219        endfor
1220        newList = SortList(newList,";",0)
1221        return(newList)
1222End
Note: See TracBrowser for help on using the repository browser.