source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ILL_Utils.ipf @ 575

Last change on this file since 575 was 573, checked in by srkline, 13 years ago

Merging changes of NCNR_ in to the ILL_ files. This is mostly the :Packages:NIST: data folder structure that is new since Lionel made his changes.

Removed Lionel's InitializeILL file, and moved his specific changes (just some global variables) to the initialization routine in ILL_Utils, where it belongs.

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