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 | |
---|
44 | ReadHeaderAndData(filename) //this is the full Path+file |
---|
45 | |
---|
46 | Return(0) |
---|
47 | End |
---|
48 | |
---|
49 | |
---|
50 | //function that does the guts of reading the binary data file |
---|
51 | //fname is the full path:name;vers required to open the file |
---|
52 | // |
---|
53 | // The final root:RAW:data wave is the real |
---|
54 | //neutron counts and can be directly operated on |
---|
55 | // |
---|
56 | // header information is put into three waves: integersRead, realsRead, and textRead |
---|
57 | // logicals in the header are currently skipped, since they are no use in the |
---|
58 | // data reduction process. |
---|
59 | // |
---|
60 | // The output is the three R/T/I waves that are filled at least with minimal values |
---|
61 | // and the detector data loaded into an array named "data" |
---|
62 | // |
---|
63 | // see documentation for the expected information in each element of the R/T/I waves |
---|
64 | // and the minimum set of information. These waves can be increased in length so that |
---|
65 | // more information can be accessed as needed (propagating changes...) |
---|
66 | // |
---|
67 | // called by multiple .ipfs (when the file name is known) |
---|
68 | // |
---|
69 | // |
---|
70 | // THIS FUNCTION DOES NOT NEED TO BE MODIFIED. ONLY THE DATA ACCESSORS NEED TO BE CONSTRUCTED |
---|
71 | // |
---|
72 | Function ReadHeaderAndData(fname) |
---|
73 | String fname |
---|
74 | //this function is for reading in RAW data only, so it will always put data in RAW folder |
---|
75 | String curPath = "root:RAW" |
---|
76 | SetDataFolder curPath //use the full path, so it will always work |
---|
77 | Variable/G root:RAW:gIsLogScale = 0 //initial state is linear, keep this in RAW folder |
---|
78 | |
---|
79 | Variable refNum,integer,realval,ii |
---|
80 | String sansfname,textstr,v0 |
---|
81 | |
---|
82 | Make/D/O/N=23 $"root:RAW:IntegersRead" |
---|
83 | Make/D/O/N=52 $"root:RAW:RealsRead" |
---|
84 | Make/O/T/N=11 $"root:RAW:TextRead" |
---|
85 | |
---|
86 | Wave intw=$"root:RAW:IntegersRead" |
---|
87 | Wave realw=$"root:RAW:RealsRead" |
---|
88 | Wave/T textw=$"root:RAW:TextRead" |
---|
89 | |
---|
90 | // FILL IN 3 ARRAYS WITH HEADER INFORMATION FOR LATER USE |
---|
91 | // THESE ARE JUST THE MINIMALLY NECESSARY VALUES |
---|
92 | |
---|
93 | // filename as stored in the file header |
---|
94 | Open/R refNum as fname |
---|
95 | //skip first two bytes (VAX record length markers, not needed here) |
---|
96 | // FSetPos refNum, 2 |
---|
97 | //read the next 21 bytes as characters (fname) |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | for (ii=0;ii<2;ii+=1) |
---|
102 | FReadLine refNum,textstr |
---|
103 | sscanf textstr,"%s",v0 |
---|
104 | |
---|
105 | endfor |
---|
106 | |
---|
107 | Close refnum |
---|
108 | |
---|
109 | textw[0]= v0 |
---|
110 | |
---|
111 | // print "function read raw used" |
---|
112 | |
---|
113 | // date and time of collection |
---|
114 | textw[1]= getFileCreationDate(fname) |
---|
115 | |
---|
116 | // run type identifier (this is a reader for RAW data) |
---|
117 | textw[2]= "RAW" |
---|
118 | |
---|
119 | // user account identifier (currently used only for NCNR-specific operations) |
---|
120 | textw[3]= getFileInstrument(fname) |
---|
121 | |
---|
122 | // sample label |
---|
123 | textw[6]= getSampleLabel(fname) |
---|
124 | |
---|
125 | // identifier of detector type, useful for setting detector constants |
---|
126 | //(currently used only for NCNR-specific operations) |
---|
127 | textw[9]= "" |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | //total counting time in seconds |
---|
132 | intw[2] = getCountTime(fname) |
---|
133 | |
---|
134 | |
---|
135 | // total monitor count |
---|
136 | realw[0] = getMonitorCount(fname) |
---|
137 | |
---|
138 | // total detector count |
---|
139 | realw[2] = getDetCount(fname) |
---|
140 | |
---|
141 | // attenuator number (NCNR-specific, your stub returns 0) |
---|
142 | // may also be used to hold attenuator transmission (< 1) |
---|
143 | realw[3] = getAttenNumber(fname) |
---|
144 | |
---|
145 | // sample transmission |
---|
146 | realw[4] = getSampleTrans(fname) |
---|
147 | |
---|
148 | //sample thickness (cm) |
---|
149 | realw[5] = getSampleThickness(fname) |
---|
150 | |
---|
151 | // following 6 values are for non-linear spatial corrections to a detector (RC timing) |
---|
152 | // these values are set for a detctor that has a linear correspondence between |
---|
153 | // pixel number and real-space distance |
---|
154 | // 10 and 13 are the X and Y pixel dimensions, respectively (in mm!) |
---|
155 | //(11,12 and 13,14 are set to values for a linear response, as from a new Ordela detector) |
---|
156 | realw[10] = getDetectorPixelXSize(fname) |
---|
157 | realw[11] = 10000 |
---|
158 | realw[12] = 0 |
---|
159 | realw[13] = getDetectorPixelYSize(fname) |
---|
160 | realw[14] = 10000 |
---|
161 | realw[15] = 0 |
---|
162 | |
---|
163 | // beam center X,Y on the detector (in units of pixel coordinates (1,N)) |
---|
164 | realw[16] = getBeamXPos(fname) |
---|
165 | realw[17] = getBeamYPos(fname) |
---|
166 | |
---|
167 | // sample to detector distance (meters) |
---|
168 | realw[18] = getSDD(fname) |
---|
169 | |
---|
170 | // detector physical width (right now assumes square...) (in cm) |
---|
171 | realw[20] = 102 |
---|
172 | |
---|
173 | // beam stop diameter (assumes circular) (in mm) |
---|
174 | realw[21] = getBSDiameter(fname) |
---|
175 | |
---|
176 | // source aperture diameter (mm) |
---|
177 | realw[23] = getSourceApertureDiam(fname) |
---|
178 | |
---|
179 | // sample aperture diameter (mm) |
---|
180 | realw[24] = getSampleApertureDiam(fname) |
---|
181 | |
---|
182 | // source aperture to sample aperture distance |
---|
183 | realw[25] = getSourceToSampleDist(fname) |
---|
184 | |
---|
185 | // wavelength (A) |
---|
186 | realw[26] = getWavelength(fname) |
---|
187 | |
---|
188 | // wavelength spread (FWHM) |
---|
189 | realw[27] = getWavelengthSpread(fname) |
---|
190 | |
---|
191 | realw[52] = getreactorpower(fname) |
---|
192 | |
---|
193 | // beam stop X-position (motor reading, approximate cm from zero position) |
---|
194 | // currently NCNR-specific use to identify transmission measurements |
---|
195 | // you return 0 |
---|
196 | realw[37] = 0 |
---|
197 | |
---|
198 | |
---|
199 | // the actual data array, dimensions are set as globals in |
---|
200 | // InitFacilityGlobals() |
---|
201 | NVAR XPix = root:myGlobals:gNPixelsX |
---|
202 | NVAR YPix = root:myGlobals:gNPixelsX |
---|
203 | |
---|
204 | SetDataFolder curPath |
---|
205 | |
---|
206 | Make/D/O/N=(XPix,YPix) $"root:RAW:data" |
---|
207 | WAVE data=$"root:RAW:data" |
---|
208 | |
---|
209 | // fill the data array with the detector values |
---|
210 | getDetectorData(fname,data) |
---|
211 | |
---|
212 | Setdatafolder curpath |
---|
213 | |
---|
214 | |
---|
215 | //keep a string with the filename in the RAW folder |
---|
216 | String/G root:RAW:fileList = textw[0] |
---|
217 | |
---|
218 | Setdatafolder root: |
---|
219 | |
---|
220 | |
---|
221 | Return 0 |
---|
222 | |
---|
223 | End |
---|
224 | |
---|
225 | //**************** |
---|
226 | //main entry procedure for reading a "WORK.DIV" file |
---|
227 | //displays a quick image of the file, to check that it's correct |
---|
228 | //data is deposited in root:DIV data folder |
---|
229 | // |
---|
230 | // local, just for testing |
---|
231 | // |
---|
232 | Proc ReadWork_DIV() |
---|
233 | |
---|
234 | String fname = PromptForPath("Select detector sensitivity file") |
---|
235 | ReadHeaderAndWork("DIV",fname) //puts what is read in work.div |
---|
236 | |
---|
237 | String waveStr = "root:DIV:data" |
---|
238 | NewImage/F/K=1/S=2 $waveStr |
---|
239 | ModifyImage '' ctab= {*,*,YellowHot,0} |
---|
240 | |
---|
241 | String/G root:DIV:fileList = "WORK.DIV" |
---|
242 | |
---|
243 | SetDataFolder root: //(redundant) |
---|
244 | End |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | // Detector sensitivity files have the same header structure as RAW SANS data |
---|
249 | // as NCNR, just with a different data array (real, rather than integer data) |
---|
250 | // |
---|
251 | // So for your facility, make this reader specific to the format of whatever |
---|
252 | // file you use for a pixel-by-pixel division of the raw detector data |
---|
253 | // to correct for non-uniform sensitivities of the detector. This is typically a |
---|
254 | // measurement of water, plexiglas, or another uniform scattering sample. |
---|
255 | // |
---|
256 | // The data must be normalized to a mean value of 1 |
---|
257 | // |
---|
258 | // called from ProtocolAsPanel.ipf |
---|
259 | // |
---|
260 | // type is "DIV" on input |
---|
261 | Function ReadHeaderAndWork1(type,fname) |
---|
262 | String type,fname |
---|
263 | |
---|
264 | //type is the desired folder to read the workfile to |
---|
265 | //this data will NOT be automatically displayed |
---|
266 | // gDataDisplayType is unchanged |
---|
267 | |
---|
268 | String cur_folder = type |
---|
269 | String curPath = "root:"+cur_folder |
---|
270 | SetDataFolder curPath //use the full path, so it will always work |
---|
271 | |
---|
272 | Variable refNum,integer,realval |
---|
273 | String sansfname,textstr |
---|
274 | Variable/G $(curPath + ":gIsLogScale") = 0 //initial state is linear, keep this in DIV folder |
---|
275 | |
---|
276 | Make/O/D/N=23 $(curPath + ":IntegersRead") |
---|
277 | Make/O/D/N=52 $(curPath + ":RealsRead") |
---|
278 | Make/O/T/N=11 $(curPath + ":TextRead") |
---|
279 | |
---|
280 | WAVE intw=$(curPath + ":IntegersRead") |
---|
281 | WAVE realw=$(curPath + ":RealsRead") |
---|
282 | WAVE/T textw=$(curPath + ":TextRead") |
---|
283 | |
---|
284 | // the actual data array, dimensions are set as globals in |
---|
285 | // InitFacilityGlobals() |
---|
286 | NVAR XPix = root:myGlobals:gNPixelsX |
---|
287 | NVAR YPix = root:myGlobals:gNPixelsX |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | Make/O/D/N=(XPix,YPix) $(curPath + ":data") |
---|
292 | WAVE data = $(curPath + ":data") |
---|
293 | |
---|
294 | |
---|
295 | // print "function used" |
---|
296 | |
---|
297 | |
---|
298 | // (1) |
---|
299 | // fill in your reader for the header here so that intw, realw, and textW are filled in |
---|
300 | // ? possibly a duplication of the raw data reader |
---|
301 | Duplicate/O $("root:raw:realsread"),$("curPath"+ ":realsread") |
---|
302 | Duplicate/O $("root:raw:integersread"),$("curPath"+ ":integersread") |
---|
303 | Duplicate/T $("root:raw:Textread"),$("curPath"+ ":Textread") |
---|
304 | |
---|
305 | |
---|
306 | //(2) |
---|
307 | // then fill in a reader for the data array that will DIVIDE your data |
---|
308 | // to get the corrected values. |
---|
309 | // fill the data array with the detector values |
---|
310 | |
---|
311 | duplicate/O $("root:raw:data"),$("curPath"+ ":data") |
---|
312 | |
---|
313 | |
---|
314 | //keep a string with the filename in the DIV folder |
---|
315 | String/G $(curPath + ":fileList") = textw[0] |
---|
316 | |
---|
317 | //return the data folder to root |
---|
318 | SetDataFolder root: |
---|
319 | |
---|
320 | Return(0) |
---|
321 | End |
---|
322 | |
---|
323 | |
---|
324 | /////////DIV file created with NIST reduction so has the VAX format.... painful |
---|
325 | |
---|
326 | Function ReadHeaderAndWork(type,fname) |
---|
327 | String type,fname |
---|
328 | |
---|
329 | //type is the desired folder to read the workfile to |
---|
330 | //this data will NOT be automatically displayed gDataDisplayType is unchanged |
---|
331 | |
---|
332 | // SVAR cur_folder=root:myGlobals:gDataDisplayType |
---|
333 | String cur_folder = type |
---|
334 | String curPath = "root:"+cur_folder |
---|
335 | SetDataFolder curPath //use the full path, so it will always work |
---|
336 | |
---|
337 | Variable refNum,integer,realval |
---|
338 | String sansfname,textstr |
---|
339 | Variable/G $(curPath + ":gIsLogScale") = 0 //initial state is linear, keep this in DIV folder |
---|
340 | |
---|
341 | Make/O/N=23 $(curPath + ":IntegersRead") |
---|
342 | Make/O/N=52 $(curPath + ":RealsRead") |
---|
343 | Make/O/T/N=11 $(curPath + ":TextRead") |
---|
344 | |
---|
345 | WAVE intw=$(curPath + ":IntegersRead") |
---|
346 | WAVE realw=$(curPath + ":RealsRead") |
---|
347 | WAVE/T textw=$(curPath + ":TextRead") |
---|
348 | |
---|
349 | //***NOTE **** |
---|
350 | // the "current path" gets mysteriously reset to "root:" after the SECOND pass through |
---|
351 | // this read routine, after the open dialog is presented |
---|
352 | // the "--read" waves end up in the correct folder, but the data does not! Why? |
---|
353 | //must re-set data folder before writing data array (done below) |
---|
354 | |
---|
355 | SetDataFolder curPath |
---|
356 | |
---|
357 | //actually open the file |
---|
358 | Open/R refNum as fname |
---|
359 | //skip first two bytes |
---|
360 | FSetPos refNum, 2 |
---|
361 | //read the next 21 bytes as characters (fname) |
---|
362 | FReadLine/N=21 refNum,textstr |
---|
363 | textw[0]= textstr |
---|
364 | //read four i*4 values /F=3 flag, B=3 flag |
---|
365 | FBinRead/F=3/B=3 refNum, integer |
---|
366 | intw[0] = integer |
---|
367 | // |
---|
368 | FBinRead/F=3/B=3 refNum, integer |
---|
369 | intw[1] = integer |
---|
370 | // |
---|
371 | FBinRead/F=3/B=3 refNum, integer |
---|
372 | intw[2] = integer |
---|
373 | // |
---|
374 | FBinRead/F=3/B=3 refNum, integer |
---|
375 | intw[3] = integer |
---|
376 | // 6 text fields |
---|
377 | FSetPos refNum,55 //will start reading at byte 56 |
---|
378 | FReadLine/N=20 refNum,textstr |
---|
379 | textw[1]= textstr |
---|
380 | FReadLine/N=3 refNum,textstr |
---|
381 | textw[2]= textstr |
---|
382 | FReadLine/N=11 refNum,textstr |
---|
383 | textw[3]= textstr |
---|
384 | FReadLine/N=1 refNum,textstr |
---|
385 | textw[4]= textstr |
---|
386 | FReadLine/N=8 refNum,textstr |
---|
387 | textw[5]= textstr |
---|
388 | FReadLine/N=60 refNum,textstr |
---|
389 | textw[6]= textstr |
---|
390 | |
---|
391 | //3 integers |
---|
392 | FSetPos refNum,174 |
---|
393 | FBinRead/F=3/B=3 refNum, integer |
---|
394 | intw[4] = integer |
---|
395 | FBinRead/F=3/B=3 refNum, integer |
---|
396 | intw[5] = integer |
---|
397 | FBinRead/F=3/B=3 refNum, integer |
---|
398 | intw[6] = integer |
---|
399 | |
---|
400 | //2 integers, 3 text fields |
---|
401 | FSetPos refNum,194 |
---|
402 | FBinRead/F=3/B=3 refNum, integer |
---|
403 | intw[7] = integer |
---|
404 | FBinRead/F=3/B=3 refNum, integer |
---|
405 | intw[8] = integer |
---|
406 | FReadLine/N=6 refNum,textstr |
---|
407 | textw[7]= textstr |
---|
408 | FReadLine/N=6 refNum,textstr |
---|
409 | textw[8]= textstr |
---|
410 | FReadLine/N=6 refNum,textstr |
---|
411 | textw[9]= textstr |
---|
412 | |
---|
413 | //2 integers |
---|
414 | FSetPos refNum,244 |
---|
415 | FBinRead/F=3/B=3 refNum, integer |
---|
416 | intw[9] = integer |
---|
417 | FBinRead/F=3/B=3 refNum, integer |
---|
418 | intw[10] = integer |
---|
419 | |
---|
420 | //2 integers |
---|
421 | FSetPos refNum,308 |
---|
422 | FBinRead/F=3/B=3 refNum, integer |
---|
423 | intw[11] = integer |
---|
424 | FBinRead/F=3/B=3 refNum, integer |
---|
425 | intw[12] = integer |
---|
426 | |
---|
427 | //2 integers |
---|
428 | FSetPos refNum,332 |
---|
429 | FBinRead/F=3/B=3 refNum, integer |
---|
430 | intw[13] = integer |
---|
431 | FBinRead/F=3/B=3 refNum, integer |
---|
432 | intw[14] = integer |
---|
433 | |
---|
434 | //3 integers |
---|
435 | FSetPos refNum,376 |
---|
436 | FBinRead/F=3/B=3 refNum, integer |
---|
437 | intw[15] = integer |
---|
438 | FBinRead/F=3/B=3 refNum, integer |
---|
439 | intw[16] = integer |
---|
440 | FBinRead/F=3/B=3 refNum, integer |
---|
441 | intw[17] = integer |
---|
442 | |
---|
443 | //1 text field - the file association for transmission are the first 4 bytes |
---|
444 | FSetPos refNum,404 |
---|
445 | FReadLine/N=42 refNum,textstr |
---|
446 | textw[10]= textstr |
---|
447 | |
---|
448 | //1 integer |
---|
449 | FSetPos refNum,458 |
---|
450 | FBinRead/F=3/B=3 refNum, integer |
---|
451 | intw[18] = integer |
---|
452 | |
---|
453 | //4 integers |
---|
454 | FSetPos refNum,478 |
---|
455 | FBinRead/F=3/B=3 refNum, integer |
---|
456 | intw[19] = integer |
---|
457 | FBinRead/F=3/B=3 refNum, integer |
---|
458 | intw[20] = integer |
---|
459 | FBinRead/F=3/B=3 refNum, integer |
---|
460 | intw[21] = integer |
---|
461 | FBinRead/F=3/B=3 refNum, integer |
---|
462 | intw[22] = integer |
---|
463 | |
---|
464 | Close refNum |
---|
465 | |
---|
466 | //now get all of the reals |
---|
467 | // |
---|
468 | //Do all the GBLoadWaves at the end |
---|
469 | // |
---|
470 | //FBinRead Cannot handle 32 bit VAX floating point |
---|
471 | //GBLoadWave, however, can properly read it |
---|
472 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
473 | String strToExecute |
---|
474 | //append "/S=offset/U=numofreals" to control the read |
---|
475 | // then append fname to give the full file path |
---|
476 | // then execute |
---|
477 | |
---|
478 | Variable a=0,b=0 |
---|
479 | |
---|
480 | SetDataFolder curPath |
---|
481 | // 4 R*4 values |
---|
482 | strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" |
---|
483 | Execute strToExecute |
---|
484 | |
---|
485 | SetDataFolder curPath |
---|
486 | Wave w=$(curPath + ":tempGBWave0") |
---|
487 | b=4 //num of reals read |
---|
488 | realw[a,a+b-1] = w[p-a] |
---|
489 | a+=b |
---|
490 | |
---|
491 | // 4 R*4 values |
---|
492 | SetDataFolder curPath |
---|
493 | strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\"" |
---|
494 | Execute strToExecute |
---|
495 | b=4 |
---|
496 | realw[a,a+b-1] = w[p-a] |
---|
497 | a+=b |
---|
498 | |
---|
499 | /////////// |
---|
500 | // 2 R*4 values |
---|
501 | SetDataFolder curPath |
---|
502 | strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" |
---|
503 | Execute strToExecute |
---|
504 | b=2 |
---|
505 | realw[a,a+b-1] = w[p-a] |
---|
506 | a+=b |
---|
507 | |
---|
508 | // 6 R*4 values |
---|
509 | SetDataFolder curPath |
---|
510 | strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\"" |
---|
511 | Execute strToExecute |
---|
512 | b=6 |
---|
513 | realw[a,a+b-1] = w[p-a] |
---|
514 | a+=b |
---|
515 | |
---|
516 | // 13 R*4 values |
---|
517 | SetDataFolder curPath |
---|
518 | strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\"" |
---|
519 | Execute strToExecute |
---|
520 | b=13 |
---|
521 | realw[a,a+b-1] = w[p-a] |
---|
522 | a+=b |
---|
523 | |
---|
524 | // 3 R*4 values |
---|
525 | SetDataFolder curPath |
---|
526 | strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\"" |
---|
527 | Execute strToExecute |
---|
528 | b=3 |
---|
529 | realw[a,a+b-1] = w[p-a] |
---|
530 | a+=b |
---|
531 | |
---|
532 | // 7 R*4 values |
---|
533 | SetDataFolder curPath |
---|
534 | strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\"" |
---|
535 | Execute strToExecute |
---|
536 | b=7 |
---|
537 | realw[a,a+b-1] = w[p-a] |
---|
538 | a+=b |
---|
539 | |
---|
540 | // 4 R*4 values |
---|
541 | SetDataFolder curPath |
---|
542 | strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\"" |
---|
543 | Execute strToExecute |
---|
544 | b=4 |
---|
545 | realw[a,a+b-1] = w[p-a] |
---|
546 | a+=b |
---|
547 | |
---|
548 | // 2 R*4 values |
---|
549 | SetDataFolder curPath |
---|
550 | strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\"" |
---|
551 | Execute strToExecute |
---|
552 | b=2 |
---|
553 | realw[a,a+b-1] = w[p-a] |
---|
554 | a+=b |
---|
555 | |
---|
556 | // 2 R*4 values |
---|
557 | SetDataFolder curPath |
---|
558 | strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\"" |
---|
559 | Execute strToExecute |
---|
560 | b=2 |
---|
561 | realw[a,a+b-1] = w[p-a] |
---|
562 | a+=b |
---|
563 | |
---|
564 | // 5 R*4 values |
---|
565 | SetDataFolder curPath |
---|
566 | strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\"" |
---|
567 | Execute strToExecute |
---|
568 | b=5 |
---|
569 | realw[a,a+b-1] = w[p-a] |
---|
570 | |
---|
571 | //if the binary VAX data ws transferred to a MAC, all is OK |
---|
572 | //if the data was trasnferred to an Intel machine (IBM), all the real values must be |
---|
573 | //divided by 4 to get the correct floating point values |
---|
574 | // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly |
---|
575 | // on an Intel machine. |
---|
576 | //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read |
---|
577 | //VAX reals correctly, and no checking is necessary 12 APR 99 |
---|
578 | //if(cmpstr("Macintosh",IgorInfo(2)) == 0) |
---|
579 | //do nothing |
---|
580 | //else |
---|
581 | //either Windows or Windows NT |
---|
582 | //realw /= 4 |
---|
583 | //endif |
---|
584 | |
---|
585 | //read in the data |
---|
586 | GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
587 | |
---|
588 | curPath = "root:"+cur_folder |
---|
589 | SetDataFolder curPath //use the full path, so it will always work |
---|
590 | |
---|
591 | Make/O/N=16384 $(curPath + ":data") |
---|
592 | WAVE data = $(curPath + ":data") |
---|
593 | |
---|
594 | Variable skip,ii,offset |
---|
595 | |
---|
596 | //read in a total of 16384 values (ii) |
---|
597 | //as follows : |
---|
598 | // skip first 2 bytes |
---|
599 | // skip 512 byte header |
---|
600 | // skip first 2 bytes of data |
---|
601 | //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values |
---|
602 | // read the final 48 values in seperately to avoid EOF error |
---|
603 | |
---|
604 | ///////////// |
---|
605 | SetDataFolder curPath |
---|
606 | skip = 0 |
---|
607 | ii=0 |
---|
608 | offset = 514 +2 |
---|
609 | a=0 |
---|
610 | do |
---|
611 | SetDataFolder curPath |
---|
612 | |
---|
613 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\"" |
---|
614 | Execute strToExecute |
---|
615 | //Print strToExecute |
---|
616 | b=511 |
---|
617 | data[a,a+b-1] = w[p-a] |
---|
618 | a+=b |
---|
619 | |
---|
620 | offset += 511*4 +2 |
---|
621 | |
---|
622 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\"" |
---|
623 | SetDataFolder curPath |
---|
624 | Execute strToExecute |
---|
625 | //Print strToExecute |
---|
626 | b=510 |
---|
627 | data[a,a+b-1] = w[p-a] |
---|
628 | a+=b |
---|
629 | |
---|
630 | offset += 510*4 +2 |
---|
631 | |
---|
632 | ii+=1 |
---|
633 | //Print "inside do, data[2] =",data[2] |
---|
634 | //Print "inside do, tempGBwave0[0] = ",w[0] |
---|
635 | while(ii<16) |
---|
636 | |
---|
637 | // 16336 values have been read in -- |
---|
638 | //read in last 64 values |
---|
639 | strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\"" |
---|
640 | |
---|
641 | SetDataFolder curPath |
---|
642 | Execute strToExecute |
---|
643 | b=48 |
---|
644 | data[a,a+b-1] = w[p-a] |
---|
645 | a+=b |
---|
646 | // |
---|
647 | /// done reading in raw data |
---|
648 | // |
---|
649 | //Print "in workdatareader , data = ", data[1][1] |
---|
650 | |
---|
651 | Redimension/n=(128,128) data |
---|
652 | |
---|
653 | //clean up - get rid of w = $"tempGBWave0" |
---|
654 | KillWaves w |
---|
655 | |
---|
656 | //divide the FP data by 4 if read from a PC (not since GBLoadWave update) |
---|
657 | //if(cmpstr("Macintosh",IgorInfo(2)) == 0) |
---|
658 | //do nothing |
---|
659 | //else |
---|
660 | //either Windows or Windows NT |
---|
661 | //data /= 4 |
---|
662 | //endif |
---|
663 | |
---|
664 | //keep a string with the filename in the DIV folder |
---|
665 | String/G $(curPath + ":fileList") = textw[0] |
---|
666 | |
---|
667 | //return the data folder to root |
---|
668 | SetDataFolder root: |
---|
669 | |
---|
670 | Return(0) |
---|
671 | End |
---|
672 | |
---|
673 | |
---|
674 | |
---|
675 | |
---|
676 | |
---|
677 | ///// ASC FORMAT READER ////// |
---|
678 | ///// FOR WORKFILE MATH PANEL ////// |
---|
679 | // |
---|
680 | //function to read in the ASC output of SANS reduction |
---|
681 | // currently the file has 20 header lines, followed by a single column |
---|
682 | // of 16384 values, Data is written by row, starting with Y=1 and X=(1->128) |
---|
683 | // |
---|
684 | //returns 0 if read was ok |
---|
685 | //returns 1 if there was an error |
---|
686 | // |
---|
687 | // called by WorkFileUtils.ipf |
---|
688 | // |
---|
689 | // |
---|
690 | // If the ASC data was generated by the NCNR data writer, then |
---|
691 | // NOTHING NEEDS TO BE CHANGED HERE |
---|
692 | // |
---|
693 | Function ReadASCData(fname,destPath) |
---|
694 | String fname, destPath |
---|
695 | //this function is for reading in ASCII data so put data in user-specified folder |
---|
696 | SetDataFolder "root:"+destPath |
---|
697 | |
---|
698 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
699 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
700 | Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=220 ///waas 20 for NIST |
---|
701 | String str="" |
---|
702 | //data is initially linear scale |
---|
703 | Variable/G :gIsLogScale=0 |
---|
704 | Make/O/T/N=(numHdrLines) hdrLines |
---|
705 | Make/O/D/N=(pixelsX*pixelsY) data //,linear_data |
---|
706 | |
---|
707 | //full filename and path is now passed in... |
---|
708 | //actually open the file |
---|
709 | // SetDataFolder destPath |
---|
710 | Open/R/Z refNum as fname // /Z flag means I must handle open errors |
---|
711 | if(refnum==0) //FNF error, get out |
---|
712 | DoAlert 0,"Could not find file: "+fname |
---|
713 | Close/A |
---|
714 | SetDataFolder root: |
---|
715 | return(1) |
---|
716 | endif |
---|
717 | if(V_flag!=0) |
---|
718 | DoAlert 0,"File open error: V_flag="+num2Str(V_Flag) |
---|
719 | Close/A |
---|
720 | SetDataFolder root: |
---|
721 | return(1) |
---|
722 | Endif |
---|
723 | // |
---|
724 | for(ii=0;ii<numHdrLines;ii+=1) //read (or skip) 18 header lines |
---|
725 | FReadLine refnum,str |
---|
726 | hdrLines[ii]=str |
---|
727 | endfor |
---|
728 | // |
---|
729 | Close refnum |
---|
730 | |
---|
731 | // SetDataFolder destPath |
---|
732 | |
---|
733 | //loadwave /A=tempGBwave/L={0, start, numrow, 0, numcol}/N/G/D/O/E=1/K=1 |
---|
734 | |
---|
735 | |
---|
736 | LoadWave/Q/G/D/N=temp fName |
---|
737 | Wave/Z temp0=temp0 |
---|
738 | data=temp0 |
---|
739 | Redimension/N=(pixelsX,pixelsY) data //,linear_data |
---|
740 | |
---|
741 | //linear_data = data |
---|
742 | |
---|
743 | KillWaves/Z temp0 |
---|
744 | |
---|
745 | //return the data folder to root |
---|
746 | SetDataFolder root: |
---|
747 | |
---|
748 | Return(0) |
---|
749 | End |
---|
750 | |
---|
751 | // fills the "default" fake header so that the SANS Reduction machinery does not have to be altered |
---|
752 | // pay attention to what is/not to be trusted due to "fake" information. |
---|
753 | // uses what it can from the header lines from the ASC file (hdrLines wave) |
---|
754 | // |
---|
755 | // destFolder is of the form "myGlobals:WorkMath:AAA" |
---|
756 | // |
---|
757 | // |
---|
758 | // called by WorkFileUtils.ipf |
---|
759 | // |
---|
760 | // If the ASC data was generated by the NCNR data writer, then |
---|
761 | // NOTHING NEEDS TO BE CHANGED HERE |
---|
762 | // |
---|
763 | Function FillFakeHeader_ASC(destFolder) |
---|
764 | String destFolder |
---|
765 | Make/O/N=23 $("root:"+destFolder+":IntegersRead") |
---|
766 | Make/O/N=52 $("root:"+destFolder+":RealsRead") |
---|
767 | Make/O/T/N=11 $("root:"+destFolder+":TextRead") |
---|
768 | |
---|
769 | Wave intw=$("root:"+destFolder+":IntegersRead") |
---|
770 | Wave realw=$("root:"+destFolder+":RealsRead") |
---|
771 | Wave/T textw=$("root:"+destFolder+":TextRead") |
---|
772 | |
---|
773 | //Put in appropriate "fake" values |
---|
774 | //parse values as needed from headerLines |
---|
775 | Wave/T hdr=$("root:"+destFolder+":hdrLines") |
---|
776 | Variable monCt,lam,offset,sdd,trans,thick |
---|
777 | Variable xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam |
---|
778 | String detTyp="" |
---|
779 | String tempStr="",formatStr="",junkStr="" |
---|
780 | formatStr = "%g %g %g %g %g %g" |
---|
781 | tempStr=hdr[3] |
---|
782 | sscanf tempStr, formatStr, monCt,lam,offset,sdd,trans,thick |
---|
783 | // Print monCt,lam,offset,sdd,trans,thick,avStr,step |
---|
784 | formatStr = "%g %g %g %g %g %g %g %s" |
---|
785 | tempStr=hdr[5] |
---|
786 | sscanf tempStr,formatStr,xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp |
---|
787 | // Print xCtr,yCtr,a1,a2,a1a2Dist,dlam,bsDiam,detTyp |
---|
788 | |
---|
789 | realw[16]=xCtr //xCtr(pixels) |
---|
790 | realw[17]=yCtr //yCtr (pixels) |
---|
791 | realw[18]=sdd //SDD (m) |
---|
792 | realw[26]=lam //wavelength (A) |
---|
793 | // |
---|
794 | // necessary values |
---|
795 | realw[10]=8 //detector calibration constants, needed for averaging |
---|
796 | realw[11]=10000 |
---|
797 | realw[12]=0 |
---|
798 | realw[13]=8 |
---|
799 | realw[14]=10000 |
---|
800 | realw[15]=0 |
---|
801 | // |
---|
802 | // used in the resolution calculation, ONLY here to keep the routine from crashing |
---|
803 | realw[20]=102 //det size |
---|
804 | realw[27]=dlam //delta lambda |
---|
805 | realw[21]=bsDiam //BS size |
---|
806 | realw[23]=a1 //A1 |
---|
807 | realw[24]=a2 //A2 |
---|
808 | realw[25]=a1a2Dist //A1A2 distance |
---|
809 | realw[4]=trans //trans |
---|
810 | realw[3]=0 //atten |
---|
811 | realw[5]=thick //thick |
---|
812 | // |
---|
813 | // |
---|
814 | realw[0]=monCt //def mon cts |
---|
815 | |
---|
816 | // fake values to get valid deadtime and detector constants |
---|
817 | // |
---|
818 | textw[9]=detTyp+" " //6 characters 4+2 spaces |
---|
819 | textw[3]="[NGxSANS00]" //11 chars, NGx will return default values for atten trans, deadtime... |
---|
820 | |
---|
821 | //set the string values |
---|
822 | formatStr="FILE: %s CREATED: %s" |
---|
823 | sscanf hdr[0],formatStr,tempStr,junkStr |
---|
824 | // Print tempStr |
---|
825 | // Print junkStr |
---|
826 | String/G $("root:"+destFolder+":fileList") = tempStr |
---|
827 | textw[0] = tempStr //filename |
---|
828 | textw[1] = junkStr //run date-time |
---|
829 | |
---|
830 | //file label = hdr[1] |
---|
831 | tempStr = hdr[1] |
---|
832 | tempStr = tempStr[0,strlen(tempStr)-2] //clean off the last LF |
---|
833 | // Print tempStr |
---|
834 | textW[6] = tempStr //sample label |
---|
835 | |
---|
836 | return(0) |
---|
837 | End |
---|
838 | |
---|
839 | |
---|
840 | ///////// ACCESSORS FOR WRITING DATA TO HEADER ///////// |
---|
841 | ///// |
---|
842 | |
---|
843 | // Write* routines all must: |
---|
844 | // (1) open file "fname". fname is a full file path and name to the file on disk |
---|
845 | // (2) write the specified value to the header at the correct location in the file |
---|
846 | // (3) close the file |
---|
847 | |
---|
848 | //sample transmission (0<T<=1) |
---|
849 | Function WriteTransmissionToHeader(fname,trans) |
---|
850 | String fname |
---|
851 | Variable trans |
---|
852 | |
---|
853 | // your writer here |
---|
854 | |
---|
855 | WriteReal(fname,trans,5589) //I will define at position 10 lines position 1 by myself |
---|
856 | |
---|
857 | // 16 bites between numbers and 81 per line |
---|
858 | |
---|
859 | return(0) |
---|
860 | End |
---|
861 | |
---|
862 | //whole transmission is NCNR-specific right now |
---|
863 | // leave this stub empty |
---|
864 | Function WriteWholeTransToHeader(fname,trans) |
---|
865 | String fname |
---|
866 | Variable trans |
---|
867 | |
---|
868 | // do nothing for now |
---|
869 | WriteReal(fname,trans,6885) /// //I will define at position last lines position 1 by myself |
---|
870 | |
---|
871 | return(0) |
---|
872 | End |
---|
873 | |
---|
874 | //box sum counts is a real value |
---|
875 | // used for transmission calculation module |
---|
876 | Function WriteBoxCountsToHeader(fname,counts) |
---|
877 | String fname |
---|
878 | Variable counts |
---|
879 | |
---|
880 | // do nothing if not using NCNR Transmission module |
---|
881 | |
---|
882 | WriteReal(fname,counts,6868) |
---|
883 | |
---|
884 | ////I will define at position 2 lines before the end and last position by myself |
---|
885 | |
---|
886 | |
---|
887 | return(0) |
---|
888 | End |
---|
889 | |
---|
890 | //beam stop X-position |
---|
891 | // used for transmission module to manually tag transmission files |
---|
892 | Function WriteBSXPosToHeader(fname,xpos) |
---|
893 | String fname |
---|
894 | Variable xpos |
---|
895 | |
---|
896 | // do nothing if not using NCNR Transmission module |
---|
897 | |
---|
898 | WriteReal(fname,xpos,5119) ////should do it for ypos for ILL ....NEED TO REMEMBER HERE |
---|
899 | /// line 4 column 2 |
---|
900 | |
---|
901 | return(0) |
---|
902 | End |
---|
903 | |
---|
904 | //sample thickness in cm |
---|
905 | Function WriteThicknessToHeader(fname,num) |
---|
906 | String fname |
---|
907 | Variable num |
---|
908 | |
---|
909 | // your code here |
---|
910 | |
---|
911 | WriteReal(fname,num,5508) //define at 9 lines column 1 just above transmission by myself |
---|
912 | |
---|
913 | return(0) |
---|
914 | End |
---|
915 | |
---|
916 | //beam center X pixel location (detector coordinates) |
---|
917 | Function WriteBeamCenterXToHeader(fname,num) |
---|
918 | String fname |
---|
919 | Variable num |
---|
920 | |
---|
921 | // your code here |
---|
922 | |
---|
923 | // pos (1) on line 71 => 70 lines x 81 char |
---|
924 | WriteReal(fname,num*10,5670) |
---|
925 | |
---|
926 | /// line 11 column 1 |
---|
927 | |
---|
928 | return(0) |
---|
929 | End |
---|
930 | |
---|
931 | //beam center Y pixel location (detector coordinates) |
---|
932 | Function WriteBeamCenterYToHeader(fname,num) |
---|
933 | String fname |
---|
934 | Variable num |
---|
935 | |
---|
936 | // your code here |
---|
937 | |
---|
938 | WriteReal(fname,num*10,5686) |
---|
939 | |
---|
940 | /// line 11 column 2 |
---|
941 | |
---|
942 | return(0) |
---|
943 | End |
---|
944 | |
---|
945 | //attenuator number (not its transmission) |
---|
946 | // if your beam attenuation is indexed in some way, use that number here |
---|
947 | // if not, write a 1 to the file here as a default |
---|
948 | // |
---|
949 | Function WriteAttenNumberToHeader(fname,num) |
---|
950 | String fname |
---|
951 | Variable num |
---|
952 | |
---|
953 | // your code here, default of 1 |
---|
954 | WriteReal(fname,num,5799) |
---|
955 | |
---|
956 | /// line 12 column 4 |
---|
957 | |
---|
958 | return(0) |
---|
959 | End |
---|
960 | |
---|
961 | |
---|
962 | Function WritereactorpowerToHeader(fname,num) |
---|
963 | String fname |
---|
964 | Variable num |
---|
965 | |
---|
966 | // your code here, default of 1 |
---|
967 | WriteReal(fname,num,6204) |
---|
968 | |
---|
969 | /// line 12 column 4 |
---|
970 | |
---|
971 | return(0) |
---|
972 | End |
---|
973 | |
---|
974 | |
---|
975 | |
---|
976 | |
---|
977 | |
---|
978 | |
---|
979 | |
---|
980 | |
---|
981 | // total monitor count during data collection |
---|
982 | Function WriteMonitorCountToHeader(fname,num) |
---|
983 | String fname |
---|
984 | Variable num |
---|
985 | |
---|
986 | // your code here |
---|
987 | |
---|
988 | WriteReal(fname,num,4924) |
---|
989 | |
---|
990 | /// line 1 column 5 |
---|
991 | |
---|
992 | return(0) |
---|
993 | End |
---|
994 | |
---|
995 | //total detector count |
---|
996 | Function WriteDetectorCountToHeader(fname,num) |
---|
997 | String fname |
---|
998 | Variable num |
---|
999 | |
---|
1000 | // your code here |
---|
1001 | |
---|
1002 | WriteReal(fname,num,4908) |
---|
1003 | |
---|
1004 | /// line 1 column 4 |
---|
1005 | |
---|
1006 | return(0) |
---|
1007 | End |
---|
1008 | |
---|
1009 | //transmission detector count |
---|
1010 | // (currently unused in data reduction) |
---|
1011 | Function WriteTransDetCountToHeader(fname,num) |
---|
1012 | String fname |
---|
1013 | Variable num |
---|
1014 | |
---|
1015 | // do nothing for now |
---|
1016 | |
---|
1017 | return(0) |
---|
1018 | End |
---|
1019 | |
---|
1020 | //wavelength (Angstroms) |
---|
1021 | Function WriteWavelengthToHeader(fname,num) |
---|
1022 | String fname |
---|
1023 | Variable num |
---|
1024 | |
---|
1025 | // your code here |
---|
1026 | WriteReal(fname,num,5703) |
---|
1027 | |
---|
1028 | // line 11 column 3 |
---|
1029 | |
---|
1030 | return(0) |
---|
1031 | End |
---|
1032 | |
---|
1033 | //wavelength spread (FWHM) |
---|
1034 | Function WriteWavelengthDistrToHeader(fname,num) |
---|
1035 | String fname |
---|
1036 | Variable num |
---|
1037 | |
---|
1038 | // your code here |
---|
1039 | |
---|
1040 | WriteReal(fname,num,5719) |
---|
1041 | |
---|
1042 | // line 11 column 4 |
---|
1043 | |
---|
1044 | return(0) |
---|
1045 | End |
---|
1046 | |
---|
1047 | //temperature of the sample (C) |
---|
1048 | Function WriteTemperatureToHeader(fname,num) |
---|
1049 | String fname |
---|
1050 | Variable num |
---|
1051 | |
---|
1052 | // your code here |
---|
1053 | |
---|
1054 | WriteReal(fname,num,5347) |
---|
1055 | |
---|
1056 | // line 7 column 1 |
---|
1057 | |
---|
1058 | return(0) |
---|
1059 | End |
---|
1060 | |
---|
1061 | //magnetic field (Oe) |
---|
1062 | Function WriteMagnFieldToHeader(fname,num) |
---|
1063 | String fname |
---|
1064 | Variable num |
---|
1065 | |
---|
1066 | // your code here |
---|
1067 | |
---|
1068 | return(0) |
---|
1069 | End |
---|
1070 | |
---|
1071 | //Source Aperture diameter (millimeters) |
---|
1072 | Function WriteSourceApDiamToHeader(fname,num) |
---|
1073 | String fname |
---|
1074 | Variable num |
---|
1075 | |
---|
1076 | // your code here |
---|
1077 | // WriteReal(fname,num,5348) |
---|
1078 | WriteReal(fname,num,6027) ///4*81 = 324 |
---|
1079 | |
---|
1080 | // line 15 colum 3 |
---|
1081 | |
---|
1082 | return(0) |
---|
1083 | End |
---|
1084 | |
---|
1085 | //Sample Aperture diameter (millimeters) |
---|
1086 | Function WriteSampleApDiamToHeader(fname,num) |
---|
1087 | String fname |
---|
1088 | Variable num |
---|
1089 | |
---|
1090 | //your code here |
---|
1091 | WriteReal(fname,num,6043) |
---|
1092 | |
---|
1093 | // line 15 colum 4 |
---|
1094 | |
---|
1095 | return(0) |
---|
1096 | End |
---|
1097 | |
---|
1098 | //Source aperture to sample aperture distance (meters) |
---|
1099 | Function WriteSrcToSamDistToHeader(fname,num) |
---|
1100 | String fname |
---|
1101 | Variable num |
---|
1102 | |
---|
1103 | // your code here |
---|
1104 | WriteReal(fname,num,5784) //it is collimation at ILL |
---|
1105 | |
---|
1106 | |
---|
1107 | return(0) |
---|
1108 | End |
---|
1109 | |
---|
1110 | //lateral detector offset (centimeters) |
---|
1111 | Function WriteDetectorOffsetToHeader(fname,num) |
---|
1112 | String fname |
---|
1113 | Variable num |
---|
1114 | |
---|
1115 | //your code here |
---|
1116 | |
---|
1117 | WriteReal(fname,10*num,5849) |
---|
1118 | |
---|
1119 | |
---|
1120 | |
---|
1121 | // line 13 column 2 |
---|
1122 | |
---|
1123 | return(0) |
---|
1124 | End |
---|
1125 | |
---|
1126 | //beam stop diameter (millimeters) |
---|
1127 | Function WriteBeamStopDiamToHeader(fname,num) |
---|
1128 | String fname |
---|
1129 | Variable num |
---|
1130 | |
---|
1131 | // your code here |
---|
1132 | WriteReal(fname,num,6059) |
---|
1133 | |
---|
1134 | //line 15 column 5 |
---|
1135 | |
---|
1136 | return(0) |
---|
1137 | End |
---|
1138 | |
---|
1139 | //sample to detector distance (meters) |
---|
1140 | Function WriteSDDToHeader(fname,num) |
---|
1141 | String fname |
---|
1142 | Variable num |
---|
1143 | |
---|
1144 | //your code here |
---|
1145 | //WriteReal(fname,num,5152) |
---|
1146 | |
---|
1147 | |
---|
1148 | WriteReal(fname,num,5265) |
---|
1149 | |
---|
1150 | // line 4 column 4 |
---|
1151 | |
---|
1152 | // real calculated distance line 6 colunm1 |
---|
1153 | |
---|
1154 | return(0) |
---|
1155 | End |
---|
1156 | |
---|
1157 | // physical dimension of detector x-pixel (mm) |
---|
1158 | Function WriteDetPixelXToHeader(fname,num) |
---|
1159 | String fname |
---|
1160 | Variable num |
---|
1161 | |
---|
1162 | //your code here |
---|
1163 | WriteReal(fname,num,5735) |
---|
1164 | |
---|
1165 | // line 11 column 5 |
---|
1166 | |
---|
1167 | return(0) |
---|
1168 | end |
---|
1169 | |
---|
1170 | // physical dimension of detector y-pixel (mm) |
---|
1171 | Function WriteDetPixelYToHeader(fname,num) |
---|
1172 | String fname |
---|
1173 | Variable num |
---|
1174 | |
---|
1175 | //your code here |
---|
1176 | WriteReal(fname,num,5752) |
---|
1177 | |
---|
1178 | return(0) |
---|
1179 | end |
---|
1180 | |
---|
1181 | // sample label string |
---|
1182 | Function WriteSamLabelToHeader(fname,str) |
---|
1183 | String fname,str |
---|
1184 | |
---|
1185 | // your code here |
---|
1186 | // WriteText(fname," ",2075) // need to write in 30 bites no more.... |
---|
1187 | |
---|
1188 | Variable numChars=30 |
---|
1189 | String blankStr="" |
---|
1190 | blankStr = PadString(blankStr, numChars, 0x20) |
---|
1191 | WriteText(fname,blankStr,2075) |
---|
1192 | |
---|
1193 | if(strlen(str)>numChars) |
---|
1194 | str = str[0,numchars-1] |
---|
1195 | endif |
---|
1196 | |
---|
1197 | WriteText(fname,str,2075) //// need to change that in order to erase the title and write a new one |
---|
1198 | |
---|
1199 | return(0) |
---|
1200 | End |
---|
1201 | |
---|
1202 | // total counting time (stored here as seconds/10??) |
---|
1203 | Function WriteCountTimeToHeader(fname,num) |
---|
1204 | String fname |
---|
1205 | Variable num |
---|
1206 | |
---|
1207 | // your code here |
---|
1208 | // WriteReal(fname,num,4894) |
---|
1209 | WriteReal(fname,10*num,4892) |
---|
1210 | |
---|
1211 | |
---|
1212 | |
---|
1213 | return(0) |
---|
1214 | End |
---|
1215 | |
---|
1216 | |
---|
1217 | |
---|
1218 | //////// ACCESSORS FOR READING DATA FROM THE HEADER ////////////// |
---|
1219 | // |
---|
1220 | // read specific bits of information from the header |
---|
1221 | // each of these operations MUST take care of open/close on their own |
---|
1222 | // |
---|
1223 | // fname is the full path and filname to the file on disk |
---|
1224 | // return values are either strings or real values as appropriate |
---|
1225 | // |
---|
1226 | ////// |
---|
1227 | |
---|
1228 | |
---|
1229 | // function that reads in the 2D detector data and fills the array |
---|
1230 | // data[nx][ny] with the data values |
---|
1231 | // fname is the full name and path to the data file for opening and closing |
---|
1232 | // |
---|
1233 | // |
---|
1234 | Function getDetectorData(fname,data) |
---|
1235 | String fname |
---|
1236 | Wave data |
---|
1237 | |
---|
1238 | |
---|
1239 | // your reader here |
---|
1240 | |
---|
1241 | // value = getRealValueFromHeader_2(fname,60,28,5,1,3) // data start at 60+58 lines |
---|
1242 | ReadILLData2(fname,data) |
---|
1243 | |
---|
1244 | return (0) |
---|
1245 | End |
---|
1246 | |
---|
1247 | // file suffix (NCNR data file name specific) |
---|
1248 | // return null string |
---|
1249 | Function/S getSuffix(fname) |
---|
1250 | String fname |
---|
1251 | |
---|
1252 | String suffix = getStringFromHeader(fname,9341,6) |
---|
1253 | |
---|
1254 | // replace the leading space w/ "0" |
---|
1255 | suffix = ReplaceString(" ",suffix,"0") |
---|
1256 | |
---|
1257 | return(suffix) //// file suffix (6 characters @ byte 9341) |
---|
1258 | End |
---|
1259 | |
---|
1260 | // associated file suffix (for transmission) |
---|
1261 | // NCNR Transmission calculation specific |
---|
1262 | // return null string |
---|
1263 | Function/S getAssociatedFileSuffix(fname) |
---|
1264 | String fname |
---|
1265 | |
---|
1266 | string str |
---|
1267 | |
---|
1268 | str= getStringFromHeader(fname,9350,6) |
---|
1269 | |
---|
1270 | // replace leading space(s) w/zero |
---|
1271 | str = ReplaceString(" ", str, "0" ) |
---|
1272 | // print str |
---|
1273 | |
---|
1274 | return(str) // 6 characters @ byte 9350 |
---|
1275 | End |
---|
1276 | |
---|
1277 | // sample label |
---|
1278 | Function/S getSampleLabel(fname) |
---|
1279 | String fname |
---|
1280 | |
---|
1281 | String str |
---|
1282 | |
---|
1283 | // your code, returning str |
---|
1284 | str = (getStringFromHeader(fname,2075,30)) /// 25*81 + 50////+51 30 lines before the end |
---|
1285 | |
---|
1286 | |
---|
1287 | return(str) |
---|
1288 | End |
---|
1289 | |
---|
1290 | // file creation date |
---|
1291 | Function/S getFileCreationDate(fname) |
---|
1292 | String fname |
---|
1293 | |
---|
1294 | String str |
---|
1295 | |
---|
1296 | // your code, returning str |
---|
1297 | |
---|
1298 | str = (getStringFromHeader(fname,2106,50)) //324 +12 |
---|
1299 | |
---|
1300 | return(str) |
---|
1301 | End |
---|
1302 | |
---|
1303 | |
---|
1304 | Function/S getFileInstrument(fname) |
---|
1305 | String fname |
---|
1306 | |
---|
1307 | String str |
---|
1308 | |
---|
1309 | // your code, returning str |
---|
1310 | |
---|
1311 | str = (getStringFromHeader(fname,324,3)) //324 +12 |
---|
1312 | |
---|
1313 | return(str) |
---|
1314 | End |
---|
1315 | |
---|
1316 | |
---|
1317 | //reactor power |
---|
1318 | Function getReactorpower(fname) |
---|
1319 | String fname |
---|
1320 | |
---|
1321 | Variable value |
---|
1322 | |
---|
1323 | // your code returning value |
---|
1324 | |
---|
1325 | // value = getRealValueFromHeader_2(fname,60,28,5,1,5) // |
---|
1326 | |
---|
1327 | value = getRealValueFromHeader(fname,83) |
---|
1328 | |
---|
1329 | // print value |
---|
1330 | |
---|
1331 | return(value) |
---|
1332 | end |
---|
1333 | |
---|
1334 | |
---|
1335 | |
---|
1336 | |
---|
1337 | |
---|
1338 | //monitor count |
---|
1339 | Function getMonitorCount(fname) |
---|
1340 | String fname |
---|
1341 | |
---|
1342 | Variable value |
---|
1343 | |
---|
1344 | // your code returning value |
---|
1345 | |
---|
1346 | // value = getRealValueFromHeader_2(fname,60,28,5,1,5) // |
---|
1347 | |
---|
1348 | value = getRealValueFromHeader(fname,4) |
---|
1349 | |
---|
1350 | // print value |
---|
1351 | |
---|
1352 | return(value) |
---|
1353 | end |
---|
1354 | |
---|
1355 | //saved monitor count |
---|
1356 | // NCNR specific for pre-processed data, never used |
---|
1357 | // return 0 |
---|
1358 | Function getSavMon(fname) |
---|
1359 | String fname |
---|
1360 | |
---|
1361 | Variable value |
---|
1362 | |
---|
1363 | // your code returning value |
---|
1364 | |
---|
1365 | return(0) |
---|
1366 | end |
---|
1367 | |
---|
1368 | //total detector count |
---|
1369 | Function getDetCount(fname) |
---|
1370 | String fname |
---|
1371 | |
---|
1372 | Variable value |
---|
1373 | |
---|
1374 | // your code returning value |
---|
1375 | |
---|
1376 | // value = getRealValueFromHeader_2(fname,60,28,5,1,4) |
---|
1377 | |
---|
1378 | value = getRealValueFromHeader(fname,3) |
---|
1379 | |
---|
1380 | return(value) |
---|
1381 | end |
---|
1382 | |
---|
1383 | //Attenuator number, return 1 if your attenuators are not |
---|
1384 | // indexed by number |
---|
1385 | Function getAttenNumber(fname) |
---|
1386 | String fname |
---|
1387 | |
---|
1388 | Variable value |
---|
1389 | |
---|
1390 | // your code returning value |
---|
1391 | |
---|
1392 | // value = getRealValueFromHeader_2(fname,60,28,5,56,4) |
---|
1393 | |
---|
1394 | value = getRealValueFromHeader(fname,58) |
---|
1395 | |
---|
1396 | return(value) |
---|
1397 | end |
---|
1398 | |
---|
1399 | //transmission |
---|
1400 | Function getSampleTrans(fname) |
---|
1401 | String fname |
---|
1402 | |
---|
1403 | Variable value |
---|
1404 | |
---|
1405 | // your code returning value |
---|
1406 | |
---|
1407 | value = getRealValueFromHeader(fname,45) |
---|
1408 | |
---|
1409 | return(value) |
---|
1410 | end |
---|
1411 | |
---|
1412 | //box counts from stored transmission calculation |
---|
1413 | // return 0 if not using NCNR transmission module |
---|
1414 | Function getBoxCounts(fname) |
---|
1415 | String fname |
---|
1416 | |
---|
1417 | Variable value |
---|
1418 | |
---|
1419 | // your code returning value |
---|
1420 | value = getRealValueFromHeader(fname,124) |
---|
1421 | |
---|
1422 | return(value) |
---|
1423 | end |
---|
1424 | |
---|
1425 | //whole detector trasmission |
---|
1426 | // return 0 if not using NCNR transmission module |
---|
1427 | Function getSampleTransWholeDetector(fname) |
---|
1428 | String fname |
---|
1429 | |
---|
1430 | Variable value |
---|
1431 | |
---|
1432 | // your code returning value |
---|
1433 | |
---|
1434 | return(value) |
---|
1435 | end |
---|
1436 | |
---|
1437 | //SampleThickness in centimeters |
---|
1438 | Function getSampleThickness(fname) |
---|
1439 | String fname |
---|
1440 | |
---|
1441 | Variable value |
---|
1442 | |
---|
1443 | // your code returning value |
---|
1444 | value = getRealValueFromHeader(fname,40) //mm |
---|
1445 | |
---|
1446 | return(value) |
---|
1447 | end |
---|
1448 | |
---|
1449 | //Sample Rotation Angle (degrees) |
---|
1450 | Function getSampleRotationAngle(fname) |
---|
1451 | String fname |
---|
1452 | |
---|
1453 | Variable value |
---|
1454 | |
---|
1455 | // your code returning value |
---|
1456 | value = getRealValueFromHeader(fname,64) |
---|
1457 | |
---|
1458 | return(value) |
---|
1459 | end |
---|
1460 | |
---|
1461 | //temperature (C) |
---|
1462 | Function getTemperature(fname) |
---|
1463 | String fname |
---|
1464 | |
---|
1465 | Variable value |
---|
1466 | |
---|
1467 | // your code returning value |
---|
1468 | |
---|
1469 | // value = getRealValueFromHeader_2(fname,60,28,5,7,1) |
---|
1470 | |
---|
1471 | value = getRealValueFromHeader(fname,30) |
---|
1472 | |
---|
1473 | return(value) |
---|
1474 | end |
---|
1475 | |
---|
1476 | //field strength (Oe) |
---|
1477 | Function getFieldStrength(fname) |
---|
1478 | String fname |
---|
1479 | |
---|
1480 | Variable value |
---|
1481 | |
---|
1482 | // your code returning value |
---|
1483 | |
---|
1484 | return(value) |
---|
1485 | end |
---|
1486 | |
---|
1487 | //center of beam xPos in pixel coordinates |
---|
1488 | Function getBeamXPos(fname) |
---|
1489 | String fname |
---|
1490 | |
---|
1491 | Variable value |
---|
1492 | |
---|
1493 | // your code returning value |
---|
1494 | // value = getRealValueFromHeader(fname,14) //Lionel |
---|
1495 | value = getRealValueFromHeader(fname,50)/10 //SRK |
---|
1496 | |
---|
1497 | return(value) |
---|
1498 | end |
---|
1499 | |
---|
1500 | //center of beam Y pos in pixel coordinates |
---|
1501 | Function getBeamYPos(fname) |
---|
1502 | String fname |
---|
1503 | |
---|
1504 | Variable value |
---|
1505 | |
---|
1506 | // your code returning value |
---|
1507 | // value = getRealValueFromHeader(fname,15) //Lionel |
---|
1508 | value = getRealValueFromHeader(fname,51)/10 //SRK |
---|
1509 | |
---|
1510 | return(value) |
---|
1511 | end |
---|
1512 | |
---|
1513 | //sample to detector distance (meters) |
---|
1514 | Function getSDD(fname) |
---|
1515 | String fname |
---|
1516 | |
---|
1517 | Variable value |
---|
1518 | |
---|
1519 | // your code returning value |
---|
1520 | // value = getRealValueFromHeader_2(fname,60,28,5,4,4) |
---|
1521 | // value = getRealValueFromHeader(fname,18) detector distance but need to add the offset due to the table |
---|
1522 | |
---|
1523 | value = getRealValueFromHeader(fname,25) |
---|
1524 | |
---|
1525 | |
---|
1526 | return(value) |
---|
1527 | end |
---|
1528 | |
---|
1529 | //lateral detector offset (centimeters) |
---|
1530 | Function getDetectorOffset(fname) |
---|
1531 | String fname |
---|
1532 | |
---|
1533 | Variable value |
---|
1534 | |
---|
1535 | // your code returning value |
---|
1536 | // value = getRealValueFromHeader_2(fname,60,28,5,13,2) |
---|
1537 | value = getRealValueFromHeader(fname,61) |
---|
1538 | |
---|
1539 | return(value/10) // need in cm ILL write in mm |
---|
1540 | end |
---|
1541 | |
---|
1542 | //Beamstop diameter (millimeters) |
---|
1543 | Function getBSDiameter(fname) |
---|
1544 | String fname |
---|
1545 | |
---|
1546 | Variable value |
---|
1547 | |
---|
1548 | // your code returning value |
---|
1549 | |
---|
1550 | // value = getRealValueFromHeader_2(fname,60,28,5,15,5) |
---|
1551 | value = getRealValueFromHeader(fname,74) |
---|
1552 | |
---|
1553 | return(value) |
---|
1554 | end |
---|
1555 | |
---|
1556 | //source aperture diameter (millimeters) |
---|
1557 | Function getSourceApertureDiam(fname) |
---|
1558 | String fname |
---|
1559 | |
---|
1560 | Variable value |
---|
1561 | |
---|
1562 | // your code returning value |
---|
1563 | |
---|
1564 | value = 52 |
---|
1565 | |
---|
1566 | return(value) |
---|
1567 | end |
---|
1568 | |
---|
1569 | //sample aperture diameter (millimeters) |
---|
1570 | Function getSampleApertureDiam(fname) |
---|
1571 | String fname |
---|
1572 | |
---|
1573 | Variable value |
---|
1574 | |
---|
1575 | // your code returning value |
---|
1576 | // value = getRealValueFromHeader_2(fname,60,28,5,15,3) |
---|
1577 | value = getRealValueFromHeader(fname,72) |
---|
1578 | |
---|
1579 | value = 10 |
---|
1580 | |
---|
1581 | return(value) |
---|
1582 | end |
---|
1583 | |
---|
1584 | //source AP to Sample AP distance (meters) |
---|
1585 | Function getSourceToSampleDist(fname) |
---|
1586 | String fname |
---|
1587 | |
---|
1588 | Variable value |
---|
1589 | |
---|
1590 | // your code returning value |
---|
1591 | |
---|
1592 | // value = getRealValueFromHeader_2(fname,60,28,5,12,3) |
---|
1593 | |
---|
1594 | value = getRealValueFromHeader(fname,57) |
---|
1595 | |
---|
1596 | return(value) |
---|
1597 | end |
---|
1598 | |
---|
1599 | //wavelength (Angstroms) |
---|
1600 | Function getWavelength(fname) |
---|
1601 | String fname |
---|
1602 | |
---|
1603 | Variable value |
---|
1604 | |
---|
1605 | // your code returning value |
---|
1606 | // value = getRealValueFromHeader_2(fname,60,28,5,11,3) |
---|
1607 | value = getRealValueFromHeader(fname,52) |
---|
1608 | |
---|
1609 | return(value) |
---|
1610 | end |
---|
1611 | |
---|
1612 | //wavelength spread (FWHM) |
---|
1613 | Function getWavelengthSpread(fname) |
---|
1614 | String fname |
---|
1615 | |
---|
1616 | Variable value |
---|
1617 | |
---|
1618 | // your code returning value |
---|
1619 | value = getRealValueFromHeader(fname,53) |
---|
1620 | |
---|
1621 | |
---|
1622 | return(value) |
---|
1623 | end |
---|
1624 | |
---|
1625 | // physical x-dimension of a detector pixel, in mm |
---|
1626 | Function getDetectorPixelXSize(fname) |
---|
1627 | String fname |
---|
1628 | |
---|
1629 | Variable value |
---|
1630 | |
---|
1631 | // your code here returning value |
---|
1632 | // value = getRealValueFromHeader_2(fname,60,28,5,11,5) |
---|
1633 | value = getRealValueFromHeader(fname,54) |
---|
1634 | |
---|
1635 | return(value) |
---|
1636 | end |
---|
1637 | |
---|
1638 | // physical y-dimension of a detector pixel, in mm |
---|
1639 | Function getDetectorPixelYSize(fname) |
---|
1640 | String fname |
---|
1641 | |
---|
1642 | Variable value |
---|
1643 | |
---|
1644 | // your code here returning value |
---|
1645 | // value = getRealValueFromHeader_2(fname,60,28,5,12,1) |
---|
1646 | value = getRealValueFromHeader(fname,55) |
---|
1647 | |
---|
1648 | return(value) |
---|
1649 | end |
---|
1650 | |
---|
1651 | //transmission detector count (unused, return 0) |
---|
1652 | // |
---|
1653 | Function getTransDetectorCounts(fname) |
---|
1654 | String fname |
---|
1655 | |
---|
1656 | Variable value |
---|
1657 | |
---|
1658 | // your code returning value |
---|
1659 | |
---|
1660 | return(0) |
---|
1661 | end |
---|
1662 | |
---|
1663 | |
---|
1664 | //total count time (seconds) |
---|
1665 | // stored here as (s/10), so multiply by 10 ? |
---|
1666 | Function getCountTime(fname) |
---|
1667 | String fname |
---|
1668 | |
---|
1669 | Variable value |
---|
1670 | |
---|
1671 | // your code returning value |
---|
1672 | |
---|
1673 | // value = getRealValueFromHeader_2(fname,60,28,5,1,3) /// line 1 col 3 |
---|
1674 | |
---|
1675 | value = getRealValueFromHeader(fname,2)/10 |
---|
1676 | |
---|
1677 | return(value) |
---|
1678 | end |
---|
1679 | |
---|
1680 | |
---|
1681 | //reads the wavelength from a reduced data file (not very reliable) |
---|
1682 | // - does not work with NSORTed files |
---|
1683 | // - only used in FIT/RPA (which itself is almost NEVER used...) |
---|
1684 | // |
---|
1685 | // DOES NOT NEED TO BE CHANGED IF USING NCNR DATA WRITER |
---|
1686 | Function GetLambdaFromReducedData(tempName) |
---|
1687 | String tempName |
---|
1688 | |
---|
1689 | String junkString |
---|
1690 | Variable lambdaFromFile, fileVar |
---|
1691 | lambdaFromFile = 6.0 |
---|
1692 | Open/R/P=catPathName fileVar as tempName |
---|
1693 | FReadLine fileVar, junkString |
---|
1694 | FReadLine fileVar, junkString |
---|
1695 | FReadLine fileVar, junkString |
---|
1696 | if(strsearch(LowerStr(junkString),"lambda",0) != -1) |
---|
1697 | FReadLine/N=11 fileVar, junkString |
---|
1698 | FReadLine/N=10 fileVar, junkString |
---|
1699 | lambdaFromFile = str2num(junkString) |
---|
1700 | endif |
---|
1701 | Close fileVar |
---|
1702 | |
---|
1703 | return(lambdaFromFile) |
---|
1704 | End |
---|
1705 | |
---|
1706 | ///// TRANSMISSION RELATED FUNCTIONS //////// |
---|
1707 | //box coordinate are returned by reference |
---|
1708 | // |
---|
1709 | // box to sum over is bounded (x1,y1) to (x2,y2) |
---|
1710 | // |
---|
1711 | // this function returns the bounding coordinates as stored in |
---|
1712 | // the header |
---|
1713 | // |
---|
1714 | // if not using the NCNR Transmission module, this function default to |
---|
1715 | // returning 0000, and no changes needed |
---|
1716 | // |
---|
1717 | // filename is the full path:name to the file |
---|
1718 | Function getXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
1719 | String filename |
---|
1720 | Variable &x1,&x2,&y1,&y2 |
---|
1721 | |
---|
1722 | // return your bounding box coordinates or default values of 0 |
---|
1723 | x1=getRealValueFromHeader(filename,120) |
---|
1724 | x2=getRealValueFromHeader(filename,121) |
---|
1725 | y1=getRealValueFromHeader(filename,122) |
---|
1726 | y2=getRealValueFromHeader(filename,123) |
---|
1727 | |
---|
1728 | // print "in get", x1,x2,y1,y2 |
---|
1729 | |
---|
1730 | return(0) |
---|
1731 | End |
---|
1732 | |
---|
1733 | // Writes the coordinates of the box to the header after user input |
---|
1734 | // |
---|
1735 | // box to sum over bounded (x1,y1) to (x2,y2) |
---|
1736 | // |
---|
1737 | // if not using the NCNR Transmission module, this function is null |
---|
1738 | // |
---|
1739 | // filename as passed in is a full path:filename |
---|
1740 | // |
---|
1741 | Function WriteXYBoxToHeader(filename,x1,x2,y1,y2) |
---|
1742 | String filename |
---|
1743 | Variable x1,x2,y1,y2 |
---|
1744 | |
---|
1745 | // your code to write bounding box to the header, or nothing |
---|
1746 | |
---|
1747 | WriteReal(filename,x1,6804) |
---|
1748 | WriteReal(filename,x2,6820) |
---|
1749 | WriteReal(filename,y1,6836) |
---|
1750 | WriteReal(filename,y2,6852) |
---|
1751 | |
---|
1752 | // use the last full line and the 4 first numbers |
---|
1753 | |
---|
1754 | // print "in write",x1,x2,y1,y2 |
---|
1755 | |
---|
1756 | // should start at 120 for read and line 25 |
---|
1757 | |
---|
1758 | /// 84 *81 |
---|
1759 | |
---|
1760 | return(0) |
---|
1761 | End |
---|
1762 | |
---|
1763 | // for transmission calculation, writes an NCNR-specific alphanumeric identifier |
---|
1764 | // (suffix of the data file) |
---|
1765 | // |
---|
1766 | // if not using the NCNR Transmission module, this function is null |
---|
1767 | Function WriteAssocFileSuffixToHeader(fname,suffix) |
---|
1768 | String fname,suffix |
---|
1769 | |
---|
1770 | // replace leading space(s) w/zero |
---|
1771 | suffix = ReplaceString(" ", suffix, "0" ) |
---|
1772 | |
---|
1773 | suffix = suffix[0,5] //limit to 6 characters |
---|
1774 | |
---|
1775 | WriteText(fname,suffix,9350) |
---|
1776 | |
---|
1777 | |
---|
1778 | return(0) |
---|
1779 | end |
---|
1780 | |
---|
1781 | Function/S getStringFromHeader(fname,start,num) |
---|
1782 | String fname //full path:name |
---|
1783 | Variable start,num //starting byte and number of characters to read |
---|
1784 | |
---|
1785 | String str |
---|
1786 | Variable refnum |
---|
1787 | Open/R refNum as fname |
---|
1788 | FSetPos refNum,start |
---|
1789 | FReadLine/N=(num) refNum,str |
---|
1790 | Close refnum |
---|
1791 | |
---|
1792 | return(str) |
---|
1793 | End |
---|
1794 | |
---|
1795 | Function getRealValueFromHeader(fname,start) |
---|
1796 | String fname |
---|
1797 | Variable start |
---|
1798 | Variable numLinesLoaded = 0,firstchar,countTime |
---|
1799 | variable refnum |
---|
1800 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread,result |
---|
1801 | String buffer |
---|
1802 | Make/O/D/N=128 TemporaryHeader |
---|
1803 | // Make/O/D/N=(128) data |
---|
1804 | |
---|
1805 | Open/R refNum as fname //if fname is "", a dialog will be presented |
---|
1806 | if(refnum==0) |
---|
1807 | return(1) //user cancelled |
---|
1808 | endif |
---|
1809 | |
---|
1810 | //skip the next 10 lines |
---|
1811 | For(ii=0;ii<60;ii+=1) |
---|
1812 | FReadLine refnum,buffer |
---|
1813 | EndFor |
---|
1814 | |
---|
1815 | // read in the whole header |
---|
1816 | For (ii=60;ii<188;ii+=1) |
---|
1817 | |
---|
1818 | numlinesloaded = ii-60 |
---|
1819 | FReadLine refNum,buffer //assume a 2nd line is there, w/16 values |
---|
1820 | sscanf buffer,"%g %g %g %g %g ",v0,v1,v2,v3,v4 |
---|
1821 | valuesRead = V_flag |
---|
1822 | // print valuesRead |
---|
1823 | |
---|
1824 | // print buffer |
---|
1825 | |
---|
1826 | //valuesRead = V_flag |
---|
1827 | // print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9 |
---|
1828 | // print buffer |
---|
1829 | |
---|
1830 | TemporaryHeader[5*numlinesloaded] = v0 |
---|
1831 | TemporaryHeader[5*numlinesloaded+1] = v1 //monitor |
---|
1832 | TemporaryHeader[5*numlinesloaded+2] = v2 |
---|
1833 | TemporaryHeader[5*numlinesloaded+3] = v3 |
---|
1834 | TemporaryHeader[5*numlinesloaded+4] = v4 |
---|
1835 | Endfor |
---|
1836 | |
---|
1837 | Close refNum |
---|
1838 | result= TemporaryHeader[start] |
---|
1839 | // KillWaves/Z TemporaryHeader |
---|
1840 | |
---|
1841 | return (result) |
---|
1842 | End |
---|
1843 | |
---|
1844 | //Function getRealValueFromHeader_1(fname,start) |
---|
1845 | // String fname |
---|
1846 | // Variable start |
---|
1847 | // |
---|
1848 | // String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=1/W=1/Q" |
---|
1849 | // |
---|
1850 | // GBLoadStr += "/S="+num2str(start)+"/U=10" + "\"" + fname + "\"" |
---|
1851 | // Execute GBLoadStr |
---|
1852 | // Wave w=$"tempGBWave0" |
---|
1853 | // |
---|
1854 | // return(w[0]) |
---|
1855 | //End |
---|
1856 | |
---|
1857 | //Function getRealValueFromHeader_2(fname,start,numrow,numcol,rowbit,colbit) |
---|
1858 | // String fname |
---|
1859 | // Variable start,numcol,numrow,colbit,rowbit |
---|
1860 | // variable result |
---|
1861 | // make /O/D/N=(numrow) w0,w1,w2,w3,w4 |
---|
1862 | // Make/O/D/N=(numrow,numcol) dataread |
---|
1863 | // |
---|
1864 | // |
---|
1865 | // loadwave /A=tempGBwave/L={0, start, numrow, 0, numcol}/N/G/D/O/K=1 fname |
---|
1866 | // |
---|
1867 | // Wave/Z tempGBwave0=tempGBwave0 |
---|
1868 | // Wave/Z tempGBwave1=tempGBwave1 |
---|
1869 | // Wave/Z tempGBwave2=tempGBwave2 |
---|
1870 | // Wave/Z tempGBwave3=tempGBwave3 |
---|
1871 | // Wave/Z tempGBwave4=tempGBwave4 |
---|
1872 | // |
---|
1873 | // |
---|
1874 | // w0=tempGBWave0 |
---|
1875 | // w1=tempGBWave1 |
---|
1876 | // w2=tempGBWave2 |
---|
1877 | // w3=tempGBWave3 |
---|
1878 | // w4=tempGBWave4 |
---|
1879 | // |
---|
1880 | ///// redimension could use that to redimension dataread in only one colunm... but will see later.. |
---|
1881 | // |
---|
1882 | // |
---|
1883 | // |
---|
1884 | // KillWaves/Z tempGBwave0,tempGBwave1,tempGBwave3,tempGBwave2,tempGBwave4 |
---|
1885 | // /// Make/O/D/N=(numrow,numcol),wres |
---|
1886 | // |
---|
1887 | // dataread[][0] = w0[p] |
---|
1888 | // dataread[][1] = w1[p] |
---|
1889 | // dataread[][2] = w2[p] |
---|
1890 | // dataread[][3] = w3[p] |
---|
1891 | // dataread[][4] = w4[p] |
---|
1892 | // |
---|
1893 | //KillWaves/Z w0,w1,w2,w3,w4 |
---|
1894 | // |
---|
1895 | //// wave wres = $"tempGBwave" +num2str(linebit-1) |
---|
1896 | // result = dataread[rowbit-1][colbit-1] |
---|
1897 | // |
---|
1898 | // return(result) |
---|
1899 | //End |
---|
1900 | |
---|
1901 | |
---|
1902 | //Function ReadILLData(fname) |
---|
1903 | // String fname |
---|
1904 | // |
---|
1905 | // NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
1906 | // NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
1907 | // Variable refNum=0,ii,p1,p2,tot,num=pixelsX,numHdrLines=118 ///waas 20 for NIST |
---|
1908 | // String str="" |
---|
1909 | // //data is initially linear scale |
---|
1910 | // Variable/G :gIsLogScale=0 |
---|
1911 | // Make/O/T/N=(numHdrLines) hdrLines |
---|
1912 | // Make/O/D/N=(pixelsX*pixelsY) data |
---|
1913 | // Make/O/D/N=(1638,10) datahelp //,linear_data |
---|
1914 | // |
---|
1915 | // //full filename and path is now passed in... |
---|
1916 | // //actually open the file |
---|
1917 | //// SetDataFolder destPath |
---|
1918 | // Open/R/Z refNum as fname // /Z flag means I must handle open errors |
---|
1919 | // if(refnum==0) //FNF error, get out |
---|
1920 | // DoAlert 0,"Could not find file: "+fname |
---|
1921 | // Close/A |
---|
1922 | // SetDataFolder root: |
---|
1923 | // return(1) |
---|
1924 | // endif |
---|
1925 | // if(V_flag!=0) |
---|
1926 | // DoAlert 0,"File open error: V_flag="+num2Str(V_Flag) |
---|
1927 | // Close/A |
---|
1928 | // SetDataFolder root: |
---|
1929 | // return(1) |
---|
1930 | // Endif |
---|
1931 | // // |
---|
1932 | // for(ii=0;ii<numHdrLines;ii+=1) //read (or skip) 18 header lines |
---|
1933 | // FReadLine refnum,str |
---|
1934 | // hdrLines[ii]=str |
---|
1935 | // endfor |
---|
1936 | // // |
---|
1937 | // Close refnum |
---|
1938 | // |
---|
1939 | //// SetDataFolder destPath |
---|
1940 | // |
---|
1941 | //// loadwave /A=tempt/L={0, 118, 1638, 1, 10}/N/J/D/O/E=1/K=1 fname |
---|
1942 | // |
---|
1943 | //loadwave /A=tempt/L={0, 0, 1638, 0, 10}/N/G/D/O/E=1/K=1 fname |
---|
1944 | // |
---|
1945 | //Wave/Z tempt0=tempt0 |
---|
1946 | // Wave/Z tempt1=tempt1 |
---|
1947 | // Wave/Z tempt2=tempt2 |
---|
1948 | // Wave/Z tempt3=tempt3 |
---|
1949 | // Wave/Z tempt4=tempt4 |
---|
1950 | // Wave/Z tempt5=tempt5 |
---|
1951 | // Wave/Z tempt6=tempt6 |
---|
1952 | // Wave/Z tempt7=tempt7 |
---|
1953 | // Wave/Z tempt8=tempt8 |
---|
1954 | // Wave/Z tempt9=tempt9 |
---|
1955 | // |
---|
1956 | // |
---|
1957 | // |
---|
1958 | // |
---|
1959 | // datahelp[][0]=tempt0[p] |
---|
1960 | // datahelp[][1]=tempt1[p] |
---|
1961 | // datahelp[][2]=tempt2[p] |
---|
1962 | // datahelp[][3]=tempt3[p] |
---|
1963 | // datahelp[][4]=tempt4[p] |
---|
1964 | // datahelp[][5]=tempt5[p] |
---|
1965 | // datahelp[][6]=tempt6[p] |
---|
1966 | // datahelp[][7]=tempt7[p] |
---|
1967 | // datahelp[][8]=tempt8[p] |
---|
1968 | // datahelp[][9]=tempt9[p] |
---|
1969 | // |
---|
1970 | // Killwaves/Z tempt1,tempt2,tempt3,tempt4,tempt0,tempt5,tempt6,tempt7,tempt8,tempt9 |
---|
1971 | // |
---|
1972 | /////////////Wave/Z tempt0=tempt0 |
---|
1973 | /////data=tempt |
---|
1974 | // |
---|
1975 | // |
---|
1976 | // Redimension/N=(pixelsX,pixelsY) datahelp |
---|
1977 | // |
---|
1978 | // |
---|
1979 | //// LoadWave/Q/J/D/E=1/V={" " ,"non",1,1}/N=temp fName |
---|
1980 | //// Wave/Z temp0=temp0 |
---|
1981 | //// data=temp0 |
---|
1982 | //// Redimension/N=(pixelsX,pixelsY) data //,linear_data |
---|
1983 | // |
---|
1984 | // //linear_data = data |
---|
1985 | // |
---|
1986 | // KillWaves/Z temp0 |
---|
1987 | // |
---|
1988 | // //return the data folder to root |
---|
1989 | // SetDataFolder root: |
---|
1990 | // |
---|
1991 | // Return(0) |
---|
1992 | //End |
---|
1993 | |
---|
1994 | |
---|
1995 | |
---|
1996 | Function ReadILLData2(fname,data) |
---|
1997 | String fname |
---|
1998 | wave data |
---|
1999 | |
---|
2000 | Variable numLinesLoaded = 0,firstchar,countTime |
---|
2001 | variable refnum |
---|
2002 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v0,ii,valuesread |
---|
2003 | String buffer |
---|
2004 | Make/O/D/N=16384 Dataline //temporary storage |
---|
2005 | |
---|
2006 | Open/R refNum as fname //if fname is "", a dialog will be presented |
---|
2007 | if(refnum==0) |
---|
2008 | return(1) //user cancelled |
---|
2009 | endif |
---|
2010 | |
---|
2011 | //skip the next 10 lines |
---|
2012 | For(ii=0;ii<118;ii+=1) |
---|
2013 | FReadLine refnum,buffer |
---|
2014 | EndFor |
---|
2015 | |
---|
2016 | For (ii=118;ii<1757;ii+=1) |
---|
2017 | numlinesloaded = ii-118 |
---|
2018 | FReadLine refNum,buffer //assume a 2nd line is there, w/16 values |
---|
2019 | sscanf buffer,"%g %g %g %g %g %g %g %g %g %g",v0,v1,v2,v3,v4,v5,v6,v7,v8,v9 |
---|
2020 | valuesRead = V_flag |
---|
2021 | // print valuesRead |
---|
2022 | // buffer |
---|
2023 | //valuesRead = V_flag |
---|
2024 | // print ii,refnum,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9 |
---|
2025 | // print buffer |
---|
2026 | |
---|
2027 | if(ii == 1756) |
---|
2028 | dataline[10*numlinesloaded] = v0 //last line has only four values |
---|
2029 | dataline[10*numlinesloaded+1] = v1 |
---|
2030 | dataline[10*numlinesloaded+2] = v2 |
---|
2031 | dataline[10*numlinesloaded+3] = v3 |
---|
2032 | else |
---|
2033 | dataline[10*numlinesloaded] = v0 //reading in 10 values per line |
---|
2034 | dataline[10*numlinesloaded+1] = v1 |
---|
2035 | dataline[10*numlinesloaded+2] = v2 |
---|
2036 | dataline[10*numlinesloaded+3] = v3 |
---|
2037 | dataline[10*numlinesloaded+4] = v4 |
---|
2038 | dataline[10*numlinesloaded+5] = v5 |
---|
2039 | dataline[10*numlinesloaded+6] = v6 |
---|
2040 | dataline[10*numlinesloaded+7] = v7 |
---|
2041 | dataline[10*numlinesloaded+8] = v8 |
---|
2042 | dataline[10*numlinesloaded+9] = v9 |
---|
2043 | endif |
---|
2044 | Endfor |
---|
2045 | |
---|
2046 | Close refNum |
---|
2047 | |
---|
2048 | data = dataline |
---|
2049 | redimension /N=(128,128) data |
---|
2050 | |
---|
2051 | // Killwaves/Z dataline |
---|
2052 | |
---|
2053 | return (0) |
---|
2054 | |
---|
2055 | end |
---|
2056 | |
---|
2057 | // Write* routines all must: |
---|
2058 | // (1) open file "fname". fname is a full file path and name to the file on disk |
---|
2059 | // (2) write the specified value to the header at the correct location in the file |
---|
2060 | // (3) close the file |
---|
2061 | |
---|
2062 | // |
---|
2063 | // ILL header values are 16 characters: one space followed by 15 bytes of the value, in scientific notation (pos 2 is the sign, last 4 are "e(+-)XX" ) |
---|
2064 | // SRK - May 2008 |
---|
2065 | Function WriteReal(path,value,start) |
---|
2066 | string path |
---|
2067 | variable value,start |
---|
2068 | |
---|
2069 | variable refnum |
---|
2070 | |
---|
2071 | String valStr |
---|
2072 | sprintf valStr, " %14e",value |
---|
2073 | // print valstr, strlen(valStr) |
---|
2074 | |
---|
2075 | Open/A/T= "????" refnum as path |
---|
2076 | |
---|
2077 | FStatus refnum |
---|
2078 | FSetPos refnum, start |
---|
2079 | FBinWrite refNum, valStr |
---|
2080 | FSetpos refnum,V_logEOF // correct length is 142317 total bytes |
---|
2081 | |
---|
2082 | Close refnum |
---|
2083 | |
---|
2084 | return (0) |
---|
2085 | |
---|
2086 | end |
---|
2087 | |
---|
2088 | |
---|
2089 | Function/S PromptForPathtest(msgStr) |
---|
2090 | String msgStr |
---|
2091 | String fullPath |
---|
2092 | Variable refnum |
---|
2093 | |
---|
2094 | //this just asks for the filename, doesn't open the file |
---|
2095 | Open/D/R/T="????"/M=(msgStr) refNum |
---|
2096 | fullPath = S_FileName //fname is the full path |
---|
2097 | // Print refnum,fullPath |
---|
2098 | |
---|
2099 | //null string is returned in S_FileName if user cancelled, and is passed back to calling function |
---|
2100 | Return(fullPath) |
---|
2101 | End |
---|
2102 | |
---|
2103 | |
---|
2104 | /// !!!! Make sure the text string is the correct LENGTH before sending it here!!! |
---|
2105 | // SRK - May 2008 |
---|
2106 | Function WriteText(path,str,start) |
---|
2107 | string path,str |
---|
2108 | variable start |
---|
2109 | |
---|
2110 | variable refnum |
---|
2111 | |
---|
2112 | Open/A/T= "????TEXT" refnum as path |
---|
2113 | |
---|
2114 | FStatus refnum |
---|
2115 | FSetPos refnum, start |
---|
2116 | FBinWrite/F=0 refnum, str //native object format (character) |
---|
2117 | FSetPos refnum,V_logEOF |
---|
2118 | |
---|
2119 | Close refnum |
---|
2120 | |
---|
2121 | return (0) |
---|
2122 | |
---|
2123 | end |
---|
2124 | ////// OCT 2009, facility specific bits from ProDiv() |
---|
2125 | //"type" is the data folder that has the corrected, patched, and normalized DIV data array |
---|
2126 | // |
---|
2127 | // the header of this file is rather unimportant. Filling in a title at least would be helpful/ |
---|
2128 | // |
---|
2129 | Function Write_DIV_File(type) |
---|
2130 | String type |
---|
2131 | |
---|
2132 | // Your file writing function here. Don't try to duplicate the VAX binary format... |
---|
2133 | |
---|
2134 | return(0) |
---|
2135 | End |
---|