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