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

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

changes to ILL- files to properly read in DIV data, and XY box.

Some minor changes to NCNR-files for consistency of reading the XY box.

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