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

Last change on this file since 66 was 41, checked in by srkline, 16 years ago

change to UNIX line endings

File size: 21.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//**************************
6//
7// Vers. 1.2 092101
8//
9// functions for reading raw data files from the VAX
10// - RAW data files are read into the RAW folder - integer data from the detector
11//   is decompressed and given the proper orientation
12// - header information is placed into real,integer, or text waves in the order they appear
13//   in the file header
14//
15// Work data (DIV File) is read into the DIV folder
16//
17//*****************************
18
19//simple, main entry procedure that will load a RAW sans data file (not a work file)
20//into the RAW dataFolder
21//(typically called from main panel button)
22//
23Proc LoadSANSData()
24        String msgStr = "Select a SANS data file"
25       
26        Variable err
27        err = ReadBinarySANS(msgStr)            //will prompt for file
28        //ignore the error here
29End
30
31//function that does the guts of reading the binary data file
32//fname is the full path:name;vers required to open the file
33//VAX record markers are skipped as needed
34//the data as read in is in compressed I*2 format, and is decompressed
35//immediately after being read in. The final root:RAW:data wave is the real
36//neutron counts and can be directly operated on
37//header information is put into three wave, integers,reals, and text
38//logicals in the header are currently skipped, since they are no use in the
39//data reduction process. the logicals, however are left untouched.
40//
41Function ReadHeaderAndData(fname)
42        String fname
43        //this function is for reading in RAW data only, so it will always put data in RAW folder
44        String curPath = "root:RAW"
45        SetDataFolder curPath           //use the full path, so it will always work
46        Variable/G root:RAW:gIsLogScale = 0             //initial state is linear, keep this in RAW folder
47       
48        Variable refNum,integer,realval
49        String sansfname,textstr
50       
51        Make/O/N=23 $"root:RAW:IntegersRead"
52        Make/O/N=52 $"root:RAW:RealsRead"
53        Make/O/T/N=11 $"root:RAW:TextRead"
54       
55        Wave intw=$"root:RAW:IntegersRead"
56        Wave realw=$"root:RAW:RealsRead"
57        Wave/T textw=$"root:RAW:TextRead"
58       
59        //***NOTE ****
60        // the "current path" gets mysteriously reset to "root:" after the SECOND pass through
61        // this read routine, after the open dialog is presented
62        // the "--read" waves end up in the correct folder, but the data does not! Why?
63        //must re-set data folder before writing data array (done below)
64       
65        //full filename and path is now passed in...
66        //actually open the file
67        Open/R refNum as fname
68        //skip first two bytes (VAX record length markers, not needed here)
69        FSetPos refNum, 2
70        //read the next 21 bytes as characters (fname)
71        FReadLine/N=21 refNum,textstr
72        textw[0]= textstr
73        //read four i*4 values  /F=3 flag, B=3 flag
74        FBinRead/F=3/B=3 refNum, integer
75        intw[0] = integer
76        //
77        FBinRead/F=3/B=3 refNum, integer
78        intw[1] = integer
79        //
80        FBinRead/F=3/B=3 refNum, integer
81        intw[2] = integer
82        //
83        FBinRead/F=3/B=3 refNum, integer
84        intw[3] = integer
85        // 6 text fields
86        FSetPos refNum,55               //will start reading at byte 56
87        FReadLine/N=20 refNum,textstr
88        textw[1]= textstr
89        FReadLine/N=3 refNum,textstr
90        textw[2]= textstr
91        FReadLine/N=11 refNum,textstr
92        textw[3]= textstr
93        FReadLine/N=1 refNum,textstr
94        textw[4]= textstr
95        FReadLine/N=8 refNum,textstr
96        textw[5]= textstr
97        FReadLine/N=60 refNum,textstr
98        textw[6]= textstr
99       
100        //3 integers
101        FSetPos refNum,174
102        FBinRead/F=3/B=3 refNum, integer
103        intw[4] = integer
104        FBinRead/F=3/B=3 refNum, integer
105        intw[5] = integer
106        FBinRead/F=3/B=3 refNum, integer
107        intw[6] = integer
108       
109        //2 integers, 3 text fields
110        FSetPos refNum,194
111        FBinRead/F=3/B=3 refNum, integer
112        intw[7] = integer
113        FBinRead/F=3/B=3 refNum, integer
114        intw[8] = integer
115        FReadLine/N=6 refNum,textstr
116        textw[7]= textstr
117        FReadLine/N=6 refNum,textstr
118        textw[8]= textstr
119        FReadLine/N=6 refNum,textstr
120        textw[9]= textstr
121       
122        //2 integers
123        FSetPos refNum,244
124        FBinRead/F=3/B=3 refNum, integer
125        intw[9] = integer
126        FBinRead/F=3/B=3 refNum, integer
127        intw[10] = integer
128       
129        //2 integers
130        FSetPos refNum,308
131        FBinRead/F=3/B=3 refNum, integer
132        intw[11] = integer
133        FBinRead/F=3/B=3 refNum, integer
134        intw[12] = integer
135       
136        //2 integers
137        FSetPos refNum,332
138        FBinRead/F=3/B=3 refNum, integer
139        intw[13] = integer
140        FBinRead/F=3/B=3 refNum, integer
141        intw[14] = integer
142       
143        //3 integers
144        FSetPos refNum,376
145        FBinRead/F=3/B=3 refNum, integer
146        intw[15] = integer
147        FBinRead/F=3/B=3 refNum, integer
148        intw[16] = integer
149        FBinRead/F=3/B=3 refNum, integer
150        intw[17] = integer
151       
152        //1 text field
153        FSetPos refNum,404
154        FReadLine/N=42 refNum,textstr
155        textw[10]= textstr
156       
157        //1 integer
158        FSetPos refNum,458
159        FBinRead/F=3/B=3 refNum, integer
160        intw[18] = integer
161       
162        //4 integers
163        FSetPos refNum,478
164        FBinRead/F=3/B=3 refNum, integer
165        intw[19] = integer
166        FBinRead/F=3/B=3 refNum, integer
167        intw[20] = integer
168        FBinRead/F=3/B=3 refNum, integer
169        intw[21] = integer
170        FBinRead/F=3/B=3 refNum, integer
171        intw[22] = integer
172       
173        Close refNum
174       
175        //now get all of the reals
176        //
177        //Do all the GBLoadWaves at the end
178        //
179        //FBinRead Cannot handle 32 bit VAX floating point
180        //GBLoadWave, however, can properly read it
181        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
182        String strToExecute
183        //append "/S=offset/U=numofreals" to control the read
184        // then append fname to give the full file path
185        // then execute
186       
187        Variable a=0,b=0
188       
189        SetDataFolder curPath
190       
191        // 4 R*4 values
192        strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
193        Execute strToExecute
194        Wave w=$"root:RAW:tempGBWave0"
195        b=4     //num of reals read
196        realw[a,a+b-1] = w[p-a]
197        a+=b
198       
199        // 4 R*4 values
200        SetDataFolder curPath
201        strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""
202        Execute strToExecute
203        b=4     
204        realw[a,a+b-1] = w[p-a]
205        a+=b
206
207///////////
208        // 2 R*4 values
209        SetDataFolder curPath
210        strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
211        Execute strToExecute
212        b=2     
213        realw[a,a+b-1] = w[p-a]
214        a+=b
215
216        // 6 R*4 values
217        SetDataFolder curPath
218        strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""
219        Execute strToExecute
220        b=6     
221        realw[a,a+b-1] = w[p-a]
222        a+=b
223       
224        // 13 R*4 values
225        SetDataFolder curPath
226        strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""
227        Execute strToExecute
228        b=13
229        realw[a,a+b-1] = w[p-a]
230        a+=b
231       
232        // 3 R*4 values
233        SetDataFolder curPath
234        strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""
235        Execute strToExecute
236        b=3     
237        realw[a,a+b-1] = w[p-a]
238        a+=b
239       
240        // 7 R*4 values
241        SetDataFolder curPath
242        strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""
243        Execute strToExecute
244        b=7
245        realw[a,a+b-1] = w[p-a]
246        a+=b
247       
248        // 4 R*4 values
249        SetDataFolder curPath
250        strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""
251        Execute strToExecute
252        b=4     
253        realw[a,a+b-1] = w[p-a]
254        a+=b
255       
256        // 2 R*4 values
257        SetDataFolder curPath
258        strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""
259        Execute strToExecute
260        b=2
261        realw[a,a+b-1] = w[p-a]
262        a+=b
263       
264        // 2 R*4 values
265        SetDataFolder curPath
266        strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""
267        Execute strToExecute
268        b=2
269        realw[a,a+b-1] = w[p-a]
270        a+=b
271       
272        // 5 R*4 values
273        SetDataFolder curPath
274        strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""
275        Execute strToExecute
276        b=5     
277        realw[a,a+b-1] = w[p-a]
278       
279        //if the binary VAX data ws transferred to a MAC, all is OK
280        //if the data was trasnferred to an Intel machine (IBM), all the real values must be
281        //divided by 4 to get the correct floating point values
282        // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly
283        // on an Intel machine.
284        //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read
285        //VAX reals correctly, and no checking is necessary 12 APR 99
286        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
287                //do nothing
288        //else
289                //either Windows or Windows NT
290                //realw /= 4
291        //endif
292       
293        SetDataFolder curPath
294        //read in the data
295        strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\""
296        Execute strToExecute
297
298        SetDataFolder curPath           //use the full path, so it will always work
299       
300        Make/O/N=16384 $"root:RAW:data"
301        WAVE data=$"root:RAW:data"
302        SkipAndDecompressVAX(w,data)
303        Redimension/N=(128,128) data                    //NIST raw data is 128x128 - do not generalize
304       
305        //keep a string with the filename in the RAW folder
306        String/G root:RAW:fileList = textw[0]
307       
308        //set the globals to the detector dimensions (pixels)
309        Variable/G root:myGlobals:gNPixelsX=128         //default for Ordela data (also set in Initialize.ipf)
310        Variable/G root:myGlobals:gNPixelsY=128
311//      if(cmpstr(textW[9],"ILL   ")==0)                //override if OLD Cerca data
312//              Variable/G root:myGlobals:gNPixelsX=64
313//              Variable/G root:myGlobals:gNPixelsY=64
314//      endif
315       
316        //clean up - get rid of w = $"root:RAW:tempGBWave0"
317        KillWaves/Z w
318       
319        //return the data folder to root
320        SetDataFolder root:
321       
322        Return 0
323
324End
325
326//function called by the main entry procedure
327//sets global display variable, reads in the data, and displays it
328//displays alert, and returns error if no file was selected
329//
330// calling routine must decide whether to abort the execution or not...
331Function ReadBinarySANS(msgStr)
332        String msgStr
333
334        String filename=""
335
336        //each routine is responsible for checking the current (displayed) data folder
337        //selecting it, and returning to root when done
338        PathInfo/S catPathName          //should set the next dialog to the proper path...
339        //get the filename, then read it in
340        filename = PromptForPath(msgStr)
341        //check for cancel from dialog
342        if(strlen(filename)==0)
343                //user cancelled, abort
344                SetDataFolder root:
345                DoAlert 0, "No file selected, action aborted"
346                return(1)
347        Endif
348        //Print  "GetFileNameFromPath(filename) = " +  GetFileNameFromPathNoSemi(filename)
349        ReadHeaderAndData(filename)     //this is the full Path+file
350
351        //the calling macro must change the display type
352        String/G root:myGlobals:gDataDisplayType="RAW"          //displayed data type is raw
353       
354        //data is displayed here
355        fRawWindowHook()
356       
357        Return(0)
358End
359
360//function to take the I*2 data that was read in, in VAX format
361//where the integers are "normal", but there are 2-byte record markers
362//sprinkled evenly through the data
363//there are skipped, leaving 128x128=16384 data values
364//the input array (in) is larger than 16384
365//(out) is 128x128 data (single precision) as defined in ReadHeaderAndData()
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.
398Function Decompress(val)
399        Variable val
400
401        Variable i4,npw,ipw,ib,nd
402
403        ib=10
404        nd=4
405        ipw=ib^nd
406        i4=val
407
408        if (i4 <= -ipw)
409                npw=trunc(-i4/ipw)
410                i4=mod(-i4,ipw)*(ib^npw)
411                return i4
412        else
413                return i4
414        endif
415End
416
417//****************
418//main entry procedure for reading a "WORK.DIV" file
419//displays a quick image of the  file, to check that it's correct
420//data is deposited in root:DIV data folder
421//
422Proc ReadWork_DIV()
423//      Silent 1
424       
425        String fname = PromptForPath("Select detector sensitivity file")
426        ReadHeaderAndWork("DIV",fname)          //puts what is read in work.div
427       
428        String waveStr = "root:DIV:data"
429        NewImage/F/K=1/S=2 $waveStr             //this is an experimental IGOR operation
430        ModifyImage '' ctab= {*,*,YellowHot,0}
431        //Display;AppendImage $waveStr
432       
433        //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage
434        String/G root:DIV:fileList = "WORK.DIV"
435       
436        SetDataFolder root:             //(redundant)
437//      Silent 0
438End
439
440//testing procedure that is not called anymore and is out-of-date
441//with the new data structures. update before re-implementing
442Proc ReadBinaryWork()           //this procedure is not called anymore
443
444//      Silent 1
445       
446        //make sure the globals are reset properly
447        Variable/G root:myGlobals:gIsLogScale=0 //image is linearly scaled to begin with
448        String/G root:myGlobals:gDataDisplayType="RAW"          //displayed data type is raw
449       
450        //each routine is responsible for checking the current (displayed) data folder
451        //selecting it, and returning to root when done
452       
453        ReadHeaderAndWork()
454
455        SetDataFolder root:RAW
456        //data is displayed here
457        Display;AppendImage data
458       
459//      Silent 0
460       
461        //data folder was changed from root in this macro
462        SetDataFolder root:
463End
464
465//this function is the guts of reading a rinary VAX file of real (4-byte) values
466// (i.e. a WORK.aaa file)
467// work files have the same header structure as RAW SANS data, just with
468//different data (real, rather than compressed integer data)
469//
470//************
471//this routine incorrectly reads in several data values where the VAX record
472//marker splits the 4-byte real (at alternating record markers)
473//this error seems to not be severe, but shoud be corrected (at great pain)
474//************
475//
476Function ReadHeaderAndWork(type,fname)
477        String type,fname
478       
479        //type is the desired folder to read the workfile to
480        //this data will NOT be automatically displayed gDataDisplayType is unchanged
481
482//      SVAR cur_folder=root:myGlobals:gDataDisplayType
483        String cur_folder = type
484        String curPath = "root:"+cur_folder
485        SetDataFolder curPath           //use the full path, so it will always work
486       
487        Variable refNum,integer,realval
488        String sansfname,textstr
489        Variable/G $(curPath + ":gIsLogScale") = 0              //initial state is linear, keep this in DIV folder
490       
491        Make/O/N=23 $(curPath + ":IntegersRead")
492        Make/O/N=52 $(curPath + ":RealsRead")
493        Make/O/T/N=11 $(curPath + ":TextRead")
494       
495        WAVE intw=$(curPath + ":IntegersRead")
496        WAVE realw=$(curPath + ":RealsRead")
497        WAVE/T textw=$(curPath + ":TextRead")
498       
499        //***NOTE ****
500        // the "current path" gets mysteriously reset to "root:" after the SECOND pass through
501        // this read routine, after the open dialog is presented
502        // the "--read" waves end up in the correct folder, but the data does not! Why?
503        //must re-set data folder before writing data array (done below)
504       
505        SetDataFolder curPath
506       
507        //actually open the file
508        Open/R refNum as fname
509        //skip first two bytes
510        FSetPos refNum, 2
511        //read the next 21 bytes as characters (fname)
512        FReadLine/N=21 refNum,textstr
513        textw[0]= textstr
514        //read four i*4 values  /F=3 flag, B=3 flag
515        FBinRead/F=3/B=3 refNum, integer
516        intw[0] = integer
517        //
518        FBinRead/F=3/B=3 refNum, integer
519        intw[1] = integer
520        //
521        FBinRead/F=3/B=3 refNum, integer
522        intw[2] = integer
523        //
524        FBinRead/F=3/B=3 refNum, integer
525        intw[3] = integer
526        // 6 text fields
527        FSetPos refNum,55               //will start reading at byte 56
528        FReadLine/N=20 refNum,textstr
529        textw[1]= textstr
530        FReadLine/N=3 refNum,textstr
531        textw[2]= textstr
532        FReadLine/N=11 refNum,textstr
533        textw[3]= textstr
534        FReadLine/N=1 refNum,textstr
535        textw[4]= textstr
536        FReadLine/N=8 refNum,textstr
537        textw[5]= textstr
538        FReadLine/N=60 refNum,textstr
539        textw[6]= textstr
540       
541        //3 integers
542        FSetPos refNum,174
543        FBinRead/F=3/B=3 refNum, integer
544        intw[4] = integer
545        FBinRead/F=3/B=3 refNum, integer
546        intw[5] = integer
547        FBinRead/F=3/B=3 refNum, integer
548        intw[6] = integer
549       
550        //2 integers, 3 text fields
551        FSetPos refNum,194
552        FBinRead/F=3/B=3 refNum, integer
553        intw[7] = integer
554        FBinRead/F=3/B=3 refNum, integer
555        intw[8] = integer
556        FReadLine/N=6 refNum,textstr
557        textw[7]= textstr
558        FReadLine/N=6 refNum,textstr
559        textw[8]= textstr
560        FReadLine/N=6 refNum,textstr
561        textw[9]= textstr
562       
563        //2 integers
564        FSetPos refNum,244
565        FBinRead/F=3/B=3 refNum, integer
566        intw[9] = integer
567        FBinRead/F=3/B=3 refNum, integer
568        intw[10] = integer
569       
570        //2 integers
571        FSetPos refNum,308
572        FBinRead/F=3/B=3 refNum, integer
573        intw[11] = integer
574        FBinRead/F=3/B=3 refNum, integer
575        intw[12] = integer
576       
577        //2 integers
578        FSetPos refNum,332
579        FBinRead/F=3/B=3 refNum, integer
580        intw[13] = integer
581        FBinRead/F=3/B=3 refNum, integer
582        intw[14] = integer
583       
584        //3 integers
585        FSetPos refNum,376
586        FBinRead/F=3/B=3 refNum, integer
587        intw[15] = integer
588        FBinRead/F=3/B=3 refNum, integer
589        intw[16] = integer
590        FBinRead/F=3/B=3 refNum, integer
591        intw[17] = integer
592       
593        //1 text field
594        FSetPos refNum,404
595        FReadLine/N=42 refNum,textstr
596        textw[10]= textstr
597       
598        //1 integer
599        FSetPos refNum,458
600        FBinRead/F=3/B=3 refNum, integer
601        intw[18] = integer
602       
603        //4 integers
604        FSetPos refNum,478
605        FBinRead/F=3/B=3 refNum, integer
606        intw[19] = integer
607        FBinRead/F=3/B=3 refNum, integer
608        intw[20] = integer
609        FBinRead/F=3/B=3 refNum, integer
610        intw[21] = integer
611        FBinRead/F=3/B=3 refNum, integer
612        intw[22] = integer
613       
614        Close refNum
615       
616        //now get all of the reals
617        //
618        //Do all the GBLoadWaves at the end
619        //
620        //FBinRead Cannot handle 32 bit VAX floating point
621        //GBLoadWave, however, can properly read it
622        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
623        String strToExecute
624        //append "/S=offset/U=numofreals" to control the read
625        // then append fname to give the full file path
626        // then execute
627       
628        Variable a=0,b=0
629       
630        SetDataFolder curPath
631        // 4 R*4 values
632        strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
633        Execute strToExecute
634       
635        SetDataFolder curPath
636        Wave w=$(curPath + ":tempGBWave0")
637        b=4     //num of reals read
638        realw[a,a+b-1] = w[p-a]
639        a+=b
640       
641        // 4 R*4 values
642        SetDataFolder curPath
643        strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""
644        Execute strToExecute
645        b=4     
646        realw[a,a+b-1] = w[p-a]
647        a+=b
648
649///////////
650        // 2 R*4 values
651        SetDataFolder curPath
652        strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
653        Execute strToExecute
654        b=2     
655        realw[a,a+b-1] = w[p-a]
656        a+=b
657
658        // 6 R*4 values
659        SetDataFolder curPath
660        strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""
661        Execute strToExecute
662        b=6     
663        realw[a,a+b-1] = w[p-a]
664        a+=b
665       
666        // 13 R*4 values
667        SetDataFolder curPath
668        strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""
669        Execute strToExecute
670        b=13
671        realw[a,a+b-1] = w[p-a]
672        a+=b
673       
674        // 3 R*4 values
675        SetDataFolder curPath
676        strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""
677        Execute strToExecute
678        b=3     
679        realw[a,a+b-1] = w[p-a]
680        a+=b
681       
682        // 7 R*4 values
683        SetDataFolder curPath
684        strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""
685        Execute strToExecute
686        b=7
687        realw[a,a+b-1] = w[p-a]
688        a+=b
689       
690        // 4 R*4 values
691        SetDataFolder curPath
692        strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""
693        Execute strToExecute
694        b=4     
695        realw[a,a+b-1] = w[p-a]
696        a+=b
697       
698        // 2 R*4 values
699        SetDataFolder curPath
700        strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""
701        Execute strToExecute
702        b=2
703        realw[a,a+b-1] = w[p-a]
704        a+=b
705       
706        // 2 R*4 values
707        SetDataFolder curPath
708        strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""
709        Execute strToExecute
710        b=2
711        realw[a,a+b-1] = w[p-a]
712        a+=b
713       
714        // 5 R*4 values
715        SetDataFolder curPath
716        strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""
717        Execute strToExecute
718        b=5     
719        realw[a,a+b-1] = w[p-a]
720       
721        //if the binary VAX data ws transferred to a MAC, all is OK
722        //if the data was trasnferred to an Intel machine (IBM), all the real values must be
723        //divided by 4 to get the correct floating point values
724        // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly
725        // on an Intel machine.
726        //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read
727        //VAX reals correctly, and no checking is necessary 12 APR 99
728        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
729                //do nothing
730        //else
731                //either Windows or Windows NT
732                //realw /= 4
733        //endif
734       
735        //read in the data
736         GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
737
738        curPath = "root:"+cur_folder
739        SetDataFolder curPath           //use the full path, so it will always work
740       
741        Make/O/N=16384 $(curPath + ":data")
742        WAVE data = $(curPath + ":data")
743       
744        Variable skip,ii,offset
745       
746        //read in a total of 16384 values (ii)
747        //as follows :
748        // skip first 2 bytes
749        // skip 512 byte header
750        // skip first 2 bytes of data
751        //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values
752        // read the final 48 values in seperately to avoid EOF error
753       
754        /////////////
755        SetDataFolder curPath
756        skip = 0
757        ii=0
758        offset = 514 +2
759        a=0
760        do
761                SetDataFolder curPath
762               
763                strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\""
764                Execute strToExecute
765                //Print strToExecute
766                b=511
767                data[a,a+b-1] = w[p-a]
768                a+=b
769               
770                offset += 511*4 +2
771               
772                strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\""
773                SetDataFolder curPath
774                Execute strToExecute
775                //Print strToExecute
776                b=510
777                data[a,a+b-1] = w[p-a]
778                a+=b
779               
780                offset += 510*4 +2
781               
782                ii+=1
783                //Print "inside do, data[2] =",data[2]
784                //Print "inside do, tempGBwave0[0] = ",w[0]
785        while(ii<16)
786       
787        // 16336 values have been read in --
788        //read in last 64 values
789        strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\""
790       
791        SetDataFolder curPath
792        Execute strToExecute
793        b=48
794        data[a,a+b-1] = w[p-a]
795        a+=b
796//
797/// done reading in raw data
798//
799        //Print "in workdatareader , data = ", data[1][1]
800
801        Redimension/n=(128,128) data
802       
803        //clean up - get rid of w = $"tempGBWave0"
804        KillWaves w
805       
806        //divide the FP data by 4 if read from a PC (not since GBLoadWave update)
807        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
808                //do nothing
809        //else
810                //either Windows or Windows NT
811                //data /= 4
812        //endif
813       
814        //keep a string with the filename in the DIV folder
815        String/G $(curPath + ":fileList") = textw[0]
816       
817        //return the data folder to root
818        SetDataFolder root:
819       
820        Return(0)
821End
822
823//returns the path to the file, or null if cancel
824Function/S DoOpenFileDialog(msg)
825        String msg
826       
827        Variable refNum
828//      String message = "Select a file"
829        String outputPath
830       
831        Open/D/R/T="????"/M=msg refNum
832        outputPath = S_fileName
833       
834        return outputPath
835End
836
837// returns the path to the file, or null if the user cancelled
838Function/S DoSaveFileDialog(msg)
839        String msg
840        Variable refNum
841//      String message = "Save the file as"
842        String outputPath
843       
844        Open/D/M=msg refNum
845        outputPath = S_fileName
846       
847        return outputPath
848End
Note: See TracBrowser for help on using the repository browser.