source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_Utils.ipf @ 536

Last change on this file since 536 was 536, checked in by srkline, 14 years ago

July 22 version of Jae-Hie's changes to the HFIR reader

File size: 25.6 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// initializes globals that are specific to a particular facility
13// - number of XY pixels
14// - pixexl resolution [cm]
15// - detector deadtime constant [s]
16//
17// called by Initialize.ipf
18//
19Function InitFacilityGlobals()
20
21        //Detector -specific globals
22        Variable/G root:myGlobals:gNPixelsX=192                                 // number of detector X and Y pixels
23        Variable/G root:myGlobals:gNPixelsY=192
24       
25        // pixel dimensions are now read directly from the file header.
26        Variable/G root:myGlobals:PixelResDefault = 0.51        //pixel resolution in cm
27       
28        Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6              //deadtime in seconds?????????????????????????????????????????????????????????????????????
29
30        Variable/G root:myGlobals:apOff = 5.0           // (cm) distance from sample aperture to sample position???????????????????????????????????????????????????
31
32End
33
34
35//**********************
36// Resolution calculation - used by the averaging routines
37// to calculate the resolution function at each q-value
38// - the return value is not used
39//
40// equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR
41// Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114
42//
43// - 21 MAR 07 uses projected BS diameter on the detector
44// - APR 07 still need to add resolution with lenses. currently there is no flag in the
45//          raw data header to indicate the presence of lenses.
46//
47// - Aug 07 - added input to switch calculation based on lenses (==1 if in)
48//
49// - called by CircSectAvg.ipf and RectAnnulAvg.ipf
50//
51// passed values are read from RealsRead
52// except DDet and apOff, which are set from globals before passing
53//
54//
55Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,SigmaQ,QBar,fSubS)
56        Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses
57        Variable &fSubS, &QBar, &SigmaQ         //these are the output quantities at the input Q value
58       
59        //lots of calculation variables
60        Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g
61        Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r
62
63        //Constants
64        Variable vz_1 = 3.956e5         //velocity [cm/s] of 1 A neutron
65        Variable g = 981.0                              //gravity acceleration [cm/s^2]
66
67        String results
68        results ="Failure"
69
70        S1 *= 0.5*0.1                   //convert to radius and [cm]
71        S2 *= 0.5*0.1
72
73        L1 *= 100.0                     // [cm]
74        L1 -= apOff                             //correct the distance
75
76        L2 *= 100.0
77        L2 += apOff
78        del_r *= 0.1                            //width of annulus, convert mm to [cm]
79       
80        BS *= 0.5*0.1                   //nominal BS diameter passed in, convert to radius and [cm]
81        // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture
82        Variable LB
83        LB = 20.1 + 1.61*BS                     //distance in cm from beamstop to anode plane (empirical)
84        BS = bs + bs*lb/(l2-lb)         //adjusted diameter of shadow from parallax
85       
86        //Start resolution calculation
87        a2 = S1*L2/L1 + S2*(L1+L2)/L1
88        q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2)
89        lp = 1.0/( 1.0/L1 + 1.0/L2)
90
91        v_lambda = lambdaWidth^2/6.0
92       
93//      if(usingLenses==1)                      //SRK 2007
94        if(usingLenses != 0)                    //SRK 2008 allows for the possibility of different numbers of lenses in header
95                v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2         //correction to 2nd term
96        else
97                v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2              //original form
98        endif
99       
100        v_d = (DDet/2.3548)^2 + del_r^2/12.0
101        vz = vz_1 / lambda
102        yg = 0.5*g*L2*(L1+L2)/vz^2
103        v_g = 2.0*(2.0*yg^2*v_lambda)                                   //factor of 2 correction, B. Hammouda, 2007
104
105        r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) ))
106        delta = 0.5*(BS - r0)^2/v_d
107
108        if (r0 < BS)
109                inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta))
110        else
111                inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta))
112        endif
113
114        fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) )
115        if (fSubS <= 0.0)
116                fSubS = 1.e-10
117        endif
118        fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi))
119        fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d
120
121        rmd = fr*r0
122        v_r1 = v_b + fv*v_d +v_g
123
124        rm = rmd + 0.5*v_r1/rmd
125        v_r = v_r1 - 0.5*(v_r1/rmd)^2
126        if (v_r < 0.0)
127                v_r = 0.0
128        endif
129        QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2))
130        SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda)
131
132        results = "success"
133        Return results
134End
135
136//**********************
137// 2D resolution function calculation - in terms of X and Y
138//
139// see same-named function in NCNR_Utils
140//
141Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS)
142        Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist
143        Variable &SigmaQX,&SigmaQY,&fSubS               //these are the output quantities at the input Q value
144
145
146        String results = "success"
147        Return results
148End
149
150
151//Utility function that returns the detector resolution (in cm)
152//Global values are set in the Initialize procedure
153//
154// - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf
155//
156// fileStr is passed as TextRead[3] and is the filename
157// detStr is passed as TextRead[9] and is an identifier for the detector
158//
159// depricated - pixel dimensions are read directly from the file header
160Function xDetectorPixelResolution(fileStr,detStr)
161        String fileStr,detStr
162       
163        Variable DDet
164        NVAR PixelResDefault = root:myGlobals:PixelResDefault
165        //your code here
166        DDet = PixelResDefault  //0.515 cm, typical for new ORNL detectors
167        return(DDet)
168End
169
170//Utility function that returns the detector deadtime (in seconds)
171//Global values are set in the Initialize procedure
172//
173// - called by WorkFileUtils.ipf
174//
175// fileStr is passed as TextRead[3] and is the filename
176// detStr is passed as TextRead[9] and is an identifier for the detector
177//
178Function DetectorDeadtime(fileStr,detStr)
179        String fileStr,detStr
180       
181        Variable deadtime
182        NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault
183       
184        deadtime = DeadtimeDefault      //3.4e-6 seconds, typical for new ORNL detectors //???????????????????????????
185        return(deadtime)
186End
187
188
189
190// item is a filename
191//
192// this function extracts some sort of number from the file
193// presumably some sort of automatically incrementing run number set by the
194// acquisition system
195//
196// this run number should be a unique identifier for the file
197//
198Function GetRunNumFromFile(item)
199        String item
200        Variable invalid = -1   //negative numbers are invalid
201        Variable num=-1
202       
203        //find the "dot"
204        String runStr=""
205        Variable pos = strsearch(item,".",0)
206        if(pos == -1)
207                //"dot" not found
208                return (invalid)
209        else
210                //found, get the nine characters preceeding it
211                if (pos <=8)
212                        //not enough characters
213                        return (invalid)
214                else
215                        runStr = item[pos-9,pos-5]
216                        //convert to a number
217                        num = str2num(runStr)
218                        //if valid, return it
219                        if (num == NaN)
220                                //4 characters were not a number
221                                return (invalid)
222                        else
223                                //run was OK
224                                return (num)
225                        Endif
226                Endif
227        Endif
228End
229
230
231// item is a filename
232//
233// this function extracts some sort of number from the file
234// presumably some sort of automatically incrementing run number set by the
235// acquisition system
236//
237// this run number should be a unique identifier for the file
238//
239// same as GetRunNumFromFile(0), just with a string return
240//
241// "ABC" returned as an invalid result
242Function/S GetRunNumStrFromFile(item)
243        String item
244       
245        String invalid = "ABC"  //"ABC" is not a valid run number, since it's text
246        String retStr
247        retStr=invalid
248       
249        //your code here
250        //find the "dot"
251        Variable pos = strsearch( LowerStr(item),".xml",0)
252        if(pos == -1)
253                //"dotxml" not found
254                return (retStr)
255        else
256                pos = strsearch( LowerStr(item),"_scan",0)
257                //found, get the nine characters preceeding it
258                if (pos ==-1)
259                        //not a raw data file
260                        return (retStr)
261                else
262                        //Take the first four
263                        retStr= item[pos+5,pos+8]
264                        return (retStr)
265                       
266                Endif
267        Endif
268       
269End
270
271//returns a string containing the full path to the file containing the
272//run number "num". The null string is returned if no valid file can be found.
273//
274//
275// search in the path "catPathName" (hard-wired), will abort if this path does not exist
276//the file returned will be a RAW SANS data file, other types of files are
277//filtered out.
278//
279// called by Buttons.ipf and Transmission.ipf, and locally by parsing routines
280//
281Function/S FindFileFromRunNumber(num)
282        Variable num
283        String fullName="",partialName="",item=""
284        //get list of raw data files in folder that match "num" (add leading zeros)
285        if( (num>999) || (num<=0) )
286                //Print "error in  FindFileFromRunNumber(num), file number too large or too small"
287                Return ("")
288        Endif
289        //make a three character string of the run number
290        String numStr=""
291        if(num<10)
292                numStr = "00"+num2str(num)
293        else
294                if(num<100)
295                        numStr = "0"+num2str(num)
296                else
297                        numStr = num2str(num)
298                Endif
299        Endif
300       
301        //make sure that path exists
302        PathInfo catPathName
303        String path = S_path
304        if (V_flag == 0)
305                Abort "folder path does not exist - use Pick Path button"
306        Endif
307        String list="",newList="",testStr=""
308       
309        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
310        //find (the) one with the number in the run # location in the name
311        Variable numItems,ii,runFound,isRAW
312        numItems = ItemsInList(list,";")                //get the new number of items in the list
313        ii=0
314        do
315                //parse through the list in this order:
316                // 1 - does item contain run number (as a string) "NAMESANS_expNN_scan####_####.xml" : Let the first ### is the run num.
317                // 2 - exclude by isRaw? (to minimize disk access)
318                item = StringFromList(ii, list  ,";" )
319                if(strlen(item) != 0)
320                        //find the run number, if it exists as a three character string
321                        testStr = GetRunNumStrFromFile(item)
322                        runFound= cmpstr(numStr,testStr)        //compare the three character strings, 0 if equal
323                        if(runFound == 0)
324                                //the run Number was found
325                                //build valid filename
326                                partialName = FindValidFileName(item)
327
328                                if(strlen(partialName) != 0)            //non-null return from FindValidFileName()
329                                        fullName = path + partialName
330                                        //check if RAW, if so,this must be the file!
331                                        isRAW = CheckIfRawData(fullName)
332                                        if(isRaw)
333                                                //stop here
334                                                return(fullname)
335                                        Endif
336                                Endif
337                        Endif
338                Endif
339                ii+=1
340        while(ii<numItems)              //process all items in list
341        print "Please type 'scan number(s)' from your file name..."
342        Return ("")     //null return if file not found in list
343End
344
345//function to test a binary file to see if it is a RAW binary SANS file
346//first checks the total bytes in the file (which for raw data is 33316 bytes)
347//**note that the "DIV" file will also show up as a raw file by the run field
348//should be listed in CAT/SHORT and in patch windows
349//
350//Function then checks the file fname (full path:file) for "RAW" run.type field
351//if not found, the data is not raw data and zero is returned
352//
353// called by many procedures (both external and local)
354//
355Function CheckIfRawData(fname)
356        String fname
357             
358        String tempheadhfir                                           
359        Variable ind=0
360        Variable refNum
361       
362        //If not have .xml extension, return 0.
363        if (stringmatch(fname,"*.xml") <1)
364                print fname+": Failed. Not a *.xml file."
365                return 0                                //Not *.xml. Do nothing...
366        endif
367        //actually open the file
368        refNum = XmlOpenFile(fname)     
369        if (refNum < 0)
370                print "==> "+ fname+ "\r  ==> Failed to load: Not a standard xml file format or broken.. Please check the file if properly written..."
371                return 0                                //Not a xml file. Do nothing...
372        endif
373
374        //temp list of ns
375        MAKE/T/N=(1)/O nsList
376        nsList[0] = "1.1"
377       
378        // Check if  it is the SPICE version = 1.1
379        Variable  item,i
380        String thislocation,ns = ""
381        if (refNum >0)
382                for (item = 0; item < DimSize(nsList, 0); item += 1)            // loop over all possible namespaces
383                        XMLlistAttr(refNum, "/SPICErack", nsList[item])
384                        wave/T M_listAttr
385       
386                        for (i = 0; i < DimSize(M_listAttr,0); i+=1)                    // loop over all available attributes
387                                // Expect the required hfir XML header (will fail if "schemalocation" is not found)
388                                if ( CmpStr(  LowerStr(M_listAttr[i][1]),  LowerStr("SPICE_version") ) == 0 )
389                                        thisLocation = HFIR_TrimWS(M_listAttr[i][2])
390                                        if ( StringMatch(thisLocation, nsList[item] ) )
391                                                ns = nsList[item]                       
392                                       
393                                                Break   // found it!
394                                        endif
395                                endif
396                        endfor
397                        if (strlen(ns))                 
398                                Break           
399                        endif
400                endfor
401        endif
402        XmlCloseFile(refNum,0)
403        KillWaves/Z M_listAttr, nsList
404        if (StringMatch(ns,"1.1") <1)
405                ns = "0"
406        else
407                ns = "1"
408        endif
409       
410        return str2num(ns)
411End
412
413// function returns 1 if file is a transmission file, 0 if not
414//
415// called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf
416//
417Function isTransFile(fName)   ///  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
418        String fname
419       
420        Variable beamtrap_1y=0,beamtrap_2y=0,beamtrap_3y=0,beamtrap_4y=0
421//      if(your test here)
422        beamtrap_1y=getRealValueFromHeader(fname,"trap_y_101mm","mm")
423        beamtrap_2y=getRealValueFromHeader(fname,"trap_y_25mm","mm")
424        beamtrap_3y=getRealValueFromHeader(fname,"trap_y_50mm","mm")
425        beamtrap_4y=getRealValueFromHeader(fname,"trap_y_76mm","mm")
426
427         if (beamtrap_1y<10 && beamtrap_2y<10 && beamtrap_3y<10 && beamtrap_4y<10)     
428        //yes, its a transmisison file
429                return (1)
430        else
431        //some other file
432                return (0)
433        endif
434End
435
436
437
438//function to remove all spaces from names when searching for filenames
439//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
440//but the text field in the header WILL, if less than 3 characters were used for the
441//user's initials, and can have leading spaces if prefix was less than 5 characters
442//
443//returns a string identical to the original string, except with the interior spaces removed
444//
445// local function for file name manipulation
446//
447// NO CHANGE NEEDED
448//
449Function/S RemoveAllSpaces(str)
450        String str
451       
452        String tempstr = str
453        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
454        ii=0
455        do
456                len = strlen(tempStr)
457                spc = strsearch(tempStr," ",0)          //is the last character a space?
458                if (spc == -1)
459                        break           //no more spaces found, get out
460                endif
461                str = tempstr
462                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
463        While(1)        //should never be more than 2 or 3
464       
465        If(strlen(tempStr) < 1)
466                tempStr = ""            //be sure to return a null string if problem found
467        Endif
468       
469        //Print strlen(tempstr)
470       
471        Return(tempStr)
472               
473End
474
475
476
477//Function attempts to find valid filename from partial name by checking for
478// the existence of the file on disk
479//
480// returns a valid filename (No path prepended) or a null string
481//
482// called by any functions, both external and local
483//
484Function/S FindValidFilename(partialName)
485        String PartialName
486       
487        String retStr=partialName
488
489        //your code here
490        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
491        retStr = ValidFileString(partialName)
492        if(cmpstr(retStr,"") !=0)
493                return(retStr)
494        endif
495       
496        //if the partial name is derived from the file header, there can be spaces at the beginning
497        //or in the middle of the filename - depending on the prefix and initials used
498        //
499        //remove any leading spaces from the name before starting
500        partialName = RemoveAllSpaces(partialName)
501       
502        //try name with no spaces
503        retStr = ValidFileString(partialName)
504        if(cmpstr(retStr,"") !=0)
505                //non-null return
506                return(retStr)
507        endif
508       
509        //try all UPPERCASE
510        partialName = UpperStr(partialName)
511        retStr = ValidFileString(partialName)
512        if(cmpstr(retStr,"") !=0)
513                //non-null return
514                return(retStr)
515        endif
516       
517        //try all lowercase (ret null if failure)
518        partialName = LowerStr(partialName)
519        retStr = ValidFileString(partialName)
520        if(cmpstr(retStr,"") !=0)
521                //non-null return
522                return(retStr)
523        else
524                return(retStr)
525        endif
526End
527
528// Function checks for the existence of a file
529
530// *** the PATH is hard-wired to catPathName (which is assumed to exist)
531// version numers up to ;10 are tried
532// only the "name;vers" is returned if successful. The path is not prepended
533//
534// local function
535//
536Function/S ValidFileString(partialName)
537        String partialName
538
539        String tempName = ""
540        //Variable ii,refnum
541        tempName = partialName
542        Return (tempName)
543End
544
545
546//returns a string containing filename (WITHOUT the ;vers)
547//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
548//with the folders separated by colons
549//
550// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf
551//
552// NO CHANGE NEEDED
553//
554
555Function/S GetFileNameFromPathNoSemi(fullPath)
556        String fullPath
557       
558        Variable offset1,offset2
559        String filename=""
560        //String PartialPath
561        offset1 = 0
562        do
563                offset2 = StrSearch(fullPath, ":", offset1)
564                if (offset2 == -1)                              // no more colons ?
565                        fileName = FullPath[offset1,strlen(FullPath) ]
566                        //PartialPath = FullPath[0, offset1-1]
567                        break
568                endif
569                offset1 = offset2+1
570        while (1)
571       
572        //remove version number from name, if it's there - format should be: filename;N
573        filename =  StringFromList(0,filename,";")              //returns null if error
574       
575        Return filename
576End
577
578//returns a string containing filename (INCLUDING the ;vers)
579//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
580//with the folders separated by colons
581//
582// local, currently unused
583//
584// NO CHANGE NEEDED
585//
586
587Function/S GetFileNameFromPathKeepSemi(fullPath)
588        String fullPath
589       
590        Variable offset1,offset2
591        String filename
592        //String PartialPath
593        offset1 = 0
594        do
595                offset2 = StrSearch(fullPath, ":", offset1)
596                if (offset2 == -1)                              // no more colons ?
597                        fileName = FullPath[offset1,strlen(FullPath) ]
598                        //PartialPath = FullPath[0, offset1-1]
599                        break
600                endif
601                offset1 = offset2+1
602        while (1)
603       
604        //keep version number from name, if it's there - format should be: filename;N
605       
606        Return filename
607End
608
609//given the full path and filename (fullPath), strips the data path
610//(Mac-style, separated by colons) and returns this path
611//this partial path is the same string that would be returned from PathInfo, for example
612//
613// - allows the user to save to a different path than catPathName
614//
615// called by WriteQIS.ipf
616//
617// NO CHANGE NEEDED
618//
619
620Function/S GetPathStrFromfullName(fullPath)
621        String fullPath
622       
623        Variable offset1,offset2
624        //String filename
625        String PartialPath
626        offset1 = 0
627        do
628                offset2 = StrSearch(fullPath, ":", offset1)
629                if (offset2 == -1)                              // no more colons ?
630                        //fileName = FullPath[offset1,strlen(FullPath) ]
631                        PartialPath = FullPath[0, offset1-1]
632                        break
633                endif
634                offset1 = offset2+1
635        while (1)
636       
637        Return PartialPath
638End
639
640//given the filename trim or modify the filename to get a new
641//file string that can be used for naming averaged 1-d files
642//
643// called by ProtocolAsPanel.ipf and Tile_2D.ipf
644//
645Function/S GetNameFromHeader(fullName)
646        String fullName
647        String temp, newName = ""
648        Variable spc,ii=0
649       
650        //filename is 31-33 characters INSTRNAMESANS_exp##_scan####_####.xml (where # : numbers)
651        //returns a null string if no name can be found
652        Variable iimax =  strlen(fullName)
653        do
654                temp = fullname[ii,iimax-1-4]           //characters ii,all of the name
655                spc = strsearch(temp," ",0)
656                if (spc == -1)
657                        break           //no more spaces found
658                endif
659                ii+=1
660        While(ii<iimax)
661       
662        If(strlen(temp) < 1)
663                newName = ""            //be sure to return a null string if problem found
664        else
665                newName = temp
666        Endif
667       
668        Return(newName)
669End
670
671//list (input) is a list, typically returned from IndexedFile()
672//which is semicolon-delimited, and may contain filenames from the VAX
673//that contain version numbers, where the version number appears as a separate list item
674//(and also as a non-existent file)
675//these numbers must be purged from the list, especially for display in a popup
676//or list processing of filenames
677//the function returns the list, cleaned of version numbers (up to 11)
678//raw data files will typically never have a version number other than 1.
679//
680// if there are no version numbers in the list, the input list is returned
681//
682// called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf
683//
684// NO CHANGE NEEDED
685//
686
687Function/S RemoveVersNumsFromList(list)
688        String list
689       
690        //get rid of version numbers first (up to 11)
691        Variable ii,num
692        String item
693        num = ItemsInList(list,";")
694        ii=1
695        do
696                item = num2str(ii)
697                list = RemoveFromList(item, list ,";" )
698                ii+=1
699        while(ii<12)
700       
701        return (list)
702End
703
704//input is a list of run numbers, and output is a list of filenames (not the full path)
705//*** input list must be COMMA delimited***
706//output is equivalent to selecting from the CAT table
707//if some or all of the list items are valid filenames, keep them...
708//if an error is encountered, notify of the offending element and return a null list
709//
710//output is COMMA delimited
711//
712// this routine is expecting that the "ask", "none" special cases are handled elsewhere
713//and not passed here
714//
715// called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf
716//
717// NO CHANGE NEEDED
718//
719
720Function/S ParseRunNumberList(list)
721        String list
722       
723        String newList="",item="",tempStr=""
724        Variable num,ii,runNum
725       
726        //expand number ranges, if any
727        list = ExpandNumRanges(list)
728       
729        num=itemsinlist(list,",")
730       
731        for(ii=0;ii<num;ii+=1)
732                //get the item
733                item = StringFromList(ii,list,",")
734                //is it already a valid filename?
735                tempStr=FindValidFilename(item) //returns filename if good, null if error
736                if(strlen(tempstr)!=0)
737                        //valid name, add to list
738                        //Print "it's a file"
739                        newList += tempStr + ","
740                else
741                        //not a valid name
742                        //is it a number?
743                        runNum=str2num(item)
744                        //print runnum
745                        if(numtype(runNum) != 0)
746                                //not a number -  maybe an error                       
747                                DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename."
748                                return("")
749                        else
750                                //a run number or an error
751                                tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) )
752                                if(strlen(tempstr)==0)
753                                        //file not found, error
754                                        DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number."
755                                        return("")
756                                else
757                                        newList += tempStr + ","
758                                endif
759                        endif
760                endif
761        endfor          //loop over all items in list
762       
763        return(newList)
764End
765
766//takes a comma delimited list that MAY contain number range, and
767//expands any range of run numbers into a comma-delimited list...
768//and returns the new list - if not a range, return unchanged
769//
770// local function
771//
772// NO CHANGE NEEDED
773//
774
775Function/S ExpandNumRanges(list)
776        String list
777       
778        String newList="",dash="-",item,str
779        Variable num,ii,hasDash
780       
781        num=itemsinlist(list,",")
782//      print num
783        for(ii=0;ii<num;ii+=1)
784                //get the item
785                item = StringFromList(ii,list,",")
786                //does it contain a dash?
787                hasDash = strsearch(item,dash,0)                //-1 if no dash found
788                if(hasDash == -1)
789                        //not a range, keep it in the list
790                        newList += item + ","
791                else
792                        //has a dash (so it's a range), expand (or add null)
793                        newList += ListFromDash(item)           
794                endif
795        endfor
796       
797        return newList
798End
799
800//be sure to add a trailing comma to the return string...
801//
802// local function
803//
804// NO CHANGE NEEDED
805//
806Function/S ListFromDash(item)
807        String item
808       
809        String numList="",loStr="",hiStr=""
810        Variable lo,hi,ii
811       
812        loStr=StringFromList(0,item,"-")        //treat the range as a list
813        hiStr=StringFromList(1,item,"-")
814        lo=str2num(loStr)
815        hi=str2num(hiStr)
816        if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) )
817                numList=""
818                return numList
819        endif
820        for(ii=lo;ii<=hi;ii+=1)
821                numList += num2str(ii) + ","
822        endfor
823       
824        Return numList
825End
826
827
828//returns the proper attenuation factor based on the instrument
829//
830// filestr is passed from TextRead[3] = the default directory, used to identify the instrument
831// lam is passed from RealsRead[26]
832// AttenNo is passed from ReaslRead[3]
833//
834// Attenuation factor as defined here is <= 1
835//
836// Facilities can pass ("",1,attenuationFactor) and have this function simply
837// spit back the attenuationFactor (that was read into rw[3])
838//
839// called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf
840//
841Function AttenuationFactor(fileStr,lam,attenpercent)
842        String fileStr
843        Variable lam,attenpercent
844       
845        Variable attenFactor=1
846       
847        // your code here
848        attenFactor = 1- attenpercent /100  //???Attenuate transmission
849
850        return(attenFactor)
851End
852
853//function called by the popups to get a file list of data that can be sorted
854// this procedure simply removes the raw data files from the string - there
855//can be lots of other junk present, but this is very fast...
856//
857// could also use the alternate procedure of keeping only file with the proper extension
858//
859// another possibility is to get a listing of the text files, but is unreliable on
860// Windows, where the data file must be .txt (and possibly OSX)
861//
862// called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf
863//
864Function/S ReducedDataFileList(ctrlName)
865        String ctrlName
866
867        String list="",newList="",item=""
868        Variable num,ii
869       
870        //check for the path
871        PathInfo catPathName
872        if(V_Flag==0)
873                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
874                Return("")
875        Endif
876       
877        list = IndexedFile(catpathName,-1,"????")
878        num=ItemsInList(list,";")
879        //print "num = ",num
880        for(ii=(num-1);ii>=0;ii-=1)
881                item = StringFromList(ii, list  ,";")
882                //simply remove all that are not raw data files (SA1 SA2 SA3)
883                if( !stringmatch(item,"*.xml") )
884                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
885                                newlist += item + ";"
886                        endif
887                endif
888        endfor
889        //remove VAX version numbers
890        newList = RemoveVersNumsFromList(newList)
891        //sort
892        newList = SortList(newList,";",0)
893
894        return newlist
895End
896
897// returns a list of raw data files in the catPathName directory on disk
898// - list is SEMICOLON-delimited
899//
900// does it the "cheap" way, simply finding the ".SAn" in the file name
901// = does not check for proper byte length.
902//
903// called by PatchFiles.ipf, Tile_2D.ipf
904//
905Function/S GetRawDataFileList()
906       
907        //make sure that path exists
908        PathInfo catPathName
909        if (V_flag == 0)
910                Abort "Folder path does not exist - use Pick Path button on Main Panel"
911        Endif
912       
913        String list=IndexedFile(catPathName,-1,"????")
914        String newList="",item=""
915        Variable num=ItemsInList(list,";"),ii
916        for(ii=0;ii<num;ii+=1)
917                item = StringFromList(ii, list  ,";")
918                if( stringmatch(item,"*.xml") )
919                        if (CheckIfRawData(S_path+item) >0)
920                                newlist += item + ";"
921                        endif
922                endif
923        endfor
924        newList = SortList(newList,";",0)
925        return(newList)
926End
Note: See TracBrowser for help on using the repository browser.