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