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

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

Merging changes:

NCNR_Utils -> merging these into FACILITY, HFIR, and ILL_Utils

HFIR files merged by hand to reflect JaeHie?'s 29JUL09 version

Changed MainPanel? to look for TISANE or RealTime? functions to prevent button procedures from being called when the procedures aren't there. Seemed easier than separate versions without the buttons. #define at the begining of TISANE.ipf -> #ifdef in MainPanel? didn't work for some reason?

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