source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/KIST_DataReadWrite.ipf @ 890

Last change on this file since 890 was 810, checked in by srkline, 11 years ago

Adding KIST_USANS_Reduction.pxt template for use.

Fixed missing function definition in KIST_DataReadWrite.ipf

File size: 26.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//**************************
6//
7// Vers. 1.2 092101
8// Vers. 5.0 29MAR07 - branched from main reduction to split out facility
9//                     specific calls
10//
11// functions for reading raw data files from the VAX
12// - RAW data files are read into the RAW folder - integer data from the detector
13//   is decompressed and given the proper orientation
14// - header information is placed into real,integer, or text waves in the order they appear
15//   in the file header
16//
17// Work data (DIV File) is read into the DIV folder
18//
19//*****************************
20
21//simple, main entry procedure that will load a RAW sans data file (not a work file)
22//into the RAW dataFolder. It is up to the calling procedure to display the file
23//
24// called by MainPanel.ipf and ProtocolAsPanel.ipf
25//
26Function LoadRawSANSData(msgStr)
27        String msgStr
28
29        String filename=""
30
31        //each routine is responsible for checking the current (displayed) data folder
32        //selecting it, and returning to root when done
33        PathInfo/S catPathName          //should set the next dialog to the proper path...
34        //get the filename, then read it in
35        filename = PromptForPath(msgStr)                //in SANS_Utils.ipf
36        //check for cancel from dialog
37        if(strlen(filename)==0)
38                //user cancelled, abort
39                SetDataFolder root:
40                DoAlert 0, "No file selected, action aborted"
41                return(1)
42        Endif
43
44        ReadHeaderAndData(filename)     //this is the full Path+file
45       
46        Return(0)
47End
48
49
50//function that does the guts of reading the binary data file
51//fname is the full path:name;vers required to open the file
52//
53// The final root:RAW:data wave is the real
54//neutron counts and can be directly operated on
55//
56// header information is put into three waves: integersRead, realsRead, and textRead
57// logicals in the header are currently skipped, since they are no use in the
58// data reduction process.
59//
60// The output is the three R/T/I waves that are filled at least with minimal values
61// and the detector data loaded into an array named "data"
62//
63// see documentation for the expected information in each element of the R/T/I waves
64// and the minimum set of information. These waves can be increased in length so that
65// more information can be accessed as needed (propagating changes...)
66//
67// called by multiple .ipfs (when the file name is known)
68//
69//
70// THIS FUNCTION DOES NOT NEED TO BE MODIFIED. ONLY THE DATA ACCESSORS NEED TO BE CONSTRUCTED
71//
72Function ReadHeaderAndData(fname)
73        String fname
74        //this function is for reading in RAW data only, so it will always put data in RAW folder
75        String curPath = "root:Packages:NIST:RAW:"
76        SetDataFolder curPath           //use the full path, so it will always work
77        Variable/G root:Packages:NIST:RAW:gIsLogScale = 0               //initial state is linear, keep this in RAW folder
78       
79        Variable refNum,integer,realval
80        String sansfname,textstr
81       
82        Make/O/D/N=23 $"root:Packages:NIST:RAW:IntegersRead"
83        Make/O/D/N=52 $"root:Packages:NIST:RAW:RealsRead"
84        Make/O/T/N=11 $"root:Packages:NIST:RAW:TextRead"
85        Make/O/N=7 $"root:Packages:NIST:RAW:LogicalsRead"
86       
87        Wave intw=$"root:Packages:NIST:RAW:IntegersRead"
88        Wave realw=$"root:Packages:NIST:RAW:RealsRead"
89        Wave/T textw=$"root:Packages:NIST:RAW:TextRead"
90        Wave logw=$"root:Packages:NIST:RAW:LogicalsRead"
91       
92        // FILL IN 3 ARRAYS WITH HEADER INFORMATION FOR LATER USE
93        // THESE ARE JUST THE MINIMALLY NECESSARY VALUES
94       
95        // filename as stored in the file header
96        textw[0]= fname
97       
98        // date and time of collection
99        textw[1]= getFileCreationDate(fname)
100       
101        // run type identifier (this is a reader for RAW data)
102        textw[2]= "RAW"
103       
104        // user account identifier (currently used only for NCNR-specific operations)
105        textw[3]= ""
106
107        // sample label
108        textw[6]= getSampleLabel(fname)
109       
110        // identifier of detector type, useful for setting detector constants
111        //(currently used only for NCNR-specific operations)
112        textw[9]= ""
113
114        //total counting time in seconds
115        intw[2] = getCountTime(fname)
116       
117       
118        // total monitor count
119        realw[0] = getMonitorCount(fname)
120       
121        // total detector count
122        realw[2] = getDetCount(fname)
123       
124        // attenuator number (NCNR-specific, your stub returns 0)
125        // may also be used to hold attenuator transmission (< 1)
126        realw[3] = getAttenNumber(fname)
127       
128        // sample transmission
129        realw[4] = getSampleTrans(fname)
130       
131        //sample thickness (cm)
132        realw[5] = getSampleThickness(fname)
133       
134        // following 6 values are for non-linear spatial corrections to a detector (RC timing)
135        // these values are set for a detctor that has a linear correspondence between
136        // pixel number and real-space distance
137        // 10 and 13 are the X and Y pixel dimensions, respectively (in mm!)
138        //(11,12 and 13,14 are set to values for a linear response, as from a new Ordela detector)
139        realw[10] = getDetectorPixelXSize(fname)
140        realw[11] = 10000
141        realw[12] = 0
142        realw[13] = getDetectorPixelYSize(fname)
143        realw[14] = 10000
144        realw[15] = 0
145       
146        // beam center X,Y on the detector (in units of pixel coordinates (1,N))
147        realw[16] = getBeamXPos(fname)
148        realw[17] = getBeamYPos(fname)
149       
150        // sample to detector distance (meters)
151        realw[18] = getSDD(fname)
152
153        // detector physical width (right now assumes square...) (in cm)
154        realw[20] = 65
155       
156        // beam stop diameter (assumes circular) (in mm)
157        realw[21] = getBSDiameter(fname)
158       
159        // source aperture diameter (mm)
160        realw[23] = getSourceApertureDiam(fname)
161       
162        // sample aperture diameter (mm)
163        realw[24] = getSampleApertureDiam(fname)
164       
165        // source aperture to sample aperture distance
166        realw[25] = getSourceToSampleDist(fname)
167       
168        // wavelength (A)
169        realw[26] = getWavelength(fname)
170       
171        // wavelength spread (FWHM)
172        realw[27] = getWavelengthSpread(fname)
173       
174        // beam stop X-position (motor reading, approximate cm from zero position)
175        // currently NCNR-specific use to identify transmission measurements
176        // you return 0
177        realw[37] = 0
178
179// the actual data array, dimensions are set as globals in
180// InitFacilityGlobals()
181        NVAR XPix = root:myGlobals:gNPixelsX
182        NVAR YPix = root:myGlobals:gNPixelsX
183       
184        Make/D/O/N=(XPix,YPix) $"root:RAW:data"
185        WAVE data=$"root:RAW:data"
186
187        // fill the data array with the detector values
188        getDetectorData(fname,data)
189       
190        Duplicate/O data linear_data                    // at this point, the data is still the raw data, and is linear_data
191       
192        // proper error for counting statistics, good for low count values too
193        // rather than just sqrt(n)
194        // see N. Gehrels, Astrophys. J., 303 (1986) 336-346, equation (7)
195        // for S = 1 in eq (7), this corresponds to one sigma error bars
196        Duplicate/O linear_data linear_data_error
197        linear_data_error = 1 + sqrt(linear_data + 0.75)                               
198        //
199       
200        //keep a string with the filename in the RAW folder
201        String/G root:RAW:fileList = textw[0]
202       
203        Return 0
204
205End
206
207//****************
208//main entry procedure for reading a "WORK.DIV" file
209//displays a quick image of the  file, to check that it's correct
210//data is deposited in root:Packages:NIST:DIV data folder
211//
212// local, currently unused
213//
214//
215Proc ReadWork_DIV()
216       
217        String fname = PromptForPath("Select detector sensitivity file")
218        ReadHeaderAndWork("DIV",fname)          //puts what is read in work.div
219       
220        String waveStr = "root:Packages:NIST:DIV:data"
221//      NewImage/F/K=1/S=2 $waveStr             //this is an experimental IGOR operation
222//      ModifyImage '' ctab= {*,*,YellowHot,0}
223        //Display;AppendImage $waveStr
224       
225        //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage
226//      String/G root:Packages:NIST:DIV:fileList = "WORK.DIV"
227        ChangeDisplay("DIV")
228       
229        SetDataFolder root:             //(redundant)
230End
231
232
233
234// Detector sensitivity files have the same header structure as RAW SANS data
235// as NCNR, just with a different data array (real, rather than integer data)
236//
237// So for your facility, make this reader specific to the format of whatever
238// file you use for a pixel-by-pixel division of the raw detector data
239// to correct for non-uniform sensitivities of the detector. This is typically a
240// measurement of water, plexiglas, or another uniform scattering sample.
241//
242// The data must be normalized to a mean value of 1
243//
244// called from ProtocolAsPanel.ipf
245//
246// type is "DIV" on input
247Function ReadHeaderAndWork(type,fname)
248        String type,fname
249       
250        //type is the desired folder to read the workfile to
251        //this data will NOT be automatically displayed
252        // gDataDisplayType is unchanged
253
254        String cur_folder = type
255        String curPath = "root:Packages:NIST:"+cur_folder
256        SetDataFolder curPath           //use the full path, so it will always work
257       
258        Variable refNum,integer,realval
259        String sansfname,textstr
260        Variable/G $(curPath + ":gIsLogScale") = 0              //initial state is linear, keep this in DIV folder
261       
262        Make/O/D/N=23 $(curPath + ":IntegersRead")
263        Make/O/D/N=52 $(curPath + ":RealsRead")
264        Make/O/T/N=11 $(curPath + ":TextRead")
265       
266        WAVE intw=$(curPath + ":IntegersRead")
267        WAVE realw=$(curPath + ":RealsRead")
268        WAVE/T textw=$(curPath + ":TextRead")
269       
270        // the actual data array, dimensions are set as globals in
271        // InitFacilityGlobals()
272        NVAR XPix = root:myGlobals:gNPixelsX
273        NVAR YPix = root:myGlobals:gNPixelsX
274       
275        Make/O/D/N=(XPix,YPix) $(curPath + ":data")
276        WAVE data = $(curPath + ":data")
277       
278       
279        // (1)
280        // fill in your reader for the header here so that intw, realw, and textW are filled in
281        // ? possibly a duplication of the raw data reader
282       
283       
284       
285        //(2)
286        // then fill in a reader for the data array that will DIVIDE your data
287        // to get the corrected values.
288       
289
290       
291
292        //keep a string with the filename in the DIV folder
293        String/G $(curPath + ":fileList") = textw[0]
294       
295        //return the data folder to root
296        SetDataFolder root:
297       
298        Return(0)
299End
300
301
302
303/////   ASC FORMAT READER  //////
304/////   FOR WORKFILE MATH PANEL //////
305//
306//function to read in the ASC output of SANS reduction
307// currently the file has 20 header lines, followed by a single column
308// of 16384 values, Data is written by row, starting with Y=1 and X=(1->128)
309//
310//returns 0 if read was ok
311//returns 1 if there was an error
312//
313// called by WorkFileUtils.ipf
314//
315//
316// If the ASC data was generated by the NCNR data writer, then
317// NOTHING NEEDS TO BE CHANGED HERE
318//
319Function ReadASCData(fname,destPath)
320        String fname, destPath
321        //this function is for reading in ASCII data so put data in user-specified folder
322        SetDataFolder "root:Packages:NIST:"+destPath
323
324        NVAR pixelsX = root:myGlobals:gNPixelsX
325        NVAR pixelsY = root:myGlobals:gNPixelsY
326        Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=20
327        String str=""
328        //data is initially linear scale
329        Variable/G :gIsLogScale=0
330        Make/O/T/N=(numHdrLines) hdrLines
331        Make/O/D/N=(pixelsX*pixelsY) data                       //,linear_data
332       
333        //full filename and path is now passed in...
334        //actually open the file
335//      SetDataFolder destPath
336        Open/R/Z refNum as fname                // /Z flag means I must handle open errors
337        if(refnum==0)           //FNF error, get out
338                DoAlert 0,"Could not find file: "+fname
339                Close/A
340                SetDataFolder root:
341                return(1)
342        endif
343        if(V_flag!=0)
344                DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
345                Close/A
346                SetDataFolder root:
347                return(1)
348        Endif
349        //
350        for(ii=0;ii<numHdrLines;ii+=1)          //read (or skip) 18 header lines
351                FReadLine refnum,str
352                hdrLines[ii]=str
353        endfor
354        //     
355        Close refnum
356       
357//      SetDataFolder destPath
358        LoadWave/Q/G/D/N=temp fName
359        Wave/Z temp0=temp0
360        data=temp0
361        Redimension/N=(pixelsX,pixelsY) data            //,linear_data
362
363        Duplicate/O data linear_data_error
364        linear_data_error = 1 + sqrt(data + 0.75)
365       
366        //just in case there are odd inputs to this, like negative intensities
367        WaveStats/Q linear_data_error
368        linear_data_error = numtype(linear_data_error[p]) == 0 ? linear_data_error[p] : V_avg
369        linear_data_error = linear_data_error[p] != 0 ? linear_data_error[p] : V_avg
370       
371        //linear_data = data
372       
373        KillWaves/Z temp0
374       
375        //return the data folder to root
376        SetDataFolder root:
377       
378        Return(0)
379End
380
381// fills the "default" fake header so that the SANS Reduction machinery does not have to be altered
382// pay attention to what is/not to be trusted due to "fake" information.
383// uses what it can from the header lines from the ASC file (hdrLines wave)
384//
385// destFolder is of the form "myGlobals:WorkMath:AAA"
386//
387//
388// called by WorkFileUtils.ipf
389//
390// If the ASC data was generated by the NCNR data writer, then
391// NOTHING NEEDS TO BE CHANGED HERE
392//
393Function FillFakeHeader_ASC(destFolder)
394        String destFolder
395        Make/O/D/N=23 $("root:Packages:NIST:"+destFolder+":IntegersRead")
396        Make/O/D/N=52 $("root:Packages:NIST:"+destFolder+":RealsRead")
397        Make/O/T/N=11 $("root:Packages:NIST:"+destFolder+":TextRead")
398       
399        Wave intw=$("root:Packages:NIST:"+destFolder+":IntegersRead")
400        Wave realw=$("root:Packages:NIST:"+destFolder+":RealsRead")
401        Wave/T textw=$("root:Packages:NIST:"+destFolder+":TextRead")
402       
403        //Put in appropriate "fake" values
404        //parse values as needed from headerLines
405        Wave/T hdr=$("root:Packages:NIST:"+destFolder+":hdrLines")
406        Variable monCt,lam,offset,sdd,trans,thick
407        Variable xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam
408        String detTyp=""
409        String tempStr="",formatStr="",junkStr=""
410        formatStr = "%g %g %g %g %g %g"
411        tempStr=hdr[3]
412        sscanf tempStr, formatStr, monCt,lam,offset,sdd,trans,thick
413//      Print monCt,lam,offset,sdd,trans,thick,avStr,step
414        formatStr = "%g %g %g %g %g %g %g %s"
415        tempStr=hdr[5]
416        sscanf tempStr,formatStr,xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
417//      Print xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
418       
419        realw[16]=xCtr          //xCtr(pixels)
420        realw[17]=yCtr  //yCtr (pixels)
421        realw[18]=sdd           //SDD (m)
422        realw[26]=lam           //wavelength (A)
423        //
424        // necessary values
425        realw[10]=5                     //detector calibration constants, needed for averaging
426        realw[11]=10000
427        realw[12]=0
428        realw[13]=5
429        realw[14]=10000
430        realw[15]=0
431        //
432        // used in the resolution calculation, ONLY here to keep the routine from crashing
433        realw[20]=65            //det size
434        realw[27]=dlam  //delta lambda
435        realw[21]=bsDiam        //BS size
436        realw[23]=a1            //A1
437        realw[24]=a2    //A2
438        realw[25]=a1a2Dist      //A1A2 distance
439        realw[4]=trans          //trans
440        realw[3]=0              //atten
441        realw[5]=thick          //thick
442        //
443        //
444        realw[0]=monCt          //def mon cts
445
446        // fake values to get valid deadtime and detector constants
447        //
448        textw[9]=detTyp+"  "            //6 characters 4+2 spaces
449        textw[3]="[NGxSANS00]"  //11 chars, NGx will return default values for atten trans, deadtime...
450       
451        //set the string values
452        formatStr="FILE: %s CREATED: %s"
453        sscanf hdr[0],formatStr,tempStr,junkStr
454//      Print tempStr
455//      Print junkStr
456        String/G $("root:Packages:NIST:"+destFolder+":fileList") = tempStr
457        textw[0] = tempStr              //filename
458        textw[1] = junkStr              //run date-time
459       
460        //file label = hdr[1]
461        tempStr = hdr[1]
462        tempStr = tempStr[0,strlen(tempStr)-2]          //clean off the last LF
463//      Print tempStr
464        textW[6] = tempStr      //sample label
465       
466        return(0)
467End
468
469
470///////// ACCESSORS FOR WRITING DATA TO HEADER  /////////
471/////
472
473// Write* routines all must:
474// (1) open file "fname". fname is a full file path and name to the file on disk
475// (2) write the specified value to the header at the correct location in the file
476// (3) close the file
477
478// new, April 2011 for error propagation. fill these in with the facility-
479// specific versions, if desired.
480Function WriteTransmissionErrorToHeader(fname,transErr)
481        String fname
482        Variable transErr
483       
484
485        return(0)
486End
487
488Function WriteBoxCountsErrorToHeader(fname,rel_err)
489        String fname
490        Variable rel_err
491       
492        return(0)
493End
494
495Function getSampleTransError(fname)
496        String fname
497       
498        return(0)
499end
500
501Function getBoxCountsError(fname)
502        String fname
503       
504        return(0)
505end
506
507
508// end April 2011 additions
509
510//sample transmission (0<T<=1)
511Function WriteTransmissionToHeader(fname,trans)
512        String fname
513        Variable trans
514       
515        // your writer here
516       
517        return(0)
518End
519
520//whole transmission is NCNR-specific right now
521// leave this stub empty
522Function WriteWholeTransToHeader(fname,trans)
523        String fname
524        Variable trans
525       
526        // do nothing for now
527       
528        return(0)
529End
530
531//box sum counts is a real value
532// used for transmission calculation module
533Function WriteBoxCountsToHeader(fname,counts)
534        String fname
535        Variable counts
536       
537        // do nothing if not using NCNR Transmission module
538       
539        return(0)
540End
541
542//beam stop X-position
543// used for transmission module to manually tag transmission files
544Function WriteBSXPosToHeader(fname,xpos)
545        String fname
546        Variable xpos
547       
548        // do nothing if not using NCNR Transmission module
549       
550        return(0)
551End
552
553//sample thickness in cm
554Function WriteThicknessToHeader(fname,num)
555        String fname
556        Variable num
557       
558        // your code here
559       
560        return(0)
561End
562
563//beam center X pixel location (detector coordinates)
564Function WriteBeamCenterXToHeader(fname,num)
565        String fname
566        Variable num
567       
568        // your code here
569       
570        return(0)
571End
572
573//beam center Y pixel location (detector coordinates)
574Function WriteBeamCenterYToHeader(fname,num)
575        String fname
576        Variable num
577       
578        // your code here
579       
580        return(0)
581End
582
583//attenuator number (not its transmission)
584// if your beam attenuation is indexed in some way, use that number here
585// if not, write a 1 to the file here as a default
586//
587Function WriteAttenNumberToHeader(fname,num)
588        String fname
589        Variable num
590       
591        // your code here, default of 1
592       
593        return(0)
594End
595
596// total monitor count during data collection
597Function WriteMonitorCountToHeader(fname,num)
598        String fname
599        Variable num
600       
601        // your code here
602       
603        return(0)
604End
605
606//total detector count
607Function WriteDetectorCountToHeader(fname,num)
608        String fname
609        Variable num
610       
611        // your code here
612       
613        return(0)
614End
615
616//transmission detector count
617// (currently unused in data reduction)
618Function WriteTransDetCountToHeader(fname,num)
619        String fname
620        Variable num
621       
622        // do nothing for now
623       
624        return(0)
625End
626
627//wavelength (Angstroms)
628Function WriteWavelengthToHeader(fname,num)
629        String fname
630        Variable num
631       
632        // your code here
633       
634        return(0)
635End
636
637//wavelength spread (FWHM)
638Function WriteWavelengthDistrToHeader(fname,num)
639        String fname
640        Variable num
641       
642        // your code here
643       
644        return(0)
645End
646
647//temperature of the sample (C)
648Function WriteTemperatureToHeader(fname,num)
649        String fname
650        Variable num
651       
652        //  your code here
653       
654        return(0)
655End
656
657//magnetic field (Oe)
658Function WriteMagnFieldToHeader(fname,num)
659        String fname
660        Variable num
661       
662        // your code here
663       
664        return(0)
665End
666
667//Source Aperture diameter (millimeters)
668Function WriteSourceApDiamToHeader(fname,num)
669        String fname
670        Variable num
671       
672        // your code here
673       
674        return(0)
675End
676
677//Sample Aperture diameter (millimeters)
678Function WriteSampleApDiamToHeader(fname,num)
679        String fname
680        Variable num
681       
682        //your code here
683       
684        return(0)
685End
686
687//Source aperture to sample aperture distance (meters)
688Function WriteSrcToSamDistToHeader(fname,num)
689        String fname
690        Variable num
691       
692        //      your code here
693       
694        return(0)
695End
696
697//lateral detector offset (centimeters)
698Function WriteDetectorOffsetToHeader(fname,num)
699        String fname
700        Variable num
701       
702        //your code here
703       
704        return(0)
705End
706
707//beam stop diameter (millimeters)
708Function WriteBeamStopDiamToHeader(fname,num)
709        String fname
710        Variable num
711       
712        // your code here
713       
714        return(0)
715End
716
717//sample to detector distance (meters)
718Function WriteSDDToHeader(fname,num)
719        String fname
720        Variable num
721       
722        //your code here
723       
724        return(0)
725End
726
727// physical dimension of detector x-pixel (mm)
728Function WriteDetPixelXToHeader(fname,num)
729        String fname
730        Variable num
731       
732        //your code here
733       
734        return(0)
735end
736
737// physical dimension of detector y-pixel (mm)
738Function WriteDetPixelYToHeader(fname,num)
739        String fname
740        Variable num
741       
742        //your code here
743       
744        return(0)
745end
746
747// sample label string
748Function WriteSamLabelToHeader(fname,str)
749        String fname,str
750       
751        // your code here
752
753        return(0)
754End
755
756// total counting time (seconds)
757Function WriteCountTimeToHeader(fname,num)
758        String fname
759        Variable num
760       
761        // your code here
762       
763        return(0)
764End
765
766
767
768//////// ACCESSORS FOR READING DATA FROM THE HEADER  //////////////
769//
770// read specific bits of information from the header
771// each of these operations MUST take care of open/close on their own
772//
773// fname is the full path and filname to the file on disk
774// return values are either strings or real values as appropriate
775//
776//////
777
778
779// function that reads in the 2D detector data and fills the array
780// data[nx][ny] with the data values
781// fname is the full name and path to the data file for opening and closing
782//
783//
784Function getDetectorData(fname,data)
785        String fname
786        Wave data
787       
788       
789        // your reader here
790       
791        return(0)
792End
793
794// file suffix (NCNR data file name specific)
795// return null string
796Function/S getSuffix(fname)
797        String fname
798       
799        return("")
800End
801
802// associated file suffix (for transmission)
803// NCNR Transmission calculation specific
804// return null string
805Function/S getAssociatedFileSuffix(fname)
806        String fname
807       
808        return("")
809End
810
811// sample label
812Function/S getSampleLabel(fname)
813        String fname
814       
815        String str
816       
817        // your code, returning str
818       
819        return(str)
820End
821
822// file creation date
823Function/S getFileCreationDate(fname)
824        String fname
825       
826        String str
827       
828        // your code, returning str
829       
830        return(str)
831End
832
833
834//monitor count
835Function getMonitorCount(fname)
836        String fname
837       
838        Variable value
839       
840        // your code returning value
841       
842        return(value)
843end
844
845//saved monitor count
846// NCNR specific for pre-processed data, never used
847// return 0
848Function getSavMon(fname)
849        String fname
850       
851        Variable value
852       
853        // your code returning value
854       
855        return(0)
856end
857
858//total detector count
859Function getDetCount(fname)
860        String fname
861       
862        Variable value
863       
864        // your code returning value
865       
866        return(value)
867end
868
869//Attenuator number, return 1 if your attenuators are not
870// indexed by number
871Function getAttenNumber(fname)
872        String fname
873       
874        Variable value
875       
876        // your code returning value
877       
878        return(value)
879end
880
881//transmission
882Function getSampleTrans(fname)
883        String fname
884       
885        Variable value
886       
887        // your code returning value
888       
889        return(value)
890end
891
892//box counts from stored transmission calculation
893// return 0 if not using NCNR transmission module
894Function getBoxCounts(fname)
895        String fname
896       
897        Variable value
898       
899        // your code returning value
900       
901        return(value)
902end
903
904//whole detector trasmission
905// return 0 if not using NCNR transmission module
906Function getSampleTransWholeDetector(fname)
907        String fname
908       
909        Variable value
910       
911        // your code returning value
912       
913        return(value)
914end
915
916//SampleThickness in centimeters
917Function getSampleThickness(fname)
918        String fname
919       
920        Variable value
921       
922        // your code returning value
923       
924        return(value)
925end
926
927//Sample Rotation Angle (degrees)
928Function getSampleRotationAngle(fname)
929        String fname
930       
931        Variable value
932       
933        // your code returning value
934       
935        return(value)
936end
937
938//temperature (C)
939Function getTemperature(fname)
940        String fname
941       
942        Variable value
943       
944        // your code returning value
945       
946        return(value)
947end
948
949//field strength (Oe)
950Function getFieldStrength(fname)
951        String fname
952       
953        Variable value
954       
955        // your code returning value
956       
957        return(value)
958end
959
960//center of beam xPos in pixel coordinates
961Function getBeamXPos(fname)
962        String fname
963       
964        Variable value
965       
966        // your code returning value
967       
968        return(value)
969end
970
971//center of beam Y pos in pixel coordinates
972Function getBeamYPos(fname)
973        String fname
974       
975        Variable value
976       
977        // your code returning value
978       
979        return(value)
980end
981
982//sample to detector distance (meters)
983Function getSDD(fname)
984        String fname
985       
986        Variable value
987       
988        // your code returning value
989       
990        return(value)
991end
992
993//lateral detector offset (centimeters)
994Function getDetectorOffset(fname)
995        String fname
996       
997        Variable value
998       
999        // your code returning value
1000       
1001        return(value)
1002end
1003
1004//Beamstop diameter (millimeters)
1005Function getBSDiameter(fname)
1006        String fname
1007       
1008        Variable value
1009       
1010        // your code returning value
1011       
1012        return(value)
1013end
1014
1015//source aperture diameter (millimeters)
1016Function getSourceApertureDiam(fname)
1017        String fname
1018       
1019        Variable value
1020       
1021        // your code returning value
1022       
1023        return(value)
1024end
1025
1026//sample aperture diameter (millimeters)
1027Function getSampleApertureDiam(fname)
1028        String fname
1029       
1030        Variable value
1031       
1032        // your code returning value
1033       
1034        return(value)
1035end
1036
1037//source AP to Sample AP distance (meters)
1038Function getSourceToSampleDist(fname)
1039        String fname
1040       
1041        Variable value
1042       
1043        // your code returning value
1044       
1045        return(value)
1046end
1047
1048//wavelength (Angstroms)
1049Function getWavelength(fname)
1050        String fname
1051       
1052        Variable value
1053       
1054        // your code returning value
1055       
1056        return(value)
1057end
1058
1059//wavelength spread (FWHM)
1060Function getWavelengthSpread(fname)
1061        String fname
1062       
1063        Variable value
1064       
1065        // your code returning value
1066       
1067        return(value)
1068end
1069
1070// physical x-dimension of a detector pixel, in mm
1071Function getDetectorPixelXSize(fname)
1072        String fname
1073       
1074        Variable value
1075       
1076        // your code here returning value
1077       
1078        return(value)
1079end
1080
1081// physical y-dimension of a detector pixel, in mm
1082Function getDetectorPixelYSize(fname)
1083        String fname
1084       
1085        Variable value
1086       
1087        // your code here returning value
1088       
1089        return(value)
1090end
1091
1092//transmission detector count (unused, return 0)
1093//
1094Function getTransDetectorCounts(fname)
1095        String fname
1096       
1097        Variable value
1098       
1099        // your code returning value
1100       
1101        return(0)
1102end
1103
1104
1105//total count time (seconds)
1106Function getCountTime(fname)
1107        String fname
1108       
1109        Variable value
1110       
1111        // your code returning value
1112       
1113        return(value)
1114end
1115
1116
1117//reads the wavelength from a reduced data file (not very reliable)
1118// - does not work with NSORTed files
1119// - only used in FIT/RPA (which itself is almost NEVER used...)
1120//
1121// DOES NOT NEED TO BE CHANGED IF USING NCNR DATA WRITER
1122Function GetLambdaFromReducedData(tempName)
1123        String tempName
1124       
1125        String junkString
1126        Variable lambdaFromFile, fileVar
1127        lambdaFromFile = 6.0
1128        Open/R/P=catPathName fileVar as tempName
1129        FReadLine fileVar, junkString
1130        FReadLine fileVar, junkString
1131        FReadLine fileVar, junkString
1132        if(strsearch(LowerStr(junkString),"lambda",0) != -1)
1133                FReadLine/N=11 fileVar, junkString
1134                FReadLine/N=10 fileVar, junkString
1135                lambdaFromFile = str2num(junkString)
1136        endif
1137        Close fileVar
1138       
1139        return(lambdaFromFile)
1140End
1141
1142/////   TRANSMISSION RELATED FUNCTIONS    ////////
1143//box coordinate are returned by reference
1144//
1145// box to sum over is bounded (x1,y1) to (x2,y2)
1146//
1147// this function returns the bounding coordinates as stored in
1148// the header
1149//
1150// if not using the NCNR Transmission module, this function default to
1151// returning 0000, and no changes needed
1152Function getXYBoxFromFile(filename,x1,x2,y1,y2)
1153        String filename
1154        Variable &x1,&x2,&y1,&y2
1155       
1156        Variable refnum
1157        String tmpFile = FindValidFilename(filename)
1158        // tmpFile is only a parital path
1159
1160        // return your bounding box coordinates or default values of 0
1161        x1=0
1162        y1=0
1163        x2=0
1164        y2=0
1165       
1166        return(0)
1167End
1168
1169// Writes the coordinates of the box to the header after user input
1170//
1171// box to sum over bounded (x1,y1) to (x2,y2)
1172//
1173// if not using the NCNR Transmission module, this function is null
1174Function WriteXYBoxToHeader(filename,x1,x2,y1,y2)
1175        String filename
1176        Variable x1,x2,y1,y2
1177       
1178        // your code to write bounding box to the header, or nothing
1179       
1180        return(0)
1181End
1182
1183// for transmission calculation, writes an NCNR-specific alphanumeric identifier
1184// (suffix of the data file)
1185//
1186// if not using the NCNR Transmission module, this function is null
1187Function WriteAssocFileSuffixToHeader(fname,suffix)
1188        String fname,suffix
1189               
1190        // your code to write bounding box to the header, or nothing
1191       
1192        return(0)
1193end
1194
1195////// OCT 2009, facility specific bits from ProDiv()
1196//"type" is the data folder that has the corrected, patched, and normalized DIV data array
1197//
1198// the header of this file is rather unimportant. Filling in a title at least would be helpful/
1199//
1200Function Write_DIV_File(type)
1201        String type
1202       
1203        // Your file writing function here. Don't try to duplicate the VAX binary format...
1204        Print "Write_DIV_File stub"
1205       
1206        return(0)
1207End
1208
1209////// OCT 2009, facility specific bits from MonteCarlo functions()
1210//"type" is the data folder that has the data array that is to be (re)written as a full
1211// data file, as if it was a raw data file
1212//
1213// not really necessary
1214//
1215Function/S Write_RawData_File(type,fullpath,dialog)
1216        String type,fullpath
1217        Variable dialog         //=1 will present dialog for name
1218       
1219        // Your file writing function here. Don't try to duplicate the VAX binary format...
1220        Print "Write_RawData_File stub"
1221       
1222        return("")
1223End
Note: See TracBrowser for help on using the repository browser.