source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/NCNR_DataReadWrite.ipf @ 80

Last change on this file since 80 was 80, checked in by srkline, 15 years ago

Redefinition of SANS data reader functions (main entry points)
More commenting of NCNR_DataReadWrite.ipf

File size: 38.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion = 5.0
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        //Print  "GetFileNameFromPath(filename) = " +  GetFileNameFromPathNoSemi(filename)
44        ReadHeaderAndData(filename)     //this is the full Path+file
45
46///***** done by a call to UpdateDisplayInformation()
47//      //the calling macro must change the display type
48//      String/G root:myGlobals:gDataDisplayType="RAW"          //displayed data type is raw
49//     
50//      //data is displayed here
51//      fRawWindowHook()
52       
53        Return(0)
54End
55
56
57//function that does the guts of reading the binary data file
58//fname is the full path:name;vers required to open the file
59//VAX record markers are skipped as needed
60//the data as read in is in compressed I*2 format, and is decompressed
61//immediately after being read in. The final root:RAW:data wave is the real
62//neutron counts and can be directly operated on
63//header information is put into three wave, integers,reals, and text
64//logicals in the header are currently skipped, since they are no use in the
65//data reduction process.
66//
67// detector data is loaded into an array named "data"
68//
69// called by multiple ipfs (when the file name is known)
70//
71Function ReadHeaderAndData(fname)
72        String fname
73        //this function is for reading in RAW data only, so it will always put data in RAW folder
74        String curPath = "root:RAW"
75        SetDataFolder curPath           //use the full path, so it will always work
76        Variable/G root:RAW:gIsLogScale = 0             //initial state is linear, keep this in RAW folder
77       
78        Variable refNum,integer,realval
79        String sansfname,textstr
80       
81        Make/O/N=23 $"root:RAW:IntegersRead"
82        Make/O/N=52 $"root:RAW:RealsRead"
83        Make/O/T/N=11 $"root:RAW:TextRead"
84       
85        Wave intw=$"root:RAW:IntegersRead"
86        Wave realw=$"root:RAW:RealsRead"
87        Wave/T textw=$"root:RAW:TextRead"
88       
89        //***NOTE ****
90        // the "current path" gets mysteriously reset to "root:" after the SECOND pass through
91        // this read routine, after the open dialog is presented
92        // the "--read" waves end up in the correct folder, but the data does not! Why?
93        //must re-set data folder before writing data array (done below)
94       
95        //full filename and path is now passed in...
96        //actually open the file
97        Open/R refNum as fname
98        //skip first two bytes (VAX record length markers, not needed here)
99        FSetPos refNum, 2
100        //read the next 21 bytes as characters (fname)
101        FReadLine/N=21 refNum,textstr
102        textw[0]= textstr
103        //read four i*4 values  /F=3 flag, B=3 flag
104        FBinRead/F=3/B=3 refNum, integer
105        intw[0] = integer
106        //
107        FBinRead/F=3/B=3 refNum, integer
108        intw[1] = integer
109        //
110        FBinRead/F=3/B=3 refNum, integer
111        intw[2] = integer
112        //
113        FBinRead/F=3/B=3 refNum, integer
114        intw[3] = integer
115        // 6 text fields
116        FSetPos refNum,55               //will start reading at byte 56
117        FReadLine/N=20 refNum,textstr
118        textw[1]= textstr
119        FReadLine/N=3 refNum,textstr
120        textw[2]= textstr
121        FReadLine/N=11 refNum,textstr
122        textw[3]= textstr
123        FReadLine/N=1 refNum,textstr
124        textw[4]= textstr
125        FReadLine/N=8 refNum,textstr
126        textw[5]= textstr
127        FReadLine/N=60 refNum,textstr
128        textw[6]= textstr
129       
130        //3 integers
131        FSetPos refNum,174
132        FBinRead/F=3/B=3 refNum, integer
133        intw[4] = integer
134        FBinRead/F=3/B=3 refNum, integer
135        intw[5] = integer
136        FBinRead/F=3/B=3 refNum, integer
137        intw[6] = integer
138       
139        //2 integers, 3 text fields
140        FSetPos refNum,194
141        FBinRead/F=3/B=3 refNum, integer
142        intw[7] = integer
143        FBinRead/F=3/B=3 refNum, integer
144        intw[8] = integer
145        FReadLine/N=6 refNum,textstr
146        textw[7]= textstr
147        FReadLine/N=6 refNum,textstr
148        textw[8]= textstr
149        FReadLine/N=6 refNum,textstr
150        textw[9]= textstr
151       
152        //2 integers
153        FSetPos refNum,244
154        FBinRead/F=3/B=3 refNum, integer
155        intw[9] = integer
156        FBinRead/F=3/B=3 refNum, integer
157        intw[10] = integer
158       
159        //2 integers
160        FSetPos refNum,308
161        FBinRead/F=3/B=3 refNum, integer
162        intw[11] = integer
163        FBinRead/F=3/B=3 refNum, integer
164        intw[12] = integer
165       
166        //2 integers
167        FSetPos refNum,332
168        FBinRead/F=3/B=3 refNum, integer
169        intw[13] = integer
170        FBinRead/F=3/B=3 refNum, integer
171        intw[14] = integer
172       
173        //3 integers
174        FSetPos refNum,376
175        FBinRead/F=3/B=3 refNum, integer
176        intw[15] = integer
177        FBinRead/F=3/B=3 refNum, integer
178        intw[16] = integer
179        FBinRead/F=3/B=3 refNum, integer
180        intw[17] = integer
181       
182        //1 text field - the file association for transmission are the first 4 bytes
183        FSetPos refNum,404
184        FReadLine/N=42 refNum,textstr
185        textw[10]= textstr
186       
187        //1 integer
188        FSetPos refNum,458
189        FBinRead/F=3/B=3 refNum, integer
190        intw[18] = integer
191       
192        //4 integers
193        FSetPos refNum,478
194        FBinRead/F=3/B=3 refNum, integer
195        intw[19] = integer
196        FBinRead/F=3/B=3 refNum, integer
197        intw[20] = integer
198        FBinRead/F=3/B=3 refNum, integer
199        intw[21] = integer
200        FBinRead/F=3/B=3 refNum, integer
201        intw[22] = integer
202       
203        Close refNum
204       
205        //now get all of the reals
206        //
207        //Do all the GBLoadWaves at the end
208        //
209        //FBinRead Cannot handle 32 bit VAX floating point
210        //GBLoadWave, however, can properly read it
211        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
212        String strToExecute
213        //append "/S=offset/U=numofreals" to control the read
214        // then append fname to give the full file path
215        // then execute
216       
217        Variable a=0,b=0
218       
219        SetDataFolder curPath
220       
221        // 4 R*4 values
222        strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
223        Execute strToExecute
224        Wave w=$"root:RAW:tempGBWave0"
225        b=4     //num of reals read
226        realw[a,a+b-1] = w[p-a]
227        a+=b
228       
229        // 4 R*4 values
230        SetDataFolder curPath
231        strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""
232        Execute strToExecute
233        b=4     
234        realw[a,a+b-1] = w[p-a]
235        a+=b
236
237///////////
238        // 2 R*4 values
239        SetDataFolder curPath
240        strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
241        Execute strToExecute
242        b=2     
243        realw[a,a+b-1] = w[p-a]
244        a+=b
245
246        // 6 R*4 values
247        SetDataFolder curPath
248        strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""
249        Execute strToExecute
250        b=6     
251        realw[a,a+b-1] = w[p-a]
252        a+=b
253       
254        // 13 R*4 values
255        SetDataFolder curPath
256        strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""
257        Execute strToExecute
258        b=13
259        realw[a,a+b-1] = w[p-a]
260        a+=b
261       
262        // 3 R*4 values
263        SetDataFolder curPath
264        strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""
265        Execute strToExecute
266        b=3     
267        realw[a,a+b-1] = w[p-a]
268        a+=b
269       
270        // 7 R*4 values
271        SetDataFolder curPath
272        strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""
273        Execute strToExecute
274        b=7
275        realw[a,a+b-1] = w[p-a]
276        a+=b
277       
278        // 4 R*4 values
279        SetDataFolder curPath
280        strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""
281        Execute strToExecute
282        b=4     
283        realw[a,a+b-1] = w[p-a]
284        a+=b
285       
286        // 2 R*4 values
287        SetDataFolder curPath
288        strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""
289        Execute strToExecute
290        b=2
291        realw[a,a+b-1] = w[p-a]
292        a+=b
293       
294        // 2 R*4 values
295        SetDataFolder curPath
296        strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""
297        Execute strToExecute
298        b=2
299        realw[a,a+b-1] = w[p-a]
300        a+=b
301       
302        // 5 R*4 values
303        SetDataFolder curPath
304        strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""
305        Execute strToExecute
306        b=5     
307        realw[a,a+b-1] = w[p-a]
308       
309        //if the binary VAX data ws transferred to a MAC, all is OK
310        //if the data was trasnferred to an Intel machine (IBM), all the real values must be
311        //divided by 4 to get the correct floating point values
312        // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly
313        // on an Intel machine.
314        //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read
315        //VAX reals correctly, and no checking is necessary 12 APR 99
316        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
317                //do nothing
318        //else
319                //either Windows or Windows NT
320                //realw /= 4
321        //endif
322       
323        SetDataFolder curPath
324        //read in the data
325        strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\""
326        Execute strToExecute
327
328        SetDataFolder curPath           //use the full path, so it will always work
329       
330        Make/O/N=16384 $"root:RAW:data"
331        WAVE data=$"root:RAW:data"
332        SkipAndDecompressVAX(w,data)
333        Redimension/N=(128,128) data                    //NIST raw data is 128x128 - do not generalize
334       
335        //keep a string with the filename in the RAW folder
336        String/G root:RAW:fileList = textw[0]
337       
338        //set the globals to the detector dimensions (pixels)
339        Variable/G root:myGlobals:gNPixelsX=128         //default for Ordela data (also set in Initialize/NCNR_Utils.ipf)
340        Variable/G root:myGlobals:gNPixelsY=128
341//      if(cmpstr(textW[9],"ILL   ")==0)                //override if OLD Cerca data
342//              Variable/G root:myGlobals:gNPixelsX=64
343//              Variable/G root:myGlobals:gNPixelsY=64
344//      endif
345       
346        //clean up - get rid of w = $"root:RAW:tempGBWave0"
347        KillWaves/Z w
348       
349        //return the data folder to root
350        SetDataFolder root:
351       
352        Return 0
353
354End
355
356
357//function to take the I*2 data that was read in, in VAX format
358//where the integers are "normal", but there are 2-byte record markers
359//sprinkled evenly through the data
360//there are skipped, leaving 128x128=16384 data values
361//the input array (in) is larger than 16384
362//(out) is 128x128 data (single precision) as defined in ReadHeaderAndData()
363//
364// local function to post-process compressed VAX binary data
365//
366//
367Function SkipAndDecompressVAX(in,out)
368        Wave in,out
369       
370        Variable skip,ii
371
372        ii=0
373        skip=0
374        do
375                if(mod(ii+skip,1022)==0)
376                        skip+=1
377                endif
378                out[ii] = Decompress(in[ii+skip])
379                ii+=1
380        while(ii<16384)
381        return(0)
382End
383
384//decompresses each I*2 data value to its real I*4 value
385//using the decompression routine written by Jim Ryhne, many moons ago
386//
387// the compression routine (not shown here, contained in the VAX fortran RW_DATAFILE.FOR) maps I4 to I2 values.
388// (back in the days where disk space *really* mattered). the I4toI2 function spit out:
389// I4toI2 = I4                                                          when I4 in [0,32767]
390// I4toI2 = -777                                                        when I4 in [2,767,000,...]
391// I4toI2 mapped to -13277 to -32768    otherwise
392//
393// the mapped values [-776,-1] and [-13276,-778] are not used.
394// in this compression scheme, only 4 significant digits are retained (to allow room for the exponent)
395// technically, the maximum value should be 2,768,499 since this maps to -32768. But this is of
396// little consequence. If you have individual pixel values on the detector that are that large, you need
397// to re-think your experiment.
398//
399// local function to post-process compressed VAX binary data
400//
401//
402Function Decompress(val)
403        Variable val
404
405        Variable i4,npw,ipw,ib,nd
406
407        ib=10
408        nd=4
409        ipw=ib^nd
410        i4=val
411
412        if (i4 <= -ipw)
413                npw=trunc(-i4/ipw)
414                i4=mod(-i4,ipw)*(ib^npw)
415                return i4
416        else
417                return i4
418        endif
419End
420
421//****************
422//main entry procedure for reading a "WORK.DIV" file
423//displays a quick image of the  file, to check that it's correct
424//data is deposited in root:DIV data folder
425//
426// local, currently unused
427//
428//
429Proc ReadWork_DIV()
430//      Silent 1
431       
432        String fname = PromptForPath("Select detector sensitivity file")
433        ReadHeaderAndWork("DIV",fname)          //puts what is read in work.div
434       
435        String waveStr = "root:DIV:data"
436        NewImage/F/K=1/S=2 $waveStr             //this is an experimental IGOR operation
437        ModifyImage '' ctab= {*,*,YellowHot,0}
438        //Display;AppendImage $waveStr
439       
440        //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage
441        String/G root:DIV:fileList = "WORK.DIV"
442       
443        SetDataFolder root:             //(redundant)
444//      Silent 0
445End
446
447
448//this function is the guts of reading a binary VAX file of real (4-byte) values
449// (i.e. a WORK.aaa file)
450// work files have the same header structure as RAW SANS data, just with
451//different data (real, rather than compressed integer data)
452//
453//************
454//this routine incorrectly reads in several data values where the VAX record
455//marker splits the 4-byte real (at alternating record markers)
456//this error seems to not be severe, but shoud be corrected (at great pain)
457//************
458//
459// called from ProtocolAsPanel.ipf
460//
461//
462Function ReadHeaderAndWork(type,fname)
463        String type,fname
464       
465        //type is the desired folder to read the workfile to
466        //this data will NOT be automatically displayed gDataDisplayType is unchanged
467
468//      SVAR cur_folder=root:myGlobals:gDataDisplayType
469        String cur_folder = type
470        String curPath = "root:"+cur_folder
471        SetDataFolder curPath           //use the full path, so it will always work
472       
473        Variable refNum,integer,realval
474        String sansfname,textstr
475        Variable/G $(curPath + ":gIsLogScale") = 0              //initial state is linear, keep this in DIV folder
476       
477        Make/O/N=23 $(curPath + ":IntegersRead")
478        Make/O/N=52 $(curPath + ":RealsRead")
479        Make/O/T/N=11 $(curPath + ":TextRead")
480       
481        WAVE intw=$(curPath + ":IntegersRead")
482        WAVE realw=$(curPath + ":RealsRead")
483        WAVE/T textw=$(curPath + ":TextRead")
484       
485        //***NOTE ****
486        // the "current path" gets mysteriously reset to "root:" after the SECOND pass through
487        // this read routine, after the open dialog is presented
488        // the "--read" waves end up in the correct folder, but the data does not! Why?
489        //must re-set data folder before writing data array (done below)
490       
491        SetDataFolder curPath
492       
493        //actually open the file
494        Open/R refNum as fname
495        //skip first two bytes
496        FSetPos refNum, 2
497        //read the next 21 bytes as characters (fname)
498        FReadLine/N=21 refNum,textstr
499        textw[0]= textstr
500        //read four i*4 values  /F=3 flag, B=3 flag
501        FBinRead/F=3/B=3 refNum, integer
502        intw[0] = integer
503        //
504        FBinRead/F=3/B=3 refNum, integer
505        intw[1] = integer
506        //
507        FBinRead/F=3/B=3 refNum, integer
508        intw[2] = integer
509        //
510        FBinRead/F=3/B=3 refNum, integer
511        intw[3] = integer
512        // 6 text fields
513        FSetPos refNum,55               //will start reading at byte 56
514        FReadLine/N=20 refNum,textstr
515        textw[1]= textstr
516        FReadLine/N=3 refNum,textstr
517        textw[2]= textstr
518        FReadLine/N=11 refNum,textstr
519        textw[3]= textstr
520        FReadLine/N=1 refNum,textstr
521        textw[4]= textstr
522        FReadLine/N=8 refNum,textstr
523        textw[5]= textstr
524        FReadLine/N=60 refNum,textstr
525        textw[6]= textstr
526       
527        //3 integers
528        FSetPos refNum,174
529        FBinRead/F=3/B=3 refNum, integer
530        intw[4] = integer
531        FBinRead/F=3/B=3 refNum, integer
532        intw[5] = integer
533        FBinRead/F=3/B=3 refNum, integer
534        intw[6] = integer
535       
536        //2 integers, 3 text fields
537        FSetPos refNum,194
538        FBinRead/F=3/B=3 refNum, integer
539        intw[7] = integer
540        FBinRead/F=3/B=3 refNum, integer
541        intw[8] = integer
542        FReadLine/N=6 refNum,textstr
543        textw[7]= textstr
544        FReadLine/N=6 refNum,textstr
545        textw[8]= textstr
546        FReadLine/N=6 refNum,textstr
547        textw[9]= textstr
548       
549        //2 integers
550        FSetPos refNum,244
551        FBinRead/F=3/B=3 refNum, integer
552        intw[9] = integer
553        FBinRead/F=3/B=3 refNum, integer
554        intw[10] = integer
555       
556        //2 integers
557        FSetPos refNum,308
558        FBinRead/F=3/B=3 refNum, integer
559        intw[11] = integer
560        FBinRead/F=3/B=3 refNum, integer
561        intw[12] = integer
562       
563        //2 integers
564        FSetPos refNum,332
565        FBinRead/F=3/B=3 refNum, integer
566        intw[13] = integer
567        FBinRead/F=3/B=3 refNum, integer
568        intw[14] = integer
569       
570        //3 integers
571        FSetPos refNum,376
572        FBinRead/F=3/B=3 refNum, integer
573        intw[15] = integer
574        FBinRead/F=3/B=3 refNum, integer
575        intw[16] = integer
576        FBinRead/F=3/B=3 refNum, integer
577        intw[17] = integer
578       
579        //1 text field - the file association for transmission are the first 4 bytes
580        FSetPos refNum,404
581        FReadLine/N=42 refNum,textstr
582        textw[10]= textstr
583       
584        //1 integer
585        FSetPos refNum,458
586        FBinRead/F=3/B=3 refNum, integer
587        intw[18] = integer
588       
589        //4 integers
590        FSetPos refNum,478
591        FBinRead/F=3/B=3 refNum, integer
592        intw[19] = integer
593        FBinRead/F=3/B=3 refNum, integer
594        intw[20] = integer
595        FBinRead/F=3/B=3 refNum, integer
596        intw[21] = integer
597        FBinRead/F=3/B=3 refNum, integer
598        intw[22] = integer
599       
600        Close refNum
601       
602        //now get all of the reals
603        //
604        //Do all the GBLoadWaves at the end
605        //
606        //FBinRead Cannot handle 32 bit VAX floating point
607        //GBLoadWave, however, can properly read it
608        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
609        String strToExecute
610        //append "/S=offset/U=numofreals" to control the read
611        // then append fname to give the full file path
612        // then execute
613       
614        Variable a=0,b=0
615       
616        SetDataFolder curPath
617        // 4 R*4 values
618        strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
619        Execute strToExecute
620       
621        SetDataFolder curPath
622        Wave w=$(curPath + ":tempGBWave0")
623        b=4     //num of reals read
624        realw[a,a+b-1] = w[p-a]
625        a+=b
626       
627        // 4 R*4 values
628        SetDataFolder curPath
629        strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""
630        Execute strToExecute
631        b=4     
632        realw[a,a+b-1] = w[p-a]
633        a+=b
634
635///////////
636        // 2 R*4 values
637        SetDataFolder curPath
638        strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
639        Execute strToExecute
640        b=2     
641        realw[a,a+b-1] = w[p-a]
642        a+=b
643
644        // 6 R*4 values
645        SetDataFolder curPath
646        strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""
647        Execute strToExecute
648        b=6     
649        realw[a,a+b-1] = w[p-a]
650        a+=b
651       
652        // 13 R*4 values
653        SetDataFolder curPath
654        strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""
655        Execute strToExecute
656        b=13
657        realw[a,a+b-1] = w[p-a]
658        a+=b
659       
660        // 3 R*4 values
661        SetDataFolder curPath
662        strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""
663        Execute strToExecute
664        b=3     
665        realw[a,a+b-1] = w[p-a]
666        a+=b
667       
668        // 7 R*4 values
669        SetDataFolder curPath
670        strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""
671        Execute strToExecute
672        b=7
673        realw[a,a+b-1] = w[p-a]
674        a+=b
675       
676        // 4 R*4 values
677        SetDataFolder curPath
678        strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""
679        Execute strToExecute
680        b=4     
681        realw[a,a+b-1] = w[p-a]
682        a+=b
683       
684        // 2 R*4 values
685        SetDataFolder curPath
686        strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""
687        Execute strToExecute
688        b=2
689        realw[a,a+b-1] = w[p-a]
690        a+=b
691       
692        // 2 R*4 values
693        SetDataFolder curPath
694        strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""
695        Execute strToExecute
696        b=2
697        realw[a,a+b-1] = w[p-a]
698        a+=b
699       
700        // 5 R*4 values
701        SetDataFolder curPath
702        strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""
703        Execute strToExecute
704        b=5     
705        realw[a,a+b-1] = w[p-a]
706       
707        //if the binary VAX data ws transferred to a MAC, all is OK
708        //if the data was trasnferred to an Intel machine (IBM), all the real values must be
709        //divided by 4 to get the correct floating point values
710        // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly
711        // on an Intel machine.
712        //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read
713        //VAX reals correctly, and no checking is necessary 12 APR 99
714        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
715                //do nothing
716        //else
717                //either Windows or Windows NT
718                //realw /= 4
719        //endif
720       
721        //read in the data
722         GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
723
724        curPath = "root:"+cur_folder
725        SetDataFolder curPath           //use the full path, so it will always work
726       
727        Make/O/N=16384 $(curPath + ":data")
728        WAVE data = $(curPath + ":data")
729       
730        Variable skip,ii,offset
731       
732        //read in a total of 16384 values (ii)
733        //as follows :
734        // skip first 2 bytes
735        // skip 512 byte header
736        // skip first 2 bytes of data
737        //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values
738        // read the final 48 values in seperately to avoid EOF error
739       
740        /////////////
741        SetDataFolder curPath
742        skip = 0
743        ii=0
744        offset = 514 +2
745        a=0
746        do
747                SetDataFolder curPath
748               
749                strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\""
750                Execute strToExecute
751                //Print strToExecute
752                b=511
753                data[a,a+b-1] = w[p-a]
754                a+=b
755               
756                offset += 511*4 +2
757               
758                strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\""
759                SetDataFolder curPath
760                Execute strToExecute
761                //Print strToExecute
762                b=510
763                data[a,a+b-1] = w[p-a]
764                a+=b
765               
766                offset += 510*4 +2
767               
768                ii+=1
769                //Print "inside do, data[2] =",data[2]
770                //Print "inside do, tempGBwave0[0] = ",w[0]
771        while(ii<16)
772       
773        // 16336 values have been read in --
774        //read in last 64 values
775        strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\""
776       
777        SetDataFolder curPath
778        Execute strToExecute
779        b=48
780        data[a,a+b-1] = w[p-a]
781        a+=b
782//
783/// done reading in raw data
784//
785        //Print "in workdatareader , data = ", data[1][1]
786
787        Redimension/n=(128,128) data
788       
789        //clean up - get rid of w = $"tempGBWave0"
790        KillWaves w
791       
792        //divide the FP data by 4 if read from a PC (not since GBLoadWave update)
793        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
794                //do nothing
795        //else
796                //either Windows or Windows NT
797                //data /= 4
798        //endif
799       
800        //keep a string with the filename in the DIV folder
801        String/G $(curPath + ":fileList") = textw[0]
802       
803        //return the data folder to root
804        SetDataFolder root:
805       
806        Return(0)
807End
808
809/////   ASC FORMAT READER  //////
810/////   FOR WORKFILE MATH PANEL //////
811
812//function to read in the ASC output of SANS reduction
813// currently the file has 20 header lines, followed by a single column
814// of 16384 values, Data is written by row, starting with Y=1 and X=(1->128)
815//
816//returns 0 if read was ok
817//returns 1 if there was an error
818//
819// called by WorkFileUtils.ipf
820//
821Function ReadASCData(fname,destPath)
822        String fname, destPath
823        //this function is for reading in ASCII data so put data in user-specified folder
824        SetDataFolder "root:"+destPath
825
826        NVAR pixelsX = root:myGlobals:gNPixelsX
827        NVAR pixelsY = root:myGlobals:gNPixelsY
828        Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=20
829        String str=""
830        //data is initially linear scale
831        Variable/G :gIsLogScale=0
832        Make/O/T/N=(numHdrLines) hdrLines
833        Make/O/D/N=(pixelsX*pixelsY) data                       //,linear_data
834       
835        //full filename and path is now passed in...
836        //actually open the file
837//      SetDataFolder destPath
838        Open/R/Z refNum as fname                // /Z flag means I must handle open errors
839        if(refnum==0)           //FNF error, get out
840                DoAlert 0,"Could not find file: "+fname
841                Close/A
842                SetDataFolder root:
843                return(1)
844        endif
845        if(V_flag!=0)
846                DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
847                Close/A
848                SetDataFolder root:
849                return(1)
850        Endif
851        //
852        for(ii=0;ii<numHdrLines;ii+=1)          //read (or skip) 18 header lines
853                FReadLine refnum,str
854                hdrLines[ii]=str
855        endfor
856        //     
857        Close refnum
858       
859//      SetDataFolder destPath
860        LoadWave/Q/G/D/N=temp fName
861        Wave/Z temp0=temp0
862        data=temp0
863        Redimension/N=(pixelsX,pixelsY) data            //,linear_data
864       
865        //linear_data = data
866       
867        KillWaves/Z temp0
868       
869        //return the data folder to root
870        SetDataFolder root:
871       
872        Return(0)
873End
874
875// fills the "default" fake header so that the SANS Reduction machinery does not have to be altered
876// pay attention to what is/not to be trusted due to "fake" information.
877// uses what it can from the header lines from the ASC file (hdrLines wave)
878//
879// destFolder is of the form "myGlobals:WorkMath:AAA"
880//
881//
882// called by WorkFileUtils.ipf
883//
884Function FillFakeHeader_ASC(destFolder)
885        String destFolder
886        Make/O/N=23 $("root:"+destFolder+":IntegersRead")
887        Make/O/N=52 $("root:"+destFolder+":RealsRead")
888        Make/O/T/N=11 $("root:"+destFolder+":TextRead")
889       
890        Wave intw=$("root:"+destFolder+":IntegersRead")
891        Wave realw=$("root:"+destFolder+":RealsRead")
892        Wave/T textw=$("root:"+destFolder+":TextRead")
893       
894        //Put in appropriate "fake" values
895        //parse values as needed from headerLines
896        Wave/T hdr=$("root:"+destFolder+":hdrLines")
897        Variable monCt,lam,offset,sdd,trans,thick
898        Variable xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam
899        String detTyp=""
900        String tempStr="",formatStr="",junkStr=""
901        formatStr = "%g %g %g %g %g %g"
902        tempStr=hdr[3]
903        sscanf tempStr, formatStr, monCt,lam,offset,sdd,trans,thick
904//      Print monCt,lam,offset,sdd,trans,thick,avStr,step
905        formatStr = "%g %g %g %g %g %g %g %s"
906        tempStr=hdr[5]
907        sscanf tempStr,formatStr,xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
908//      Print xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp
909       
910        realw[16]=xCtr          //xCtr(pixels)
911        realw[17]=yCtr  //yCtr (pixels)
912        realw[18]=sdd           //SDD (m)
913        realw[26]=lam           //wavelength (A)
914        //
915        // necessary values
916        realw[10]=5                     //detector calibration constants, needed for averaging
917        realw[11]=10000
918        realw[12]=0
919        realw[13]=5
920        realw[14]=10000
921        realw[15]=0
922        //
923        // used in the resolution calculation, ONLY here to keep the routine from crashing
924        realw[20]=65            //det size
925        realw[27]=dlam  //delta lambda
926        realw[21]=bsDiam        //BS size
927        realw[23]=a1            //A1
928        realw[24]=a2    //A2
929        realw[25]=a1a2Dist      //A1A2 distance
930        realw[4]=trans          //trans
931        realw[3]=0              //atten
932        realw[5]=thick          //thick
933        //
934        //
935        realw[0]=monCt          //def mon cts
936
937        // fake values to get valid deadtime and detector constants
938        //
939        textw[9]=detTyp+"  "            //6 characters 4+2 spaces
940        textw[3]="[NGxSANS00]"  //11 chars, NGx will return default values for atten trans, deadtime...
941       
942        //set the string values
943        formatStr="FILE: %s CREATED: %s"
944        sscanf hdr[0],formatStr,tempStr,junkStr
945//      Print tempStr
946//      Print junkStr
947        String/G $("root:"+destFolder+":fileList") = tempStr
948        textw[0] = tempStr              //filename
949        textw[1] = junkStr              //run date-time
950       
951        //file label = hdr[1]
952        tempStr = hdr[1]
953        tempStr = tempStr[0,strlen(tempStr)-2]          //clean off the last LF
954//      Print tempStr
955        textW[6] = tempStr      //sample label
956       
957        return(0)
958End
959
960
961/////*****************
962////unused testing procedure for writing a 4 byte floating point value in VAX format
963//Proc TestReWriteReal()
964//      String Path
965//      Variable value,start
966//     
967//      GetFileAndPath()
968//      Path = S_Path + S_filename
969//     
970//      value = 0.2222
971//      start = 158             //trans starts at byte 159
972//      ReWriteReal(path,value,start)
973//     
974//      SetDataFolder root:
975//End
976
977//function will re-write a real value (4bytes) to the header of a RAW data file
978//to ensure re-readability, the real value must be written mimicking VAX binary format
979//which is done in this function
980//path is the full path:file;vers to the file
981//value is the real value to write
982//start is the position to move the file marker to, to begin writing
983//--so start is actually the "end byte" of the previous value
984//
985//this procedure takes care of all file open/close pairs needed
986//
987Function WriteVAXReal(path,value,start)
988        String path
989        Variable value,start
990       
991        //Print " in F(), path = " + path
992        Variable refnum,int1,int2, value4
993
994//////
995        value4 = 4*value
996       
997        Open/A/T="????TEXT" refnum as path
998        //write IEEE FP, 4*desired value
999        FSetPos refnum,start
1000        FBinWrite/B=3/F=4 refnum,value4         //write out as little endian
1001       
1002        //move to the end of the file
1003        FStatus refnum
1004        FSetPos refnum,V_logEOF
1005        //Print "Wrote end of header to " + num2str(V_filePOS)
1006       
1007        Close refnum
1008       
1009///////
1010        Open/R refnum as path
1011        //read back as two 16-bit integers
1012        FSetPos refnum,start
1013        FBinRead/B=2/F=2 refnum,int1    //read as big-endian
1014        FBinRead/B=2/F=2 refnum,int2
1015       
1016        //file was opened read-only
1017        //no need to move to the end of the file, just close it
1018       
1019        Close refnum
1020///////
1021        Open/A/T="????TEXT" refnum as path
1022        //write the two 16-bit integers, reversed
1023        FSetPos refnum,start
1024        FBinWrite/B=2/F=2 refnum,int2   //re-write as big endian
1025        FBinWrite/B=2/F=2 refnum,int1
1026       
1027        //move to the end of the file
1028        FStatus refnum
1029        FSetPos refnum,V_logEOF
1030        //Print "Wrote end of header to " + num2str(V_filePOS)
1031       
1032        Close refnum            //at this point, it is as the VAX would have written it.
1033       
1034        Return(0)
1035End
1036
1037//sample transmission is a real value at byte 158
1038Function WriteTransmissionToHeader(fname,trans)
1039        String fname
1040        Variable trans
1041       
1042        WriteVAXReal(fname,trans,158)           //transmission start byte is 158
1043        return(0)
1044End
1045
1046//whole transmission is a real value at byte 392
1047Function WriteWholeTransToHeader(fname,trans)
1048        String fname
1049        Variable trans
1050       
1051        WriteVAXReal(fname,trans,392)           //transmission start byte is 392
1052        return(0)
1053End
1054
1055//box sum counts is a real value at byte 494
1056Function WriteBoxCountsToHeader(fname,counts)
1057        String fname
1058        Variable counts
1059       
1060        WriteVAXReal(fname,counts,494)          // start byte is 494
1061        return(0)
1062End
1063
1064//beam stop X-pos is at byte 368
1065Function WriteBSXPosToHeader(fname,xpos)
1066        String fname
1067        Variable xpos
1068       
1069        WriteVAXReal(fname,xpos,368)
1070        return(0)
1071End
1072
1073//sample thickness is at byte 162
1074Function WriteThicknessToHeader(fname,num)
1075        String fname
1076        Variable num
1077       
1078        WriteVAXReal(fname,num,162)
1079        return(0)
1080End
1081
1082//beam center X pixel location is at byte 252
1083Function WriteBeamCenterXToHeader(fname,num)
1084        String fname
1085        Variable num
1086       
1087        WriteVAXReal(fname,num,252)
1088        return(0)
1089End
1090
1091//beam center Y pixel location is at byte 256
1092Function WriteBeamCenterYToHeader(fname,num)
1093        String fname
1094        Variable num
1095       
1096        WriteVAXReal(fname,num,256)
1097        return(0)
1098End
1099
1100//attenuator number (not its transmission) is at byte 51
1101Function WriteAttenNumberToHeader(fname,num)
1102        String fname
1103        Variable num
1104       
1105        WriteVAXReal(fname,num,51)
1106        return(0)
1107End
1108
1109//monitor count is at byte 39
1110Function WriteMonitorCountToHeader(fname,num)
1111        String fname
1112        Variable num
1113       
1114        WriteVAXReal(fname,num,39)
1115        return(0)
1116End
1117
1118//total detector count is at byte 47
1119Function WriteDetectorCountToHeader(fname,num)
1120        String fname
1121        Variable num
1122       
1123        WriteVAXReal(fname,num,47)
1124        return(0)
1125End
1126
1127//transmission detector count is at byte 388
1128Function WriteTransDetCountToHeader(fname,num)
1129        String fname
1130        Variable num
1131       
1132        WriteVAXReal(fname,num,388)
1133        return(0)
1134End
1135
1136//wavelength is at byte 292
1137Function WriteWavelengthToHeader(fname,num)
1138        String fname
1139        Variable num
1140       
1141        WriteVAXReal(fname,num,292)
1142        return(0)
1143End
1144
1145//wavelength spread is at byte 296
1146Function WriteWavelengthDistrToHeader(fname,num)
1147        String fname
1148        Variable num
1149       
1150        WriteVAXReal(fname,num,296)
1151        return(0)
1152End
1153
1154//temperature is at byte 186
1155Function WriteTemperatureToHeader(fname,num)
1156        String fname
1157        Variable num
1158       
1159        WriteVAXReal(fname,num,186)
1160        return(0)
1161End
1162
1163//magnetic field is at byte 190
1164Function WriteMagnFieldToHeader(fname,num)
1165        String fname
1166        Variable num
1167       
1168        WriteVAXReal(fname,num,190)
1169        return(0)
1170End
1171
1172//Source Aperture diameter is at byte 280
1173Function WriteSourceApDiamToHeader(fname,num)
1174        String fname
1175        Variable num
1176       
1177        WriteVAXReal(fname,num,280)
1178        return(0)
1179End
1180
1181//Sample Aperture diameter is at byte 284
1182Function WriteSampleApDiamToHeader(fname,num)
1183        String fname
1184        Variable num
1185       
1186        WriteVAXReal(fname,num,284)
1187        return(0)
1188End
1189
1190//Source to sample distance is at byte 288
1191Function WriteSrcToSamDistToHeader(fname,num)
1192        String fname
1193        Variable num
1194       
1195        WriteVAXReal(fname,num,288)
1196        return(0)
1197End
1198
1199//detector offset is at byte 264
1200Function WriteDetectorOffsetToHeader(fname,num)
1201        String fname
1202        Variable num
1203       
1204        WriteVAXReal(fname,num,264)
1205        return(0)
1206End
1207
1208//beam stop diameter is at byte 272
1209Function WriteBeamStopDiamToHeader(fname,num)
1210        String fname
1211        Variable num
1212       
1213        WriteVAXReal(fname,num,272)
1214        return(0)
1215End
1216
1217//detector offset is at byte 260
1218Function WriteSDDToHeader(fname,num)
1219        String fname
1220        Variable num
1221       
1222        WriteVAXReal(fname,num,260)
1223        return(0)
1224End
1225
1226
1227//rewrite a text field back to the header
1228// fname is the full path:name
1229// str is the CORRECT length - it will all be written - pad before sending
1230// start is the start byte
1231Function RewriteTextToHeader(fname,str,start)
1232        String fname,str
1233        Variable start
1234       
1235        Variable refnum
1236        Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing!
1237        FSetPos refnum,start
1238        FBinWrite/F=0 refnum, str      //native object format (character)
1239        //move to the end of the file before closing
1240        FStatus refnum
1241        FSetPos refnum,V_logEOF
1242        //Print "Wrote end of header to " + num2str(V_filePOS)
1243        Close refnum
1244               
1245        return(0)
1246end
1247
1248Function WriteSamLabelToHeader(fname,str)
1249        String fname,str
1250       
1251        RewriteTextToHeader(fname,str,98)
1252        return(0)
1253End
1254
1255//rewrite an integer field back to the header
1256// fname is the full path:name
1257// val is the integer value
1258// start is the start byte
1259Function RewriteIntegerToHeader(fname,val,start)
1260        String fname
1261        Variable val,start
1262       
1263        Variable refnum
1264        Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing!
1265        FSetPos refnum,31
1266        FBinWrite/B=3/F=3 refnum, val      //write a 4-byte integer
1267        //move to the end of the file before closing
1268        FStatus refnum
1269        FSetPos refnum,V_logEOF
1270        //Print "Wrote end of header to " + num2str(V_filePOS)
1271        Close refnum
1272               
1273        return(0)
1274end
1275
1276Function WriteCountTimeToHeader(fname,num)
1277        String fname
1278        Variable num
1279       
1280        RewriteIntegerToHeader(fname,num,31)
1281        return(0)
1282End
1283
1284// read specific bits of information from the header
1285// each of these operations MUST take care of open/close on their own
1286
1287Function/S getStringFromHeader(fname,start,num)
1288        String fname                            //full path:name
1289        Variable start,num              //starting byte and number of characters to read
1290       
1291        String str
1292        Variable refnum
1293        Open/R refNum as fname
1294        FSetPos refNum,start
1295        FReadLine/N=(num) refNum,str
1296        Close refnum
1297       
1298        return(str)
1299End
1300
1301// file suffix (4 characters @ byte 19)
1302Function/S getSuffix(fname)
1303        String fname
1304       
1305        return(getStringFromHeader(fname,19,4))
1306End
1307
1308// associated file suffix (for transmission) (4 characters @ byte 404)
1309Function/S getAssociatedFileSuffix(fname)
1310        String fname
1311       
1312        return(getStringFromHeader(fname,404,4))
1313End
1314
1315// sample label (60 characters @ byte 98)
1316Function/S getSampleLabel(fname)
1317        String fname
1318       
1319        return(getStringFromHeader(fname,98,60))
1320End
1321
1322// file creation date (20 characters @ byte 55)
1323Function/S getFileCreationDate(fname)
1324        String fname
1325       
1326        return(getStringFromHeader(fname,55,20))
1327End
1328
1329// read a single real value with GBLoadWave
1330Function getRealValueFromHeader(fname,start)
1331        String fname
1332        Variable start
1333
1334        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
1335       
1336        GBLoadStr += "/S="+num2str(start)+"/U=1" + "\"" + fname + "\""
1337        Execute GBLoadStr
1338        Wave w=$"tempGBWave0"
1339       
1340        return(w[0])
1341End
1342
1343//monitor count is at byte 39
1344Function getMonitorCount(fname)
1345        String fname
1346       
1347        return(getRealValueFromHeader(fname,39))
1348end
1349
1350//saved monitor count is at byte 43
1351Function getSavMon(fname)
1352        String fname
1353       
1354        return(getRealValueFromHeader(fname,43))
1355end
1356
1357//detector count is at byte 47
1358Function getDetCount(fname)
1359        String fname
1360       
1361        return(getRealValueFromHeader(fname,47))
1362end
1363
1364//Attenuator number is at byte 51
1365Function getAttenNumber(fname)
1366        String fname
1367       
1368        return(getRealValueFromHeader(fname,51))
1369end
1370
1371//transmission is at byte 158
1372Function getSampleTrans(fname)
1373        String fname
1374       
1375        return(getRealValueFromHeader(fname,158))
1376end
1377
1378//box counts are stored at byte 494
1379Function getBoxCounts(fname)
1380        String fname
1381       
1382        return(getRealValueFromHeader(fname,494))
1383end
1384
1385//whole detector trasmission is at byte 392
1386Function getSampleTransWholeDetector(fname)
1387        String fname
1388       
1389        return(getRealValueFromHeader(fname,392))
1390end
1391
1392//SampleThickness is at byte 162
1393Function getSampleThickness(fname)
1394        String fname
1395       
1396        return(getRealValueFromHeader(fname,162))
1397end
1398
1399//Sample Rotation Angle is at byte 170
1400Function getSampleRotationAngle(fname)
1401        String fname
1402       
1403        return(getRealValueFromHeader(fname,170))
1404end
1405
1406//temperature is at byte 186
1407Function getTemperature(fname)
1408        String fname
1409       
1410        return(getRealValueFromHeader(fname,186))
1411end
1412
1413//field strength is at byte 190
1414Function getFieldStrength(fname)
1415        String fname
1416       
1417        return(getRealValueFromHeader(fname,190))
1418end
1419
1420//beam xPos is at byte 252
1421Function getBeamXPos(fname)
1422        String fname
1423       
1424        return(getRealValueFromHeader(fname,252))
1425end
1426
1427//beam Y pos is at byte 256
1428Function getBeamYPos(fname)
1429        String fname
1430       
1431        return(getRealValueFromHeader(fname,256))
1432end
1433
1434//sample to detector distance is at byte 260
1435Function getSDD(fname)
1436        String fname
1437       
1438        return(getRealValueFromHeader(fname,260))
1439end
1440
1441//detector offset is at byte 264
1442Function getDetectorOffset(fname)
1443        String fname
1444       
1445        return(getRealValueFromHeader(fname,264))
1446end
1447
1448//Beamstop diameter is at byte 272
1449Function getBSDiameter(fname)
1450        String fname
1451       
1452        return(getRealValueFromHeader(fname,272))
1453end
1454
1455//source aperture diameter is at byte 280
1456Function getSourceApertureDiam(fname)
1457        String fname
1458       
1459        return(getRealValueFromHeader(fname,280))
1460end
1461
1462//sample aperture diameter is at byte 284
1463Function getSampleApertureDiam(fname)
1464        String fname
1465       
1466        return(getRealValueFromHeader(fname,284))
1467end
1468
1469//source AP to Sample AP distance is at byte 288
1470Function getSourceToSampleDist(fname)
1471        String fname
1472       
1473        return(getRealValueFromHeader(fname,288))
1474end
1475
1476//wavelength is at byte 292
1477Function getWavelength(fname)
1478        String fname
1479       
1480        return(getRealValueFromHeader(fname,292))
1481end
1482
1483//wavelength spread is at byte 296
1484Function getWavelengthSpread(fname)
1485        String fname
1486       
1487        return(getRealValueFromHeader(fname,296))
1488end
1489
1490//transmission detector count is at byte 388
1491Function getTransDetectorCounts(fname)
1492        String fname
1493       
1494        return(getRealValueFromHeader(fname,388))
1495end
1496
1497//////  integer values
1498
1499Function getIntegerFromHeader(fname,start)
1500        String fname                            //full path:name
1501        Variable start          //starting byte
1502       
1503        Variable refnum,val
1504        Open/R refNum as fname
1505        FSetPos refNum,start
1506        FBinRead/B=3/F=3 refnum,val
1507        Close refnum
1508       
1509        return(val)
1510End
1511
1512//total count time is at byte 31       
1513Function getCountTime(fname)
1514        String fname
1515        return(getIntegerFromHeader(fname,31))
1516end
1517
1518
1519//reads the wavelength from a reduced data file (not very reliable)
1520// - does not work with NSORTed files
1521// - only used in FIT/RPA (which itself is almost NEVER used...)
1522//
1523Function GetLambdaFromReducedData(tempName)
1524        String tempName
1525       
1526        String junkString
1527        Variable lambdaFromFile, fileVar
1528        lambdaFromFile = 6.0
1529        Open/R/P=catPathName fileVar as tempName
1530        FReadLine fileVar, junkString
1531        FReadLine fileVar, junkString
1532        FReadLine fileVar, junkString
1533        if(strsearch(LowerStr(junkString),"lambda",0) != -1)
1534                FReadLine/N=11 fileVar, junkString
1535                FReadLine/N=10 fileVar, junkString
1536                lambdaFromFile = str2num(junkString)
1537        endif
1538        Close fileVar
1539       
1540        return(lambdaFromFile)
1541End
1542
1543/////   TRANSMISSION RELATED FUNCTIONS    ////////
1544//box coordinate are returned by reference
1545Function getXYBoxFromFile(filename,x1,x2,y1,y2)
1546        String filename
1547        Variable &x1,&x2,&y1,&y2
1548       
1549        Variable refnum
1550        String tmpFile = FindValidFilename(filename)
1551               
1552        Open/R/P=catPathName refnum as tmpFile
1553        FSetPos refnum,478
1554        FBinRead/F=3/B=3 refnum, x1
1555        FBinRead/F=3/B=3 refnum, x2
1556        FBinRead/F=3/B=3 refnum, y1
1557        FBinRead/F=3/B=3 refnum, y2
1558        Close refnum
1559       
1560        return(0)
1561End
1562
1563//go find the file, open it and write 4 integers to the file
1564//in the positions for analysis.rows(2), .cols(2) = 4 unused 4byte integers
1565Function WriteXYBoxToHeader(filename,x1,x2,y1,y2)
1566        String filename
1567        Variable x1,x2,y1,y2
1568       
1569        Variable refnum
1570        Open/A/T="????TEXT" refnum as filename
1571        FSetPos refnum,478
1572        FBinWrite/F=3/B=3 refNum, x1
1573        FBinWrite/F=3/B=3 refNum, x2
1574        FBinWrite/F=3/B=3 refNum, y1
1575        FBinWrite/F=3/B=3 refNum, y2
1576        //move to the end of the file before closing
1577        FStatus refnum
1578        FSetPos refnum,V_logEOF
1579        Close refnum
1580       
1581        return(0)
1582End
1583
1584//associated file suffix is the first 4 characters of a text field starting
1585// at byte 404
1586Function WriteAssocFileSuffixToHeader(fname,suffix)
1587        String fname,suffix
1588       
1589        Variable refnum
1590       
1591        Open/A/T="????TEXT" refnum as fname
1592        FSetPos refnum,404
1593        FBinWrite refnum, suffix
1594        FStatus refnum
1595        FSetPos refnum,V_logEOF
1596        Close refnum
1597       
1598        return(0)
1599end
Note: See TracBrowser for help on using the repository browser.