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

Last change on this file was 940, checked in by srkline, 8 years ago

Updated the reduction Read/Write? and corresponding factility stubs to accomodate detector dead time written to the VAX header. It is currently not written to the header, but may be with NICE (hopefully).

With the move of NG3 SANS to CGB(upper), the NG3 designation in the account name [NGxSANSxx] has been replaced with CGB. Folders on charlotte and radio button on SASCALC are labeled "NGB30" to be more obvious which instrument it is.

FFT routines have minor typos cleaned up.

  • Property svn:executable set to *
File size: 42.5 KB
RevLine 
[353]1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
[570]3#pragma IgorVersion=6.1
[353]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
[573]75        String curPath = "root:Packages:NIST:RAW:"
[353]76        SetDataFolder curPath           //use the full path, so it will always work
[573]77        Variable/G root:Packages:NIST:RAW:gIsLogScale = 0               //initial state is linear, keep this in RAW folder
[353]78       
79        Variable refNum,integer,realval,ii
80        String sansfname,textstr,v0
81       
[573]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"
[353]86       
[573]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"
[353]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       
[370]113//      print "function read raw used"
[353]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)
[394]173        realw[20] = 102
[353]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       
[394]193        realw[52] = getreactorpower(fname)
194       
[353]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       
[573]208        Make/D/O/N=(XPix,YPix) $"root:Packages:NIST:RAW:data"
209        WAVE data=$"root:Packages:NIST:RAW:data"
[353]210
211        // fill the data array with the detector values
212        getDetectorData(fname,data)
213       
214        Setdatafolder curpath
215       
[795]216        Duplicate/O data linear_data            // data is "fresh" and linear scale, so copy it now
[353]217       
[795]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       
[353]226        //keep a string with the filename in the RAW folder
[573]227        String/G root:Packages:NIST:RAW:fileList = textw[0]
[353]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       
[573]248        String waveStr = "root:Packages:NIST:DIV:data"
[353]249        NewImage/F/K=1/S=2 $waveStr
250        ModifyImage '' ctab= {*,*,YellowHot,0}
251       
[573]252        String/G root:Packages:NIST:DIV:fileList = "WORK.DIV"
[353]253       
254        SetDataFolder root:             //(redundant)
255End
256
257
258
259
[370]260/////////DIV file created with NIST reduction so has the VAX format.... painful
[769]261//     
[764]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
[370]275Function ReadHeaderAndWork(type,fname)
276        String type,fname
277       
278        //type is the desired folder to read the workfile to
[764]279        //this data will NOT be automatically displayed
280        // gDataDisplayType is unchanged
[370]281
282        String cur_folder = type
[573]283        String curPath = "root:Packages:NIST:"+cur_folder
[370]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       
[764]290        Make/O/D/N=23 $(curPath + ":IntegersRead")
291        Make/O/D/N=52 $(curPath + ":RealsRead")
[370]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       
[764]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
[370]302       
[764]303        Make/O/D/N=(XPix,YPix) $(curPath + ":data")
304        WAVE data = $(curPath + ":data")
[370]305       
[764]306        Make/O/D/N=(XPix,YPix) $(curPath + ":linear_data")
307        WAVE linear_data = $(curPath + ":linear_data")
[370]308       
[769]309        // (1)
[764]310        // fill in your reader for the header here so that intw, realw, and textW are filled in
[769]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
[370]318
[764]319        //(2)
320        // then fill in a reader for the data array that will DIVIDE your data
321        // to get the corrected values.
[370]322
[764]323        //here you load in your file, you're already in the DIV folder
[769]324        LoadWave/O fname                //since fname is the full path
325               
[764]326        String loadedStr = StringFromList(0,S_waveNames,";")            //then name of the wave loaded
[776]327       
328//      data loaded should be named "linear_data" (this is set in the DIV writer)
[777]329        Duplicate/O linear_data,data                    // folder is in linear scale in its as-loaded state, so both are linear
[370]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
[353]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
[573]360        SetDataFolder "root:Packages:NIST:"+destPath
[353]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       
[795]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       
[353]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
[573]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")
[353]440       
[573]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")
[353]444       
445        //Put in appropriate "fake" values
446        //parse values as needed from headerLines
[573]447        Wave/T hdr=$("root:Packages:NIST:"+destFolder+":hdrLines")
[353]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
[448]467        realw[10]=8                     //detector calibration constants, needed for averaging
[353]468        realw[11]=10000
469        realw[12]=0
[448]470        realw[13]=8
[353]471        realw[14]=10000
472        realw[15]=0
473        //
474        // used in the resolution calculation, ONLY here to keep the routine from crashing
[448]475        realw[20]=102           //det size
[353]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
[573]498        String/G $("root:Packages:NIST:"+destFolder+":fileList") = tempStr
[353]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
[795]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
[353]554//sample transmission (0<T<=1)
555Function WriteTransmissionToHeader(fname,trans)
556        String fname
557        Variable trans
558       
559        // your writer here
560       
[376]561        WriteReal(fname,trans,5589)     //I will define at position 10 lines position 1  by myself
[353]562       
[376]563        // 16 bites between numbers and 81 per line
564       
[353]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
[376]575        WriteReal(fname,trans,6885)   /// //I will define at position last  lines  position 1  by myself
[353]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       
[370]588        WriteReal(fname,counts,6868)
[353]589       
[376]590        ////I will define at position 2   lines before the end and  last position   by myself
591       
592       
[353]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       
[376]604        WriteReal(fname,xpos,5119)    ////should do it for ypos for ILL ....NEED TO REMEMBER HERE
605        /// line 4 column 2   
[353]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       
[376]617        WriteReal(fname,num,5508)  //define at 9 lines  column 1 just above transmission by myself
[353]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
[394]630        WriteReal(fname,num*10,5670)
[353]631       
[376]632        ///   line 11 column 1
633       
[353]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       
[394]644        WriteReal(fname,num*10,5686)
[353]645       
[376]646        ///   line 11 column 2
647       
[353]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
[376]660        WriteReal(fname,num,5799)
[353]661       
[376]662        ///   line 12 column 4
663       
[353]664        return(0)
665End
666
[394]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
[353]687// total monitor count during data collection
688Function WriteMonitorCountToHeader(fname,num)
689        String fname
690        Variable num
691       
692        // your code here
693       
[376]694        WriteReal(fname,num,4924)
[353]695       
[376]696        ///   line 1 column 5
697       
[353]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       
[376]708        WriteReal(fname,num,4908)
[353]709       
[376]710        ///   line 1 column 4
711       
[353]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
[376]732        WriteReal(fname,num,5703)
[353]733       
[376]734        //   line 11 column 3
735       
[353]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       
[376]746        WriteReal(fname,num,5719)
[353]747       
[376]748        //   line 11 column 4
749       
[353]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       
[376]760        WriteReal(fname,num,5347)
[353]761       
[376]762        //   line 7 column 1
763       
[353]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)
[376]784      WriteReal(fname,num,6027)    ///4*81 = 324
785     
786      // line 15 colum 3
[353]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
[376]797        WriteReal(fname,num,6043)
[353]798       
[376]799            // line 15 colum 4
800       
[353]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
[376]810        WriteReal(fname,num,5784)  //it is collimation at ILL
[353]811       
[376]812       
[353]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       
[394]823        WriteReal(fname,10*num,5849)
[353]824       
[376]825       
826       
827        // line 13 column 2
828       
[353]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
[376]838        WriteReal(fname,num,6059)
[353]839       
[376]840        //line 15 column 5
841       
[353]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
[448]851        //WriteReal(fname,num,5152)
[353]852       
[448]853       
854        WriteReal(fname,num,5265)
855       
[376]856        // line 4 column 4
857       
[448]858        // real calculated distance line 6 colunm1
859       
[353]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
[376]869        WriteReal(fname,num,5735)
[353]870       
[376]871        //  line 11 column 5   
872       
[353]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
[376]882        WriteReal(fname,num,5752)
[353]883       
884        return(0)
885end
886
887// sample label string
888Function WriteSamLabelToHeader(fname,str)
889        String fname,str
890       
891        // your code here
[394]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       
[376]903        WriteText(fname,str,2075)   //// need to change that in order to erase the title and write a new one
[353]904
905        return(0)
906End
907
[370]908// total counting time (stored here as seconds/10??)
[353]909Function WriteCountTimeToHeader(fname,num)
910        String fname
911        Variable num
912       
913        // your code here
[370]914//      WriteReal(fname,num,4894)
[376]915        WriteReal(fname,10*num,4892)
[353]916       
917       
918       
919        return(0)
920End
921
[940]922// Write the detector deadtime to the file header (in seconds)
923Function WriteDeadtimeToHeader(fname,num)
924        String fname
925        Variable num
926       
927        return(0)
928End
[353]929
930
931//////// ACCESSORS FOR READING DATA FROM THE HEADER  //////////////
932//
933// read specific bits of information from the header
934// each of these operations MUST take care of open/close on their own
935//
936// fname is the full path and filname to the file on disk
937// return values are either strings or real values as appropriate
938//
939//////
940
941
942// function that reads in the 2D detector data and fills the array
943// data[nx][ny] with the data values
944// fname is the full name and path to the data file for opening and closing
945//
946//
947Function getDetectorData(fname,data)
948        String fname
949        Wave data
950       
951       
952        // your reader here
953       
954//      value = getRealValueFromHeader_2(fname,60,28,5,1,3)  // data start at 60+58 lines
955        ReadILLData2(fname,data)
956       
957        return (0)
958End
959
960// file suffix (NCNR data file name specific)
961// return null string
962Function/S getSuffix(fname)
963        String fname
964       
[394]965        String suffix = getStringFromHeader(fname,9341,6)
966       
967        // replace the leading space w/ "0"
968        suffix = ReplaceString(" ",suffix,"0")
969       
970        return(suffix)   //// file suffix (6 characters @ byte 9341)
[353]971End
972
973// associated file suffix (for transmission)
974// NCNR Transmission calculation specific
975// return null string
976Function/S getAssociatedFileSuffix(fname)
977        String fname
978       
[394]979        string str
980       
981        str= getStringFromHeader(fname,9350,6)
982       
983        // replace leading space(s) w/zero
984        str = ReplaceString(" ", str, "0" )
985//      print  str
986       
987        return(str)  //  6 characters @ byte 9350
[353]988End
989
990// sample label
991Function/S getSampleLabel(fname)
992        String fname
993       
994        String str
995       
996        // your code, returning str
[370]997        str = (getStringFromHeader(fname,2075,30))  /// 25*81  +  50////+51 30 lines before the end
[353]998       
999       
1000        return(str)
1001End
1002
1003// file creation date
1004Function/S getFileCreationDate(fname)
1005        String fname
1006       
1007        String str
1008       
1009        // your code, returning str
1010       
1011        str = (getStringFromHeader(fname,2106,50))   //324 +12
1012       
1013        return(str)
1014End
1015
1016
1017Function/S getFileInstrument(fname)
1018        String fname
1019       
1020        String str
1021       
1022        // your code, returning str
1023       
1024        str = (getStringFromHeader(fname,324,3))   //324 +12
1025       
1026        return(str)
1027End
1028
1029
[394]1030//reactor power
1031Function getReactorpower(fname)
1032        String fname
1033       
1034        Variable value
1035       
1036        // your code returning value
1037       
1038//      value = getRealValueFromHeader_2(fname,60,28,5,1,5)  //
1039       
1040        value = getRealValueFromHeader(fname,83)
1041       
1042//      print value
1043       
1044        return(value)
1045end
[353]1046
1047
[394]1048
1049
1050
[353]1051//monitor count
1052Function getMonitorCount(fname)
1053        String fname
1054       
1055        Variable value
1056       
1057        // your code returning value
1058       
1059//      value = getRealValueFromHeader_2(fname,60,28,5,1,5)  //
1060       
1061        value = getRealValueFromHeader(fname,4)
1062       
1063//      print value
1064       
1065        return(value)
1066end
1067
1068//saved monitor count
1069// NCNR specific for pre-processed data, never used
1070// return 0
1071Function getSavMon(fname)
1072        String fname
1073       
1074        Variable value
1075       
1076        // your code returning value
1077       
1078        return(0)
1079end
1080
1081//total detector count
1082Function getDetCount(fname)
1083        String fname
1084       
1085        Variable value
1086       
1087        // your code returning value
1088       
1089//      value = getRealValueFromHeader_2(fname,60,28,5,1,4)
1090       
1091        value = getRealValueFromHeader(fname,3)
1092       
1093        return(value)
1094end
1095
1096//Attenuator number, return 1 if your attenuators are not
1097// indexed by number
1098Function getAttenNumber(fname)
1099        String fname
1100       
1101        Variable value
1102       
1103        // your code returning value
1104       
1105//      value = getRealValueFromHeader_2(fname,60,28,5,56,4)
1106       
1107        value = getRealValueFromHeader(fname,58)
1108       
1109        return(value)
1110end
1111
1112//transmission
1113Function getSampleTrans(fname)
1114        String fname
1115       
1116        Variable value
1117       
1118        // your code returning value
1119       
[370]1120        value = getRealValueFromHeader(fname,45)
[353]1121       
1122        return(value)
1123end
1124
1125//box counts from stored transmission calculation
1126// return 0 if not using NCNR transmission module
1127Function getBoxCounts(fname)
1128        String fname
1129       
1130        Variable value
1131       
1132        // your code returning value
[370]1133        value = getRealValueFromHeader(fname,124)
[353]1134       
1135        return(value)
1136end
1137
1138//whole detector trasmission
1139// return 0 if not using NCNR transmission module
1140Function getSampleTransWholeDetector(fname)
1141        String fname
1142       
1143        Variable value
1144       
1145        // your code returning value
1146       
1147        return(value)
1148end
1149
1150//SampleThickness in centimeters
1151Function getSampleThickness(fname)
1152        String fname
1153       
1154        Variable value
1155       
1156        // your code returning value
[370]1157        value = getRealValueFromHeader(fname,40)  //mm
[353]1158       
1159        return(value)
1160end
1161
1162//Sample Rotation Angle (degrees)
1163Function getSampleRotationAngle(fname)
1164        String fname
1165       
1166        Variable value
1167       
1168        // your code returning value
1169        value = getRealValueFromHeader(fname,64)
1170       
1171        return(value)
1172end
1173
1174//temperature (C)
1175Function getTemperature(fname)
1176        String fname
1177       
1178        Variable value
1179       
1180        // your code returning value
1181       
1182//      value = getRealValueFromHeader_2(fname,60,28,5,7,1)
1183       
1184        value = getRealValueFromHeader(fname,30)
1185       
1186        return(value)
1187end
1188
1189//field strength (Oe)
1190Function getFieldStrength(fname)
1191        String fname
1192       
1193        Variable value
1194       
1195        // your code returning value
1196       
1197        return(value)
1198end
1199
1200//center of beam xPos in pixel coordinates
1201Function getBeamXPos(fname)
1202        String fname
1203       
1204        Variable value
1205       
1206        // your code returning value   
1207//      value = getRealValueFromHeader(fname,14)                //Lionel
[394]1208        value = getRealValueFromHeader(fname,50)/10             //SRK
[353]1209       
1210        return(value)
1211end
1212
1213//center of beam Y pos in pixel coordinates
1214Function getBeamYPos(fname)
1215        String fname
1216       
1217        Variable value
1218       
1219        // your code returning value
1220//      value = getRealValueFromHeader(fname,15)                //Lionel
[394]1221        value = getRealValueFromHeader(fname,51)/10             //SRK
[353]1222       
1223        return(value)
1224end
1225
1226//sample to detector distance (meters)
1227Function getSDD(fname)
1228        String fname
1229       
1230        Variable value
1231       
1232        // your code returning value
1233//      value = getRealValueFromHeader_2(fname,60,28,5,4,4)
[448]1234//      value = getRealValueFromHeader(fname,18)  detector distance but need to add the offset due to the table
[353]1235       
[448]1236        value = getRealValueFromHeader(fname,25)
1237       
1238       
[353]1239        return(value)
1240end
1241
1242//lateral detector offset (centimeters)
1243Function getDetectorOffset(fname)
1244        String fname
1245       
1246        Variable value
1247       
1248        // your code returning value
1249//      value = getRealValueFromHeader_2(fname,60,28,5,13,2)
1250        value = getRealValueFromHeader(fname,61)
1251       
[394]1252        return(value/10)  // need in cm ILL write in mm
[353]1253end
1254
1255//Beamstop diameter (millimeters)
1256Function getBSDiameter(fname)
1257        String fname
1258       
1259        Variable value
1260       
1261        // your code returning value
1262       
1263//      value = getRealValueFromHeader_2(fname,60,28,5,15,5)
1264        value = getRealValueFromHeader(fname,74)
1265       
1266        return(value)
1267end
1268
1269//source aperture diameter (millimeters)
1270Function getSourceApertureDiam(fname)
1271        String fname
1272       
1273        Variable value
1274       
1275        // your code returning value
1276       
[376]1277        value  = 52
1278       
[353]1279        return(value)
1280end
1281
1282//sample aperture diameter (millimeters)
1283Function getSampleApertureDiam(fname)
1284        String fname
1285       
1286        Variable value
1287       
1288        // your code returning value
1289//      value = getRealValueFromHeader_2(fname,60,28,5,15,3)
[779]1290        value = getRealValueFromHeader(fname,73)
[353]1291       
[779]1292        if(value == 0)          //in case no aperture size was written to raw data file
1293                value = 10
1294        endif
[370]1295       
[353]1296        return(value)
1297end
1298
1299//source AP to Sample AP distance (meters)
1300Function getSourceToSampleDist(fname)
1301        String fname
1302       
1303        Variable value
1304       
1305        // your code returning value
1306       
1307//      value = getRealValueFromHeader_2(fname,60,28,5,12,3)
1308       
1309        value = getRealValueFromHeader(fname,57)
1310       
1311        return(value)
1312end
1313
1314//wavelength (Angstroms)
1315Function getWavelength(fname)
1316        String fname
1317       
1318        Variable value
1319       
1320        // your code returning value
1321//      value = getRealValueFromHeader_2(fname,60,28,5,11,3)
1322        value = getRealValueFromHeader(fname,52)
1323       
1324        return(value)
1325end
1326
1327//wavelength spread (FWHM)
1328Function getWavelengthSpread(fname)
1329        String fname
1330       
1331        Variable value
1332       
1333        // your code returning value
1334        value = getRealValueFromHeader(fname,53)
1335
1336       
1337        return(value)
1338end
1339
1340// physical x-dimension of a detector pixel, in mm
1341Function getDetectorPixelXSize(fname)
1342        String fname
1343       
1344        Variable value
1345       
1346        // your code here returning value
1347//      value = getRealValueFromHeader_2(fname,60,28,5,11,5)
1348        value = getRealValueFromHeader(fname,54)
1349       
1350        return(value)
1351end
1352
1353// physical y-dimension of a detector pixel, in mm
1354Function getDetectorPixelYSize(fname)
1355        String fname
1356       
1357        Variable value
1358       
1359        // your code here returning value
1360//      value = getRealValueFromHeader_2(fname,60,28,5,12,1)
1361        value = getRealValueFromHeader(fname,55)
1362       
1363        return(value)
1364end
1365
1366//transmission detector count (unused, return 0)
1367//
1368Function getTransDetectorCounts(fname)
1369        String fname
1370       
1371        Variable value
1372       
1373        // your code returning value
1374       
1375        return(0)
1376end
1377
1378
1379//total count time (seconds)
[370]1380// stored here as (s/10), so multiply by 10 ?
[353]1381Function getCountTime(fname)
1382        String fname
1383       
1384        Variable value
1385       
1386        // your code returning value
1387       
1388//      value = getRealValueFromHeader_2(fname,60,28,5,1,3)  ///  line 1 col 3
1389       
[370]1390        value = getRealValueFromHeader(fname,2)/10
[353]1391       
1392        return(value)
1393end
1394
[940]1395// read the detector deadtime (in seconds)
1396Function getDetectorDeadtime(fname)
1397        String fname
1398       
1399        return(0)
1400end
[353]1401
1402//reads the wavelength from a reduced data file (not very reliable)
1403// - does not work with NSORTed files
1404// - only used in FIT/RPA (which itself is almost NEVER used...)
1405//
1406// DOES NOT NEED TO BE CHANGED IF USING NCNR DATA WRITER
1407Function GetLambdaFromReducedData(tempName)
1408        String tempName
1409       
1410        String junkString
1411        Variable lambdaFromFile, fileVar
1412        lambdaFromFile = 6.0
1413        Open/R/P=catPathName fileVar as tempName
1414        FReadLine fileVar, junkString
1415        FReadLine fileVar, junkString
1416        FReadLine fileVar, junkString
1417        if(strsearch(LowerStr(junkString),"lambda",0) != -1)
1418                FReadLine/N=11 fileVar, junkString
1419                FReadLine/N=10 fileVar, junkString
1420                lambdaFromFile = str2num(junkString)
1421        endif
1422        Close fileVar
1423       
1424        return(lambdaFromFile)
1425End
1426
1427/////   TRANSMISSION RELATED FUNCTIONS    ////////
1428//box coordinate are returned by reference
1429//
1430// box to sum over is bounded (x1,y1) to (x2,y2)
1431//
1432// this function returns the bounding coordinates as stored in
1433// the header
1434//
1435// if not using the NCNR Transmission module, this function default to
1436// returning 0000, and no changes needed
[370]1437//
1438// filename is the full path:name to the file
[353]1439Function getXYBoxFromFile(filename,x1,x2,y1,y2)
1440        String filename
1441        Variable &x1,&x2,&y1,&y2
1442
1443        // return your bounding box coordinates or default values of 0
[370]1444        x1=getRealValueFromHeader(filename,120)
1445        x2=getRealValueFromHeader(filename,121)
1446        y1=getRealValueFromHeader(filename,122)
1447        y2=getRealValueFromHeader(filename,123)
[353]1448       
[370]1449//      print "in get", x1,x2,y1,y2
1450       
[353]1451        return(0)
1452End
1453
1454// Writes the coordinates of the box to the header after user input
1455//
1456// box to sum over bounded (x1,y1) to (x2,y2)
1457//
1458// if not using the NCNR Transmission module, this function is null
[370]1459//
1460// filename as passed in is a full path:filename
1461//
[353]1462Function WriteXYBoxToHeader(filename,x1,x2,y1,y2)
1463        String filename
1464        Variable x1,x2,y1,y2
1465       
1466        // your code to write bounding box to the header, or nothing
1467       
[370]1468        WriteReal(filename,x1,6804)
1469        WriteReal(filename,x2,6820)
1470        WriteReal(filename,y1,6836)
1471        WriteReal(filename,y2,6852)
1472       
[376]1473        // use the last full line and the 4 first numbers
[370]1474       
[376]1475//      print "in write",x1,x2,y1,y2
1476       
[370]1477        //  should start at 120  for read and  line 25
1478       
1479        /// 84 *81
1480       
[353]1481        return(0)
1482End
1483
1484// for transmission calculation, writes an NCNR-specific alphanumeric identifier
1485// (suffix of the data file)
1486//
1487// if not using the NCNR Transmission module, this function is null
1488Function WriteAssocFileSuffixToHeader(fname,suffix)
1489        String fname,suffix
1490               
[394]1491        // replace leading space(s) w/zero
1492        suffix = ReplaceString(" ", suffix, "0" )
1493               
1494        suffix = suffix[0,5]            //limit to 6 characters
[353]1495       
[394]1496        WriteText(fname,suffix,9350)
1497       
1498       
[353]1499        return(0)
1500end
1501
1502Function/S getStringFromHeader(fname,start,num)
1503        String fname                            //full path:name
1504        Variable start,num              //starting byte and number of characters to read
1505       
1506        String str
1507        Variable refnum
1508        Open/R refNum as fname
1509        FSetPos refNum,start
1510        FReadLine/N=(num) refNum,str
1511        Close refnum
1512       
1513        return(str)
1514End
1515
1516Function getRealValueFromHeader(fname,start)
1517        String fname
1518        Variable start
1519        Variable numLinesLoaded = 0,firstchar,countTime
1520        variable refnum
1521        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread,result
1522        String buffer
1523        Make/O/D/N=128 TemporaryHeader
1524//      Make/O/D/N=(128) data
1525
1526        Open/R refNum as fname          //if fname is "", a dialog will be presented
1527        if(refnum==0)
1528                return(1)               //user cancelled
1529        endif
1530
1531//skip the next 10 lines
1532        For(ii=0;ii<60;ii+=1)
1533                FReadLine refnum,buffer
1534        EndFor
1535
1536// read in the whole header
1537        For (ii=60;ii<188;ii+=1)
1538
1539                numlinesloaded = ii-60
1540                FReadLine refNum,buffer //assume a 2nd line is there, w/16 values
1541                sscanf buffer,"%g %g %g %g %g ",v0,v1,v2,v3,v4
1542                valuesRead = V_flag
1543//              print valuesRead
1544               
1545//              print buffer
1546               
1547                //valuesRead = V_flag
1548//              print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1549//              print buffer
1550               
1551                TemporaryHeader[5*numlinesloaded] = v0
1552                TemporaryHeader[5*numlinesloaded+1] = v1                //monitor
1553                TemporaryHeader[5*numlinesloaded+2] = v2
1554                TemporaryHeader[5*numlinesloaded+3] = v3
1555                TemporaryHeader[5*numlinesloaded+4] = v4
1556        Endfor
1557                                               
1558        Close refNum           
1559        result= TemporaryHeader[start]
1560//      KillWaves/Z TemporaryHeader
1561       
1562        return (result)
1563End
1564
1565//Function getRealValueFromHeader_1(fname,start)
1566//      String fname
1567//      Variable start
1568//
1569//      String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=1/W=1/Q"
1570//     
1571//      GBLoadStr += "/S="+num2str(start)+"/U=10" + "\"" + fname + "\""
1572//      Execute GBLoadStr
1573//      Wave w=$"tempGBWave0"
1574//     
1575//      return(w[0])
1576//End
1577
1578//Function getRealValueFromHeader_2(fname,start,numrow,numcol,rowbit,colbit)
1579//      String fname
1580//      Variable start,numcol,numrow,colbit,rowbit
1581//      variable result
1582//      make /O/D/N=(numrow) w0,w1,w2,w3,w4
1583//      Make/O/D/N=(numrow,numcol) dataread
1584//     
1585//             
1586//      loadwave  /A=tempGBwave/L={0, start, numrow, 0, numcol}/N/G/D/O/K=1 fname
1587//     
1588//      Wave/Z tempGBwave0=tempGBwave0
1589//      Wave/Z tempGBwave1=tempGBwave1
1590//      Wave/Z tempGBwave2=tempGBwave2
1591//      Wave/Z tempGBwave3=tempGBwave3
1592//      Wave/Z tempGBwave4=tempGBwave4
1593//     
1594//     
1595//      w0=tempGBWave0
1596//       w1=tempGBWave1
1597//       w2=tempGBWave2
1598//       w3=tempGBWave3
1599//       w4=tempGBWave4
1600//     
1601/////                   redimension could use that to redimension dataread in only one colunm... but will see later..
1602//
1603//
1604//
1605//      KillWaves/Z tempGBwave0,tempGBwave1,tempGBwave3,tempGBwave2,tempGBwave4
1606//      ///        Make/O/D/N=(numrow,numcol),wres
1607//     
1608//      dataread[][0] = w0[p]
1609//      dataread[][1] = w1[p]
1610//      dataread[][2] = w2[p]
1611//      dataread[][3] = w3[p]
1612//      dataread[][4] = w4[p]
1613//
1614//KillWaves/Z w0,w1,w2,w3,w4
1615//     
1616////    wave wres = $"tempGBwave"  +num2str(linebit-1)
1617//      result  = dataread[rowbit-1][colbit-1]
1618//     
1619//      return(result)
1620//End
1621
1622
1623//Function ReadILLData(fname)
1624//      String fname
1625//     
1626//      NVAR pixelsX = root:myGlobals:gNPixelsX
1627//      NVAR pixelsY = root:myGlobals:gNPixelsY
1628//      Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=118   ///waas 20 for NIST
1629//      String str=""
1630//      //data is initially linear scale
1631//      Variable/G :gIsLogScale=0
1632//      Make/O/T/N=(numHdrLines) hdrLines
1633//      Make/O/D/N=(pixelsX*pixelsY) data       
1634//      Make/O/D/N=(1638,10)    datahelp        //,linear_data
1635//     
1636//      //full filename and path is now passed in...
1637//      //actually open the file
1638////    SetDataFolder destPath
1639//      Open/R/Z refNum as fname                // /Z flag means I must handle open errors
1640//      if(refnum==0)           //FNF error, get out
1641//              DoAlert 0,"Could not find file: "+fname
1642//              Close/A
1643//              SetDataFolder root:
1644//              return(1)
1645//      endif
1646//      if(V_flag!=0)
1647//              DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
1648//              Close/A
1649//              SetDataFolder root:
1650//              return(1)
1651//      Endif
1652//      //
1653//      for(ii=0;ii<numHdrLines;ii+=1)          //read (or skip) 18 header lines
1654//              FReadLine refnum,str
1655//              hdrLines[ii]=str
1656//      endfor
1657//      //     
1658//      Close refnum
1659//     
1660////    SetDataFolder destPath
1661//
1662//// loadwave  /A=tempt/L={0, 118, 1638, 1, 10}/N/J/D/O/E=1/K=1 fname
1663//
1664//loadwave  /A=tempt/L={0, 0, 1638, 0, 10}/N/G/D/O/E=1/K=1 fname
1665//
1666//Wave/Z tempt0=tempt0
1667//      Wave/Z tempt1=tempt1
1668//      Wave/Z tempt2=tempt2
1669//      Wave/Z tempt3=tempt3
1670//      Wave/Z tempt4=tempt4
1671//      Wave/Z tempt5=tempt5
1672//      Wave/Z tempt6=tempt6
1673//      Wave/Z tempt7=tempt7
1674//      Wave/Z tempt8=tempt8
1675//      Wave/Z tempt9=tempt9
1676//     
1677//     
1678//     
1679//     
1680//      datahelp[][0]=tempt0[p]
1681//      datahelp[][1]=tempt1[p]
1682//      datahelp[][2]=tempt2[p]
1683//      datahelp[][3]=tempt3[p]
1684//      datahelp[][4]=tempt4[p]
1685//      datahelp[][5]=tempt5[p]
1686//      datahelp[][6]=tempt6[p]
1687//      datahelp[][7]=tempt7[p]
1688//      datahelp[][8]=tempt8[p]
1689//      datahelp[][9]=tempt9[p]
1690//     
1691//      Killwaves/Z tempt1,tempt2,tempt3,tempt4,tempt0,tempt5,tempt6,tempt7,tempt8,tempt9
1692//
1693/////////////Wave/Z tempt0=tempt0
1694/////data=tempt
1695//     
1696//     
1697//      Redimension/N=(pixelsX,pixelsY) datahelp
1698//
1699//
1700////    LoadWave/Q/J/D/E=1/V={" " ,"non",1,1}/N=temp fName
1701////    Wave/Z temp0=temp0
1702////    data=temp0
1703////    Redimension/N=(pixelsX,pixelsY) data            //,linear_data
1704//     
1705//      //linear_data = data
1706//     
1707//      KillWaves/Z temp0
1708//     
1709//      //return the data folder to root
1710//      SetDataFolder root:
1711//     
1712//      Return(0)
1713//End
1714
1715
1716
1717Function ReadILLData2(fname,data)
1718        String fname
1719        wave data
1720
1721        Variable numLinesLoaded = 0,firstchar,countTime
1722        variable refnum
1723        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread
1724        String buffer
1725        Make/O/D/N=16384 Dataline               //temporary storage
1726
1727        Open/R refNum as fname          //if fname is "", a dialog will be presented
1728        if(refnum==0)
1729                return(1)               //user cancelled
1730        endif
1731
1732//skip the next 10 lines
1733        For(ii=0;ii<118;ii+=1)
1734                FReadLine refnum,buffer
1735        EndFor
1736
1737        For (ii=118;ii<1757;ii+=1)
1738                numlinesloaded = ii-118
1739                FReadLine refNum,buffer //assume a 2nd line is there, w/16 values
1740                sscanf buffer,"%g %g %g %g %g %g %g %g %g %g",v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1741                valuesRead = V_flag
1742//              print valuesRead               
[370]1743//               buffer         
[353]1744                //valuesRead = V_flag
1745//              print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9
1746//              print buffer
1747               
1748                if(ii == 1756)
1749                        dataline[10*numlinesloaded] = v0                                //last line has only four values
1750                        dataline[10*numlinesloaded+1] = v1
1751                        dataline[10*numlinesloaded+2] = v2
1752                        dataline[10*numlinesloaded+3] = v3
1753                else
1754                        dataline[10*numlinesloaded] = v0                //reading in 10 values per line
1755                        dataline[10*numlinesloaded+1] = v1
1756                        dataline[10*numlinesloaded+2] = v2
1757                        dataline[10*numlinesloaded+3] = v3
1758                        dataline[10*numlinesloaded+4] = v4
1759                        dataline[10*numlinesloaded+5] = v5
1760                        dataline[10*numlinesloaded+6] = v6
1761                        dataline[10*numlinesloaded+7] = v7
1762                        dataline[10*numlinesloaded+8] = v8
1763                        dataline[10*numlinesloaded+9] = v9
1764                endif
1765        Endfor
1766                                               
1767        Close refNum   
1768       
1769        data = dataline
1770        redimension /N=(128,128) data
1771       
1772//      Killwaves/Z dataline
1773       
1774        return (0)
1775
1776end
1777
1778// Write* routines all must:
1779// (1) open file "fname". fname is a full file path and name to the file on disk
1780// (2) write the specified value to the header at the correct location in the file
1781// (3) close the file
1782
1783//
1784// 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" )
1785// SRK - May 2008
1786Function WriteReal(path,value,start)
1787        string path
1788        variable value,start
1789
1790        variable refnum
1791       
1792        String valStr
1793        sprintf valStr, "  %14e",value
1794//      print valstr, strlen(valStr)
1795       
1796        Open/A/T= "????" refnum as path
1797       
1798        FStatus refnum
1799        FSetPos refnum, start   
1800        FBinWrite refNum, valStr       
1801        FSetpos refnum,V_logEOF         // correct length is 142317 total bytes
1802       
1803        Close refnum
1804       
1805        return (0)
1806
1807end
1808
1809
1810Function/S PromptForPathtest(msgStr)
1811        String msgStr
1812        String fullPath
1813        Variable refnum
1814       
1815        //this just asks for the filename, doesn't open the file
1816        Open/D/R/T="????"/M=(msgStr) refNum
1817        fullPath = S_FileName           //fname is the full path
1818        //      Print refnum,fullPath
1819       
1820        //null string is returned in S_FileName if user cancelled, and is passed back to calling  function
1821        Return(fullPath)
1822End
1823
1824
1825/// !!!! Make sure the text string is the correct LENGTH before sending it here!!!
1826// SRK - May 2008
[394]1827Function WriteText(path,str,start)
1828        string path,str
[353]1829        variable start
1830       
1831        variable refnum
1832       
[394]1833        Open/A/T= "????TEXT" refnum as path
[353]1834       
1835        FStatus refnum
1836        FSetPos refnum, start
[394]1837        FBinWrite/F=0 refnum, str      //native object format (character)
[353]1838        FSetPos refnum,V_logEOF
1839       
1840        Close refnum
1841       
1842        return (0)
1843
1844end
[571]1845////// OCT 2009, facility specific bits from ProDiv()
1846//"type" is the data folder that has the corrected, patched, and normalized DIV data array
1847//
1848// the header of this file is rather unimportant. Filling in a title at least would be helpful/
1849//
1850Function Write_DIV_File(type)
1851        String type
1852       
[764]1853        // should have the linear display.....
[776]1854        ConvertFolderToLogScale(type)
1855
1856        // Your file writing function here. Don't try to duplicate the VAX binary format...
[764]1857       
[776]1858        SetDataFolder $("root:Packages:NIST:"+type)
1859        Save/C linear_data as "plex.DIV"
[764]1860       
[776]1861        SetDataFolder root:
[571]1862        return(0)
[572]1863End
1864
1865////// OCT 2009, facility specific bits from MonteCarlo functions()
1866//"type" is the data folder that has the data array that is to be (re)written as a full
1867// data file, as if it was a raw data file
1868//
1869// not really necessary
1870//
[588]1871Function/S Write_RawData_File(type,fullpath,dialog)
[572]1872        String type,fullpath
1873        Variable dialog         //=1 will present dialog for name
1874       
1875        // Your file writing function here. Don't try to duplicate the VAX binary format...
1876        Print "Write_RawData_File stub"
1877       
[588]1878        return(fullPath)
[571]1879End
Note: See TracBrowser for help on using the repository browser.