source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ILL_DataReadWrite.ipf @ 795

Last change on this file since 795 was 795, checked in by srkline, 12 years ago

Changes to SANS reduction that apply to other Facilities:

These changes are related to the propagation of errors in 2D, on a
per-pixel basis. These changes only affect the errors that are reported in
the QxQy? ASCII file output. The 1D code is unaffected.

If these changes are not implemented, then errors of zero will be substitued as defaults
for these experimental errors.

Upon data loading, an error matrix, linear_data_error is generated and filled with
error values appropriate for Poisson statistics (not simply sqrt(n)).

4 functions in FACILITY_DataReadWrite.ipf have been added, and they are rather
self-explanatory:

In FACILITY_Utils.ipf, the AttenuatorTransmission?() function now returns
an additional parameter, atten_err, which is one standard deviation of the
attenuator transmission value. It returns a default error=0 (which is
correct if no attenuation is used). Facilities can fill this function in
with their own estimates for the uncertainty in the attenutator transmission.

  • Property svn:executable set to *
File size: 42.2 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,ii
80        String sansfname,textstr,v0
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        Open/R refNum as fname
97        //skip first two bytes (VAX record length markers, not needed here)
98//      FSetPos refNum, 2
99        //read the next 21 bytes as characters (fname)
100       
101       
102       
103        for (ii=0;ii<2;ii+=1)
104                FReadLine refNum,textstr
105                sscanf textstr,"%s",v0
106       
107        endfor
108       
109        Close refnum
110       
111        textw[0]= v0
112       
113//      print "function read raw used"
114       
115        // date and time of collection
116        textw[1]= getFileCreationDate(fname)
117       
118        // run type identifier (this is a reader for RAW data)
119        textw[2]= "RAW"
120       
121        // user account identifier (currently used only for NCNR-specific operations)
122        textw[3]= getFileInstrument(fname)
123
124        // sample label
125        textw[6]= getSampleLabel(fname)
126       
127        // identifier of detector type, useful for setting detector constants
128        //(currently used only for NCNR-specific operations)
129        textw[9]= ""
130       
131       
132
133        //total counting time in seconds
134        intw[2] = getCountTime(fname)
135       
136       
137        // total monitor count
138        realw[0] = getMonitorCount(fname)
139       
140        // total detector count
141        realw[2] = getDetCount(fname)
142       
143        // attenuator number (NCNR-specific, your stub returns 0)
144        // may also be used to hold attenuator transmission (< 1)
145        realw[3] = getAttenNumber(fname)
146       
147        // sample transmission
148        realw[4] = getSampleTrans(fname)
149       
150        //sample thickness (cm)
151        realw[5] = getSampleThickness(fname)
152       
153        // following 6 values are for non-linear spatial corrections to a detector (RC timing)
154        // these values are set for a detctor that has a linear correspondence between
155        // pixel number and real-space distance
156        // 10 and 13 are the X and Y pixel dimensions, respectively (in mm!)
157        //(11,12 and 13,14 are set to values for a linear response, as from a new Ordela detector)
158        realw[10] = getDetectorPixelXSize(fname)
159        realw[11] = 10000
160        realw[12] = 0
161        realw[13] = getDetectorPixelYSize(fname)
162        realw[14] = 10000
163        realw[15] = 0
164       
165        // beam center X,Y on the detector (in units of pixel coordinates (1,N))
166        realw[16] = getBeamXPos(fname)
167        realw[17] = getBeamYPos(fname)
168       
169        // sample to detector distance (meters)
170        realw[18] = getSDD(fname)
171
172        // detector physical width (right now assumes square...) (in cm)
173        realw[20] = 102
174       
175        // beam stop diameter (assumes circular) (in mm)
176        realw[21] = getBSDiameter(fname)
177       
178        // source aperture diameter (mm)
179        realw[23] = getSourceApertureDiam(fname)
180       
181        // sample aperture diameter (mm)
182        realw[24] = getSampleApertureDiam(fname)
183       
184        // source aperture to sample aperture distance
185        realw[25] = getSourceToSampleDist(fname)
186       
187        // wavelength (A)
188        realw[26] = getWavelength(fname)
189       
190        // wavelength spread (FWHM)
191        realw[27] = getWavelengthSpread(fname)
192       
193        realw[52] = getreactorpower(fname)
194       
195        // beam stop X-position (motor reading, approximate cm from zero position)
196        // currently NCNR-specific use to identify transmission measurements
197        // you return 0
198        realw[37] = 0
199       
200       
201// the actual data array, dimensions are set as globals in
202// InitFacilityGlobals()
203        NVAR XPix = root:myGlobals:gNPixelsX
204        NVAR YPix = root:myGlobals:gNPixelsX
205       
206        SetDataFolder curPath
207       
208        Make/D/O/N=(XPix,YPix) $"root:Packages:NIST:RAW:data"
209        WAVE data=$"root:Packages:NIST:RAW:data"
210
211        // fill the data array with the detector values
212        getDetectorData(fname,data)
213       
214        Setdatafolder curpath
215       
216        Duplicate/O data linear_data            // data is "fresh" and linear scale, so copy it now
217       
218        // proper error for counting statistics, good for low count values too
219        // rather than just sqrt(n)
220        // see N. Gehrels, Astrophys. J., 303 (1986) 336-346, equation (7)
221        // for S = 1 in eq (7), this corresponds to one sigma error bars
222        Duplicate/O linear_data linear_data_error
223        linear_data_error = 1 + sqrt(linear_data + 0.75)                               
224        //
225       
226        //keep a string with the filename in the RAW folder
227        String/G root:Packages:NIST:RAW:fileList = textw[0]
228       
229        Setdatafolder root:
230
231       
232        Return 0
233
234End
235
236//****************
237//main entry procedure for reading a "WORK.DIV" file
238//displays a quick image of the  file, to check that it's correct
239//data is deposited in root:DIV data folder
240//
241// local, just for testing
242//
243Proc ReadWork_DIV()
244       
245        String fname = PromptForPath("Select detector sensitivity file")
246        ReadHeaderAndWork("DIV",fname)          //puts what is read in work.div
247       
248        String waveStr = "root:Packages:NIST:DIV:data"
249        NewImage/F/K=1/S=2 $waveStr
250        ModifyImage '' ctab= {*,*,YellowHot,0}
251       
252        String/G root:Packages:NIST:DIV:fileList = "WORK.DIV"
253       
254        SetDataFolder root:             //(redundant)
255End
256
257
258
259
260/////////DIV file created with NIST reduction so has the VAX format.... painful
261//     
262// Detector sensitivity files have the same header structure as RAW SANS data
263// as NCNR, just with a different data array (real, rather than integer data)
264//
265// So for your facility, make this reader specific to the format of whatever
266// file you use for a pixel-by-pixel division of the raw detector data
267// to correct for non-uniform sensitivities of the detector. This is typically a
268// measurement of water, plexiglas, or another uniform scattering sample.
269//
270// The data must be normalized to a mean value of 1
271//
272// called from ProtocolAsPanel.ipf
273//
274// type is "DIV" on input
275Function ReadHeaderAndWork(type,fname)
276        String type,fname
277       
278        //type is the desired folder to read the workfile to
279        //this data will NOT be automatically displayed
280        // gDataDisplayType is unchanged
281
282        String cur_folder = type
283        String curPath = "root:Packages:NIST:"+cur_folder
284        SetDataFolder curPath           //use the full path, so it will always work
285       
286        Variable refNum,integer,realval
287        String sansfname,textstr
288        Variable/G $(curPath + ":gIsLogScale") = 0              //initial state is linear, keep this in DIV folder
289       
290        Make/O/D/N=23 $(curPath + ":IntegersRead")
291        Make/O/D/N=52 $(curPath + ":RealsRead")
292        Make/O/T/N=11 $(curPath + ":TextRead")
293       
294        WAVE intw=$(curPath + ":IntegersRead")
295        WAVE realw=$(curPath + ":RealsRead")
296        WAVE/T textw=$(curPath + ":TextRead")
297       
298        // the actual data array, dimensions are set as globals inÊ
299        // InitFacilityGlobals()
300        NVAR XPix = root:myGlobals:gNPixelsX
301        NVAR YPix = root:myGlobals:gNPixelsX
302       
303        Make/O/D/N=(XPix,YPix) $(curPath + ":data")
304        WAVE data = $(curPath + ":data")
305       
306        Make/O/D/N=(XPix,YPix) $(curPath + ":linear_data")
307        WAVE linear_data = $(curPath + ":linear_data")
308       
309        // (1)
310        // fill in your reader for the header here so that intw, realw, and textW are filled in
311        // -- these are not really needed at all, so skip them for now
312        // a simple duplication of some other data may be sufficient
313        if(exists("root:Packages:NIST:raw:realsread") == 1)
314                Duplicate/O $("root:Packages:NIST:raw:realsread"),$(curPath+ ":realsread")
315                Duplicate/O $("root:Packages:NIST:raw:integersread"),$(curPath+ ":integersread")
316                Duplicate/O/T $("root:Packages:NIST:raw:Textread"),$(curPath+ ":Textread")
317        endif
318
319        //(2)
320        // then fill in a reader for the data array that will DIVIDE your data
321        // to get the corrected values.
322
323        //here you load in your file, you're already in the DIV folder
324        LoadWave/O fname                //since fname is the full path
325               
326        String loadedStr = StringFromList(0,S_waveNames,";")            //then name of the wave loaded
327       
328//      data loaded should be named "linear_data" (this is set in the DIV writer)
329        Duplicate/O linear_data,data                    // folder is in linear scale in its as-loaded state, so both are linear
330
331        //keep a string with the filename in the DIV folder
332        String/G $(curPath + ":fileList") = textw[0]
333       
334        //return the data folder to root
335        SetDataFolder root:
336       
337        Return(0)
338End
339
340
341/////   ASC FORMAT READER  //////
342/////   FOR WORKFILE MATH PANEL //////
343//
344//function to read in the ASC output of SANS reduction
345// currently the file has 20 header lines, followed by a single column
346// of 16384 values, Data is written by row, starting with Y=1 and X=(1->128)
347//
348//returns 0 if read was ok
349//returns 1 if there was an error
350//
351// called by WorkFileUtils.ipf
352//
353//
354// If the ASC data was generated by the NCNR data writer, then
355// NOTHING NEEDS TO BE CHANGED HERE
356//
357Function ReadASCData(fname,destPath)
358        String fname, destPath
359        //this function is for reading in ASCII data so put data in user-specified folder
360        SetDataFolder "root:Packages:NIST:"+destPath
361
362        NVAR pixelsX = root:myGlobals:gNPixelsX
363        NVAR pixelsY = root:myGlobals:gNPixelsY
364        Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=220   ///waas 20 for NIST
365        String str=""
366        //data is initially linear scale
367        Variable/G :gIsLogScale=0
368        Make/O/T/N=(numHdrLines) hdrLines
369        Make/O/D/N=(pixelsX*pixelsY) data                       //,linear_data
370       
371        //full filename and path is now passed in...
372        //actually open the file
373//      SetDataFolder destPath
374        Open/R/Z refNum as fname                // /Z flag means I must handle open errors
375        if(refnum==0)           //FNF error, get out
376                DoAlert 0,"Could not find file: "+fname
377                Close/A
378                SetDataFolder root:
379                return(1)
380        endif
381        if(V_flag!=0)
382                DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
383                Close/A
384                SetDataFolder root:
385                return(1)
386        Endif
387        //
388        for(ii=0;ii<numHdrLines;ii+=1)          //read (or skip) 18 header lines
389                FReadLine refnum,str
390                hdrLines[ii]=str
391        endfor
392        //     
393        Close refnum
394       
395//      SetDataFolder destPath
396
397//loadwave  /A=tempGBwave/L={0, start, numrow, 0, numcol}/N/G/D/O/E=1/K=1
398
399
400        LoadWave/Q/G/D/N=temp fName
401        Wave/Z temp0=temp0
402        data=temp0
403        Redimension/N=(pixelsX,pixelsY) data            //,linear_data
404       
405        Duplicate/O data linear_data_error
406        linear_data_error = 1 + sqrt(data + 0.75)
407       
408        //just in case there are odd inputs to this, like negative intensities
409        WaveStats/Q linear_data_error
410        linear_data_error = numtype(linear_data_error[p]) == 0 ? linear_data_error[p] : V_avg
411        linear_data_error = linear_data_error[p] != 0 ? linear_data_error[p] : V_avg
412       
413        //linear_data = data
414       
415        KillWaves/Z temp0
416       
417        //return the data folder to root
418        SetDataFolder root:
419       
420        Return(0)
421End
422
423// fills the "default" fake header so that the SANS Reduction machinery does not have to be altered
424// pay attention to what is/not to be trusted due to "fake" information.
425// uses what it can from the header lines from the ASC file (hdrLines wave)
426//
427// destFolder is of the form "myGlobals:WorkMath:AAA"
428//
429//
430// called by WorkFileUtils.ipf
431//
432// If the ASC data was generated by the NCNR data writer, then
433// NOTHING NEEDS TO BE CHANGED HERE
434//
435Function FillFakeHeader_ASC(destFolder)
436        String destFolder
437        Make/O/D/N=23 $("root:Packages:NIST:"+destFolder+":IntegersRead")
438        Make/O/D/N=52 $("root:Packages:NIST:"+destFolder+":RealsRead")
439        Make/O/T/N=11 $("root:Packages:NIST:"+destFolder+":TextRead")
440       
441        Wave intw=$("root:Packages:NIST:"+destFolder+":IntegersRead")
442        Wave realw=$("root:Packages:NIST:"+destFolder+":RealsRead")
443        Wave/T textw=$("root:Packages:NIST:"+destFolder+":TextRead")
444       
445        //Put in appropriate "fake" values
446        //parse values as needed from headerLines
447        Wave/T hdr=$("root:Packages:NIST:"+destFolder+":hdrLines")
448        Variable monCt,lam,offset,sdd,trans,thick
449        Variable xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam
450        String detTyp=""
451        String tempStr="",formatStr="",junkStr=""
452        formatStr = "%g %g %g %g %g %g"
453        tempStr=hdr[3]
454        sscanf tempStr, formatStr, monCt,lam,offset,sdd,trans,thick
455//      Print monCt,lam,offset,sdd,trans,thick,avStr,step
456        formatStr = "%g %g %g %g %g %g %g %s"
457        tempStr=hdr[5]
458        sscanf tempStr,formatStr,xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
459//      Print xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
460       
461        realw[16]=xCtr          //xCtr(pixels)
462        realw[17]=yCtr  //yCtr (pixels)
463        realw[18]=sdd           //SDD (m)
464        realw[26]=lam           //wavelength (A)
465        //
466        // necessary values
467        realw[10]=8                     //detector calibration constants, needed for averaging
468        realw[11]=10000
469        realw[12]=0
470        realw[13]=8
471        realw[14]=10000
472        realw[15]=0
473        //
474        // used in the resolution calculation, ONLY here to keep the routine from crashing
475        realw[20]=102           //det size
476        realw[27]=dlam  //delta lambda
477        realw[21]=bsDiam        //BS size
478        realw[23]=a1            //A1
479        realw[24]=a2    //A2
480        realw[25]=a1a2Dist      //A1A2 distance
481        realw[4]=trans          //trans
482        realw[3]=0              //atten
483        realw[5]=thick          //thick
484        //
485        //
486        realw[0]=monCt          //def mon cts
487
488        // fake values to get valid deadtime and detector constants
489        //
490        textw[9]=detTyp+"  "            //6 characters 4+2 spaces
491        textw[3]="[NGxSANS00]"  //11 chars, NGx will return default values for atten trans, deadtime...
492       
493        //set the string values
494        formatStr="FILE: %s CREATED: %s"
495        sscanf hdr[0],formatStr,tempStr,junkStr
496//      Print tempStr
497//      Print junkStr
498        String/G $("root:Packages:NIST:"+destFolder+":fileList") = tempStr
499        textw[0] = tempStr              //filename
500        textw[1] = junkStr              //run date-time
501       
502        //file label = hdr[1]
503        tempStr = hdr[1]
504        tempStr = tempStr[0,strlen(tempStr)-2]          //clean off the last LF
505//      Print tempStr
506        textW[6] = tempStr      //sample label
507       
508        return(0)
509End
510
511
512///////// ACCESSORS FOR WRITING DATA TO HEADER  /////////
513/////
514
515// Write* routines all must:
516// (1) open file "fname". fname is a full file path and name to the file on disk
517// (2) write the specified value to the header at the correct location in the file
518// (3) close the file
519
520
521// new, April 2011 for error propagation. fill these in with the facility-
522// specific versions, if desired.
523Function WriteTransmissionErrorToHeader(fname,transErr)
524        String fname
525        Variable transErr
526       
527
528        return(0)
529End
530
531Function WriteBoxCountsErrorToHeader(fname,rel_err)
532        String fname
533        Variable rel_err
534       
535        return(0)
536End
537
538Function getSampleTransError(fname)
539        String fname
540       
541        return(0)
542end
543
544Function getBoxCountsError(fname)
545        String fname
546       
547        return(0)
548end
549
550
551// end April 2011 additions
552
553
554//sample transmission (0<T<=1)
555Function WriteTransmissionToHeader(fname,trans)
556        String fname
557        Variable trans
558       
559        // your writer here
560       
561        WriteReal(fname,trans,5589)     //I will define at position 10 lines position 1  by myself
562       
563        // 16 bites between numbers and 81 per line
564       
565        return(0)
566End
567
568//whole transmission is NCNR-specific right now
569// leave this stub empty
570Function WriteWholeTransToHeader(fname,trans)
571        String fname
572        Variable trans
573       
574        // do nothing for now
575        WriteReal(fname,trans,6885)   /// //I will define at position last  lines  position 1  by myself
576       
577        return(0)
578End
579
580//box sum counts is a real value
581// used for transmission calculation module
582Function WriteBoxCountsToHeader(fname,counts)
583        String fname
584        Variable counts
585       
586        // do nothing if not using NCNR Transmission module
587       
588        WriteReal(fname,counts,6868)
589       
590        ////I will define at position 2   lines before the end and  last position   by myself
591       
592       
593        return(0)
594End
595
596//beam stop X-position
597// used for transmission module to manually tag transmission files
598Function WriteBSXPosToHeader(fname,xpos)
599        String fname
600        Variable xpos
601       
602        // do nothing if not using NCNR Transmission module
603       
604        WriteReal(fname,xpos,5119)    ////should do it for ypos for ILL ....NEED TO REMEMBER HERE
605        /// line 4 column 2   
606       
607        return(0)
608End
609
610//sample thickness in cm
611Function WriteThicknessToHeader(fname,num)
612        String fname
613        Variable num
614       
615        // your code here
616       
617        WriteReal(fname,num,5508)  //define at 9 lines  column 1 just above transmission by myself
618       
619        return(0)
620End
621
622//beam center X pixel location (detector coordinates)
623Function WriteBeamCenterXToHeader(fname,num)
624        String fname
625        Variable num
626       
627        // your code here
628       
629        // pos (1) on line 71 => 70 lines x 81 char
630        WriteReal(fname,num*10,5670)
631       
632        ///   line 11 column 1
633       
634        return(0)
635End
636
637//beam center Y pixel location (detector coordinates)
638Function WriteBeamCenterYToHeader(fname,num)
639        String fname
640        Variable num
641       
642        // your code here
643       
644        WriteReal(fname,num*10,5686)
645       
646        ///   line 11 column 2
647       
648        return(0)
649End
650
651//attenuator number (not its transmission)
652// if your beam attenuation is indexed in some way, use that number here
653// if not, write a 1 to the file here as a default
654//
655Function WriteAttenNumberToHeader(fname,num)
656        String fname
657        Variable num
658       
659        // your code here, default of 1
660        WriteReal(fname,num,5799)
661       
662        ///   line 12 column 4
663       
664        return(0)
665End
666
667
668Function WritereactorpowerToHeader(fname,num)
669        String fname
670        Variable num
671       
672        // your code here, default of 1
673        WriteReal(fname,num,6204)
674       
675        ///   line 12 column 4
676       
677        return(0)
678End
679
680
681
682
683
684
685
686
687// total monitor count during data collection
688Function WriteMonitorCountToHeader(fname,num)
689        String fname
690        Variable num
691       
692        // your code here
693       
694        WriteReal(fname,num,4924)
695       
696        ///   line 1 column 5
697       
698        return(0)
699End
700
701//total detector count
702Function WriteDetectorCountToHeader(fname,num)
703        String fname
704        Variable num
705       
706        // your code here
707       
708        WriteReal(fname,num,4908)
709       
710        ///   line 1 column 4
711       
712        return(0)
713End
714
715//transmission detector count
716// (currently unused in data reduction)
717Function WriteTransDetCountToHeader(fname,num)
718        String fname
719        Variable num
720       
721        // do nothing for now
722       
723        return(0)
724End
725
726//wavelength (Angstroms)
727Function WriteWavelengthToHeader(fname,num)
728        String fname
729        Variable num
730       
731        // your code here
732        WriteReal(fname,num,5703)
733       
734        //   line 11 column 3
735       
736        return(0)
737End
738
739//wavelength spread (FWHM)
740Function WriteWavelengthDistrToHeader(fname,num)
741        String fname
742        Variable num
743       
744        // your code here
745       
746        WriteReal(fname,num,5719)
747       
748        //   line 11 column 4
749       
750        return(0)
751End
752
753//temperature of the sample (C)
754Function WriteTemperatureToHeader(fname,num)
755        String fname
756        Variable num
757       
758        //  your code here
759       
760        WriteReal(fname,num,5347)
761       
762        //   line 7 column 1
763       
764        return(0)
765End
766
767//magnetic field (Oe)
768Function WriteMagnFieldToHeader(fname,num)
769        String fname
770        Variable num
771       
772        // your code here
773       
774        return(0)
775End
776
777//Source Aperture diameter (millimeters)
778Function WriteSourceApDiamToHeader(fname,num)
779        String fname
780        Variable num
781       
782        // your code here
783//      WriteReal(fname,num,5348)
784      WriteReal(fname,num,6027)    ///4*81 = 324
785     
786      // line 15 colum 3
787       
788        return(0)
789End
790
791//Sample Aperture diameter (millimeters)
792Function WriteSampleApDiamToHeader(fname,num)
793        String fname
794        Variable num
795       
796        //your code here
797        WriteReal(fname,num,6043)
798       
799            // line 15 colum 4
800       
801        return(0)
802End
803
804//Source aperture to sample aperture distance (meters)
805Function WriteSrcToSamDistToHeader(fname,num)
806        String fname
807        Variable num
808       
809        //      your code here
810        WriteReal(fname,num,5784)  //it is collimation at ILL
811       
812       
813        return(0)
814End
815
816//lateral detector offset (centimeters)
817Function WriteDetectorOffsetToHeader(fname,num)
818        String fname
819        Variable num
820       
821        //your code here
822       
823        WriteReal(fname,10*num,5849)
824       
825       
826       
827        // line 13 column 2
828       
829        return(0)
830End
831
832//beam stop diameter (millimeters)
833Function WriteBeamStopDiamToHeader(fname,num)
834        String fname
835        Variable num
836       
837        // your code here
838        WriteReal(fname,num,6059)
839       
840        //line 15 column 5
841       
842        return(0)
843End
844
845//sample to detector distance (meters)
846Function WriteSDDToHeader(fname,num)
847        String fname
848        Variable num
849       
850        //your code here
851        //WriteReal(fname,num,5152)
852       
853       
854        WriteReal(fname,num,5265)
855       
856        // line 4 column 4
857       
858        // real calculated distance line 6 colunm1
859       
860        return(0)
861End
862
863// physical dimension of detector x-pixel (mm)
864Function WriteDetPixelXToHeader(fname,num)
865        String fname
866        Variable num
867       
868        //your code here
869        WriteReal(fname,num,5735)
870       
871        //  line 11 column 5   
872       
873        return(0)
874end
875
876// physical dimension of detector y-pixel (mm)
877Function WriteDetPixelYToHeader(fname,num)
878        String fname
879        Variable num
880       
881        //your code here
882        WriteReal(fname,num,5752)
883       
884        return(0)
885end
886
887// sample label string
888Function WriteSamLabelToHeader(fname,str)
889        String fname,str
890       
891        // your code here
892//              WriteText(fname,"                              ",2075)  // need to write in 30 bites no more....
893
894        Variable numChars=30
895        String blankStr=""
896        blankStr = PadString(blankStr, numChars, 0x20)
897        WriteText(fname,blankStr,2075)
898       
899        if(strlen(str)>numChars)
900                str = str[0,numchars-1]
901        endif
902       
903        WriteText(fname,str,2075)   //// need to change that in order to erase the title and write a new one
904
905        return(0)
906End
907
908// total counting time (stored here as seconds/10??)
909Function WriteCountTimeToHeader(fname,num)
910        String fname
911        Variable num
912       
913        // your code here
914//      WriteReal(fname,num,4894)
915        WriteReal(fname,10*num,4892)
916       
917       
918       
919        return(0)
920End
921
922
923
924//////// ACCESSORS FOR READING DATA FROM THE HEADER  //////////////
925//
926// read specific bits of information from the header
927// each of these operations MUST take care of open/close on their own
928//
929// fname is the full path and filname to the file on disk
930// return values are either strings or real values as appropriate
931//
932//////
933
934
935// function that reads in the 2D detector data and fills the array
936// data[nx][ny] with the data values
937// fname is the full name and path to the data file for opening and closing
938//
939//
940Function getDetectorData(fname,data)
941        String fname
942        Wave data
943       
944       
945        // your reader here
946       
947//      value = getRealValueFromHeader_2(fname,60,28,5,1,3)  // data start at 60+58 lines
948        ReadILLData2(fname,data)
949       
950        return (0)
951End
952
953// file suffix (NCNR data file name specific)
954// return null string
955Function/S getSuffix(fname)
956        String fname
957       
958        String suffix = getStringFromHeader(fname,9341,6)
959       
960        // replace the leading space w/ "0"
961        suffix = ReplaceString(" ",suffix,"0")
962       
963        return(suffix)   //// file suffix (6 characters @ byte 9341)
964End
965
966// associated file suffix (for transmission)
967// NCNR Transmission calculation specific
968// return null string
969Function/S getAssociatedFileSuffix(fname)
970        String fname
971       
972        string str
973       
974        str= getStringFromHeader(fname,9350,6)
975       
976        // replace leading space(s) w/zero
977        str = ReplaceString(" ", str, "0" )
978//      print  str
979       
980        return(str)  //  6 characters @ byte 9350
981End
982
983// sample label
984Function/S getSampleLabel(fname)
985        String fname
986       
987        String str
988       
989        // your code, returning str
990        str = (getStringFromHeader(fname,2075,30))  /// 25*81  +  50////+51 30 lines before the end
991       
992       
993        return(str)
994End
995
996// file creation date
997Function/S getFileCreationDate(fname)
998        String fname
999       
1000        String str
1001       
1002        // your code, returning str
1003       
1004        str = (getStringFromHeader(fname,2106,50))   //324 +12
1005       
1006        return(str)
1007End
1008
1009
1010Function/S getFileInstrument(fname)
1011        String fname
1012       
1013        String str
1014       
1015        // your code, returning str
1016       
1017        str = (getStringFromHeader(fname,324,3))   //324 +12
1018       
1019        return(str)
1020End
1021
1022
1023//reactor power
1024Function getReactorpower(fname)
1025        String fname
1026       
1027        Variable value
1028       
1029        // your code returning value
1030       
1031//      value = getRealValueFromHeader_2(fname,60,28,5,1,5)  //
1032       
1033        value = getRealValueFromHeader(fname,83)
1034       
1035//      print value
1036       
1037        return(value)
1038end
1039
1040
1041
1042
1043
1044//monitor count
1045Function getMonitorCount(fname)
1046        String fname
1047       
1048        Variable value
1049       
1050        // your code returning value
1051       
1052//      value = getRealValueFromHeader_2(fname,60,28,5,1,5)  //
1053       
1054        value = getRealValueFromHeader(fname,4)
1055       
1056//      print value
1057       
1058        return(value)
1059end
1060
1061//saved monitor count
1062// NCNR specific for pre-processed data, never used
1063// return 0
1064Function getSavMon(fname)
1065        String fname
1066       
1067        Variable value
1068       
1069        // your code returning value
1070       
1071        return(0)
1072end
1073
1074//total detector count
1075Function getDetCount(fname)
1076        String fname
1077       
1078        Variable value
1079       
1080        // your code returning value
1081       
1082//      value = getRealValueFromHeader_2(fname,60,28,5,1,4)
1083       
1084        value = getRealValueFromHeader(fname,3)
1085       
1086        return(value)
1087end
1088
1089//Attenuator number, return 1 if your attenuators are not
1090// indexed by number
1091Function getAttenNumber(fname)
1092        String fname
1093       
1094        Variable value
1095       
1096        // your code returning value
1097       
1098//      value = getRealValueFromHeader_2(fname,60,28,5,56,4)
1099       
1100        value = getRealValueFromHeader(fname,58)
1101       
1102        return(value)
1103end
1104
1105//transmission
1106Function getSampleTrans(fname)
1107        String fname
1108       
1109        Variable value
1110       
1111        // your code returning value
1112       
1113        value = getRealValueFromHeader(fname,45)
1114       
1115        return(value)
1116end
1117
1118//box counts from stored transmission calculation
1119// return 0 if not using NCNR transmission module
1120Function getBoxCounts(fname)
1121        String fname
1122       
1123        Variable value
1124       
1125        // your code returning value
1126        value = getRealValueFromHeader(fname,124)
1127       
1128        return(value)
1129end
1130
1131//whole detector trasmission
1132// return 0 if not using NCNR transmission module
1133Function getSampleTransWholeDetector(fname)
1134        String fname
1135       
1136        Variable value
1137       
1138        // your code returning value
1139       
1140        return(value)
1141end
1142
1143//SampleThickness in centimeters
1144Function getSampleThickness(fname)
1145        String fname
1146       
1147        Variable value
1148       
1149        // your code returning value
1150        value = getRealValueFromHeader(fname,40)  //mm
1151       
1152        return(value)
1153end
1154
1155//Sample Rotation Angle (degrees)
1156Function getSampleRotationAngle(fname)
1157        String fname
1158       
1159        Variable value
1160       
1161        // your code returning value
1162        value = getRealValueFromHeader(fname,64)
1163       
1164        return(value)
1165end
1166
1167//temperature (C)
1168Function getTemperature(fname)
1169        String fname
1170       
1171        Variable value
1172       
1173        // your code returning value
1174       
1175//      value = getRealValueFromHeader_2(fname,60,28,5,7,1)
1176       
1177        value = getRealValueFromHeader(fname,30)
1178       
1179        return(value)
1180end
1181
1182//field strength (Oe)
1183Function getFieldStrength(fname)
1184        String fname
1185       
1186        Variable value
1187       
1188        // your code returning value
1189       
1190        return(value)
1191end
1192
1193//center of beam xPos in pixel coordinates
1194Function getBeamXPos(fname)
1195        String fname
1196       
1197        Variable value
1198       
1199        // your code returning value   
1200//      value = getRealValueFromHeader(fname,14)                //Lionel
1201        value = getRealValueFromHeader(fname,50)/10             //SRK
1202       
1203        return(value)
1204end
1205
1206//center of beam Y pos in pixel coordinates
1207Function getBeamYPos(fname)
1208        String fname
1209       
1210        Variable value
1211       
1212        // your code returning value
1213//      value = getRealValueFromHeader(fname,15)                //Lionel
1214        value = getRealValueFromHeader(fname,51)/10             //SRK
1215       
1216        return(value)
1217end
1218
1219//sample to detector distance (meters)
1220Function getSDD(fname)
1221        String fname
1222       
1223        Variable value
1224       
1225        // your code returning value
1226//      value = getRealValueFromHeader_2(fname,60,28,5,4,4)
1227//      value = getRealValueFromHeader(fname,18)  detector distance but need to add the offset due to the table
1228       
1229        value = getRealValueFromHeader(fname,25)
1230       
1231       
1232        return(value)
1233end
1234
1235//lateral detector offset (centimeters)
1236Function getDetectorOffset(fname)
1237        String fname
1238       
1239        Variable value
1240       
1241        // your code returning value
1242//      value = getRealValueFromHeader_2(fname,60,28,5,13,2)
1243        value = getRealValueFromHeader(fname,61)
1244       
1245        return(value/10)  // need in cm ILL write in mm
1246end
1247
1248//Beamstop diameter (millimeters)
1249Function getBSDiameter(fname)
1250        String fname
1251       
1252        Variable value
1253       
1254        // your code returning value
1255       
1256//      value = getRealValueFromHeader_2(fname,60,28,5,15,5)
1257        value = getRealValueFromHeader(fname,74)
1258       
1259        return(value)
1260end
1261
1262//source aperture diameter (millimeters)
1263Function getSourceApertureDiam(fname)
1264        String fname
1265       
1266        Variable value
1267       
1268        // your code returning value
1269       
1270        value  = 52
1271       
1272        return(value)
1273end
1274
1275//sample aperture diameter (millimeters)
1276Function getSampleApertureDiam(fname)
1277        String fname
1278       
1279        Variable value
1280       
1281        // your code returning value
1282//      value = getRealValueFromHeader_2(fname,60,28,5,15,3)
1283        value = getRealValueFromHeader(fname,73)
1284       
1285        if(value == 0)          //in case no aperture size was written to raw data file
1286                value = 10
1287        endif
1288       
1289        return(value)
1290end
1291
1292//source AP to Sample AP distance (meters)
1293Function getSourceToSampleDist(fname)
1294        String fname
1295       
1296        Variable value
1297       
1298        // your code returning value
1299       
1300//      value = getRealValueFromHeader_2(fname,60,28,5,12,3)
1301       
1302        value = getRealValueFromHeader(fname,57)
1303       
1304        return(value)
1305end
1306
1307//wavelength (Angstroms)
1308Function getWavelength(fname)
1309        String fname
1310       
1311        Variable value
1312       
1313        // your code returning value
1314//      value = getRealValueFromHeader_2(fname,60,28,5,11,3)
1315        value = getRealValueFromHeader(fname,52)
1316       
1317        return(value)
1318end
1319
1320//wavelength spread (FWHM)
1321Function getWavelengthSpread(fname)
1322        String fname
1323       
1324        Variable value
1325       
1326        // your code returning value
1327        value = getRealValueFromHeader(fname,53)
1328
1329       
1330        return(value)
1331end
1332
1333// physical x-dimension of a detector pixel, in mm
1334Function getDetectorPixelXSize(fname)
1335        String fname
1336       
1337        Variable value
1338       
1339        // your code here returning value
1340//      value = getRealValueFromHeader_2(fname,60,28,5,11,5)
1341        value = getRealValueFromHeader(fname,54)
1342       
1343        return(value)
1344end
1345
1346// physical y-dimension of a detector pixel, in mm
1347Function getDetectorPixelYSize(fname)
1348        String fname
1349       
1350        Variable value
1351       
1352        // your code here returning value
1353//      value = getRealValueFromHeader_2(fname,60,28,5,12,1)
1354        value = getRealValueFromHeader(fname,55)
1355       
1356        return(value)
1357end
1358
1359//transmission detector count (unused, return 0)
1360//
1361Function getTransDetectorCounts(fname)
1362        String fname
1363       
1364        Variable value
1365       
1366        // your code returning value
1367       
1368        return(0)
1369end
1370
1371
1372//total count time (seconds)
1373// stored here as (s/10), so multiply by 10 ?
1374Function getCountTime(fname)
1375        String fname
1376       
1377        Variable value
1378       
1379        // your code returning value
1380       
1381//      value = getRealValueFromHeader_2(fname,60,28,5,1,3)  ///  line 1 col 3
1382       
1383        value = getRealValueFromHeader(fname,2)/10
1384       
1385        return(value)
1386end
1387
1388
1389//reads the wavelength from a reduced data file (not very reliable)
1390// - does not work with NSORTed files
1391// - only used in FIT/RPA (which itself is almost NEVER used...)
1392//
1393// DOES NOT NEED TO BE CHANGED IF USING NCNR DATA WRITER
1394Function GetLambdaFromReducedData(tempName)
1395        String tempName
1396       
1397        String junkString
1398        Variable lambdaFromFile, fileVar
1399        lambdaFromFile = 6.0
1400        Open/R/P=catPathName fileVar as tempName
1401        FReadLine fileVar, junkString
1402        FReadLine fileVar, junkString
1403        FReadLine fileVar, junkString
1404        if(strsearch(LowerStr(junkString),"lambda",0) != -1)
1405                FReadLine/N=11 fileVar, junkString
1406                FReadLine/N=10 fileVar, junkString
1407                lambdaFromFile = str2num(junkString)
1408        endif
1409        Close fileVar
1410       
1411        return(lambdaFromFile)
1412End
1413
1414/////   TRANSMISSION RELATED FUNCTIONS    ////////
1415//box coordinate are returned by reference
1416//
1417// box to sum over is bounded (x1,y1) to (x2,y2)
1418//
1419// this function returns the bounding coordinates as stored in
1420// the header
1421//
1422// if not using the NCNR Transmission module, this function default to
1423// returning 0000, and no changes needed
1424//
1425// filename is the full path:name to the file
1426Function getXYBoxFromFile(filename,x1,x2,y1,y2)
1427        String filename
1428        Variable &x1,&x2,&y1,&y2
1429
1430        // return your bounding box coordinates or default values of 0
1431        x1=getRealValueFromHeader(filename,120)
1432        x2=getRealValueFromHeader(filename,121)
1433        y1=getRealValueFromHeader(filename,122)
1434        y2=getRealValueFromHeader(filename,123)
1435       
1436//      print "in get", x1,x2,y1,y2
1437       
1438        return(0)
1439End
1440
1441// Writes the coordinates of the box to the header after user input
1442//
1443// box to sum over bounded (x1,y1) to (x2,y2)
1444//
1445// if not using the NCNR Transmission module, this function is null
1446//
1447// filename as passed in is a full path:filename
1448//
1449Function WriteXYBoxToHeader(filename,x1,x2,y1,y2)
1450        String filename
1451        Variable x1,x2,y1,y2
1452       
1453        // your code to write bounding box to the header, or nothing
1454       
1455        WriteReal(filename,x1,6804)
1456        WriteReal(filename,x2,6820)
1457        WriteReal(filename,y1,6836)
1458        WriteReal(filename,y2,6852)
1459       
1460        // use the last full line and the 4 first numbers
1461       
1462//      print "in write",x1,x2,y1,y2
1463       
1464        //  should start at 120  for read and  line 25
1465       
1466        /// 84 *81
1467       
1468        return(0)
1469End
1470
1471// for transmission calculation, writes an NCNR-specific alphanumeric identifier
1472// (suffix of the data file)
1473//
1474// if not using the NCNR Transmission module, this function is null
1475Function WriteAssocFileSuffixToHeader(fname,suffix)
1476        String fname,suffix
1477               
1478        // replace leading space(s) w/zero
1479        suffix = ReplaceString(" ", suffix, "0" )
1480               
1481        suffix = suffix[0,5]            //limit to 6 characters
1482       
1483        WriteText(fname,suffix,9350)
1484       
1485       
1486        return(0)
1487end
1488
1489Function/S getStringFromHeader(fname,start,num)
1490        String fname                            //full path:name
1491        Variable start,num              //starting byte and number of characters to read
1492       
1493        String str
1494        Variable refnum
1495        Open/R refNum as fname
1496        FSetPos refNum,start
1497        FReadLine/N=(num) refNum,str
1498        Close refnum
1499       
1500        return(str)
1501End
1502
1503Function getRealValueFromHeader(fname,start)
1504        String fname
1505        Variable start
1506        Variable numLinesLoaded = 0,firstchar,countTime
1507        variable refnum
1508        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread,result
1509        String buffer
1510        Make/O/D/N=128 TemporaryHeader
1511//      Make/O/D/N=(128) data
1512
1513        Open/R refNum as fname          //if fname is "", a dialog will be presented
1514        if(refnum==0)
1515                return(1)               //user cancelled
1516        endif
1517
1518//skip the next 10 lines
1519        For(ii=0;ii<60;ii+=1)
1520                FReadLine refnum,buffer
1521        EndFor
1522
1523// read in the whole header
1524        For (ii=60;ii<188;ii+=1)
1525
1526                numlinesloaded = ii-60
1527                FReadLine refNum,buffer //assume a 2nd line is there, w/16 values
1528                sscanf buffer,"%g %g %g %g %g ",v0,v1,v2,v3,v4
1529                valuesRead = V_flag
1530//              print valuesRead
1531               
1532//              print buffer
1533               
1534                //valuesRead = V_flag
1535//              print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1536//              print buffer
1537               
1538                TemporaryHeader[5*numlinesloaded] = v0
1539                TemporaryHeader[5*numlinesloaded+1] = v1                //monitor
1540                TemporaryHeader[5*numlinesloaded+2] = v2
1541                TemporaryHeader[5*numlinesloaded+3] = v3
1542                TemporaryHeader[5*numlinesloaded+4] = v4
1543        Endfor
1544                                               
1545        Close refNum           
1546        result= TemporaryHeader[start]
1547//      KillWaves/Z TemporaryHeader
1548       
1549        return (result)
1550End
1551
1552//Function getRealValueFromHeader_1(fname,start)
1553//      String fname
1554//      Variable start
1555//
1556//      String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=1/W=1/Q"
1557//     
1558//      GBLoadStr += "/S="+num2str(start)+"/U=10" + "\"" + fname + "\""
1559//      Execute GBLoadStr
1560//      Wave w=$"tempGBWave0"
1561//     
1562//      return(w[0])
1563//End
1564
1565//Function getRealValueFromHeader_2(fname,start,numrow,numcol,rowbit,colbit)
1566//      String fname
1567//      Variable start,numcol,numrow,colbit,rowbit
1568//      variable result
1569//      make /O/D/N=(numrow) w0,w1,w2,w3,w4
1570//      Make/O/D/N=(numrow,numcol) dataread
1571//     
1572//             
1573//      loadwave  /A=tempGBwave/L={0, start, numrow, 0, numcol}/N/G/D/O/K=1 fname
1574//     
1575//      Wave/Z tempGBwave0=tempGBwave0
1576//      Wave/Z tempGBwave1=tempGBwave1
1577//      Wave/Z tempGBwave2=tempGBwave2
1578//      Wave/Z tempGBwave3=tempGBwave3
1579//      Wave/Z tempGBwave4=tempGBwave4
1580//     
1581//     
1582//      w0=tempGBWave0
1583//       w1=tempGBWave1
1584//       w2=tempGBWave2
1585//       w3=tempGBWave3
1586//       w4=tempGBWave4
1587//     
1588/////                   redimension could use that to redimension dataread in only one colunm... but will see later..
1589//
1590//
1591//
1592//      KillWaves/Z tempGBwave0,tempGBwave1,tempGBwave3,tempGBwave2,tempGBwave4
1593//      ///        Make/O/D/N=(numrow,numcol),wres
1594//     
1595//      dataread[][0] = w0[p]
1596//      dataread[][1] = w1[p]
1597//      dataread[][2] = w2[p]
1598//      dataread[][3] = w3[p]
1599//      dataread[][4] = w4[p]
1600//
1601//KillWaves/Z w0,w1,w2,w3,w4
1602//     
1603////    wave wres = $"tempGBwave"  +num2str(linebit-1)
1604//      result  = dataread[rowbit-1][colbit-1]
1605//     
1606//      return(result)
1607//End
1608
1609
1610//Function ReadILLData(fname)
1611//      String fname
1612//     
1613//      NVAR pixelsX = root:myGlobals:gNPixelsX
1614//      NVAR pixelsY = root:myGlobals:gNPixelsY
1615//      Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=118   ///waas 20 for NIST
1616//      String str=""
1617//      //data is initially linear scale
1618//      Variable/G :gIsLogScale=0
1619//      Make/O/T/N=(numHdrLines) hdrLines
1620//      Make/O/D/N=(pixelsX*pixelsY) data       
1621//      Make/O/D/N=(1638,10)    datahelp        //,linear_data
1622//     
1623//      //full filename and path is now passed in...
1624//      //actually open the file
1625////    SetDataFolder destPath
1626//      Open/R/Z refNum as fname                // /Z flag means I must handle open errors
1627//      if(refnum==0)           //FNF error, get out
1628//              DoAlert 0,"Could not find file: "+fname
1629//              Close/A
1630//              SetDataFolder root:
1631//              return(1)
1632//      endif
1633//      if(V_flag!=0)
1634//              DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
1635//              Close/A
1636//              SetDataFolder root:
1637//              return(1)
1638//      Endif
1639//      //
1640//      for(ii=0;ii<numHdrLines;ii+=1)          //read (or skip) 18 header lines
1641//              FReadLine refnum,str
1642//              hdrLines[ii]=str
1643//      endfor
1644//      //     
1645//      Close refnum
1646//     
1647////    SetDataFolder destPath
1648//
1649//// loadwave  /A=tempt/L={0, 118, 1638, 1, 10}/N/J/D/O/E=1/K=1 fname
1650//
1651//loadwave  /A=tempt/L={0, 0, 1638, 0, 10}/N/G/D/O/E=1/K=1 fname
1652//
1653//Wave/Z tempt0=tempt0
1654//      Wave/Z tempt1=tempt1
1655//      Wave/Z tempt2=tempt2
1656//      Wave/Z tempt3=tempt3
1657//      Wave/Z tempt4=tempt4
1658//      Wave/Z tempt5=tempt5
1659//      Wave/Z tempt6=tempt6
1660//      Wave/Z tempt7=tempt7
1661//      Wave/Z tempt8=tempt8
1662//      Wave/Z tempt9=tempt9
1663//     
1664//     
1665//     
1666//     
1667//      datahelp[][0]=tempt0[p]
1668//      datahelp[][1]=tempt1[p]
1669//      datahelp[][2]=tempt2[p]
1670//      datahelp[][3]=tempt3[p]
1671//      datahelp[][4]=tempt4[p]
1672//      datahelp[][5]=tempt5[p]
1673//      datahelp[][6]=tempt6[p]
1674//      datahelp[][7]=tempt7[p]
1675//      datahelp[][8]=tempt8[p]
1676//      datahelp[][9]=tempt9[p]
1677//     
1678//      Killwaves/Z tempt1,tempt2,tempt3,tempt4,tempt0,tempt5,tempt6,tempt7,tempt8,tempt9
1679//
1680/////////////Wave/Z tempt0=tempt0
1681/////data=tempt
1682//     
1683//     
1684//      Redimension/N=(pixelsX,pixelsY) datahelp
1685//
1686//
1687////    LoadWave/Q/J/D/E=1/V={" " ,"non",1,1}/N=temp fName
1688////    Wave/Z temp0=temp0
1689////    data=temp0
1690////    Redimension/N=(pixelsX,pixelsY) data            //,linear_data
1691//     
1692//      //linear_data = data
1693//     
1694//      KillWaves/Z temp0
1695//     
1696//      //return the data folder to root
1697//      SetDataFolder root:
1698//     
1699//      Return(0)
1700//End
1701
1702
1703
1704Function ReadILLData2(fname,data)
1705        String fname
1706        wave data
1707
1708        Variable numLinesLoaded = 0,firstchar,countTime
1709        variable refnum
1710        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread
1711        String buffer
1712        Make/O/D/N=16384 Dataline               //temporary storage
1713
1714        Open/R refNum as fname          //if fname is "", a dialog will be presented
1715        if(refnum==0)
1716                return(1)               //user cancelled
1717        endif
1718
1719//skip the next 10 lines
1720        For(ii=0;ii<118;ii+=1)
1721                FReadLine refnum,buffer
1722        EndFor
1723
1724        For (ii=118;ii<1757;ii+=1)
1725                numlinesloaded = ii-118
1726                FReadLine refNum,buffer //assume a 2nd line is there, w/16 values
1727                sscanf buffer,"%g %g %g %g %g %g %g %g %g %g",v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1728                valuesRead = V_flag
1729//              print valuesRead               
1730//               buffer         
1731                //valuesRead = V_flag
1732//              print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1733//              print buffer
1734               
1735                if(ii == 1756)
1736                        dataline[10*numlinesloaded] = v0                                //last line has only four values
1737                        dataline[10*numlinesloaded+1] = v1
1738                        dataline[10*numlinesloaded+2] = v2
1739                        dataline[10*numlinesloaded+3] = v3
1740                else
1741                        dataline[10*numlinesloaded] = v0                //reading in 10 values per line
1742                        dataline[10*numlinesloaded+1] = v1
1743                        dataline[10*numlinesloaded+2] = v2
1744                        dataline[10*numlinesloaded+3] = v3
1745                        dataline[10*numlinesloaded+4] = v4
1746                        dataline[10*numlinesloaded+5] = v5
1747                        dataline[10*numlinesloaded+6] = v6
1748                        dataline[10*numlinesloaded+7] = v7
1749                        dataline[10*numlinesloaded+8] = v8
1750                        dataline[10*numlinesloaded+9] = v9
1751                endif
1752        Endfor
1753                                               
1754        Close refNum   
1755       
1756        data = dataline
1757        redimension /N=(128,128) data
1758       
1759//      Killwaves/Z dataline
1760       
1761        return (0)
1762
1763end
1764
1765// Write* routines all must:
1766// (1) open file "fname". fname is a full file path and name to the file on disk
1767// (2) write the specified value to the header at the correct location in the file
1768// (3) close the file
1769
1770//
1771// ILL header values are 16 characters: one space followed by 15 bytes of the value, in scientific notation (pos 2 is the sign, last 4 are "e(+-)XX" )
1772// SRK - May 2008
1773Function WriteReal(path,value,start)
1774        string path
1775        variable value,start
1776
1777        variable refnum
1778       
1779        String valStr
1780        sprintf valStr, "  %14e",value
1781//      print valstr, strlen(valStr)
1782       
1783        Open/A/T= "????" refnum as path
1784       
1785        FStatus refnum
1786        FSetPos refnum, start   
1787        FBinWrite refNum, valStr       
1788        FSetpos refnum,V_logEOF         // correct length is 142317 total bytes
1789       
1790        Close refnum
1791       
1792        return (0)
1793
1794end
1795
1796
1797Function/S PromptForPathtest(msgStr)
1798        String msgStr
1799        String fullPath
1800        Variable refnum
1801       
1802        //this just asks for the filename, doesn't open the file
1803        Open/D/R/T="????"/M=(msgStr) refNum
1804        fullPath = S_FileName           //fname is the full path
1805        //      Print refnum,fullPath
1806       
1807        //null string is returned in S_FileName if user cancelled, and is passed back to calling  function
1808        Return(fullPath)
1809End
1810
1811
1812/// !!!! Make sure the text string is the correct LENGTH before sending it here!!!
1813// SRK - May 2008
1814Function WriteText(path,str,start)
1815        string path,str
1816        variable start
1817       
1818        variable refnum
1819       
1820        Open/A/T= "????TEXT" refnum as path
1821       
1822        FStatus refnum
1823        FSetPos refnum, start
1824        FBinWrite/F=0 refnum, str      //native object format (character)
1825        FSetPos refnum,V_logEOF
1826       
1827        Close refnum
1828       
1829        return (0)
1830
1831end
1832////// OCT 2009, facility specific bits from ProDiv()
1833//"type" is the data folder that has the corrected, patched, and normalized DIV data array
1834//
1835// the header of this file is rather unimportant. Filling in a title at least would be helpful/
1836//
1837Function Write_DIV_File(type)
1838        String type
1839       
1840        // should have the linear display.....
1841        ConvertFolderToLogScale(type)
1842
1843        // Your file writing function here. Don't try to duplicate the VAX binary format...
1844       
1845        SetDataFolder $("root:Packages:NIST:"+type)
1846        Save/C linear_data as "plex.DIV"
1847       
1848        SetDataFolder root:
1849        return(0)
1850End
1851
1852////// OCT 2009, facility specific bits from MonteCarlo functions()
1853//"type" is the data folder that has the data array that is to be (re)written as a full
1854// data file, as if it was a raw data file
1855//
1856// not really necessary
1857//
1858Function/S Write_RawData_File(type,fullpath,dialog)
1859        String type,fullpath
1860        Variable dialog         //=1 will present dialog for name
1861       
1862        // Your file writing function here. Don't try to duplicate the VAX binary format...
1863        Print "Write_RawData_File stub"
1864       
1865        return(fullPath)
1866End
Note: See TracBrowser for help on using the repository browser.