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

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

Un-doing the "fix" of DisplayUtils? since this caused more problems than I expected.

Fixed the ILL_DataReadWrite ReadHeaderAndWork?() to properly keep the data on linear scale upon loading, which is the default.

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