source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ANSTO_Utils.ipf @ 707

Last change on this file since 707 was 707, checked in by ajj, 12 years ago

Updates and fixes to make ANSTO data reduction work.

  • Translated existing code from 6.x version of macros to 7.x

Plus!

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