1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.1 |
---|
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 | // |
---|
26 | Function 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) |
---|
54 | End |
---|
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 | //VAX data as read in is in compressed I*2 format, and is decompressed |
---|
61 | //immediately after being read in. The final root:Packages:NIST:RAW:data wave is the real |
---|
62 | //neutron counts and can be directly operated on |
---|
63 | // |
---|
64 | // header information is put into three waves: integersRead, realsRead, and textRead |
---|
65 | // logicals in the header are currently skipped, since they are no use in the |
---|
66 | // data reduction process. |
---|
67 | // |
---|
68 | // The output is the three R/T/I waves that are filled at least with minimal values |
---|
69 | // and the detector data loaded into an array named "data" |
---|
70 | // |
---|
71 | // see documentation for the expected information in each element of the R/T/I waves |
---|
72 | // and the minimum set of information. These waves can be increased in length so that |
---|
73 | // more information can be accessed as needed (propagating changes...) |
---|
74 | // |
---|
75 | // called by multiple .ipfs (when the file name is known) |
---|
76 | // |
---|
77 | Function ReadHeaderAndData(fname) |
---|
78 | String fname |
---|
79 | //this function is for reading in RAW data only, so it will always put data in RAW folder |
---|
80 | String curPath = "root:Packages:NIST:RAW:" |
---|
81 | SetDataFolder curPath //use the full path, so it will always work |
---|
82 | Variable/G root:Packages:NIST:RAW:gIsLogScale = 0 //initial state is linear, keep this in RAW folder |
---|
83 | |
---|
84 | Variable refNum,integer,realval |
---|
85 | String sansfname,textstr |
---|
86 | |
---|
87 | Make/O/D/N=23 $"root:Packages:NIST:RAW:IntegersRead" |
---|
88 | Make/O/D/N=52 $"root:Packages:NIST:RAW:RealsRead" |
---|
89 | Make/O/T/N=11 $"root:Packages:NIST:RAW:TextRead" |
---|
90 | Make/O/N=7 $"root:Packages:NIST:RAW:LogicalsRead" |
---|
91 | |
---|
92 | Wave intw=$"root:Packages:NIST:RAW:IntegersRead" |
---|
93 | Wave realw=$"root:Packages:NIST:RAW:RealsRead" |
---|
94 | Wave/T textw=$"root:Packages:NIST:RAW:TextRead" |
---|
95 | Wave logw=$"root:Packages:NIST:RAW:LogicalsRead" |
---|
96 | |
---|
97 | //***NOTE **** |
---|
98 | // the "current path" gets mysteriously reset to "root:" after the SECOND pass through |
---|
99 | // this read routine, after the open dialog is presented |
---|
100 | // the "--read" waves end up in the correct folder, but the data does not! Why? |
---|
101 | //must re-set data folder before writing data array (done below) |
---|
102 | |
---|
103 | //full filename and path is now passed in... |
---|
104 | //actually open the file |
---|
105 | Open/R refNum as fname |
---|
106 | //skip first two bytes (VAX record length markers, not needed here) |
---|
107 | FSetPos refNum, 2 |
---|
108 | //read the next 21 bytes as characters (fname) |
---|
109 | FReadLine/N=21 refNum,textstr |
---|
110 | textw[0]= textstr |
---|
111 | //read four i*4 values /F=3 flag, B=3 flag |
---|
112 | FBinRead/F=3/B=3 refNum, integer |
---|
113 | intw[0] = integer |
---|
114 | // |
---|
115 | FBinRead/F=3/B=3 refNum, integer |
---|
116 | intw[1] = integer |
---|
117 | // |
---|
118 | FBinRead/F=3/B=3 refNum, integer |
---|
119 | intw[2] = integer |
---|
120 | // |
---|
121 | FBinRead/F=3/B=3 refNum, integer |
---|
122 | intw[3] = integer |
---|
123 | // 6 text fields |
---|
124 | FSetPos refNum,55 //will start reading at byte 56 |
---|
125 | FReadLine/N=20 refNum,textstr |
---|
126 | textw[1]= textstr |
---|
127 | FReadLine/N=3 refNum,textstr |
---|
128 | textw[2]= textstr |
---|
129 | FReadLine/N=11 refNum,textstr |
---|
130 | textw[3]= textstr |
---|
131 | FReadLine/N=1 refNum,textstr |
---|
132 | textw[4]= textstr |
---|
133 | FReadLine/N=8 refNum,textstr |
---|
134 | textw[5]= textstr |
---|
135 | FReadLine/N=60 refNum,textstr |
---|
136 | textw[6]= textstr |
---|
137 | |
---|
138 | //3 integers |
---|
139 | FSetPos refNum,174 |
---|
140 | FBinRead/F=3/B=3 refNum, integer |
---|
141 | intw[4] = integer |
---|
142 | FBinRead/F=3/B=3 refNum, integer |
---|
143 | intw[5] = integer |
---|
144 | FBinRead/F=3/B=3 refNum, integer |
---|
145 | intw[6] = integer |
---|
146 | |
---|
147 | //2 integers, 3 text fields |
---|
148 | FSetPos refNum,194 |
---|
149 | FBinRead/F=3/B=3 refNum, integer |
---|
150 | intw[7] = integer |
---|
151 | FBinRead/F=3/B=3 refNum, integer |
---|
152 | intw[8] = integer |
---|
153 | FReadLine/N=6 refNum,textstr |
---|
154 | textw[7]= textstr |
---|
155 | FReadLine/N=6 refNum,textstr |
---|
156 | textw[8]= textstr |
---|
157 | FReadLine/N=6 refNum,textstr |
---|
158 | textw[9]= textstr |
---|
159 | |
---|
160 | //2 integers |
---|
161 | FSetPos refNum,244 |
---|
162 | FBinRead/F=3/B=3 refNum, integer |
---|
163 | intw[9] = integer |
---|
164 | FBinRead/F=3/B=3 refNum, integer |
---|
165 | intw[10] = integer |
---|
166 | |
---|
167 | |
---|
168 | //2 integers |
---|
169 | FSetPos refNum,308 |
---|
170 | FBinRead/F=3/B=3 refNum, integer |
---|
171 | intw[11] = integer |
---|
172 | FBinRead/F=3/B=3 refNum, integer |
---|
173 | intw[12] = integer |
---|
174 | |
---|
175 | //2 integers |
---|
176 | FSetPos refNum,332 |
---|
177 | FBinRead/F=3/B=3 refNum, integer |
---|
178 | intw[13] = integer |
---|
179 | FBinRead/F=3/B=3 refNum, integer |
---|
180 | intw[14] = integer |
---|
181 | |
---|
182 | //3 integers |
---|
183 | FSetPos refNum,376 |
---|
184 | FBinRead/F=3/B=3 refNum, integer |
---|
185 | intw[15] = integer |
---|
186 | FBinRead/F=3/B=3 refNum, integer |
---|
187 | intw[16] = integer |
---|
188 | FBinRead/F=3/B=3 refNum, integer |
---|
189 | intw[17] = integer |
---|
190 | |
---|
191 | //1 text field - the file association for transmission are the first 4 bytes |
---|
192 | FSetPos refNum,404 |
---|
193 | FReadLine/N=42 refNum,textstr |
---|
194 | textw[10]= textstr |
---|
195 | |
---|
196 | //1 integer |
---|
197 | FSetPos refNum,458 |
---|
198 | FBinRead/F=3/B=3 refNum, integer |
---|
199 | intw[18] = integer |
---|
200 | |
---|
201 | //4 integers |
---|
202 | FSetPos refNum,478 |
---|
203 | FBinRead/F=3/B=3 refNum, integer |
---|
204 | intw[19] = integer |
---|
205 | FBinRead/F=3/B=3 refNum, integer |
---|
206 | intw[20] = integer |
---|
207 | FBinRead/F=3/B=3 refNum, integer |
---|
208 | intw[21] = integer |
---|
209 | FBinRead/F=3/B=3 refNum, integer |
---|
210 | intw[22] = integer |
---|
211 | |
---|
212 | //Get Logicals |
---|
213 | //Read logicals as int - ICE is writing integers here |
---|
214 | FSetPos refNum,304 |
---|
215 | FBinRead/F=3/B=3 refNum, integer |
---|
216 | logw[0] = integer |
---|
217 | FSetPos refNum,316 |
---|
218 | FBinRead/F=3/B=3 refNum, integer |
---|
219 | logw[1] = integer |
---|
220 | FSetPos refNum,340 |
---|
221 | FBinRead/F=3/B=3 refNum, integer |
---|
222 | logw[2] = integer |
---|
223 | FSetPos refNum,344 |
---|
224 | FBinRead/F=3/B=3 refNum, integer |
---|
225 | logw[3] = integer |
---|
226 | FSetPos refNum,446 |
---|
227 | FBinRead/F=3/B=3 refNum, integer |
---|
228 | logw[4] = integer |
---|
229 | FSetPos refNum,462 |
---|
230 | FBinRead/F=3/B=3 refNum, integer |
---|
231 | logw[5] = integer |
---|
232 | FSetPos refNum,466 |
---|
233 | FBinRead/F=3/B=3 refNum, integer |
---|
234 | logw[6] = integer |
---|
235 | |
---|
236 | Close refNum |
---|
237 | |
---|
238 | //now get all of the reals |
---|
239 | // |
---|
240 | //Do all the GBLoadWaves at the end |
---|
241 | // |
---|
242 | //FBinRead Cannot handle 32 bit VAX floating point |
---|
243 | //GBLoadWave, however, can properly read it |
---|
244 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
245 | String strToExecute |
---|
246 | //append "/S=offset/U=numofreals" to control the read |
---|
247 | // then append fname to give the full file path |
---|
248 | // then execute |
---|
249 | |
---|
250 | Variable a=0,b=0 |
---|
251 | |
---|
252 | SetDataFolder curPath |
---|
253 | |
---|
254 | // 4 R*4 values |
---|
255 | strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" |
---|
256 | Execute strToExecute |
---|
257 | Wave w=$"root:Packages:NIST:RAW:tempGBWave0" |
---|
258 | b=4 //num of reals read |
---|
259 | realw[a,a+b-1] = w[p-a] |
---|
260 | a+=b |
---|
261 | |
---|
262 | // 4 R*4 values |
---|
263 | SetDataFolder curPath |
---|
264 | strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\"" |
---|
265 | Execute strToExecute |
---|
266 | b=4 |
---|
267 | realw[a,a+b-1] = w[p-a] |
---|
268 | a+=b |
---|
269 | |
---|
270 | /////////// |
---|
271 | // 2 R*4 values |
---|
272 | SetDataFolder curPath |
---|
273 | strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" |
---|
274 | Execute strToExecute |
---|
275 | b=2 |
---|
276 | realw[a,a+b-1] = w[p-a] |
---|
277 | a+=b |
---|
278 | |
---|
279 | // 6 R*4 values |
---|
280 | SetDataFolder curPath |
---|
281 | strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\"" |
---|
282 | Execute strToExecute |
---|
283 | b=6 |
---|
284 | realw[a,a+b-1] = w[p-a] |
---|
285 | a+=b |
---|
286 | |
---|
287 | // 13 R*4 values |
---|
288 | SetDataFolder curPath |
---|
289 | strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\"" |
---|
290 | Execute strToExecute |
---|
291 | b=13 |
---|
292 | realw[a,a+b-1] = w[p-a] |
---|
293 | a+=b |
---|
294 | |
---|
295 | // 3 R*4 values |
---|
296 | SetDataFolder curPath |
---|
297 | strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\"" |
---|
298 | Execute strToExecute |
---|
299 | b=3 |
---|
300 | realw[a,a+b-1] = w[p-a] |
---|
301 | a+=b |
---|
302 | |
---|
303 | // 7 R*4 values |
---|
304 | SetDataFolder curPath |
---|
305 | strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\"" |
---|
306 | Execute strToExecute |
---|
307 | b=7 |
---|
308 | realw[a,a+b-1] = w[p-a] |
---|
309 | a+=b |
---|
310 | |
---|
311 | // 4 R*4 values |
---|
312 | SetDataFolder curPath |
---|
313 | strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\"" |
---|
314 | Execute strToExecute |
---|
315 | b=4 |
---|
316 | realw[a,a+b-1] = w[p-a] |
---|
317 | a+=b |
---|
318 | |
---|
319 | // 2 R*4 values |
---|
320 | SetDataFolder curPath |
---|
321 | strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\"" |
---|
322 | Execute strToExecute |
---|
323 | b=2 |
---|
324 | realw[a,a+b-1] = w[p-a] |
---|
325 | a+=b |
---|
326 | |
---|
327 | // 2 R*4 values |
---|
328 | SetDataFolder curPath |
---|
329 | strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\"" |
---|
330 | Execute strToExecute |
---|
331 | b=2 |
---|
332 | realw[a,a+b-1] = w[p-a] |
---|
333 | a+=b |
---|
334 | |
---|
335 | // 5 R*4 values |
---|
336 | SetDataFolder curPath |
---|
337 | strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\"" |
---|
338 | Execute strToExecute |
---|
339 | b=5 |
---|
340 | realw[a,a+b-1] = w[p-a] |
---|
341 | |
---|
342 | //if the binary VAX data ws transferred to a MAC, all is OK |
---|
343 | //if the data was trasnferred to an Intel machine (IBM), all the real values must be |
---|
344 | //divided by 4 to get the correct floating point values |
---|
345 | // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly |
---|
346 | // on an Intel machine. |
---|
347 | //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read |
---|
348 | //VAX reals correctly, and no checking is necessary 12 APR 99 |
---|
349 | //if(cmpstr("Macintosh",IgorInfo(2)) == 0) |
---|
350 | //do nothing |
---|
351 | //else |
---|
352 | //either Windows or Windows NT |
---|
353 | //realw /= 4 |
---|
354 | //endif |
---|
355 | |
---|
356 | SetDataFolder curPath |
---|
357 | //read in the data |
---|
358 | strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\"" |
---|
359 | Execute strToExecute |
---|
360 | |
---|
361 | SetDataFolder curPath //use the full path, so it will always work |
---|
362 | |
---|
363 | Make/O/D/N=16384 $"root:Packages:NIST:RAW:data" |
---|
364 | WAVE data=$"root:Packages:NIST:RAW:data" |
---|
365 | SkipAndDecompressVAX(w,data) |
---|
366 | Redimension/N=(128,128) data //NIST raw data is 128x128 - do not generalize |
---|
367 | |
---|
368 | //keep a string with the filename in the RAW folder |
---|
369 | String/G root:Packages:NIST:RAW:fileList = textw[0] |
---|
370 | |
---|
371 | //set the globals to the detector dimensions (pixels) |
---|
372 | Variable/G root:myGlobals:gNPixelsX=128 //default for Ordela data (also set in Initialize/NCNR_Utils.ipf) |
---|
373 | Variable/G root:myGlobals:gNPixelsY=128 |
---|
374 | // if(cmpstr(textW[9],"ILL ")==0) //override if OLD Cerca data |
---|
375 | // Variable/G root:myGlobals:gNPixelsX=64 |
---|
376 | // Variable/G root:myGlobals:gNPixelsY=64 |
---|
377 | // endif |
---|
378 | |
---|
379 | //clean up - get rid of w = $"root:Packages:NIST:RAW:tempGBWave0" |
---|
380 | // KillWaves/Z w |
---|
381 | |
---|
382 | //return the data folder to root |
---|
383 | SetDataFolder root: |
---|
384 | |
---|
385 | Return 0 |
---|
386 | |
---|
387 | End |
---|
388 | |
---|
389 | |
---|
390 | //function to take the I*2 data that was read in, in VAX format |
---|
391 | //where the integers are "normal", but there are 2-byte record markers |
---|
392 | //sprinkled evenly through the data |
---|
393 | //there are skipped, leaving 128x128=16384 data values |
---|
394 | //the input array (in) is larger than 16384 |
---|
395 | //(out) is 128x128 data (single precision) as defined in ReadHeaderAndData() |
---|
396 | // |
---|
397 | // local function to post-process compressed VAX binary data |
---|
398 | // |
---|
399 | // |
---|
400 | Function SkipAndDecompressVAX(in,out) |
---|
401 | Wave in,out |
---|
402 | |
---|
403 | Variable skip,ii |
---|
404 | |
---|
405 | ii=0 |
---|
406 | skip=0 |
---|
407 | do |
---|
408 | if(mod(ii+skip,1022)==0) |
---|
409 | skip+=1 |
---|
410 | endif |
---|
411 | out[ii] = Decompress(in[ii+skip]) |
---|
412 | ii+=1 |
---|
413 | while(ii<16384) |
---|
414 | return(0) |
---|
415 | End |
---|
416 | |
---|
417 | //decompresses each I*2 data value to its real I*4 value |
---|
418 | //using the decompression routine written by Jim Ryhne, many moons ago |
---|
419 | // |
---|
420 | // the compression routine (not shown here, contained in the VAX fortran RW_DATAFILE.FOR) maps I4 to I2 values. |
---|
421 | // (back in the days where disk space *really* mattered). the I4toI2 function spit out: |
---|
422 | // I4toI2 = I4 when I4 in [0,32767] |
---|
423 | // I4toI2 = -777 when I4 in [2,767,000,...] |
---|
424 | // I4toI2 mapped to -13277 to -32768 otherwise |
---|
425 | // |
---|
426 | // the mapped values [-776,-1] and [-13276,-778] are not used. |
---|
427 | // in this compression scheme, only 4 significant digits are retained (to allow room for the exponent) |
---|
428 | // technically, the maximum value should be 2,768,499 since this maps to -32768. But this is of |
---|
429 | // little consequence. If you have individual pixel values on the detector that are that large, you need |
---|
430 | // to re-think your experiment. |
---|
431 | // |
---|
432 | // local function to post-process compressed VAX binary data |
---|
433 | // |
---|
434 | // |
---|
435 | Function Decompress(val) |
---|
436 | Variable val |
---|
437 | |
---|
438 | Variable i4,npw,ipw,ib,nd |
---|
439 | |
---|
440 | ib=10 |
---|
441 | nd=4 |
---|
442 | ipw=ib^nd |
---|
443 | i4=val |
---|
444 | |
---|
445 | if (i4 <= -ipw) |
---|
446 | npw=trunc(-i4/ipw) |
---|
447 | i4=mod(-i4,ipw)*(ib^npw) |
---|
448 | return i4 |
---|
449 | else |
---|
450 | return i4 |
---|
451 | endif |
---|
452 | End |
---|
453 | |
---|
454 | //**************** |
---|
455 | //main entry procedure for reading a "WORK.DIV" file |
---|
456 | //displays a quick image of the file, to check that it's correct |
---|
457 | //data is deposited in root:Packages:NIST:DIV data folder |
---|
458 | // |
---|
459 | // local, currently unused |
---|
460 | // |
---|
461 | // |
---|
462 | Proc ReadWork_DIV() |
---|
463 | // Silent 1 |
---|
464 | |
---|
465 | String fname = PromptForPath("Select detector sensitivity file") |
---|
466 | ReadHeaderAndWork("DIV",fname) //puts what is read in work.div |
---|
467 | |
---|
468 | String waveStr = "root:Packages:NIST:DIV:data" |
---|
469 | // NewImage/F/K=1/S=2 $waveStr //this is an experimental IGOR operation |
---|
470 | // ModifyImage '' ctab= {*,*,YellowHot,0} |
---|
471 | //Display;AppendImage $waveStr |
---|
472 | |
---|
473 | //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage |
---|
474 | // String/G root:Packages:NIST:DIV:fileList = "WORK.DIV" |
---|
475 | ChangeDisplay("DIV") |
---|
476 | |
---|
477 | SetDataFolder root: //(redundant) |
---|
478 | // Silent 0 |
---|
479 | End |
---|
480 | |
---|
481 | |
---|
482 | //this function is the guts of reading a binary VAX file of real (4-byte) values |
---|
483 | // (i.e. a WORK.aaa file) |
---|
484 | // work files have the same header structure as RAW SANS data, just with |
---|
485 | //different data (real, rather than compressed integer data) |
---|
486 | // |
---|
487 | //************ |
---|
488 | //this routine incorrectly reads in several data values where the VAX record |
---|
489 | //marker splits the 4-byte real (at alternating record markers) |
---|
490 | //this error seems to not be severe, but shoud be corrected (at great pain) |
---|
491 | //************ |
---|
492 | // |
---|
493 | // called from ProtocolAsPanel.ipf |
---|
494 | // |
---|
495 | // |
---|
496 | Function ReadHeaderAndWork(type,fname) |
---|
497 | String type,fname |
---|
498 | |
---|
499 | //type is the desired folder to read the workfile to |
---|
500 | //this data will NOT be automatically displayed gDataDisplayType is unchanged |
---|
501 | |
---|
502 | // SVAR cur_folder=root:myGlobals:gDataDisplayType |
---|
503 | String cur_folder = type |
---|
504 | String curPath = "root:Packages:NIST:"+cur_folder |
---|
505 | SetDataFolder curPath //use the full path, so it will always work |
---|
506 | |
---|
507 | Variable refNum,integer,realval |
---|
508 | String sansfname,textstr |
---|
509 | Variable/G $(curPath + ":gIsLogScale") = 0 //initial state is linear, keep this in DIV folder |
---|
510 | |
---|
511 | Make/O/D/N=23 $(curPath + ":IntegersRead") |
---|
512 | Make/O/D/N=52 $(curPath + ":RealsRead") |
---|
513 | Make/O/T/N=11 $(curPath + ":TextRead") |
---|
514 | |
---|
515 | WAVE intw=$(curPath + ":IntegersRead") |
---|
516 | WAVE realw=$(curPath + ":RealsRead") |
---|
517 | WAVE/T textw=$(curPath + ":TextRead") |
---|
518 | |
---|
519 | //***NOTE **** |
---|
520 | // the "current path" gets mysteriously reset to "root:" after the SECOND pass through |
---|
521 | // this read routine, after the open dialog is presented |
---|
522 | // the "--read" waves end up in the correct folder, but the data does not! Why? |
---|
523 | //must re-set data folder before writing data array (done below) |
---|
524 | |
---|
525 | SetDataFolder curPath |
---|
526 | |
---|
527 | //actually open the file |
---|
528 | Open/R refNum as fname |
---|
529 | //skip first two bytes |
---|
530 | FSetPos refNum, 2 |
---|
531 | //read the next 21 bytes as characters (fname) |
---|
532 | FReadLine/N=21 refNum,textstr |
---|
533 | textw[0]= textstr |
---|
534 | //read four i*4 values /F=3 flag, B=3 flag |
---|
535 | FBinRead/F=3/B=3 refNum, integer |
---|
536 | intw[0] = integer |
---|
537 | // |
---|
538 | FBinRead/F=3/B=3 refNum, integer |
---|
539 | intw[1] = integer |
---|
540 | // |
---|
541 | FBinRead/F=3/B=3 refNum, integer |
---|
542 | intw[2] = integer |
---|
543 | // |
---|
544 | FBinRead/F=3/B=3 refNum, integer |
---|
545 | intw[3] = integer |
---|
546 | // 6 text fields |
---|
547 | FSetPos refNum,55 //will start reading at byte 56 |
---|
548 | FReadLine/N=20 refNum,textstr |
---|
549 | textw[1]= textstr |
---|
550 | FReadLine/N=3 refNum,textstr |
---|
551 | textw[2]= textstr |
---|
552 | FReadLine/N=11 refNum,textstr |
---|
553 | textw[3]= textstr |
---|
554 | FReadLine/N=1 refNum,textstr |
---|
555 | textw[4]= textstr |
---|
556 | FReadLine/N=8 refNum,textstr |
---|
557 | textw[5]= textstr |
---|
558 | FReadLine/N=60 refNum,textstr |
---|
559 | textw[6]= textstr |
---|
560 | |
---|
561 | //3 integers |
---|
562 | FSetPos refNum,174 |
---|
563 | FBinRead/F=3/B=3 refNum, integer |
---|
564 | intw[4] = integer |
---|
565 | FBinRead/F=3/B=3 refNum, integer |
---|
566 | intw[5] = integer |
---|
567 | FBinRead/F=3/B=3 refNum, integer |
---|
568 | intw[6] = integer |
---|
569 | |
---|
570 | //2 integers, 3 text fields |
---|
571 | FSetPos refNum,194 |
---|
572 | FBinRead/F=3/B=3 refNum, integer |
---|
573 | intw[7] = integer |
---|
574 | FBinRead/F=3/B=3 refNum, integer |
---|
575 | intw[8] = integer |
---|
576 | FReadLine/N=6 refNum,textstr |
---|
577 | textw[7]= textstr |
---|
578 | FReadLine/N=6 refNum,textstr |
---|
579 | textw[8]= textstr |
---|
580 | FReadLine/N=6 refNum,textstr |
---|
581 | textw[9]= textstr |
---|
582 | |
---|
583 | //2 integers |
---|
584 | FSetPos refNum,244 |
---|
585 | FBinRead/F=3/B=3 refNum, integer |
---|
586 | intw[9] = integer |
---|
587 | FBinRead/F=3/B=3 refNum, integer |
---|
588 | intw[10] = integer |
---|
589 | |
---|
590 | //2 integers |
---|
591 | FSetPos refNum,308 |
---|
592 | FBinRead/F=3/B=3 refNum, integer |
---|
593 | intw[11] = integer |
---|
594 | FBinRead/F=3/B=3 refNum, integer |
---|
595 | intw[12] = integer |
---|
596 | |
---|
597 | //2 integers |
---|
598 | FSetPos refNum,332 |
---|
599 | FBinRead/F=3/B=3 refNum, integer |
---|
600 | intw[13] = integer |
---|
601 | FBinRead/F=3/B=3 refNum, integer |
---|
602 | intw[14] = integer |
---|
603 | |
---|
604 | //3 integers |
---|
605 | FSetPos refNum,376 |
---|
606 | FBinRead/F=3/B=3 refNum, integer |
---|
607 | intw[15] = integer |
---|
608 | FBinRead/F=3/B=3 refNum, integer |
---|
609 | intw[16] = integer |
---|
610 | FBinRead/F=3/B=3 refNum, integer |
---|
611 | intw[17] = integer |
---|
612 | |
---|
613 | //1 text field - the file association for transmission are the first 4 bytes |
---|
614 | FSetPos refNum,404 |
---|
615 | FReadLine/N=42 refNum,textstr |
---|
616 | textw[10]= textstr |
---|
617 | |
---|
618 | //1 integer |
---|
619 | FSetPos refNum,458 |
---|
620 | FBinRead/F=3/B=3 refNum, integer |
---|
621 | intw[18] = integer |
---|
622 | |
---|
623 | //4 integers |
---|
624 | FSetPos refNum,478 |
---|
625 | FBinRead/F=3/B=3 refNum, integer |
---|
626 | intw[19] = integer |
---|
627 | FBinRead/F=3/B=3 refNum, integer |
---|
628 | intw[20] = integer |
---|
629 | FBinRead/F=3/B=3 refNum, integer |
---|
630 | intw[21] = integer |
---|
631 | FBinRead/F=3/B=3 refNum, integer |
---|
632 | intw[22] = integer |
---|
633 | |
---|
634 | Close refNum |
---|
635 | |
---|
636 | //now get all of the reals |
---|
637 | // |
---|
638 | //Do all the GBLoadWaves at the end |
---|
639 | // |
---|
640 | //FBinRead Cannot handle 32 bit VAX floating point |
---|
641 | //GBLoadWave, however, can properly read it |
---|
642 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
643 | String strToExecute |
---|
644 | //append "/S=offset/U=numofreals" to control the read |
---|
645 | // then append fname to give the full file path |
---|
646 | // then execute |
---|
647 | |
---|
648 | Variable a=0,b=0 |
---|
649 | |
---|
650 | SetDataFolder curPath |
---|
651 | // 4 R*4 values |
---|
652 | strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" |
---|
653 | Execute strToExecute |
---|
654 | |
---|
655 | SetDataFolder curPath |
---|
656 | Wave w=$(curPath + ":tempGBWave0") |
---|
657 | b=4 //num of reals read |
---|
658 | realw[a,a+b-1] = w[p-a] |
---|
659 | a+=b |
---|
660 | |
---|
661 | // 4 R*4 values |
---|
662 | SetDataFolder curPath |
---|
663 | strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\"" |
---|
664 | Execute strToExecute |
---|
665 | b=4 |
---|
666 | realw[a,a+b-1] = w[p-a] |
---|
667 | a+=b |
---|
668 | |
---|
669 | /////////// |
---|
670 | // 2 R*4 values |
---|
671 | SetDataFolder curPath |
---|
672 | strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" |
---|
673 | Execute strToExecute |
---|
674 | b=2 |
---|
675 | realw[a,a+b-1] = w[p-a] |
---|
676 | a+=b |
---|
677 | |
---|
678 | // 6 R*4 values |
---|
679 | SetDataFolder curPath |
---|
680 | strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\"" |
---|
681 | Execute strToExecute |
---|
682 | b=6 |
---|
683 | realw[a,a+b-1] = w[p-a] |
---|
684 | a+=b |
---|
685 | |
---|
686 | // 13 R*4 values |
---|
687 | SetDataFolder curPath |
---|
688 | strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\"" |
---|
689 | Execute strToExecute |
---|
690 | b=13 |
---|
691 | realw[a,a+b-1] = w[p-a] |
---|
692 | a+=b |
---|
693 | |
---|
694 | // 3 R*4 values |
---|
695 | SetDataFolder curPath |
---|
696 | strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\"" |
---|
697 | Execute strToExecute |
---|
698 | b=3 |
---|
699 | realw[a,a+b-1] = w[p-a] |
---|
700 | a+=b |
---|
701 | |
---|
702 | // 7 R*4 values |
---|
703 | SetDataFolder curPath |
---|
704 | strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\"" |
---|
705 | Execute strToExecute |
---|
706 | b=7 |
---|
707 | realw[a,a+b-1] = w[p-a] |
---|
708 | a+=b |
---|
709 | |
---|
710 | // 4 R*4 values |
---|
711 | SetDataFolder curPath |
---|
712 | strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\"" |
---|
713 | Execute strToExecute |
---|
714 | b=4 |
---|
715 | realw[a,a+b-1] = w[p-a] |
---|
716 | a+=b |
---|
717 | |
---|
718 | // 2 R*4 values |
---|
719 | SetDataFolder curPath |
---|
720 | strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\"" |
---|
721 | Execute strToExecute |
---|
722 | b=2 |
---|
723 | realw[a,a+b-1] = w[p-a] |
---|
724 | a+=b |
---|
725 | |
---|
726 | // 2 R*4 values |
---|
727 | SetDataFolder curPath |
---|
728 | strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\"" |
---|
729 | Execute strToExecute |
---|
730 | b=2 |
---|
731 | realw[a,a+b-1] = w[p-a] |
---|
732 | a+=b |
---|
733 | |
---|
734 | // 5 R*4 values |
---|
735 | SetDataFolder curPath |
---|
736 | strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\"" |
---|
737 | Execute strToExecute |
---|
738 | b=5 |
---|
739 | realw[a,a+b-1] = w[p-a] |
---|
740 | |
---|
741 | //if the binary VAX data ws transferred to a MAC, all is OK |
---|
742 | //if the data was trasnferred to an Intel machine (IBM), all the real values must be |
---|
743 | //divided by 4 to get the correct floating point values |
---|
744 | // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly |
---|
745 | // on an Intel machine. |
---|
746 | //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read |
---|
747 | //VAX reals correctly, and no checking is necessary 12 APR 99 |
---|
748 | //if(cmpstr("Macintosh",IgorInfo(2)) == 0) |
---|
749 | //do nothing |
---|
750 | //else |
---|
751 | //either Windows or Windows NT |
---|
752 | //realw /= 4 |
---|
753 | //endif |
---|
754 | |
---|
755 | //read in the data |
---|
756 | GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
757 | |
---|
758 | curPath = "root:Packages:NIST:"+cur_folder |
---|
759 | SetDataFolder curPath //use the full path, so it will always work |
---|
760 | |
---|
761 | Make/O/D/N=16384 $(curPath + ":data") |
---|
762 | WAVE data = $(curPath + ":data") |
---|
763 | |
---|
764 | Variable skip,ii,offset |
---|
765 | |
---|
766 | //read in a total of 16384 values (ii) |
---|
767 | //as follows : |
---|
768 | // skip first 2 bytes |
---|
769 | // skip 512 byte header |
---|
770 | // skip first 2 bytes of data |
---|
771 | //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values |
---|
772 | // read the final 48 values in seperately to avoid EOF error |
---|
773 | |
---|
774 | ///////////// |
---|
775 | SetDataFolder curPath |
---|
776 | skip = 0 |
---|
777 | ii=0 |
---|
778 | offset = 514 +2 |
---|
779 | a=0 |
---|
780 | do |
---|
781 | SetDataFolder curPath |
---|
782 | |
---|
783 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\"" |
---|
784 | Execute strToExecute |
---|
785 | //Print strToExecute |
---|
786 | b=511 |
---|
787 | data[a,a+b-1] = w[p-a] |
---|
788 | a+=b |
---|
789 | |
---|
790 | offset += 511*4 +2 |
---|
791 | |
---|
792 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\"" |
---|
793 | SetDataFolder curPath |
---|
794 | Execute strToExecute |
---|
795 | //Print strToExecute |
---|
796 | b=510 |
---|
797 | data[a,a+b-1] = w[p-a] |
---|
798 | a+=b |
---|
799 | |
---|
800 | offset += 510*4 +2 |
---|
801 | |
---|
802 | ii+=1 |
---|
803 | //Print "inside do, data[2] =",data[2] |
---|
804 | //Print "inside do, tempGBwave0[0] = ",w[0] |
---|
805 | while(ii<16) |
---|
806 | |
---|
807 | // 16336 values have been read in -- |
---|
808 | //read in last 64 values |
---|
809 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\"" |
---|
810 | |
---|
811 | SetDataFolder curPath |
---|
812 | Execute strToExecute |
---|
813 | b=48 |
---|
814 | data[a,a+b-1] = w[p-a] |
---|
815 | a+=b |
---|
816 | // |
---|
817 | /// done reading in raw data |
---|
818 | // |
---|
819 | //Print "in workdatareader , data = ", data[1][1] |
---|
820 | |
---|
821 | Redimension/n=(128,128) data |
---|
822 | |
---|
823 | //clean up - get rid of w = $"tempGBWave0" |
---|
824 | KillWaves w |
---|
825 | |
---|
826 | //divide the FP data by 4 if read from a PC (not since GBLoadWave update) |
---|
827 | //if(cmpstr("Macintosh",IgorInfo(2)) == 0) |
---|
828 | //do nothing |
---|
829 | //else |
---|
830 | //either Windows or Windows NT |
---|
831 | //data /= 4 |
---|
832 | //endif |
---|
833 | |
---|
834 | //keep a string with the filename in the DIV folder |
---|
835 | String/G $(curPath + ":fileList") = textw[0] |
---|
836 | |
---|
837 | //return the data folder to root |
---|
838 | SetDataFolder root: |
---|
839 | |
---|
840 | Return(0) |
---|
841 | End |
---|
842 | |
---|
843 | ///// ASC FORMAT READER ////// |
---|
844 | ///// FOR WORKFILE MATH PANEL ////// |
---|
845 | |
---|
846 | //function to read in the ASC output of SANS reduction |
---|
847 | // currently the file has 20 header lines, followed by a single column |
---|
848 | // of 16384 values, Data is written by row, starting with Y=1 and X=(1->128) |
---|
849 | // |
---|
850 | //returns 0 if read was ok |
---|
851 | //returns 1 if there was an error |
---|
852 | // |
---|
853 | // called by WorkFileUtils.ipf |
---|
854 | // |
---|
855 | Function ReadASCData(fname,destPath) |
---|
856 | String fname, destPath |
---|
857 | //this function is for reading in ASCII data so put data in user-specified folder |
---|
858 | SetDataFolder "root:Packages:NIST:"+destPath |
---|
859 | |
---|
860 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
861 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
862 | Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=20 |
---|
863 | String str="" |
---|
864 | //data is initially linear scale |
---|
865 | Variable/G :gIsLogScale=0 |
---|
866 | Make/O/T/N=(numHdrLines) hdrLines |
---|
867 | Make/O/D/N=(pixelsX*pixelsY) data //,linear_data |
---|
868 | |
---|
869 | //full filename and path is now passed in... |
---|
870 | //actually open the file |
---|
871 | // SetDataFolder destPath |
---|
872 | Open/R/Z refNum as fname // /Z flag means I must handle open errors |
---|
873 | if(refnum==0) //FNF error, get out |
---|
874 | DoAlert 0,"Could not find file: "+fname |
---|
875 | Close/A |
---|
876 | SetDataFolder root: |
---|
877 | return(1) |
---|
878 | endif |
---|
879 | if(V_flag!=0) |
---|
880 | DoAlert 0,"File open error: V_flag="+num2Str(V_Flag) |
---|
881 | Close/A |
---|
882 | SetDataFolder root: |
---|
883 | return(1) |
---|
884 | Endif |
---|
885 | // |
---|
886 | for(ii=0;ii<numHdrLines;ii+=1) //read (or skip) 18 header lines |
---|
887 | FReadLine refnum,str |
---|
888 | hdrLines[ii]=str |
---|
889 | endfor |
---|
890 | // |
---|
891 | Close refnum |
---|
892 | |
---|
893 | // SetDataFolder destPath |
---|
894 | LoadWave/Q/G/D/N=temp fName |
---|
895 | Wave/Z temp0=temp0 |
---|
896 | data=temp0 |
---|
897 | Redimension/N=(pixelsX,pixelsY) data //,linear_data |
---|
898 | |
---|
899 | //linear_data = data |
---|
900 | |
---|
901 | KillWaves/Z temp0 |
---|
902 | |
---|
903 | //return the data folder to root |
---|
904 | SetDataFolder root: |
---|
905 | |
---|
906 | Return(0) |
---|
907 | End |
---|
908 | |
---|
909 | // fills the "default" fake header so that the SANS Reduction machinery does not have to be altered |
---|
910 | // pay attention to what is/not to be trusted due to "fake" information. |
---|
911 | // uses what it can from the header lines from the ASC file (hdrLines wave) |
---|
912 | // |
---|
913 | // destFolder is of the form "myGlobals:WorkMath:AAA" |
---|
914 | // |
---|
915 | // |
---|
916 | // called by WorkFileUtils.ipf |
---|
917 | // |
---|
918 | Function FillFakeHeader_ASC(destFolder) |
---|
919 | String destFolder |
---|
920 | Make/O/D/N=23 $("root:Packages:NIST:"+destFolder+":IntegersRead") |
---|
921 | Make/O/D/N=52 $("root:Packages:NIST:"+destFolder+":RealsRead") |
---|
922 | Make/O/T/N=11 $("root:Packages:NIST:"+destFolder+":TextRead") |
---|
923 | |
---|
924 | Wave intw=$("root:Packages:NIST:"+destFolder+":IntegersRead") |
---|
925 | Wave realw=$("root:Packages:NIST:"+destFolder+":RealsRead") |
---|
926 | Wave/T textw=$("root:Packages:NIST:"+destFolder+":TextRead") |
---|
927 | |
---|
928 | //Put in appropriate "fake" values |
---|
929 | //parse values as needed from headerLines |
---|
930 | Wave/T hdr=$("root:Packages:NIST:"+destFolder+":hdrLines") |
---|
931 | Variable monCt,lam,offset,sdd,trans,thick |
---|
932 | Variable xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam |
---|
933 | String detTyp="" |
---|
934 | String tempStr="",formatStr="",junkStr="" |
---|
935 | formatStr = "%g %g %g %g %g %g" |
---|
936 | tempStr=hdr[3] |
---|
937 | sscanf tempStr, formatStr, monCt,lam,offset,sdd,trans,thick |
---|
938 | // Print monCt,lam,offset,sdd,trans,thick,avStr,step |
---|
939 | formatStr = "%g %g %g %g %g %g %g %s" |
---|
940 | tempStr=hdr[5] |
---|
941 | sscanf tempStr,formatStr,xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp |
---|
942 | // Print xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp |
---|
943 | |
---|
944 | realw[16]=xCtr //xCtr(pixels) |
---|
945 | realw[17]=yCtr //yCtr (pixels) |
---|
946 | realw[18]=sdd //SDD (m) |
---|
947 | realw[26]=lam //wavelength (A) |
---|
948 | // |
---|
949 | // necessary values |
---|
950 | realw[10]=5 //detector calibration constants, needed for averaging |
---|
951 | realw[11]=10000 |
---|
952 | realw[12]=0 |
---|
953 | realw[13]=5 |
---|
954 | realw[14]=10000 |
---|
955 | realw[15]=0 |
---|
956 | // |
---|
957 | // used in the resolution calculation, ONLY here to keep the routine from crashing |
---|
958 | realw[20]=65 //det size |
---|
959 | realw[27]=dlam //delta lambda |
---|
960 | realw[21]=bsDiam //BS size |
---|
961 | realw[23]=a1 //A1 |
---|
962 | realw[24]=a2 //A2 |
---|
963 | realw[25]=a1a2Dist //A1A2 distance |
---|
964 | realw[4]=trans //trans |
---|
965 | realw[3]=0 //atten |
---|
966 | realw[5]=thick //thick |
---|
967 | // |
---|
968 | // |
---|
969 | realw[0]=monCt //def mon cts |
---|
970 | |
---|
971 | // fake values to get valid deadtime and detector constants |
---|
972 | // |
---|
973 | textw[9]=detTyp+" " //6 characters 4+2 spaces |
---|
974 | textw[3]="[NGxSANS00]" //11 chars, NGx will return default values for atten trans, deadtime... |
---|
975 | |
---|
976 | //set the string values |
---|
977 | formatStr="FILE: %s CREATED: %s" |
---|
978 | sscanf hdr[0],formatStr,tempStr,junkStr |
---|
979 | // Print tempStr |
---|
980 | // Print junkStr |
---|
981 | String/G $("root:Packages:NIST:"+destFolder+":fileList") = tempStr |
---|
982 | textw[0] = tempStr //filename |
---|
983 | textw[1] = junkStr //run date-time |
---|
984 | |
---|
985 | //file label = hdr[1] |
---|
986 | tempStr = hdr[1] |
---|
987 | tempStr = tempStr[0,strlen(tempStr)-2] //clean off the last LF |
---|
988 | // Print tempStr |
---|
989 | textW[6] = tempStr //sample label |
---|
990 | |
---|
991 | return(0) |
---|
992 | End |
---|
993 | |
---|
994 | |
---|
995 | /////***************** |
---|
996 | ////unused testing procedure for writing a 4 byte floating point value in VAX format |
---|
997 | //Proc TestReWriteReal() |
---|
998 | // String Path |
---|
999 | // Variable value,start |
---|
1000 | // |
---|
1001 | // GetFileAndPath() |
---|
1002 | // Path = S_Path + S_filename |
---|
1003 | // |
---|
1004 | // value = 0.2222 |
---|
1005 | // start = 158 //trans starts at byte 159 |
---|
1006 | // ReWriteReal(path,value,start) |
---|
1007 | // |
---|
1008 | // SetDataFolder root: |
---|
1009 | //End |
---|
1010 | |
---|
1011 | //function will re-write a real value (4bytes) to the header of a RAW data file |
---|
1012 | //to ensure re-readability, the real value must be written mimicking VAX binary format |
---|
1013 | //which is done in this function |
---|
1014 | //path is the full path:file;vers to the file |
---|
1015 | //value is the real value to write |
---|
1016 | //start is the position to move the file marker to, to begin writing |
---|
1017 | //--so start is actually the "end byte" of the previous value |
---|
1018 | // |
---|
1019 | // Igor cannot write VAX FP values - so to "fake it" |
---|
1020 | // (1) write IEEE FP, 4*desired value, little endian |
---|
1021 | // (2) read back as two 16-bit integers, big endian |
---|
1022 | // (3) write the two 16-bit integers, reversed, writing each as big endian |
---|
1023 | // |
---|
1024 | //this procedure takes care of all file open/close pairs needed |
---|
1025 | // |
---|
1026 | Function WriteVAXReal(path,value,start) |
---|
1027 | String path |
---|
1028 | Variable value,start |
---|
1029 | |
---|
1030 | //Print " in F(), path = " + path |
---|
1031 | Variable refnum,int1,int2, value4 |
---|
1032 | |
---|
1033 | ////// |
---|
1034 | value4 = 4*value |
---|
1035 | |
---|
1036 | Open/A/T="????TEXT" refnum as path |
---|
1037 | //write IEEE FP, 4*desired value |
---|
1038 | FSetPos refnum,start |
---|
1039 | FBinWrite/B=3/F=4 refnum,value4 //write out as little endian |
---|
1040 | //move to the end of the file |
---|
1041 | FStatus refnum |
---|
1042 | FSetPos refnum,V_logEOF |
---|
1043 | Close refnum |
---|
1044 | |
---|
1045 | /////// |
---|
1046 | Open/R refnum as path |
---|
1047 | //read back as two 16-bit integers |
---|
1048 | FSetPos refnum,start |
---|
1049 | FBinRead/B=2/F=2 refnum,int1 //read as big-endian |
---|
1050 | FBinRead/B=2/F=2 refnum,int2 |
---|
1051 | //file was opened read-only, no need to move to the end of the file, just close it |
---|
1052 | Close refnum |
---|
1053 | |
---|
1054 | /////// |
---|
1055 | Open/A/T="????TEXT" refnum as path |
---|
1056 | //write the two 16-bit integers, reversed |
---|
1057 | FSetPos refnum,start |
---|
1058 | FBinWrite/B=2/F=2 refnum,int2 //re-write as big endian |
---|
1059 | FBinWrite/B=2/F=2 refnum,int1 |
---|
1060 | //move to the end of the file |
---|
1061 | FStatus refnum |
---|
1062 | FSetPos refnum,V_logEOF |
---|
1063 | Close refnum //at this point, it is as the VAX would have written it. |
---|
1064 | |
---|
1065 | Return(0) |
---|
1066 | End |
---|
1067 | |
---|
1068 | //sample transmission is a real value at byte 158 |
---|
1069 | Function WriteTransmissionToHeader(fname,trans) |
---|
1070 | String fname |
---|
1071 | Variable trans |
---|
1072 | |
---|
1073 | WriteVAXReal(fname,trans,158) //transmission start byte is 158 |
---|
1074 | return(0) |
---|
1075 | End |
---|
1076 | |
---|
1077 | //whole transmission is a real value at byte 392 |
---|
1078 | Function WriteWholeTransToHeader(fname,trans) |
---|
1079 | String fname |
---|
1080 | Variable trans |
---|
1081 | |
---|
1082 | WriteVAXReal(fname,trans,392) //transmission start byte is 392 |
---|
1083 | return(0) |
---|
1084 | End |
---|
1085 | |
---|
1086 | //box sum counts is a real value at byte 494 |
---|
1087 | Function WriteBoxCountsToHeader(fname,counts) |
---|
1088 | String fname |
---|
1089 | Variable counts |
---|
1090 | |
---|
1091 | WriteVAXReal(fname,counts,494) // start byte is 494 |
---|
1092 | return(0) |
---|
1093 | End |
---|
1094 | |
---|
1095 | //beam stop X-pos is at byte 368 |
---|
1096 | Function WriteBSXPosToHeader(fname,xpos) |
---|
1097 | String fname |
---|
1098 | Variable xpos |
---|
1099 | |
---|
1100 | WriteVAXReal(fname,xpos,368) |
---|
1101 | return(0) |
---|
1102 | End |
---|
1103 | |
---|
1104 | //sample thickness is at byte 162 |
---|
1105 | Function WriteThicknessToHeader(fname,num) |
---|
1106 | String fname |
---|
1107 | Variable num |
---|
1108 | |
---|
1109 | WriteVAXReal(fname,num,162) |
---|
1110 | return(0) |
---|
1111 | End |
---|
1112 | |
---|
1113 | //beam center X pixel location is at byte 252 |
---|
1114 | Function WriteBeamCenterXToHeader(fname,num) |
---|
1115 | String fname |
---|
1116 | Variable num |
---|
1117 | |
---|
1118 | WriteVAXReal(fname,num,252) |
---|
1119 | return(0) |
---|
1120 | End |
---|
1121 | |
---|
1122 | //beam center Y pixel location is at byte 256 |
---|
1123 | Function WriteBeamCenterYToHeader(fname,num) |
---|
1124 | String fname |
---|
1125 | Variable num |
---|
1126 | |
---|
1127 | WriteVAXReal(fname,num,256) |
---|
1128 | return(0) |
---|
1129 | End |
---|
1130 | |
---|
1131 | //attenuator number (not its transmission) is at byte 51 |
---|
1132 | Function WriteAttenNumberToHeader(fname,num) |
---|
1133 | String fname |
---|
1134 | Variable num |
---|
1135 | |
---|
1136 | WriteVAXReal(fname,num,51) |
---|
1137 | return(0) |
---|
1138 | End |
---|
1139 | |
---|
1140 | //monitor count is at byte 39 |
---|
1141 | Function WriteMonitorCountToHeader(fname,num) |
---|
1142 | String fname |
---|
1143 | Variable num |
---|
1144 | |
---|
1145 | WriteVAXReal(fname,num,39) |
---|
1146 | return(0) |
---|
1147 | End |
---|
1148 | |
---|
1149 | //total detector count is at byte 47 |
---|
1150 | Function WriteDetectorCountToHeader(fname,num) |
---|
1151 | String fname |
---|
1152 | Variable num |
---|
1153 | |
---|
1154 | WriteVAXReal(fname,num,47) |
---|
1155 | return(0) |
---|
1156 | End |
---|
1157 | |
---|
1158 | //transmission detector count is at byte 388 |
---|
1159 | Function WriteTransDetCountToHeader(fname,num) |
---|
1160 | String fname |
---|
1161 | Variable num |
---|
1162 | |
---|
1163 | WriteVAXReal(fname,num,388) |
---|
1164 | return(0) |
---|
1165 | End |
---|
1166 | |
---|
1167 | //wavelength is at byte 292 |
---|
1168 | Function WriteWavelengthToHeader(fname,num) |
---|
1169 | String fname |
---|
1170 | Variable num |
---|
1171 | |
---|
1172 | WriteVAXReal(fname,num,292) |
---|
1173 | return(0) |
---|
1174 | End |
---|
1175 | |
---|
1176 | //wavelength spread is at byte 296 |
---|
1177 | Function WriteWavelengthDistrToHeader(fname,num) |
---|
1178 | String fname |
---|
1179 | Variable num |
---|
1180 | |
---|
1181 | WriteVAXReal(fname,num,296) |
---|
1182 | return(0) |
---|
1183 | End |
---|
1184 | |
---|
1185 | //temperature is at byte 186 |
---|
1186 | Function WriteTemperatureToHeader(fname,num) |
---|
1187 | String fname |
---|
1188 | Variable num |
---|
1189 | |
---|
1190 | WriteVAXReal(fname,num,186) |
---|
1191 | return(0) |
---|
1192 | End |
---|
1193 | |
---|
1194 | //magnetic field is at byte 190 |
---|
1195 | Function WriteMagnFieldToHeader(fname,num) |
---|
1196 | String fname |
---|
1197 | Variable num |
---|
1198 | |
---|
1199 | WriteVAXReal(fname,num,190) |
---|
1200 | return(0) |
---|
1201 | End |
---|
1202 | |
---|
1203 | //Source Aperture diameter is at byte 280 |
---|
1204 | Function WriteSourceApDiamToHeader(fname,num) |
---|
1205 | String fname |
---|
1206 | Variable num |
---|
1207 | |
---|
1208 | WriteVAXReal(fname,num,280) |
---|
1209 | return(0) |
---|
1210 | End |
---|
1211 | |
---|
1212 | //Sample Aperture diameter is at byte 284 |
---|
1213 | Function WriteSampleApDiamToHeader(fname,num) |
---|
1214 | String fname |
---|
1215 | Variable num |
---|
1216 | |
---|
1217 | WriteVAXReal(fname,num,284) |
---|
1218 | return(0) |
---|
1219 | End |
---|
1220 | |
---|
1221 | //Source to sample distance is at byte 288 |
---|
1222 | Function WriteSrcToSamDistToHeader(fname,num) |
---|
1223 | String fname |
---|
1224 | Variable num |
---|
1225 | |
---|
1226 | WriteVAXReal(fname,num,288) |
---|
1227 | return(0) |
---|
1228 | End |
---|
1229 | |
---|
1230 | //detector offset is at byte 264 |
---|
1231 | Function WriteDetectorOffsetToHeader(fname,num) |
---|
1232 | String fname |
---|
1233 | Variable num |
---|
1234 | |
---|
1235 | WriteVAXReal(fname,num,264) |
---|
1236 | return(0) |
---|
1237 | End |
---|
1238 | |
---|
1239 | //beam stop diameter is at byte 272 |
---|
1240 | Function WriteBeamStopDiamToHeader(fname,num) |
---|
1241 | String fname |
---|
1242 | Variable num |
---|
1243 | |
---|
1244 | WriteVAXReal(fname,num,272) |
---|
1245 | return(0) |
---|
1246 | End |
---|
1247 | |
---|
1248 | //sample to detector distance is at byte 260 |
---|
1249 | Function WriteSDDToHeader(fname,num) |
---|
1250 | String fname |
---|
1251 | Variable num |
---|
1252 | |
---|
1253 | WriteVAXReal(fname,num,260) |
---|
1254 | return(0) |
---|
1255 | End |
---|
1256 | |
---|
1257 | //detector pixel X size (mm) is at byte 220 |
---|
1258 | Function WriteDetPixelXToHeader(fname,num) |
---|
1259 | String fname |
---|
1260 | Variable num |
---|
1261 | |
---|
1262 | WriteVAXReal(fname,num,220) |
---|
1263 | return(0) |
---|
1264 | End |
---|
1265 | |
---|
1266 | //detector pixel Y size (mm) is at byte 232 |
---|
1267 | Function WriteDetPixelYToHeader(fname,num) |
---|
1268 | String fname |
---|
1269 | Variable num |
---|
1270 | |
---|
1271 | WriteVAXReal(fname,num,232) |
---|
1272 | return(0) |
---|
1273 | End |
---|
1274 | |
---|
1275 | //rewrite a text field back to the header |
---|
1276 | // fname is the full path:name |
---|
1277 | // str is the CORRECT length - it will all be written - pad or trim before passing |
---|
1278 | // start is the start byte |
---|
1279 | Function WriteTextToHeader(fname,str,start) |
---|
1280 | String fname,str |
---|
1281 | Variable start |
---|
1282 | |
---|
1283 | Variable refnum |
---|
1284 | Open/A/T="????TEXT" refnum as fname //Open for writing! Move to EOF before closing! |
---|
1285 | FSetPos refnum,start |
---|
1286 | FBinWrite/F=0 refnum, str //native object format (character) |
---|
1287 | //move to the end of the file before closing |
---|
1288 | FStatus refnum |
---|
1289 | FSetPos refnum,V_logEOF |
---|
1290 | Close refnum |
---|
1291 | |
---|
1292 | return(0) |
---|
1293 | end |
---|
1294 | |
---|
1295 | // sample label, starts at byte 98 |
---|
1296 | // limit to 60 characters |
---|
1297 | Function WriteSamLabelToHeader(fname,str) |
---|
1298 | String fname,str |
---|
1299 | |
---|
1300 | if(strlen(str) > 60) |
---|
1301 | str = str[0,59] |
---|
1302 | endif |
---|
1303 | WriteTextToHeader(fname,str,98) |
---|
1304 | return(0) |
---|
1305 | End |
---|
1306 | |
---|
1307 | //user account name, starts at byte 78 |
---|
1308 | // limit to 11 characters |
---|
1309 | Function WriteAcctNameToHeader(fname,str) |
---|
1310 | String fname,str |
---|
1311 | |
---|
1312 | if(strlen(str) > 9) |
---|
1313 | str = str[0,8] |
---|
1314 | endif |
---|
1315 | str = "["+str+"]" |
---|
1316 | WriteTextToHeader(fname,str,78) |
---|
1317 | return(0) |
---|
1318 | End |
---|
1319 | |
---|
1320 | // file name, starts at byte 2 |
---|
1321 | // limit to 21 characters |
---|
1322 | // |
---|
1323 | // be sure that any white space to pad to 21 characters is at the front of the string |
---|
1324 | Function WriteFileNameToHeader(fname,str) |
---|
1325 | String fname,str |
---|
1326 | |
---|
1327 | Variable i |
---|
1328 | String newStr="" |
---|
1329 | // printf "\"%s\"\t%d\r",str,strlen(str) |
---|
1330 | |
---|
1331 | //strip any white spaces from the end (from TrimWSR(str) in cansasXML.ipf) |
---|
1332 | for (i=strlen(str)-1; char2num(str[i])<=32 && i>=0; i-=1) // find last non-white space |
---|
1333 | endfor |
---|
1334 | str = str[0,i] |
---|
1335 | // printf "\"%s\"\t%d\r",str,strlen(str) |
---|
1336 | |
---|
1337 | // if the string is less than 21 characters, fix it with white space at the beginning |
---|
1338 | if(strlen(str) < 21) |
---|
1339 | newStr = PadString(newStr,21,0x20) //pad with fortran-style spaces |
---|
1340 | newStr[21-strlen(str),20] = str |
---|
1341 | else |
---|
1342 | newStr = str |
---|
1343 | endif |
---|
1344 | // printf "\"%s\"\t%d\r",newstr,strlen(newstr) |
---|
1345 | |
---|
1346 | WriteTextToHeader(fname,newstr,2) |
---|
1347 | return(0) |
---|
1348 | End |
---|
1349 | |
---|
1350 | |
---|
1351 | //rewrite an integer field back to the header |
---|
1352 | // fname is the full path:name |
---|
1353 | // val is the integer value |
---|
1354 | // start is the start byte |
---|
1355 | Function RewriteIntegerToHeader(fname,val,start) |
---|
1356 | String fname |
---|
1357 | Variable val,start |
---|
1358 | |
---|
1359 | Variable refnum |
---|
1360 | Open/A/T="????TEXT" refnum as fname //Open for writing! Move to EOF before closing! |
---|
1361 | FSetPos refnum,start |
---|
1362 | FBinWrite/B=3/F=3 refnum, val //write a 4-byte integer |
---|
1363 | //move to the end of the file before closing |
---|
1364 | FStatus refnum |
---|
1365 | FSetPos refnum,V_logEOF |
---|
1366 | Close refnum |
---|
1367 | |
---|
1368 | return(0) |
---|
1369 | end |
---|
1370 | |
---|
1371 | Function WriteCountTimeToHeader(fname,num) |
---|
1372 | String fname |
---|
1373 | Variable num |
---|
1374 | |
---|
1375 | RewriteIntegerToHeader(fname,num,31) |
---|
1376 | return(0) |
---|
1377 | End |
---|
1378 | |
---|
1379 | // read specific bits of information from the header |
---|
1380 | // each of these operations MUST take care of open/close on their own |
---|
1381 | |
---|
1382 | Function/S getStringFromHeader(fname,start,num) |
---|
1383 | String fname //full path:name |
---|
1384 | Variable start,num //starting byte and number of characters to read |
---|
1385 | |
---|
1386 | String str |
---|
1387 | Variable refnum |
---|
1388 | Open/R refNum as fname |
---|
1389 | FSetPos refNum,start |
---|
1390 | FReadLine/N=(num) refNum,str |
---|
1391 | Close refnum |
---|
1392 | |
---|
1393 | return(str) |
---|
1394 | End |
---|
1395 | |
---|
1396 | // file suffix (4 characters @ byte 19) |
---|
1397 | Function/S getSuffix(fname) |
---|
1398 | String fname |
---|
1399 | |
---|
1400 | return(getStringFromHeader(fname,19,4)) |
---|
1401 | End |
---|
1402 | |
---|
1403 | // associated file suffix (for transmission) (4 characters @ byte 404) |
---|
1404 | Function/S getAssociatedFileSuffix(fname) |
---|
1405 | String fname |
---|
1406 | |
---|
1407 | return(getStringFromHeader(fname,404,4)) |
---|
1408 | End |
---|
1409 | |
---|
1410 | // sample label (60 characters @ byte 98) |
---|
1411 | Function/S getSampleLabel(fname) |
---|
1412 | String fname |
---|
1413 | |
---|
1414 | return(getStringFromHeader(fname,98,60)) |
---|
1415 | End |
---|
1416 | |
---|
1417 | // file creation date (20 characters @ byte 55) |
---|
1418 | Function/S getFileCreationDate(fname) |
---|
1419 | String fname |
---|
1420 | |
---|
1421 | return(getStringFromHeader(fname,55,20)) |
---|
1422 | End |
---|
1423 | |
---|
1424 | // user account (11 characters @ byte 78) |
---|
1425 | Function/S getAcctName(fname) |
---|
1426 | String fname |
---|
1427 | |
---|
1428 | return(getStringFromHeader(fname,78,11)) |
---|
1429 | End |
---|
1430 | |
---|
1431 | // file name (21 characters @ byte 2) |
---|
1432 | Function/S getFileName(fname) |
---|
1433 | String fname |
---|
1434 | |
---|
1435 | return(getStringFromHeader(fname,2,21)) |
---|
1436 | End |
---|
1437 | |
---|
1438 | |
---|
1439 | // read a single real value with GBLoadWave |
---|
1440 | Function getRealValueFromHeader(fname,start) |
---|
1441 | String fname |
---|
1442 | Variable start |
---|
1443 | |
---|
1444 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
1445 | |
---|
1446 | GBLoadStr += "/S="+num2str(start)+"/U=1" + "\"" + fname + "\"" |
---|
1447 | Execute GBLoadStr |
---|
1448 | Wave w=$"tempGBWave0" |
---|
1449 | |
---|
1450 | return(w[0]) |
---|
1451 | End |
---|
1452 | |
---|
1453 | //monitor count is at byte 39 |
---|
1454 | Function getMonitorCount(fname) |
---|
1455 | String fname |
---|
1456 | |
---|
1457 | return(getRealValueFromHeader(fname,39)) |
---|
1458 | end |
---|
1459 | |
---|
1460 | //saved monitor count is at byte 43 |
---|
1461 | Function getSavMon(fname) |
---|
1462 | String fname |
---|
1463 | |
---|
1464 | return(getRealValueFromHeader(fname,43)) |
---|
1465 | end |
---|
1466 | |
---|
1467 | //detector count is at byte 47 |
---|
1468 | Function getDetCount(fname) |
---|
1469 | String fname |
---|
1470 | |
---|
1471 | return(getRealValueFromHeader(fname,47)) |
---|
1472 | end |
---|
1473 | |
---|
1474 | //Attenuator number is at byte 51 |
---|
1475 | Function getAttenNumber(fname) |
---|
1476 | String fname |
---|
1477 | |
---|
1478 | return(getRealValueFromHeader(fname,51)) |
---|
1479 | end |
---|
1480 | |
---|
1481 | //transmission is at byte 158 |
---|
1482 | Function getSampleTrans(fname) |
---|
1483 | String fname |
---|
1484 | |
---|
1485 | return(getRealValueFromHeader(fname,158)) |
---|
1486 | end |
---|
1487 | |
---|
1488 | //box counts are stored at byte 494 |
---|
1489 | Function getBoxCounts(fname) |
---|
1490 | String fname |
---|
1491 | |
---|
1492 | return(getRealValueFromHeader(fname,494)) |
---|
1493 | end |
---|
1494 | |
---|
1495 | //whole detector trasmission is at byte 392 |
---|
1496 | Function getSampleTransWholeDetector(fname) |
---|
1497 | String fname |
---|
1498 | |
---|
1499 | return(getRealValueFromHeader(fname,392)) |
---|
1500 | end |
---|
1501 | |
---|
1502 | //SampleThickness is at byte 162 |
---|
1503 | Function getSampleThickness(fname) |
---|
1504 | String fname |
---|
1505 | |
---|
1506 | return(getRealValueFromHeader(fname,162)) |
---|
1507 | end |
---|
1508 | |
---|
1509 | //Sample Rotation Angle is at byte 170 |
---|
1510 | Function getSampleRotationAngle(fname) |
---|
1511 | String fname |
---|
1512 | |
---|
1513 | return(getRealValueFromHeader(fname,170)) |
---|
1514 | end |
---|
1515 | |
---|
1516 | //temperature is at byte 186 |
---|
1517 | Function getTemperature(fname) |
---|
1518 | String fname |
---|
1519 | |
---|
1520 | return(getRealValueFromHeader(fname,186)) |
---|
1521 | end |
---|
1522 | |
---|
1523 | //field strength is at byte 190 |
---|
1524 | // 190 is not the right location, 348 looks to be correct for the electromagnets, 450 for the |
---|
1525 | // superconducting magnet. Although each place is only the voltage, it is correct |
---|
1526 | Function getFieldStrength(fname) |
---|
1527 | String fname |
---|
1528 | |
---|
1529 | // return(getRealValueFromHeader(fname,190)) |
---|
1530 | return(getRealValueFromHeader(fname,348)) |
---|
1531 | end |
---|
1532 | |
---|
1533 | //beam xPos is at byte 252 |
---|
1534 | Function getBeamXPos(fname) |
---|
1535 | String fname |
---|
1536 | |
---|
1537 | return(getRealValueFromHeader(fname,252)) |
---|
1538 | end |
---|
1539 | |
---|
1540 | //beam Y pos is at byte 256 |
---|
1541 | Function getBeamYPos(fname) |
---|
1542 | String fname |
---|
1543 | |
---|
1544 | return(getRealValueFromHeader(fname,256)) |
---|
1545 | end |
---|
1546 | |
---|
1547 | //sample to detector distance is at byte 260 |
---|
1548 | Function getSDD(fname) |
---|
1549 | String fname |
---|
1550 | |
---|
1551 | return(getRealValueFromHeader(fname,260)) |
---|
1552 | end |
---|
1553 | |
---|
1554 | //detector offset is at byte 264 |
---|
1555 | Function getDetectorOffset(fname) |
---|
1556 | String fname |
---|
1557 | |
---|
1558 | return(getRealValueFromHeader(fname,264)) |
---|
1559 | end |
---|
1560 | |
---|
1561 | //Beamstop diameter is at byte 272 |
---|
1562 | Function getBSDiameter(fname) |
---|
1563 | String fname |
---|
1564 | |
---|
1565 | return(getRealValueFromHeader(fname,272)) |
---|
1566 | end |
---|
1567 | |
---|
1568 | //source aperture diameter is at byte 280 |
---|
1569 | Function getSourceApertureDiam(fname) |
---|
1570 | String fname |
---|
1571 | |
---|
1572 | return(getRealValueFromHeader(fname,280)) |
---|
1573 | end |
---|
1574 | |
---|
1575 | //sample aperture diameter is at byte 284 |
---|
1576 | Function getSampleApertureDiam(fname) |
---|
1577 | String fname |
---|
1578 | |
---|
1579 | return(getRealValueFromHeader(fname,284)) |
---|
1580 | end |
---|
1581 | |
---|
1582 | //source AP to Sample AP distance is at byte 288 |
---|
1583 | Function getSourceToSampleDist(fname) |
---|
1584 | String fname |
---|
1585 | |
---|
1586 | return(getRealValueFromHeader(fname,288)) |
---|
1587 | end |
---|
1588 | |
---|
1589 | //wavelength is at byte 292 |
---|
1590 | Function getWavelength(fname) |
---|
1591 | String fname |
---|
1592 | |
---|
1593 | return(getRealValueFromHeader(fname,292)) |
---|
1594 | end |
---|
1595 | |
---|
1596 | //wavelength spread is at byte 296 |
---|
1597 | Function getWavelengthSpread(fname) |
---|
1598 | String fname |
---|
1599 | |
---|
1600 | return(getRealValueFromHeader(fname,296)) |
---|
1601 | end |
---|
1602 | |
---|
1603 | //transmission detector count is at byte 388 |
---|
1604 | Function getTransDetectorCounts(fname) |
---|
1605 | String fname |
---|
1606 | |
---|
1607 | return(getRealValueFromHeader(fname,388)) |
---|
1608 | end |
---|
1609 | |
---|
1610 | //detector pixel X size is at byte 220 |
---|
1611 | Function getDetectorPixelXSize(fname) |
---|
1612 | String fname |
---|
1613 | |
---|
1614 | return(getRealValueFromHeader(fname,220)) |
---|
1615 | end |
---|
1616 | |
---|
1617 | //detector pixel Y size is at byte 232 |
---|
1618 | Function getDetectorPixelYSize(fname) |
---|
1619 | String fname |
---|
1620 | |
---|
1621 | return(getRealValueFromHeader(fname,232)) |
---|
1622 | end |
---|
1623 | |
---|
1624 | // stub for ILL - power is written to their header, not ours |
---|
1625 | Function getReactorPower(fname) |
---|
1626 | String fname |
---|
1627 | |
---|
1628 | return 0 |
---|
1629 | |
---|
1630 | end |
---|
1631 | |
---|
1632 | ////// integer values |
---|
1633 | |
---|
1634 | Function getIntegerFromHeader(fname,start) |
---|
1635 | String fname //full path:name |
---|
1636 | Variable start //starting byte |
---|
1637 | |
---|
1638 | Variable refnum,val |
---|
1639 | Open/R refNum as fname |
---|
1640 | FSetPos refNum,start |
---|
1641 | FBinRead/B=3/F=3 refnum,val |
---|
1642 | Close refnum |
---|
1643 | |
---|
1644 | return(val) |
---|
1645 | End |
---|
1646 | |
---|
1647 | //total count time is at byte 31 |
---|
1648 | Function getCountTime(fname) |
---|
1649 | String fname |
---|
1650 | return(getIntegerFromHeader(fname,31)) |
---|
1651 | end |
---|
1652 | |
---|
1653 | |
---|
1654 | //reads the wavelength from a reduced data file (not very reliable) |
---|
1655 | // - does not work with NSORTed files |
---|
1656 | // - only used in FIT/RPA (which itself is almost NEVER used...) |
---|
1657 | // |
---|
1658 | Function GetLambdaFromReducedData(tempName) |
---|
1659 | String tempName |
---|
1660 | |
---|
1661 | String junkString |
---|
1662 | Variable lambdaFromFile, fileVar |
---|
1663 | lambdaFromFile = 6.0 |
---|
1664 | Open/R/P=catPathName fileVar as tempName |
---|
1665 | FReadLine fileVar, junkString |
---|
1666 | FReadLine fileVar, junkString |
---|
1667 | FReadLine fileVar, junkString |
---|
1668 | if(strsearch(LowerStr(junkString),"lambda",0) != -1) |
---|
1669 | FReadLine/N=11 fileVar, junkString |
---|
1670 | FReadLine/N=10 fileVar, junkString |
---|
1671 | lambdaFromFile = str2num(junkString) |
---|
1672 | endif |
---|
1673 | Close fileVar |
---|
1674 | |
---|
1675 | return(lambdaFromFile) |
---|
1676 | End |
---|
1677 | |
---|
1678 | ///// TRANSMISSION RELATED FUNCTIONS //////// |
---|
1679 | //box coordinate are returned by reference |
---|
1680 | // filename is the full path:name |
---|
1681 | Function getXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
1682 | String filename |
---|
1683 | Variable &x1,&x2,&y1,&y2 |
---|
1684 | |
---|
1685 | Variable refnum |
---|
1686 | // String tmpFile = FindValidFilename(filename) |
---|
1687 | |
---|
1688 | // Open/R/P=catPathName refnum as tmpFile |
---|
1689 | Open/R refnum as filename |
---|
1690 | FSetPos refnum,478 |
---|
1691 | FBinRead/F=3/B=3 refnum, x1 |
---|
1692 | FBinRead/F=3/B=3 refnum, x2 |
---|
1693 | FBinRead/F=3/B=3 refnum, y1 |
---|
1694 | FBinRead/F=3/B=3 refnum, y2 |
---|
1695 | Close refnum |
---|
1696 | |
---|
1697 | return(0) |
---|
1698 | End |
---|
1699 | |
---|
1700 | //go find the file, open it and write 4 integers to the file |
---|
1701 | //in the positions for analysis.rows(2), .cols(2) = 4 unused 4byte integers |
---|
1702 | Function WriteXYBoxToHeader(filename,x1,x2,y1,y2) |
---|
1703 | String filename |
---|
1704 | Variable x1,x2,y1,y2 |
---|
1705 | |
---|
1706 | Variable refnum |
---|
1707 | Open/A/T="????TEXT" refnum as filename |
---|
1708 | FSetPos refnum,478 |
---|
1709 | FBinWrite/F=3/B=3 refNum, x1 |
---|
1710 | FBinWrite/F=3/B=3 refNum, x2 |
---|
1711 | FBinWrite/F=3/B=3 refNum, y1 |
---|
1712 | FBinWrite/F=3/B=3 refNum, y2 |
---|
1713 | //move to the end of the file before closing |
---|
1714 | FStatus refnum |
---|
1715 | FSetPos refnum,V_logEOF |
---|
1716 | Close refnum |
---|
1717 | |
---|
1718 | return(0) |
---|
1719 | End |
---|
1720 | |
---|
1721 | //associated file suffix is the first 4 characters of a text field starting |
---|
1722 | // at byte 404 |
---|
1723 | // suffix must be four characters long, if not, it's truncated |
---|
1724 | // |
---|
1725 | Function WriteAssocFileSuffixToHeader(fname,suffix) |
---|
1726 | String fname,suffix |
---|
1727 | |
---|
1728 | suffix = suffix[0,3] //limit to 4 characters |
---|
1729 | WriteTextToHeader(fname,suffix,404) |
---|
1730 | |
---|
1731 | return(0) |
---|
1732 | end |
---|
1733 | |
---|
1734 | |
---|
1735 | // Jan 2008 |
---|
1736 | // it has been determined that the true pixel dimension of the ordela detectors is not 5.0 mm |
---|
1737 | // but somewhat larger (5.08? mm). "new" data files will be written out with the proper size |
---|
1738 | // and old files will be patched batchwise to put the prpoer value in the header |
---|
1739 | |
---|
1740 | Proc PatchDetectorPixelSize(firstFile,lastFile,XSize,YSize) |
---|
1741 | Variable firstFile=1,lastFile=100,XSize=5.08,YSize=5.08 |
---|
1742 | |
---|
1743 | fPatchDetectorPixelSize(firstFile,lastFile,XSize,YSize) |
---|
1744 | |
---|
1745 | End |
---|
1746 | |
---|
1747 | Proc ReadDetectorPixelSize(firstFile,lastFile) |
---|
1748 | Variable firstFile=1,lastFile=100 |
---|
1749 | |
---|
1750 | fReadDetectorPixelSize(firstFile,lastFile) |
---|
1751 | End |
---|
1752 | |
---|
1753 | // simple utility to patch the detector pixel size in the file headers |
---|
1754 | // pass in the dimensions in mm |
---|
1755 | // lo is the first file number |
---|
1756 | // hi is the last file number (inclusive) |
---|
1757 | // |
---|
1758 | Function fPatchDetectorPixelSize(lo,hi,xdim,ydim) |
---|
1759 | Variable lo,hi,xdim,ydim |
---|
1760 | |
---|
1761 | Variable ii |
---|
1762 | String file |
---|
1763 | |
---|
1764 | //loop over all files |
---|
1765 | for(ii=lo;ii<=hi;ii+=1) |
---|
1766 | file = FindFileFromRunNumber(ii) |
---|
1767 | if(strlen(file) != 0) |
---|
1768 | WriteDetPixelXToHeader(file,xdim) |
---|
1769 | WriteDetPixelyToHeader(file,ydim) |
---|
1770 | else |
---|
1771 | printf "run number %d not found\r",ii |
---|
1772 | endif |
---|
1773 | endfor |
---|
1774 | |
---|
1775 | return(0) |
---|
1776 | End |
---|
1777 | |
---|
1778 | // simple utility to read the pixel size stored in the file header |
---|
1779 | Function fReadDetectorPixelSize(lo,hi) |
---|
1780 | Variable lo,hi |
---|
1781 | |
---|
1782 | String file |
---|
1783 | Variable xdim,ydim,ii |
---|
1784 | |
---|
1785 | for(ii=lo;ii<=hi;ii+=1) |
---|
1786 | file = FindFileFromRunNumber(ii) |
---|
1787 | if(strlen(file) != 0) |
---|
1788 | xdim = getDetectorPixelXSize(file) |
---|
1789 | ydim = getDetectorPixelYSize(file) |
---|
1790 | printf "File %d: Pixel dimensions (mm): X = %g\t Y = %g\r",ii,xdim,ydim |
---|
1791 | else |
---|
1792 | printf "run number %d not found\r",ii |
---|
1793 | endif |
---|
1794 | endfor |
---|
1795 | |
---|
1796 | return(0) |
---|
1797 | End |
---|
1798 | |
---|
1799 | |
---|
1800 | |
---|
1801 | //******************* |
---|
1802 | //************ |
---|
1803 | // simple command - line utilities to convert/unconvert the header value |
---|
1804 | // that flags files as using lenses |
---|
1805 | // |
---|
1806 | // stored in reals[28], header byte start @ 300 |
---|
1807 | // |
---|
1808 | // currently, two values (0 | 1) = (no lens | yes lens) |
---|
1809 | // ideally, this field will have the actual number of lenses inserted. |
---|
1810 | // |
---|
1811 | // this is used in getResolution (reads the reals[]) and switches the calculation |
---|
1812 | //************ |
---|
1813 | |
---|
1814 | Proc ConvertToLens(RunNumber) |
---|
1815 | Variable RunNumber |
---|
1816 | HeaderToLensResolution(RunNumber) |
---|
1817 | End |
---|
1818 | |
---|
1819 | Proc ConvertToPinhole(RunNumber) |
---|
1820 | Variable RunNumber |
---|
1821 | HeaderToPinholeResolution(RunNumber) |
---|
1822 | End |
---|
1823 | |
---|
1824 | // sets the flag to zero in the file (= 0) |
---|
1825 | Function HeaderToPinholeResolution(num) |
---|
1826 | Variable num |
---|
1827 | |
---|
1828 | //Print "UnConvert" |
---|
1829 | String fullname="" |
---|
1830 | |
---|
1831 | fullname = FindFileFromRunNumber(num) |
---|
1832 | Print fullname |
---|
1833 | //report error or change the file |
---|
1834 | if(cmpstr(fullname,"")==0) |
---|
1835 | Print "HeaderToPinhole - file not found" |
---|
1836 | else |
---|
1837 | //Print "Unconvert",fullname |
---|
1838 | WriteVAXReal(fullname,0,300) |
---|
1839 | Endif |
---|
1840 | return(0) |
---|
1841 | End |
---|
1842 | |
---|
1843 | // sets the flag to one in the file (= 1) |
---|
1844 | Function HeaderToLensResolution(num) |
---|
1845 | Variable num |
---|
1846 | |
---|
1847 | //Print "UnConvert" |
---|
1848 | String fullname="" |
---|
1849 | |
---|
1850 | fullname = FindFileFromRunNumber(num) |
---|
1851 | Print fullname |
---|
1852 | //report error or change the file |
---|
1853 | if(cmpstr(fullname,"")==0) |
---|
1854 | Print "HeaderToPinhole - file not found" |
---|
1855 | else |
---|
1856 | //Print "Unconvert",fullname |
---|
1857 | WriteVAXReal(fullname,1,300) |
---|
1858 | Endif |
---|
1859 | return(0) |
---|
1860 | End |
---|
1861 | |
---|
1862 | |
---|
1863 | ////// OCT 2009, facility specific bits from MonteCarlo functions() |
---|
1864 | //"type" is the data folder that has the data array that is to be (re)written as a full |
---|
1865 | // data file, as if it was a raw data file |
---|
1866 | // |
---|
1867 | Function Write_RawData_File(type,fullpath,dialog) |
---|
1868 | String type,fullpath |
---|
1869 | Variable dialog //=1 will present dialog for name |
---|
1870 | |
---|
1871 | Write_VAXRaw_Data(type,fullpath,dialog) |
---|
1872 | |
---|
1873 | return(0) |
---|
1874 | End |
---|
1875 | |
---|
1876 | // given a data folder, write out the corresponding VAX binary data file. |
---|
1877 | // |
---|
1878 | // I don't think that I can generate a STRUCT and then lay that down - since the |
---|
1879 | // VAX FP format has to be duplicated with a write/read/flip/re-write dance... |
---|
1880 | // |
---|
1881 | // seems to work correctly byte for byte |
---|
1882 | // compression has bee implmented also, for complete replication of the format (n>32767 in a cell) |
---|
1883 | // |
---|
1884 | // SRK 29JAN09 |
---|
1885 | // |
---|
1886 | // other functions needed: |
---|
1887 | // |
---|
1888 | // |
---|
1889 | // one to generate a fake data file name, and put the matching name in the data header |
---|
1890 | // !! must fake the Annn suffix too! this is used... |
---|
1891 | // use a prefix, keep a run number, initials SIM, and alpha as before (start randomly, don't bother changing?) |
---|
1892 | // |
---|
1893 | // for right now, keep a run number, and generate |
---|
1894 | // PREFIXnnn.SA2_SIM_Annn |
---|
1895 | // also, start the index @ 100 to avoid leading zeros (although I have the functions available) |
---|
1896 | |
---|
1897 | // one to generate the date/time string in VAX format, right # characters// Print Secs2Time(DateTime,3) // Prints 13:07:29 |
---|
1898 | // Print Secs2Time(DateTime,3) // Prints 13:07:29 |
---|
1899 | // Print Secs2Date(DateTime,-2) // 1993-03-14 //this call is independent of System date/time!// |
---|
1900 | // |
---|
1901 | // for now, 20 characters 01-JAN-2009 12:12:12 |
---|
1902 | // |
---|
1903 | // simulation should call as ("SAS","",0) to bypass the dialog, and to fill the header |
---|
1904 | // this could be modified in the future to be more generic |
---|
1905 | // |
---|
1906 | /// |
---|
1907 | Function Write_VAXRaw_Data(type,fullpath,dialog) |
---|
1908 | String type,fullpath |
---|
1909 | Variable dialog //=1 will present dialog for name |
---|
1910 | |
---|
1911 | String destStr="" |
---|
1912 | Variable refNum,ii,val,err |
---|
1913 | |
---|
1914 | |
---|
1915 | destStr = "root:Packages:NIST:"+type |
---|
1916 | |
---|
1917 | SetDataFolder $destStr |
---|
1918 | WAVE intw=integersRead |
---|
1919 | WAVE rw=realsRead |
---|
1920 | WAVE/T textw=textRead |
---|
1921 | WAVE data=linear_data |
---|
1922 | |
---|
1923 | //check each wave |
---|
1924 | If(!(WaveExists(intw))) |
---|
1925 | Abort "intw DNExist WriteVAXData()" |
---|
1926 | Endif |
---|
1927 | If(!(WaveExists(rw))) |
---|
1928 | Abort "rw DNExist WriteVAXData()" |
---|
1929 | Endif |
---|
1930 | If(!(WaveExists(textw))) |
---|
1931 | Abort "textw DNExist WriteVAXData()" |
---|
1932 | Endif |
---|
1933 | If(!(WaveExists(data))) |
---|
1934 | Abort "linear_data DNExist WriteVAXData()" |
---|
1935 | Endif |
---|
1936 | |
---|
1937 | |
---|
1938 | // if(dialog) |
---|
1939 | // PathInfo/S catPathName |
---|
1940 | // fullPath = DoSaveFileDialog("Save data as") |
---|
1941 | // If(cmpstr(fullPath,"")==0) |
---|
1942 | // //user cancel, don't write out a file |
---|
1943 | // Close/A |
---|
1944 | // Abort "no data file was written" |
---|
1945 | // Endif |
---|
1946 | // //Print "dialog fullpath = ",fullpath |
---|
1947 | // Endif |
---|
1948 | |
---|
1949 | // save to home, or get out |
---|
1950 | // |
---|
1951 | PathInfo home |
---|
1952 | if(V_flag == 0) |
---|
1953 | Abort "no save path defined. Save the experiment to generate a home path" |
---|
1954 | endif |
---|
1955 | |
---|
1956 | fullPath = S_path //not the full path yet, still need the name, after the header is filled |
---|
1957 | |
---|
1958 | |
---|
1959 | Make/O/B/U/N=33316 tmpFile //unsigned integers for a blank data file |
---|
1960 | tmpFile=0 |
---|
1961 | |
---|
1962 | Make/O/W/N=16401 dataWRecMarkers |
---|
1963 | AddRecordMarkers(data,dataWRecMarkers) |
---|
1964 | |
---|
1965 | // need to re-compress?? maybe never a problem, but should be done for the odd case |
---|
1966 | dataWRecMarkers = CompressI4toI2(dataWRecMarkers) //unless a pixel value is > 32767, the same values are returned |
---|
1967 | |
---|
1968 | // fill the last bits of the header information |
---|
1969 | err = SimulationVAXHeader(type) |
---|
1970 | if (err == -1) |
---|
1971 | Abort "no sample label entered - no file written" // User did not fill in header correctly/completely |
---|
1972 | endif |
---|
1973 | fullPath = fullPath + textW[0] |
---|
1974 | |
---|
1975 | // lay down a blank file |
---|
1976 | Open refNum as fullpath |
---|
1977 | FBinWrite refNum,tmpFile //file is the right size, but all zeroes |
---|
1978 | Close refNum |
---|
1979 | |
---|
1980 | // fill up the header |
---|
1981 | // text values |
---|
1982 | // elements of textW are already the correct length set by the read, but just make sure |
---|
1983 | String str |
---|
1984 | |
---|
1985 | if(strlen(textw[0])>21) |
---|
1986 | textw[0] = (textw[0])[0,20] |
---|
1987 | endif |
---|
1988 | if(strlen(textw[1])>20) |
---|
1989 | textw[1] = (textw[1])[0,19] |
---|
1990 | endif |
---|
1991 | if(strlen(textw[2])>3) |
---|
1992 | textw[2] = (textw[2])[0,2] |
---|
1993 | endif |
---|
1994 | if(strlen(textw[3])>11) |
---|
1995 | textw[3] = (textw[3])[0,10] |
---|
1996 | endif |
---|
1997 | if(strlen(textw[4])>1) |
---|
1998 | textw[4] = (textw[4])[0] |
---|
1999 | endif |
---|
2000 | if(strlen(textw[5])>8) |
---|
2001 | textw[5] = (textw[5])[0,7] |
---|
2002 | endif |
---|
2003 | if(strlen(textw[6])>60) |
---|
2004 | textw[6] = (textw[6])[0,59] |
---|
2005 | endif |
---|
2006 | if(strlen(textw[7])>6) |
---|
2007 | textw[7] = (textw[7])[0,5] |
---|
2008 | endif |
---|
2009 | if(strlen(textw[8])>6) |
---|
2010 | textw[8] = (textw[8])[0,5] |
---|
2011 | endif |
---|
2012 | if(strlen(textw[9])>6) |
---|
2013 | textw[9] = (textw[9])[0,5] |
---|
2014 | endif |
---|
2015 | if(strlen(textw[10])>42) |
---|
2016 | textw[10] = (textw[10])[0,41] |
---|
2017 | endif |
---|
2018 | |
---|
2019 | ii=0 |
---|
2020 | Open/A/T="????TEXT" refnum as fullpath //Open for writing! Move to EOF before closing! |
---|
2021 | str = textW[ii] |
---|
2022 | FSetPos refnum,2 ////file name |
---|
2023 | FBinWrite/F=0 refnum, str //native object format (character) |
---|
2024 | ii+=1 |
---|
2025 | str = textW[ii] |
---|
2026 | FSetPos refnum,55 ////date/time |
---|
2027 | FBinWrite/F=0 refnum, str |
---|
2028 | ii+=1 |
---|
2029 | str = textW[ii] |
---|
2030 | FSetPos refnum,75 ////type |
---|
2031 | FBinWrite/F=0 refnum, str |
---|
2032 | ii+=1 |
---|
2033 | str = textW[ii] |
---|
2034 | FSetPos refnum,78 ////def dir |
---|
2035 | FBinWrite/F=0 refnum, str |
---|
2036 | ii+=1 |
---|
2037 | str = textW[ii] |
---|
2038 | FSetPos refnum,89 ////mode |
---|
2039 | FBinWrite/F=0 refnum, str |
---|
2040 | ii+=1 |
---|
2041 | str = textW[ii] |
---|
2042 | FSetPos refnum,90 ////reserve |
---|
2043 | FBinWrite/F=0 refnum, str |
---|
2044 | ii+=1 |
---|
2045 | str = textW[ii] |
---|
2046 | FSetPos refnum,98 ////@98, sample label |
---|
2047 | FBinWrite/F=0 refnum, str |
---|
2048 | ii+=1 |
---|
2049 | str = textW[ii] |
---|
2050 | FSetPos refnum,202 //// T units |
---|
2051 | FBinWrite/F=0 refnum, str |
---|
2052 | ii+=1 |
---|
2053 | str = textW[ii] |
---|
2054 | FSetPos refnum,208 //// F units |
---|
2055 | FBinWrite/F=0 refnum, str |
---|
2056 | ii+=1 |
---|
2057 | str = textW[ii] |
---|
2058 | FSetPos refnum,214 ////det type |
---|
2059 | FBinWrite/F=0 refnum, str |
---|
2060 | ii+=1 |
---|
2061 | str = textW[ii] |
---|
2062 | FSetPos refnum,404 ////reserve |
---|
2063 | FBinWrite/F=0 refnum, str |
---|
2064 | |
---|
2065 | //move to the end of the file before closing |
---|
2066 | FStatus refnum |
---|
2067 | FSetPos refnum,V_logEOF |
---|
2068 | Close refnum |
---|
2069 | |
---|
2070 | |
---|
2071 | // integer values (4 bytes) |
---|
2072 | ii=0 |
---|
2073 | Open/A/T="????TEXT" refnum as fullpath //Open for writing! Move to EOF before closing! |
---|
2074 | val = intw[ii] |
---|
2075 | FSetPos refnum,23 //nprefactors |
---|
2076 | FBinWrite/B=3/F=3 refnum, val //write a 4-byte integer |
---|
2077 | ii+=1 |
---|
2078 | val=intw[ii] |
---|
2079 | FSetPos refnum,27 //ctime |
---|
2080 | FBinWrite/B=3/F=3 refnum, val |
---|
2081 | ii+=1 |
---|
2082 | val=intw[ii] |
---|
2083 | FSetPos refnum,31 //rtime |
---|
2084 | FBinWrite/B=3/F=3 refnum, val |
---|
2085 | ii+=1 |
---|
2086 | val=intw[ii] |
---|
2087 | FSetPos refnum,35 //numruns |
---|
2088 | FBinWrite/B=3/F=3 refnum, val |
---|
2089 | ii+=1 |
---|
2090 | val=intw[ii] |
---|
2091 | FSetPos refnum,174 //table |
---|
2092 | FBinWrite/B=3/F=3 refnum, val |
---|
2093 | ii+=1 |
---|
2094 | val=intw[ii] |
---|
2095 | FSetPos refnum,178 //holder |
---|
2096 | FBinWrite/B=3/F=3 refnum, val |
---|
2097 | ii+=1 |
---|
2098 | val=intw[ii] |
---|
2099 | FSetPos refnum,182 //blank |
---|
2100 | FBinWrite/B=3/F=3 refnum, val |
---|
2101 | ii+=1 |
---|
2102 | val=intw[ii] |
---|
2103 | FSetPos refnum,194 //tctrlr |
---|
2104 | FBinWrite/B=3/F=3 refnum, val |
---|
2105 | ii+=1 |
---|
2106 | val=intw[ii] |
---|
2107 | FSetPos refnum,198 //magnet |
---|
2108 | FBinWrite/B=3/F=3 refnum, val |
---|
2109 | ii+=1 |
---|
2110 | val=intw[ii] |
---|
2111 | FSetPos refnum,244 //det num |
---|
2112 | FBinWrite/B=3/F=3 refnum, val |
---|
2113 | ii+=1 |
---|
2114 | val=intw[ii] |
---|
2115 | FSetPos refnum,248 //det spacer |
---|
2116 | FBinWrite/B=3/F=3 refnum, val |
---|
2117 | ii+=1 |
---|
2118 | val=intw[ii] |
---|
2119 | FSetPos refnum,308 //tslice mult |
---|
2120 | FBinWrite/B=3/F=3 refnum, val |
---|
2121 | ii+=1 |
---|
2122 | val=intw[ii] |
---|
2123 | FSetPos refnum,312 //tsclice ltslice |
---|
2124 | FBinWrite/B=3/F=3 refnum, val |
---|
2125 | ii+=1 |
---|
2126 | val=intw[ii] |
---|
2127 | FSetPos refnum,332 //extra |
---|
2128 | FBinWrite/B=3/F=3 refnum, val |
---|
2129 | ii+=1 |
---|
2130 | val=intw[ii] |
---|
2131 | FSetPos refnum,336 //reserve |
---|
2132 | FBinWrite/B=3/F=3 refnum, val |
---|
2133 | ii+=1 |
---|
2134 | val=intw[ii] |
---|
2135 | FSetPos refnum,376 //blank1 |
---|
2136 | FBinWrite/B=3/F=3 refnum, val |
---|
2137 | ii+=1 |
---|
2138 | val=intw[ii] |
---|
2139 | FSetPos refnum,380 //blank2 |
---|
2140 | FBinWrite/B=3/F=3 refnum, val |
---|
2141 | ii+=1 |
---|
2142 | val=intw[ii] |
---|
2143 | FSetPos refnum,384 //blank3 |
---|
2144 | FBinWrite/B=3/F=3 refnum, val |
---|
2145 | ii+=1 |
---|
2146 | val=intw[ii] |
---|
2147 | FSetPos refnum,458 //spacer |
---|
2148 | FBinWrite/B=3/F=3 refnum, val |
---|
2149 | ii+=1 |
---|
2150 | val=intw[ii] |
---|
2151 | FSetPos refnum,478 //box x1 |
---|
2152 | FBinWrite/B=3/F=3 refnum, val |
---|
2153 | ii+=1 |
---|
2154 | val=intw[ii] |
---|
2155 | FSetPos refnum,482 //box x2 |
---|
2156 | FBinWrite/B=3/F=3 refnum, val |
---|
2157 | ii+=1 |
---|
2158 | val=intw[ii] |
---|
2159 | FSetPos refnum,486 //box y1 |
---|
2160 | FBinWrite/B=3/F=3 refnum, val |
---|
2161 | ii+=1 |
---|
2162 | val=intw[ii] |
---|
2163 | FSetPos refnum,490 //box y2 |
---|
2164 | FBinWrite/B=3/F=3 refnum, val |
---|
2165 | |
---|
2166 | //move to the end of the file before closing |
---|
2167 | FStatus refnum |
---|
2168 | FSetPos refnum,V_logEOF |
---|
2169 | Close refnum |
---|
2170 | |
---|
2171 | |
---|
2172 | //VAX 4-byte FP values. No choice here but to write/read/re-write to get |
---|
2173 | // the proper format. there are 52! values to write |
---|
2174 | //WriteVAXReal(fullpath,rw[n],start) |
---|
2175 | // [0] |
---|
2176 | WriteVAXReal(fullpath,rw[0],39) |
---|
2177 | WriteVAXReal(fullpath,rw[1],43) |
---|
2178 | WriteVAXReal(fullpath,rw[2],47) |
---|
2179 | WriteVAXReal(fullpath,rw[3],51) |
---|
2180 | WriteVAXReal(fullpath,rw[4],158) |
---|
2181 | WriteVAXReal(fullpath,rw[5],162) |
---|
2182 | WriteVAXReal(fullpath,rw[6],166) |
---|
2183 | WriteVAXReal(fullpath,rw[7],170) |
---|
2184 | WriteVAXReal(fullpath,rw[8],186) |
---|
2185 | WriteVAXReal(fullpath,rw[9],190) |
---|
2186 | // [10] |
---|
2187 | WriteVAXReal(fullpath,rw[10],220) |
---|
2188 | WriteVAXReal(fullpath,rw[11],224) |
---|
2189 | WriteVAXReal(fullpath,rw[12],228) |
---|
2190 | WriteVAXReal(fullpath,rw[13],232) |
---|
2191 | WriteVAXReal(fullpath,rw[14],236) |
---|
2192 | WriteVAXReal(fullpath,rw[15],240) |
---|
2193 | WriteVAXReal(fullpath,rw[16],252) |
---|
2194 | WriteVAXReal(fullpath,rw[17],256) |
---|
2195 | WriteVAXReal(fullpath,rw[18],260) |
---|
2196 | WriteVAXReal(fullpath,rw[19],264) |
---|
2197 | // [20] |
---|
2198 | WriteVAXReal(fullpath,rw[20],268) |
---|
2199 | WriteVAXReal(fullpath,rw[21],272) |
---|
2200 | WriteVAXReal(fullpath,rw[22],276) |
---|
2201 | WriteVAXReal(fullpath,rw[23],280) |
---|
2202 | WriteVAXReal(fullpath,rw[24],284) |
---|
2203 | WriteVAXReal(fullpath,rw[25],288) |
---|
2204 | WriteVAXReal(fullpath,rw[26],292) |
---|
2205 | WriteVAXReal(fullpath,rw[27],296) |
---|
2206 | WriteVAXReal(fullpath,rw[28],300) |
---|
2207 | WriteVAXReal(fullpath,rw[29],320) |
---|
2208 | // [30] |
---|
2209 | WriteVAXReal(fullpath,rw[30],324) |
---|
2210 | WriteVAXReal(fullpath,rw[31],328) |
---|
2211 | WriteVAXReal(fullpath,rw[32],348) |
---|
2212 | WriteVAXReal(fullpath,rw[33],352) |
---|
2213 | WriteVAXReal(fullpath,rw[34],356) |
---|
2214 | WriteVAXReal(fullpath,rw[35],360) |
---|
2215 | WriteVAXReal(fullpath,rw[36],364) |
---|
2216 | WriteVAXReal(fullpath,rw[37],368) |
---|
2217 | WriteVAXReal(fullpath,rw[38],372) |
---|
2218 | WriteVAXReal(fullpath,rw[39],388) |
---|
2219 | // [40] |
---|
2220 | WriteVAXReal(fullpath,rw[40],392) |
---|
2221 | WriteVAXReal(fullpath,rw[41],396) |
---|
2222 | WriteVAXReal(fullpath,rw[42],400) |
---|
2223 | WriteVAXReal(fullpath,rw[43],450) |
---|
2224 | WriteVAXReal(fullpath,rw[44],454) |
---|
2225 | WriteVAXReal(fullpath,rw[45],470) |
---|
2226 | WriteVAXReal(fullpath,rw[46],474) |
---|
2227 | WriteVAXReal(fullpath,rw[47],494) |
---|
2228 | WriteVAXReal(fullpath,rw[48],498) |
---|
2229 | WriteVAXReal(fullpath,rw[49],502) |
---|
2230 | // [50] |
---|
2231 | WriteVAXReal(fullpath,rw[50],506) |
---|
2232 | WriteVAXReal(fullpath,rw[51],510) |
---|
2233 | |
---|
2234 | |
---|
2235 | // write out the data |
---|
2236 | Open refNum as fullpath |
---|
2237 | FSetPos refnum,514 // OK |
---|
2238 | FBinWrite/F=2/B=3 refNum,dataWRecMarkers //don't trust the native format |
---|
2239 | FStatus refNum |
---|
2240 | FSetPos refNum,V_logEOF |
---|
2241 | Close refNum |
---|
2242 | |
---|
2243 | |
---|
2244 | // write out the results into a text file |
---|
2245 | // SetDataFolder $destStr |
---|
2246 | WAVE results=results |
---|
2247 | WAVE/T results_desc=results_desc |
---|
2248 | |
---|
2249 | //check each wave |
---|
2250 | If(!(WaveExists(results))) |
---|
2251 | Abort "results DNExist WriteVAXData()" |
---|
2252 | Endif |
---|
2253 | If(!(WaveExists(results_desc))) |
---|
2254 | Abort "results_desc DNExist WriteVAXData()" |
---|
2255 | Endif |
---|
2256 | |
---|
2257 | Save/T results_desc,results as fullpath+".itx" |
---|
2258 | |
---|
2259 | /////////////////////////////// |
---|
2260 | |
---|
2261 | // all done |
---|
2262 | Killwaves/Z tmpFile,dataWRecMarkers |
---|
2263 | |
---|
2264 | Print "Saved VAX binary data as: ",textW[0] |
---|
2265 | SetDatafolder root: |
---|
2266 | return(0) |
---|
2267 | End |
---|
2268 | |
---|
2269 | |
---|
2270 | Function AddRecordMarkers(in,out) |
---|
2271 | Wave in,out |
---|
2272 | |
---|
2273 | Variable skip,ii |
---|
2274 | |
---|
2275 | // Duplicate/O in,out |
---|
2276 | // Redimension/N=16401 out |
---|
2277 | |
---|
2278 | out=0 |
---|
2279 | |
---|
2280 | ii=0 |
---|
2281 | skip=0 |
---|
2282 | out[ii] = 1 |
---|
2283 | ii+=1 |
---|
2284 | do |
---|
2285 | if(mod(ii+skip,1022)==0) |
---|
2286 | out[ii+skip] = 0 //999999 |
---|
2287 | skip+=1 //increment AFTER filling the current marker |
---|
2288 | endif |
---|
2289 | out[ii+skip] = in[ii-1] |
---|
2290 | ii+=1 |
---|
2291 | while(ii<=16384) |
---|
2292 | |
---|
2293 | |
---|
2294 | return(0) |
---|
2295 | End |
---|
2296 | |
---|
2297 | |
---|
2298 | |
---|
2299 | |
---|
2300 | // INTEGER*2 FUNCTION I4ToI2(I4) |
---|
2301 | //C |
---|
2302 | //C Original author : Jim Rhyne |
---|
2303 | //C Modified by : Frank Chen 09/26/90 |
---|
2304 | //C |
---|
2305 | //C I4ToI2 = I4, I4 in [0,32767] |
---|
2306 | //C I4ToI2 = -777, I4 in (2767000,...) |
---|
2307 | //C I4ToI2 mapped to -13277 to -32768, otherwise |
---|
2308 | //C |
---|
2309 | //C the mapped values [-776,-1] and [-13276,-778] are not used |
---|
2310 | //C |
---|
2311 | //C I4max should be 2768499, this value will maps to -32768 |
---|
2312 | //C and mantissa should be compared using |
---|
2313 | //C IF (R4 .GE. IPW) |
---|
2314 | //C instead of |
---|
2315 | //C IF (R4 .GT. (IPW - 1.0)) |
---|
2316 | //C |
---|
2317 | // |
---|
2318 | // |
---|
2319 | //C I4 : input I*4 |
---|
2320 | //C R4 : temperory real number storage |
---|
2321 | //C IPW : IPW = IB ** ND |
---|
2322 | //C NPW : number of power |
---|
2323 | //C IB : Base value |
---|
2324 | //C ND : Number of precision digits |
---|
2325 | //C I4max : max data value w/ some error |
---|
2326 | //C I2max : max data value w/o error |
---|
2327 | //C Error : when data value > I4max |
---|
2328 | //C |
---|
2329 | // INTEGER*4 I4 |
---|
2330 | // INTEGER*4 NPW |
---|
2331 | // REAL*4 R4 |
---|
2332 | // INTEGER*4 IPW |
---|
2333 | // INTEGER*4 IB /10/ |
---|
2334 | // INTEGER*4 ND /4/ |
---|
2335 | // INTEGER*4 I4max /2767000/ |
---|
2336 | // INTEGER*4 I2max /32767/ |
---|
2337 | // INTEGER*4 Error /-777/ |
---|
2338 | // |
---|
2339 | Function CompressI4toI2(i4) |
---|
2340 | Variable i4 |
---|
2341 | |
---|
2342 | Variable npw,ipw,ib,nd,i4max,i2max,error,i4toi2 |
---|
2343 | Variable r4 |
---|
2344 | |
---|
2345 | ib=10 |
---|
2346 | nd=4 |
---|
2347 | i4max=2767000 |
---|
2348 | i2max=32767 |
---|
2349 | error=-777 |
---|
2350 | |
---|
2351 | if(i4 <= i4max) |
---|
2352 | r4=i4 |
---|
2353 | if(r4 > i2max) |
---|
2354 | ipw = ib^nd |
---|
2355 | npw=0 |
---|
2356 | do |
---|
2357 | if( !(r4 > (ipw-1)) ) //to simulate a do-while loop evaluating at top |
---|
2358 | break |
---|
2359 | endif |
---|
2360 | npw=npw+1 |
---|
2361 | r4=r4/ib |
---|
2362 | while (1) |
---|
2363 | i4toi2 = -1*trunc(r4+ipw*npw) |
---|
2364 | else |
---|
2365 | i4toi2 = trunc(r4) //shouldn't I just return i4 (as a 2 byte value?) |
---|
2366 | endif |
---|
2367 | else |
---|
2368 | i4toi2=error |
---|
2369 | endif |
---|
2370 | return(i4toi2) |
---|
2371 | End |
---|
2372 | |
---|
2373 | |
---|
2374 | // function to fill the extra bits of header information to make a "complete" |
---|
2375 | // simulated VAX data file. |
---|
2376 | // |
---|
2377 | // |
---|
2378 | Function SimulationVAXHeader(folder) |
---|
2379 | String folder |
---|
2380 | |
---|
2381 | Wave rw=root:Packages:NIST:SAS:realsRead |
---|
2382 | Wave iw=root:Packages:NIST:SAS:integersRead |
---|
2383 | Wave/T tw=root:Packages:NIST:SAS:textRead |
---|
2384 | Wave res=root:Packages:NIST:SAS:results |
---|
2385 | |
---|
2386 | // integers needed: |
---|
2387 | //[2] count time |
---|
2388 | NVAR ctTime = root:Packages:NIST:SAS:gCntTime |
---|
2389 | iw[2] = ctTime |
---|
2390 | |
---|
2391 | //reals are partially set in SASCALC initializtion |
---|
2392 | //remaining values are updated automatically as SASCALC is modified |
---|
2393 | // -- but still need: |
---|
2394 | // [0] monitor count |
---|
2395 | // [2] detector count (w/o beamstop) |
---|
2396 | // [4] transmission |
---|
2397 | // [5] thickness (in cm) |
---|
2398 | NVAR imon = root:Packages:NIST:SAS:gImon |
---|
2399 | rw[0] = imon |
---|
2400 | rw[2] = res[9] |
---|
2401 | rw[4] = res[8] |
---|
2402 | NVAR thick = root:Packages:NIST:SAS:gThick |
---|
2403 | rw[5] = thick |
---|
2404 | |
---|
2405 | // text values needed: |
---|
2406 | // be sure they are padded to the correct length |
---|
2407 | // [0] filename (do I fake a VAX name? probably yes...) |
---|
2408 | // [1] date/time in VAX format |
---|
2409 | // [2] type (use SIM) |
---|
2410 | // [3] def dir (use [NG7SANS99]) |
---|
2411 | // [4] mode? C |
---|
2412 | // [5] reserve (another date), prob not needed |
---|
2413 | // [6] sample label |
---|
2414 | // [9] det type "ORNL " (6 chars) |
---|
2415 | |
---|
2416 | tw[1] = Secs2Date(DateTime,-2)+" "+ Secs2Time(DateTime,3) //20 chars, not quite VAX format |
---|
2417 | tw[2] = "SIM" |
---|
2418 | tw[3] = "[NG7SANS99]" |
---|
2419 | tw[4] = "C" |
---|
2420 | tw[5] = "01JAN09 " |
---|
2421 | tw[9] = "ORNL " |
---|
2422 | |
---|
2423 | NVAR index = root:Packages:NIST:SAS:gSaveIndex |
---|
2424 | SVAR prefix = root:Packages:NIST:SAS:gSavePrefix |
---|
2425 | |
---|
2426 | |
---|
2427 | |
---|
2428 | String labelStr=" " |
---|
2429 | Variable runNum = index |
---|
2430 | Prompt labelStr, "Enter sample label " // Set prompt for x param |
---|
2431 | Prompt runNum,"Run Number (automatically increments)" |
---|
2432 | DoPrompt "Enter sample label", labelStr,runNum |
---|
2433 | if (V_Flag) |
---|
2434 | //Print "no sample label entered - no file written" |
---|
2435 | //index -=1 |
---|
2436 | return -1 // User canceled |
---|
2437 | endif |
---|
2438 | |
---|
2439 | if(runNum != index) |
---|
2440 | index = runNum |
---|
2441 | endif |
---|
2442 | index += 1 |
---|
2443 | |
---|
2444 | tw[0] = prefix+num2str(runNum)+".SA2_SIM_A"+num2str(runNum) |
---|
2445 | |
---|
2446 | labelStr = PadString(labelStr,60,0x20) //60 fortran-style spaces |
---|
2447 | tw[6] = labelStr[0,59] |
---|
2448 | |
---|
2449 | return(0) |
---|
2450 | End |
---|
2451 | |
---|
2452 | Function ExamineHeader(type) |
---|
2453 | String type |
---|
2454 | |
---|
2455 | String data_folder = type |
---|
2456 | String dataPath = "root:Packages:NIST:"+data_folder |
---|
2457 | String cur_folder = "ExamineHeader" |
---|
2458 | String curPath = "root:Packages:NIST:"+cur_folder |
---|
2459 | |
---|
2460 | //SetDataFolder curPath |
---|
2461 | |
---|
2462 | Wave intw=$(dataPath+":IntegersRead") |
---|
2463 | Wave realw=$(dataPath+":RealsRead") |
---|
2464 | Wave/T textw=$(dataPath+":TextRead") |
---|
2465 | Wave logw=$(dataPath+":LogicalsRead") |
---|
2466 | |
---|
2467 | |
---|
2468 | print "----------------------------------" |
---|
2469 | print "Header Details" |
---|
2470 | print "----------------------------------" |
---|
2471 | print "fname :\t\t"+textw[0] |
---|
2472 | // |
---|
2473 | print "run.npre :\t\t"+num2str(intw[0]) |
---|
2474 | print "run.ctime :\t\t"+num2str(intw[1]) |
---|
2475 | print "run.rtime :\t\t"+num2str(intw[2]) |
---|
2476 | print "run.numruns :\t\t"+num2str(intw[3]) |
---|
2477 | // |
---|
2478 | print "run.moncnt :\t\t"+num2str(realw[0]) |
---|
2479 | print "run.savmon :\t\t"+num2str(realw[1]) |
---|
2480 | print "run.detcnt :\t\t"+num2str(realw[2]) |
---|
2481 | print "run.atten :\t\t"+num2str(realw[3]) |
---|
2482 | // |
---|
2483 | print "run.timdat:\t\t"+textw[1] |
---|
2484 | print "run.type:\t\t"+textw[2] |
---|
2485 | print "run.defdir:\t\t"+textw[3] |
---|
2486 | print "run.mode:\t\t"+textw[4] |
---|
2487 | print "run.reserve:\t\t"+textw[5] |
---|
2488 | print "sample.labl:\t\t"+textw[6] |
---|
2489 | // |
---|
2490 | print "sample.trns:\t\t"+num2str(realw[4]) |
---|
2491 | print "sample.thk:\t\t"+num2str(realw[5]) |
---|
2492 | print "sample.position:\t\t"+num2str(realw[6]) |
---|
2493 | print "sample.rotang:\t\t"+num2str(realw[7]) |
---|
2494 | // |
---|
2495 | print "sample.table:\t\t"+num2str(intw[4]) |
---|
2496 | print "sample.holder:\t\t"+num2str(intw[5]) |
---|
2497 | print "sample.blank:\t\t"+num2str(intw[6]) |
---|
2498 | // |
---|
2499 | print "sample.temp:\t\t"+num2str(realw[8]) |
---|
2500 | print "sample.field:\t\t"+num2str(realw[9]) |
---|
2501 | // |
---|
2502 | print "sample.tctrlr:\t\t"+num2str(intw[7]) |
---|
2503 | print "sample.magnet:\t\t"+num2str(intw[8]) |
---|
2504 | // |
---|
2505 | print "sample.tunits:\t\t"+textw[7] |
---|
2506 | print "sample.funits:\t\t"+textw[8] |
---|
2507 | print "det.typ:\t\t"+textw[9] |
---|
2508 | // |
---|
2509 | print "det.calx(1):\t\t"+num2str(realw[10]) |
---|
2510 | print "det.calx(2):\t\t"+num2str(realw[11]) |
---|
2511 | print "det.calx(3):\t\t"+num2str(realw[12]) |
---|
2512 | print "det.caly(1):\t\t"+num2str(realw[13]) |
---|
2513 | print "det.caly(2):\t\t"+num2str(realw[14]) |
---|
2514 | print "det.caly(3):\t\t"+num2str(realw[15]) |
---|
2515 | // |
---|
2516 | print "det.num:\t\t"+num2str(intw[9]) |
---|
2517 | print "det.spacer:\t\t"+num2str(intw[10]) |
---|
2518 | // |
---|
2519 | print "det.beamx:\t\t"+num2str(realw[16]) |
---|
2520 | print "det.beamy:\t\t"+num2str(realw[17]) |
---|
2521 | print "det.dis:\t\t"+num2str(realw[18]) |
---|
2522 | print "det.offset:\t\t"+num2str(realw[19]) |
---|
2523 | print "det.siz:\t\t"+num2str(realw[20]) |
---|
2524 | print "det.bstop:\t\t"+num2str(realw[21]) |
---|
2525 | print "det.blank:\t\t"+num2str(realw[22]) |
---|
2526 | print "resolution.ap1:\t\t"+num2str(realw[23]) |
---|
2527 | print "resolution.ap2:\t\t"+num2str(realw[24]) |
---|
2528 | print "resolution.ap12dis:\t\t"+num2str(realw[25]) |
---|
2529 | print "resolution.lmda:\t\t"+num2str(realw[26]) |
---|
2530 | print "resolution.dlmda:\t\t"+num2str(realw[27]) |
---|
2531 | print "resolution.nlenses:\t\t"+num2str(realw[28]) |
---|
2532 | // |
---|
2533 | print "tslice.slicing:\t\t"+num2str(logw[0]) |
---|
2534 | // |
---|
2535 | print "tslice.multfact:\t\t"+num2str(intw[11]) |
---|
2536 | print "tslice.ltslice:\t\t"+num2str(intw[12]) |
---|
2537 | // |
---|
2538 | print "temp.printemp:\t\t"+num2str(logw[1]) |
---|
2539 | // |
---|
2540 | print "temp.hold:\t\t"+num2str(realw[29]) |
---|
2541 | print "temp.err:\t\t"+num2str(realw[30]) |
---|
2542 | print "temp.blank:\t\t"+num2str(realw[31]) |
---|
2543 | // |
---|
2544 | print "temp.extra:\t\t"+num2str(intw[13]) |
---|
2545 | print "temp.err:\t\t"+num2str(intw[14]) |
---|
2546 | // |
---|
2547 | print "magnet.printmag:\t\t"+num2str(logw[2]) |
---|
2548 | print "magnet.sensor:\t\t"+num2str(logw[3]) |
---|
2549 | // |
---|
2550 | print "magnet.current:\t\t"+num2str(realw[32]) |
---|
2551 | print "magnet.conv:\t\t"+num2str(realw[33]) |
---|
2552 | print "magnet.fieldlast:\t\t"+num2str(realw[34]) |
---|
2553 | print "magnet.blank:\t\t"+num2str(realw[35]) |
---|
2554 | print "magnet.spacer:\t\t"+num2str(realw[36]) |
---|
2555 | print "bmstp.xpos:\t\t"+num2str(realw[37]) |
---|
2556 | print "bmstop.ypos:\t\t"+num2str(realw[38]) |
---|
2557 | // |
---|
2558 | print "params.blank1:\t\t"+num2str(intw[15]) |
---|
2559 | print "params.blank2:\t\t"+num2str(intw[16]) |
---|
2560 | print "params.blank3:\t\t"+num2str(intw[17]) |
---|
2561 | // |
---|
2562 | print "params.trnscnt:\t\t"+num2str(realw[39]) |
---|
2563 | print "params.extra1:\t\t"+num2str(realw[40]) |
---|
2564 | print "params.extra2:\t\t"+num2str(realw[41]) |
---|
2565 | print "params.extra3:\t\t"+num2str(realw[42]) |
---|
2566 | // |
---|
2567 | print "params.reserve:\t\t"+textw[10] |
---|
2568 | // |
---|
2569 | print "voltage.printemp:\t\t"+num2str(logw[4]) |
---|
2570 | // |
---|
2571 | print "voltage.volts:\t\t"+num2str(realw[43]) |
---|
2572 | print "voltage.blank:\t\t"+num2str(realw[44]) |
---|
2573 | // |
---|
2574 | print "voltage.spacer:\t\t"+num2str(intw[18]) |
---|
2575 | // |
---|
2576 | print "polarization.printpol:\t\t"+num2str(logw[5]) |
---|
2577 | print "polarization.flipper:\t\t"+num2str(logw[6]) |
---|
2578 | // |
---|
2579 | print "polarization.horiz:\t\t"+num2str(realw[45]) |
---|
2580 | print "polarization.vert:\t\t"+num2str(realw[46]) |
---|
2581 | // |
---|
2582 | print "analysis.rows(1):\t\t"+num2str(intw[19]) |
---|
2583 | print "analysis.rows(2):\t\t"+num2str(intw[20]) |
---|
2584 | print "analysis.cols(1):\t\t"+num2str(intw[21]) |
---|
2585 | print "analysis.cols(2):\t\t"+num2str(intw[22]) |
---|
2586 | // |
---|
2587 | print "analysis.factor:\t\t"+num2str(realw[47]) |
---|
2588 | print "analysis.qmin:\t\t"+num2str(realw[48]) |
---|
2589 | print "analysis.qmax:\t\t"+num2str(realw[49]) |
---|
2590 | print "analysis.imin:\t\t"+num2str(realw[50]) |
---|
2591 | print "analysis.imax:\t\t"+num2str(realw[51]) |
---|
2592 | |
---|
2593 | End |
---|
2594 | |
---|
2595 | |
---|
2596 | // Sept 2009 -SRK |
---|
2597 | // the ICE instrument control software is not correctly writing out the file name to the header in the specific |
---|
2598 | // case of a file prefix less than 5 characters. ICE is quite naturally putting the blanke space(s) at the end of |
---|
2599 | // the string. However, the VAX puts them at the beginning... |
---|
2600 | Proc PatchFileNameInHeader(firstFile,lastFile) |
---|
2601 | Variable firstFile=1,lastFile=100 |
---|
2602 | |
---|
2603 | fPatchFileName(firstFile,lastFile) |
---|
2604 | |
---|
2605 | End |
---|
2606 | |
---|
2607 | Proc ReadFileNameInHeader(firstFile,lastFile) |
---|
2608 | Variable firstFile=1,lastFile=100 |
---|
2609 | |
---|
2610 | fReadFileName(firstFile,lastFile) |
---|
2611 | End |
---|
2612 | |
---|
2613 | |
---|
2614 | // simple utility to patch the file name in the file headers |
---|
2615 | // lo is the first file number |
---|
2616 | // hi is the last file number (inclusive) |
---|
2617 | // |
---|
2618 | // will read the 21 character file name and put any spaces at the front of the string |
---|
2619 | // like the VAX does. Should have absolutely no effect if there are spaces at the |
---|
2620 | // beginning of the string, as the VAX does. |
---|
2621 | Function fPatchFileName(lo,hi) |
---|
2622 | Variable lo,hi |
---|
2623 | |
---|
2624 | Variable ii |
---|
2625 | String file,fileName |
---|
2626 | |
---|
2627 | //loop over all files |
---|
2628 | for(ii=lo;ii<=hi;ii+=1) |
---|
2629 | file = FindFileFromRunNumber(ii) |
---|
2630 | if(strlen(file) != 0) |
---|
2631 | fileName = getFileName(file) |
---|
2632 | WriteFileNameToHeader(file,fileName) |
---|
2633 | else |
---|
2634 | printf "run number %d not found\r",ii |
---|
2635 | endif |
---|
2636 | endfor |
---|
2637 | |
---|
2638 | return(0) |
---|
2639 | End |
---|
2640 | |
---|
2641 | // simple utility to read the file name stored in the file header (and the suffix) |
---|
2642 | Function fReadFileName(lo,hi) |
---|
2643 | Variable lo,hi |
---|
2644 | |
---|
2645 | String file,fileName,suffix |
---|
2646 | Variable ii |
---|
2647 | |
---|
2648 | for(ii=lo;ii<=hi;ii+=1) |
---|
2649 | file = FindFileFromRunNumber(ii) |
---|
2650 | if(strlen(file) != 0) |
---|
2651 | fileName = getFileName(file) |
---|
2652 | suffix = getSuffix(file) |
---|
2653 | printf "File %d: File name = %s\t\tSuffix = %s\r",ii,fileName,suffix |
---|
2654 | else |
---|
2655 | printf "run number %d not found\r",ii |
---|
2656 | endif |
---|
2657 | endfor |
---|
2658 | |
---|
2659 | return(0) |
---|
2660 | End |
---|
2661 | |
---|
2662 | |
---|
2663 | |
---|
2664 | |
---|
2665 | // April 2009 - AJJ |
---|
2666 | // The new ICE instrument control software was not correctly writing the run.defdir field |
---|
2667 | // The format of that field should be [NGxSANSn] where x is 3 or 7 and nn is 0 through 50 |
---|
2668 | |
---|
2669 | Proc PatchUserAccountName(firstFile,lastFile,acctName) |
---|
2670 | Variable firstFile=1,lastFile=100 |
---|
2671 | String acctName = "NG3SANS0" |
---|
2672 | |
---|
2673 | fPatchUserAccountName(firstFile,lastFile,acctName) |
---|
2674 | |
---|
2675 | End |
---|
2676 | |
---|
2677 | Proc ReadUserAccountName(firstFile,lastFile) |
---|
2678 | Variable firstFile=1,lastFile=100 |
---|
2679 | |
---|
2680 | fReadUserAccountName(firstFile,lastFile) |
---|
2681 | End |
---|
2682 | |
---|
2683 | // simple utility to patch the user account name in the file headers |
---|
2684 | // pass in the account name as a string |
---|
2685 | // lo is the first file number |
---|
2686 | // hi is the last file number (inclusive) |
---|
2687 | // |
---|
2688 | Function fPatchUserAccountName(lo,hi,acctName) |
---|
2689 | Variable lo,hi |
---|
2690 | String acctName |
---|
2691 | |
---|
2692 | Variable ii |
---|
2693 | String file |
---|
2694 | |
---|
2695 | //loop over all files |
---|
2696 | for(ii=lo;ii<=hi;ii+=1) |
---|
2697 | file = FindFileFromRunNumber(ii) |
---|
2698 | if(strlen(file) != 0) |
---|
2699 | WriteAcctNameToHeader(file,acctName) |
---|
2700 | else |
---|
2701 | printf "run number %d not found\r",ii |
---|
2702 | endif |
---|
2703 | endfor |
---|
2704 | |
---|
2705 | return(0) |
---|
2706 | End |
---|
2707 | |
---|
2708 | // simple utility to read the user account name stored in the file header |
---|
2709 | Function fReadUserAccountName(lo,hi) |
---|
2710 | Variable lo,hi |
---|
2711 | |
---|
2712 | String file,acctName |
---|
2713 | Variable ii |
---|
2714 | |
---|
2715 | for(ii=lo;ii<=hi;ii+=1) |
---|
2716 | file = FindFileFromRunNumber(ii) |
---|
2717 | if(strlen(file) != 0) |
---|
2718 | acctName = getAcctName(file) |
---|
2719 | printf "File %d: Account name = %s\r",ii,acctName |
---|
2720 | else |
---|
2721 | printf "run number %d not found\r",ii |
---|
2722 | endif |
---|
2723 | endfor |
---|
2724 | |
---|
2725 | return(0) |
---|
2726 | End |
---|
2727 | |
---|
2728 | // May 2009 - SRK |
---|
2729 | // Monitor count not written correctly to file from ICE |
---|
2730 | |
---|
2731 | Proc PatchMonitorCount(firstFile,lastFile,monCtRate) |
---|
2732 | Variable firstFile=1,lastFile=100,monCtRate |
---|
2733 | |
---|
2734 | fPatchMonitorCount(firstFile,lastFile,monCtRate) |
---|
2735 | |
---|
2736 | End |
---|
2737 | |
---|
2738 | Proc ReadMonitorCount(firstFile,lastFile) |
---|
2739 | Variable firstFile=1,lastFile=100 |
---|
2740 | |
---|
2741 | fReadMonitorCount(firstFile,lastFile) |
---|
2742 | End |
---|
2743 | |
---|
2744 | // simple utility to patch the user account name in the file headers |
---|
2745 | // pass in the account name as a string |
---|
2746 | // lo is the first file number |
---|
2747 | // hi is the last file number (inclusive) |
---|
2748 | // |
---|
2749 | Function fPatchMonitorCount(lo,hi,monCtRate) |
---|
2750 | Variable lo,hi,monCtRate |
---|
2751 | |
---|
2752 | Variable ii,ctTime |
---|
2753 | String file |
---|
2754 | |
---|
2755 | //loop over all files |
---|
2756 | for(ii=lo;ii<=hi;ii+=1) |
---|
2757 | file = FindFileFromRunNumber(ii) |
---|
2758 | if(strlen(file) != 0) |
---|
2759 | ctTime = getCountTime(file) |
---|
2760 | WriteMonitorCountToHeader(file,ctTime*monCtRate) |
---|
2761 | else |
---|
2762 | printf "run number %d not found\r",ii |
---|
2763 | endif |
---|
2764 | endfor |
---|
2765 | |
---|
2766 | return(0) |
---|
2767 | End |
---|
2768 | |
---|
2769 | // simple utility to read the user account name stored in the file header |
---|
2770 | Function fReadMonitorCount(lo,hi) |
---|
2771 | Variable lo,hi |
---|
2772 | |
---|
2773 | String file |
---|
2774 | Variable ii,monitorCount |
---|
2775 | |
---|
2776 | for(ii=lo;ii<=hi;ii+=1) |
---|
2777 | file = FindFileFromRunNumber(ii) |
---|
2778 | if(strlen(file) != 0) |
---|
2779 | monitorCount = getMonitorCount(file) |
---|
2780 | printf "File %d: Monitor Count = %g\r",ii,monitorCount |
---|
2781 | else |
---|
2782 | printf "run number %d not found\r",ii |
---|
2783 | endif |
---|
2784 | endfor |
---|
2785 | |
---|
2786 | return(0) |
---|
2787 | End |
---|
2788 | |
---|
2789 | |
---|
2790 | ///// |
---|
2791 | Proc ReadDetectorCount(firstFile,lastFile) |
---|
2792 | Variable firstFile=1,lastFile=100 |
---|
2793 | |
---|
2794 | fReadDetectorCount(firstFile,lastFile) |
---|
2795 | End |
---|
2796 | |
---|
2797 | |
---|
2798 | // simple utility to read the detector count from the header, and the summed data value |
---|
2799 | // and print out the values |
---|
2800 | Function fReadDetectorCount(lo,hi) |
---|
2801 | Variable lo,hi |
---|
2802 | |
---|
2803 | String file |
---|
2804 | Variable ii,summed |
---|
2805 | |
---|
2806 | for(ii=lo;ii<=hi;ii+=1) |
---|
2807 | file = FindFileFromRunNumber(ii) |
---|
2808 | if(strlen(file) != 0) |
---|
2809 | ReadHeaderAndData(file) |
---|
2810 | Wave rw=root:Packages:NIST:RAW:RealsRead |
---|
2811 | Wave data=root:Packages:NIST:RAW:data //data as read in is linear |
---|
2812 | summed = sum(data,-inf,inf) |
---|
2813 | printf "File %d: DetCt Header = %g\t Detector Sum = %g\t Ratio sum/hdr = %g\r",ii,rw[2],summed,summed/rw[2] |
---|
2814 | else |
---|
2815 | printf "run number %d not found\r",ii |
---|
2816 | endif |
---|
2817 | endfor |
---|
2818 | |
---|
2819 | return(0) |
---|
2820 | End |
---|
2821 | |
---|
2822 | |
---|
2823 | ////// OCT 2009, facility specific bits from ProDiv() |
---|
2824 | //"type" is the data folder that has the corrected, patched, and normalized DIV data array |
---|
2825 | // |
---|
2826 | // the header of this file is rather unimportant. Filling in a title at least would be helpful/ |
---|
2827 | // |
---|
2828 | Function Write_DIV_File(type) |
---|
2829 | String type |
---|
2830 | |
---|
2831 | // Your file writing function here. Don't try to duplicate the VAX binary format... |
---|
2832 | WriteVAXWorkFile(type) |
---|
2833 | |
---|
2834 | return(0) |
---|
2835 | End |
---|
2836 | |
---|
2837 | //writes an VAX-style WORK file, "exactly" as it would be output from the VAX |
---|
2838 | //except for the "dummy" header and the record markers - the record marker bytes are |
---|
2839 | // in the files - they are just written as zeros and are meaningless |
---|
2840 | //file is: |
---|
2841 | // 516 bytes header |
---|
2842 | // 128x128=16384 (x4) bytes of data |
---|
2843 | // + 2 byte record markers interspersed just for fun |
---|
2844 | // = 66116 bytes |
---|
2845 | //prompts for name of the output file. |
---|
2846 | // |
---|
2847 | Function WriteVAXWorkFile(type) |
---|
2848 | String type |
---|
2849 | |
---|
2850 | Wave data=$("root:Packages:NIST:"+type+":data") |
---|
2851 | |
---|
2852 | Variable refnum,ii=0,hdrBytes=516,a,b,offset |
---|
2853 | String fullpath="" |
---|
2854 | |
---|
2855 | Duplicate/O data,tempData |
---|
2856 | Redimension/S/N=(128*128) tempData |
---|
2857 | tempData *= 4 |
---|
2858 | |
---|
2859 | PathInfo/S catPathName |
---|
2860 | fullPath = DoSaveFileDialog("Save data as") //won't actually open the file |
---|
2861 | If(cmpstr(fullPath,"")==0) |
---|
2862 | //user cancel, don't write out a file |
---|
2863 | Close/A |
---|
2864 | Abort "no data file was written" |
---|
2865 | Endif |
---|
2866 | |
---|
2867 | Make/B/O/N=(hdrBytes) hdrWave |
---|
2868 | hdrWave=0 |
---|
2869 | FakeDIVHeader(hdrWave) |
---|
2870 | |
---|
2871 | Make/Y=2/O/N=(510) bw510 //Y=2 specifies 32 bit (=4 byte) floating point |
---|
2872 | Make/Y=2/O/N=(511) bw511 |
---|
2873 | Make/Y=2/O/N=(48) bw48 |
---|
2874 | |
---|
2875 | Make/O/B/N=2 recWave //two bytes |
---|
2876 | |
---|
2877 | //actually open the file |
---|
2878 | Open/C="????"/T="TEXT" refNum as fullpath |
---|
2879 | FSetPos refNum, 0 |
---|
2880 | //write header bytes (to be skipped when reading the file later) |
---|
2881 | |
---|
2882 | FBinWrite /F=1 refnum,hdrWave |
---|
2883 | |
---|
2884 | ii=0 |
---|
2885 | a=0 |
---|
2886 | do |
---|
2887 | //write 511 4-byte values (little-endian order), 4* true value |
---|
2888 | bw511[] = tempData[p+a] |
---|
2889 | FBinWrite /B=3/F=4 refnum,bw511 |
---|
2890 | a+=511 |
---|
2891 | //write a 2-byte record marker |
---|
2892 | FBinWrite refnum,recWave |
---|
2893 | |
---|
2894 | //write 510 4-byte values (little-endian) 4* true value |
---|
2895 | bw510[] = tempData[p+a] |
---|
2896 | FBinWrite /B=3/F=4 refnum,bw510 |
---|
2897 | a+=510 |
---|
2898 | |
---|
2899 | //write a 2-byte record marker |
---|
2900 | FBinWrite refnum,recWave |
---|
2901 | |
---|
2902 | ii+=1 |
---|
2903 | while(ii<16) |
---|
2904 | //write out last 48 4-byte values (little-endian) 4* true value |
---|
2905 | bw48[] = tempData[p+a] |
---|
2906 | FBinWrite /B=3/F=4 refnum,bw48 |
---|
2907 | //close the file |
---|
2908 | Close refnum |
---|
2909 | |
---|
2910 | //go back through and make it look like a VAX datafile |
---|
2911 | Make/W/U/O/N=(511*2) int511 // /W=16 bit signed integers /U=unsigned |
---|
2912 | Make/W/U/O/N=(510*2) int510 |
---|
2913 | Make/W/U/O/N=(48*2) int48 |
---|
2914 | |
---|
2915 | //skip the header for now |
---|
2916 | Open/A/T="????TEXT" refnum as fullPath |
---|
2917 | FSetPos refnum,0 |
---|
2918 | |
---|
2919 | offset=hdrBytes |
---|
2920 | ii=0 |
---|
2921 | do |
---|
2922 | //511*2 integers |
---|
2923 | FSetPos refnum,offset |
---|
2924 | FBinRead/B=2/F=2 refnum,int511 |
---|
2925 | Swap16BWave(int511) |
---|
2926 | FSetPos refnum,offset |
---|
2927 | FBinWrite/B=2/F=2 refnum,int511 |
---|
2928 | |
---|
2929 | //skip 511 4-byte FP = (511*2)*2 2byte int + 2 bytes record marker |
---|
2930 | offset += 511*2*2 + 2 |
---|
2931 | |
---|
2932 | //510*2 integers |
---|
2933 | FSetPos refnum,offset |
---|
2934 | FBinRead/B=2/F=2 refnum,int510 |
---|
2935 | Swap16BWave(int510) |
---|
2936 | FSetPos refnum,offset |
---|
2937 | FBinWrite/B=2/F=2 refnum,int510 |
---|
2938 | |
---|
2939 | // |
---|
2940 | offset += 510*2*2 + 2 |
---|
2941 | |
---|
2942 | ii+=1 |
---|
2943 | while(ii<16) |
---|
2944 | //48*2 integers |
---|
2945 | FSetPos refnum,offset |
---|
2946 | FBinRead/B=2/F=2 refnum,int48 |
---|
2947 | Swap16BWave(int48) |
---|
2948 | FSetPos refnum,offset |
---|
2949 | FBinWrite/B=2/F=2 refnum,int48 |
---|
2950 | |
---|
2951 | //move to EOF and close |
---|
2952 | FStatus refnum |
---|
2953 | FSetPos refnum,V_logEOF |
---|
2954 | |
---|
2955 | Close refnum |
---|
2956 | |
---|
2957 | Killwaves/Z hdrWave,bw48,bw511,bw510,recWave,temp16,int511,int510,int48 |
---|
2958 | End |
---|
2959 | |
---|
2960 | // given a 16 bit integer wave, read in as 2-byte pairs of 32-bit FP data |
---|
2961 | // swap the order of the 2-byte pairs |
---|
2962 | // |
---|
2963 | Function Swap16BWave(w) |
---|
2964 | Wave w |
---|
2965 | |
---|
2966 | Duplicate/O w,temp16 |
---|
2967 | //Variable num=numpnts(w),ii=0 |
---|
2968 | |
---|
2969 | //elegant way to swap even/odd values, using wave assignments |
---|
2970 | w[0,*;2] = temp16[p+1] |
---|
2971 | w[1,*;2] = temp16[p-1] |
---|
2972 | |
---|
2973 | //crude way, using a loop |
---|
2974 | // for(ii=0;ii<num;ii+=2) |
---|
2975 | // w[ii] = temp16[ii+1] |
---|
2976 | // w[ii+1] = temp16[ii] |
---|
2977 | // endfor |
---|
2978 | |
---|
2979 | return(0) |
---|
2980 | End |
---|
2981 | |
---|
2982 | // writes a fake label into the header of the DIV file |
---|
2983 | // |
---|
2984 | Function FakeDIVHeader(hdrWave) |
---|
2985 | WAVE hdrWave |
---|
2986 | |
---|
2987 | //put some fake text into the sample label position (60 characters=60 bytes) |
---|
2988 | String day=date(),tim=time(),lbl="" |
---|
2989 | Variable start=98,num,ii |
---|
2990 | |
---|
2991 | lbl = "Sensitivity (DIV) created "+day +" "+tim |
---|
2992 | num=strlen(lbl) |
---|
2993 | for(ii=0;ii<num;ii+=1) |
---|
2994 | hdrWave[start+ii] = char2num(lbl[ii]) |
---|
2995 | endfor |
---|
2996 | |
---|
2997 | return(0) |
---|
2998 | End |
---|
2999 | |
---|
3000 | ////////end of ProDiv() specifics |
---|