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

Last change on this file since 764 was 764, checked in by srkline, 12 years ago
  • fixed a few bugs with GenCurveFit?, and how the reports are generated


  • the DEFAULT.MASK file is automatically loaded when the path is set, if it can be found. this only happens from the main (yellow) panel. Nothing happens if that exact file is not found.


  • a "Sector_PlusMinus" averaging option is added. This defines the LEFT sector as being "negative" q-values. Everything else behaves as a normal sector average. This is from Lionel, a very old ticket #31


  • if sectors or annular regions are drawn on RAW data files, the drawn lines are re-drawn correctly as the data is scrolled using the < and > buttons.


  • a super secret option for a "histogram pair" has been added. May be useful for alignment, may ditch if Jeff and Cedric don't like it. To do this, put cursor A on the 2D image at the center of where you want the vertical and horizontal swath to be. +-5 pixels is hard-wired. draw any marquee(size, location is ignored) and select SANS Histogram, and you get the pair. If cursor A is not on the graph, you get the normal histogram as defined by the marquee.


  • arrow buttons on RAW 2D data display now search +- 10 data files for "next", in case there are missing file numbers.


  • Incorporated Lionel's changes to ILL_* files for his generation of a "DIV" file for D22


  • Added the offset traces checkbox back to the SASCALC panel. previously it was hidden on the simulation panels.


  • loosened the tolerance for SDD matching onn the MRED panel to 0.1 m



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