1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=1.00 |
---|
3 | #pragma IgorVersion=6.1 |
---|
4 | |
---|
5 | |
---|
6 | #if( Exists("XmlOpenFile") ) |
---|
7 | |
---|
8 | #include "cansasXML_v11", version >= 1.10 |
---|
9 | |
---|
10 | // The function is called "LoadNISTXMLData" but is actually more generic |
---|
11 | // and will load any canSAS XML v1 dataset |
---|
12 | // Dec 2008 : |
---|
13 | // Caveats - Assumes Q in /A and I in /cm |
---|
14 | // Takes outStr as output name. If outStr is specified then we must load only the first SASData in the firstSASEntry, |
---|
15 | // since anything else doesn't make sense. This is a bit of a hack to support NSORT. |
---|
16 | |
---|
17 | |
---|
18 | function LoadNISTXMLData(filestr,outStr,doPlot,forceOverwrite) |
---|
19 | String filestr,outStr |
---|
20 | Variable doPlot,forceOverwrite |
---|
21 | |
---|
22 | |
---|
23 | Variable rr,gg,bb |
---|
24 | NVAR dQv = root:Packages:NIST:USANS_dQv |
---|
25 | |
---|
26 | |
---|
27 | Print "Trying to load canSAS XML format data" |
---|
28 | Variable result = CS_XMLReader(filestr) |
---|
29 | |
---|
30 | String xmlReaderFolder = "root:Packages:CS_XMLreader:" |
---|
31 | |
---|
32 | if (result == 0) |
---|
33 | SetDataFolder xmlReaderFolder |
---|
34 | |
---|
35 | Variable i,j,numDataSets |
---|
36 | Variable np |
---|
37 | |
---|
38 | String w0,w1,w2,w3,w4,w5,basestr,fileName |
---|
39 | String xmlDataFolder,xmlDataSetFolder |
---|
40 | |
---|
41 | Variable numSASEntries |
---|
42 | |
---|
43 | if(!cmpStr(outStr,"")) |
---|
44 | //no outStr defined |
---|
45 | numSASEntries = CountObjects(xmlReaderFolder,4) |
---|
46 | else |
---|
47 | numSASEntries = 1 |
---|
48 | endif |
---|
49 | |
---|
50 | for (i = 0; i < numSASEntries; i+=1) |
---|
51 | |
---|
52 | xmlDataFolder = xmlReaderFolder+GetIndexedObjName(xmlReaderFolder,4,i)+":" |
---|
53 | if (!cmpstr(outstr,"")) |
---|
54 | numDataSets = CountObjects(xmlDataFolder,4) |
---|
55 | else |
---|
56 | numDataSets = 0 |
---|
57 | endif |
---|
58 | |
---|
59 | if (numDataSets > 0) |
---|
60 | //Multiple SASData sets in this SASEntry |
---|
61 | for (j = 0; j < numDataSets; j+=1) |
---|
62 | |
---|
63 | xmlDataSetFolder = xmlDataFolder+GetIndexedObjName(xmlDataFolder,4,j)+":" |
---|
64 | |
---|
65 | SetDataFolder xmlDataSetFolder |
---|
66 | |
---|
67 | basestr = CleanupName(getXMLDataSetTitle(xmlDataSetFolder,j),0) |
---|
68 | |
---|
69 | //String basestr = ParseFilePath(3, ParseFilePath(5,filestr,":",0,0),":",0,0) |
---|
70 | fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) |
---|
71 | |
---|
72 | |
---|
73 | //print "In NIST XML Loader" |
---|
74 | //print "fileStr: ",fileStr |
---|
75 | //print "basestr: ",basestr |
---|
76 | //print "fileName: ",fileName |
---|
77 | //remove the semicolon AND period from files from the VAX |
---|
78 | print basestr |
---|
79 | w0 = basestr + "_q" |
---|
80 | w1 = basestr + "_i" |
---|
81 | w2 = basestr + "_s" |
---|
82 | w3 = basestr + "sq" |
---|
83 | w4 = basestr + "qb" |
---|
84 | w5 = basestr + "fs" |
---|
85 | |
---|
86 | if(DataFolderExists("root:"+baseStr)) |
---|
87 | if(!forceOverwrite) |
---|
88 | DoAlert 1,"The data set " + basestr + " from file "+fileName+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
89 | if(V_flag==2) //user selected No, don't load the data |
---|
90 | SetDataFolder root: |
---|
91 | if(DataFolderExists("root:Packages:NIST")) |
---|
92 | String/G root:Packages:NIST:gLastFileName = filename |
---|
93 | endif //set the last file loaded to the one NOT loaded |
---|
94 | return 0 //quits the macro |
---|
95 | endif |
---|
96 | endif |
---|
97 | SetDataFolder $("root:"+baseStr) |
---|
98 | else |
---|
99 | NewDataFolder/S $("root:"+baseStr) |
---|
100 | endif |
---|
101 | |
---|
102 | Duplicate/O $(xmlDataSetFolder+"Qsas") $w0 |
---|
103 | Duplicate/O $(xmlDataSetFolder+"Isas") $w1 |
---|
104 | Duplicate/O $(xmlDataSetFolder+"Idev") $w2 |
---|
105 | |
---|
106 | |
---|
107 | if (exists(xmlDataSetFolder+"Qdev")) |
---|
108 | Wave Qsas = $(xmlDataSetFolder+"Qsas") |
---|
109 | Wave Qdev = $(xmlDataSetFolder+"Qdev") |
---|
110 | |
---|
111 | Duplicate/O Qdev, $w3 |
---|
112 | // make a resolution matrix for SANS data |
---|
113 | np=numpnts($w0) |
---|
114 | Make/D/O/N=(np,4) $(baseStr+"_res") |
---|
115 | Wave reswave = $(baseStr+"_res") |
---|
116 | |
---|
117 | reswave[][0] = Qdev[p] //sigQ |
---|
118 | reswave[][3] = Qsas[p] //Qvalues |
---|
119 | if(exists(xmlDataSetFolder+"Qmean")) |
---|
120 | Wave Qmean = $(xmlDataSetFolder+"Qmean") |
---|
121 | Duplicate/O Qmean,$w4 |
---|
122 | reswave[][1] = Qmean[p] //qBar |
---|
123 | endif |
---|
124 | if(exists(xmlDataSetFolder+"Shadowfactor")) |
---|
125 | Wave Shadowfactor = $(xmlDataSetFolder+"Shadowfactor") |
---|
126 | Duplicate/O Shadowfactor, $w5 |
---|
127 | reswave[][2] = Shadowfactor[p] //fShad |
---|
128 | endif |
---|
129 | elseif(exists(xmlDataSetFolder+"dQl")) |
---|
130 | //USAS Data |
---|
131 | Wave dQl = $(xmlDataSetFolder+"dQl") |
---|
132 | dQv = dQl[0] |
---|
133 | |
---|
134 | USANS_CalcWeights(baseStr,dQv) |
---|
135 | else |
---|
136 | //No resolution data |
---|
137 | endif |
---|
138 | //get rid of the resolution waves that are in the matrix |
---|
139 | |
---|
140 | SetScale d,0,0,"1/A",$w0 |
---|
141 | SetScale d,0,0,"1/cm",$w1 |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | ////// |
---|
146 | if(DataFolderExists("root:Packages:NIST")) |
---|
147 | String/G root:Packages:NIST:gLastFileName = filename |
---|
148 | endif |
---|
149 | |
---|
150 | |
---|
151 | //plot if desired |
---|
152 | if(doPlot) |
---|
153 | // assign colors randomly |
---|
154 | rr = abs(trunc(enoise(65535))) |
---|
155 | gg = abs(trunc(enoise(65535))) |
---|
156 | bb = abs(trunc(enoise(65535))) |
---|
157 | |
---|
158 | // if target window is a graph, and user wants to append, do so |
---|
159 | DoWindow/B Plot_Manager |
---|
160 | if(WinType("") == 1) |
---|
161 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
162 | if(V_Flag == 1) |
---|
163 | AppendToGraph $w1 vs $w0 |
---|
164 | ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1 |
---|
165 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
166 | ModifyGraph tickUnit(left)=1 |
---|
167 | else |
---|
168 | //new graph |
---|
169 | Display $w1 vs $w0 |
---|
170 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
171 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
172 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
173 | ModifyGraph tickUnit(left)=1 |
---|
174 | Legend |
---|
175 | endif |
---|
176 | else |
---|
177 | // graph window was not target, make new one |
---|
178 | Display $w1 vs $w0 |
---|
179 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
180 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
181 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
182 | ModifyGraph tickUnit(left)=1 |
---|
183 | Legend |
---|
184 | endif |
---|
185 | endif |
---|
186 | |
---|
187 | endfor |
---|
188 | |
---|
189 | |
---|
190 | else |
---|
191 | //No multiple SASData sets for this SASEntry |
---|
192 | SetDataFolder xmlDataFolder |
---|
193 | |
---|
194 | print xmlDataFolder |
---|
195 | |
---|
196 | //if outstr has been specified, we'll find ourselves here.... |
---|
197 | if (!cmpstr(outstr,"")) |
---|
198 | basestr = CleanupName(getXMLDataSetTitle(xmlDataFolder,0),0) |
---|
199 | else |
---|
200 | basestr = CleanupName(outstr,0) |
---|
201 | endif |
---|
202 | |
---|
203 | //String basestr = ParseFilePath(3, ParseFilePath(5,filestr,":",0,0),":",0,0) |
---|
204 | fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) |
---|
205 | |
---|
206 | //print "In NIST XML Loader" |
---|
207 | //print "fileStr: ",fileStr |
---|
208 | //print "basestr: ",basestr |
---|
209 | //print "fileName: ",fileName |
---|
210 | w0 = basestr + "_q" |
---|
211 | w1 = basestr + "_i" |
---|
212 | w2 = basestr + "_s" |
---|
213 | |
---|
214 | if(DataFolderExists("root:"+baseStr)) |
---|
215 | if(!forceOverwrite) |
---|
216 | DoAlert 1,"The data set " + basestr + " from file "+fileName+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
217 | if(V_flag==2) //user selected No, don't load the data |
---|
218 | SetDataFolder root: |
---|
219 | if(DataFolderExists("root:Packages:NIST")) |
---|
220 | String/G root:Packages:NIST:gLastFileName = filename |
---|
221 | endif //set the last file loaded to the one NOT loaded |
---|
222 | return 0 //quits the macro |
---|
223 | endif |
---|
224 | endif |
---|
225 | SetDataFolder $("root:"+baseStr) |
---|
226 | else |
---|
227 | NewDataFolder/S $("root:"+baseStr) |
---|
228 | endif |
---|
229 | |
---|
230 | Duplicate/O $(xmlDataFolder+"Qsas") $w0 |
---|
231 | Duplicate/O $(xmlDataFolder+"Isas") $w1 |
---|
232 | Duplicate/O $(xmlDataFolder+"Idev") $w2 |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | if (exists(xmlDataFolder+"Qdev")) |
---|
237 | Wave Qsas = $(xmlDataFolder+"Qsas") |
---|
238 | Wave Qdev = $(xmlDataFolder+"Qdev") |
---|
239 | |
---|
240 | // make a resolution matrix for SANS data |
---|
241 | np=numpnts($w0) |
---|
242 | Make/D/O/N=(np,4) $(baseStr+"_res") |
---|
243 | Wave reswave = $(baseStr+"_res") |
---|
244 | |
---|
245 | reswave[][0] = Qdev[p] //sigQ |
---|
246 | reswave[][3] = Qsas[p] //Qvalues |
---|
247 | if(exists(xmlDataFolder+"Qmean")) |
---|
248 | Wave Qmean = $(xmlDataFolder+"Qmean") |
---|
249 | reswave[][1] = Qmean[p] //qBar |
---|
250 | endif |
---|
251 | if(exists(xmlDataFolder+"Shadowfactor")) |
---|
252 | Wave Shadowfactor = $(xmlDataFolder+"Shadowfactor") |
---|
253 | reswave[][2] = Shadowfactor[p] //fShad |
---|
254 | endif |
---|
255 | elseif(exists(xmlDataFolder+"dQl")) |
---|
256 | //USAS Data |
---|
257 | Wave dQl = $(xmlDataFolder+"dQl") |
---|
258 | dQv = dQl[0] |
---|
259 | |
---|
260 | USANS_CalcWeights(baseStr,dQv) |
---|
261 | else |
---|
262 | //No resolution data |
---|
263 | endif |
---|
264 | //get rid of the resolution waves that are in the matrix |
---|
265 | |
---|
266 | SetScale d,0,0,"1/A",$w0 |
---|
267 | SetScale d,0,0,"1/cm",$w1 |
---|
268 | |
---|
269 | |
---|
270 | |
---|
271 | ////// |
---|
272 | if(DataFolderExists("root:Packages:NIST")) |
---|
273 | String/G root:Packages:NIST:gLastFileName = filename |
---|
274 | endif |
---|
275 | |
---|
276 | |
---|
277 | //plot if desired |
---|
278 | if(doPlot) |
---|
279 | // assign colors randomly |
---|
280 | rr = abs(trunc(enoise(65535))) |
---|
281 | gg = abs(trunc(enoise(65535))) |
---|
282 | bb = abs(trunc(enoise(65535))) |
---|
283 | |
---|
284 | // if target window is a graph, and user wants to append, do so |
---|
285 | DoWindow/B Plot_Manager |
---|
286 | if(WinType("") == 1) |
---|
287 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
288 | if(V_Flag == 1) |
---|
289 | AppendToGraph $w1 vs $w0 |
---|
290 | ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1 |
---|
291 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
292 | ModifyGraph tickUnit(left)=1 |
---|
293 | else |
---|
294 | //new graph |
---|
295 | Display $w1 vs $w0 |
---|
296 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
297 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
298 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
299 | ModifyGraph tickUnit(left)=1 |
---|
300 | Legend |
---|
301 | endif |
---|
302 | else |
---|
303 | // graph window was not target, make new one |
---|
304 | Display $w1 vs $w0 |
---|
305 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
306 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
307 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
308 | ModifyGraph tickUnit(left)=1 |
---|
309 | Legend |
---|
310 | endif |
---|
311 | endif |
---|
312 | |
---|
313 | endif |
---|
314 | endfor |
---|
315 | endif |
---|
316 | |
---|
317 | //go back to the root folder and clean up before leaving |
---|
318 | SetDataFolder root: |
---|
319 | //KillDataFolder xmlReaderFolder |
---|
320 | |
---|
321 | |
---|
322 | end |
---|
323 | |
---|
324 | |
---|
325 | function/S getXMLDataSetTitle(xmlDF,dsNum) |
---|
326 | String xmlDF |
---|
327 | Variable dsNum |
---|
328 | |
---|
329 | SVAR title = root:Packages:NIST:gXMLLoader_Title |
---|
330 | |
---|
331 | String mdstring = xmlDF+"metadata" |
---|
332 | |
---|
333 | Wave/T meta = $mdstring |
---|
334 | //Check for value when there are multiple datasets |
---|
335 | FindValue/TEXT="Title"/TXOP=4/Z meta |
---|
336 | title = TrimWS(meta[V_Value][1]) |
---|
337 | print meta[V_Value][1] |
---|
338 | print title |
---|
339 | //Check for Run value |
---|
340 | FindValue/TEXT="Run_"+num2str(dsNum)/TXOP=4/Z meta |
---|
341 | if (V_Value >= 0) |
---|
342 | title = title+" "+TrimWS(meta[V_Value][1]) |
---|
343 | print title |
---|
344 | else |
---|
345 | FindValue/TEXT="Run"/TXOP=4/Z meta |
---|
346 | if (V_Value >= 0) |
---|
347 | title = title+" "+TrimWS(meta[V_Value][1]) |
---|
348 | print title |
---|
349 | endif |
---|
350 | endif |
---|
351 | |
---|
352 | if (strlen(title) > 28) |
---|
353 | //Prompt title, "Set New Sample Name" |
---|
354 | //DoPrompt "Sample Name Is Too Long", title |
---|
355 | do |
---|
356 | Execute "getXMLShorterTitle()" |
---|
357 | while (strlen(title) > 28) |
---|
358 | endif |
---|
359 | |
---|
360 | return title |
---|
361 | end |
---|
362 | |
---|
363 | |
---|
364 | |
---|
365 | Proc getXMLShorterTitle() |
---|
366 | |
---|
367 | //NVAR title = root:myGlobals:gXMLLoader_Title |
---|
368 | |
---|
369 | DoWindow/K getNewTitle |
---|
370 | getNewTitle() |
---|
371 | |
---|
372 | PauseforUser getNewTitle |
---|
373 | end |
---|
374 | |
---|
375 | Window getNewTitle() |
---|
376 | |
---|
377 | PauseUpdate; Silent 1 // building window... |
---|
378 | NewPanel /W=(166,90,666,230) as "Sample Title Too Long!" |
---|
379 | SetDrawLayer UserBack |
---|
380 | DrawText 11,22,"The sample title is too long." |
---|
381 | DrawText 11,42,"Please enter a new one with a maximum length 28 characters" |
---|
382 | DrawText 11,72,"Current Sample Title:" |
---|
383 | GroupBox group0 pos={8,55},size={484,50} |
---|
384 | TitleBox tb_CurrentTitle,pos={150,57}, variable=root:Packages:NIST:gXMLLoader_Title,fSize=12,frame=0 |
---|
385 | SetVariable sv_NewTitle,pos={11,77},size={476,18},title="New Sample Title" |
---|
386 | SetVariable sv_NewTitle,fSize=12,value=root:Packages:NIST:gXMLLoader_Title |
---|
387 | Button btn_SetNewTitle title="Set New Title",pos={150,110},size={200,20} |
---|
388 | Button btn_SetNewTitle proc=SetNewTitleButtonProc |
---|
389 | |
---|
390 | EndMacro |
---|
391 | |
---|
392 | |
---|
393 | Proc SetNewTitleButtonProc(ctrlName) : ButtonControl |
---|
394 | String ctrlName |
---|
395 | |
---|
396 | DoWindow/K getNewTitle |
---|
397 | |
---|
398 | End |
---|
399 | |
---|
400 | //AJJ 12/5/08 |
---|
401 | |
---|
402 | //Define struct for file contents |
---|
403 | Structure NISTXMLfile |
---|
404 | // string filename |
---|
405 | string Run |
---|
406 | string title |
---|
407 | |
---|
408 | //<SASdata> |
---|
409 | Wave Q,I,Idev,Qdev,Qmean,Shadowfactor,dQl |
---|
410 | string unitsQ,unitsI,unitsIdev,unitsQdev,unitsQmean,unitsShadowfactor,unitsdQl |
---|
411 | |
---|
412 | // Variable flux_monitor |
---|
413 | // string Q_resolution |
---|
414 | |
---|
415 | //<SASsample> |
---|
416 | string sample_ID |
---|
417 | variable sample_thickness |
---|
418 | string unitssample_thickness |
---|
419 | variable sample_transmission |
---|
420 | |
---|
421 | //SASinstrument |
---|
422 | string nameSASinstrument |
---|
423 | // SASinstrument/SASsource |
---|
424 | string radiation |
---|
425 | // string beam_shape |
---|
426 | variable wavelength |
---|
427 | string unitswavelength |
---|
428 | variable wavelength_spread |
---|
429 | string unitswavelength_spread |
---|
430 | |
---|
431 | //<SAScollimation> |
---|
432 | // variable collimation_length |
---|
433 | // string unitscollimation_length |
---|
434 | variable source_aperture |
---|
435 | string unitssource_aperture |
---|
436 | string typesource_aperture |
---|
437 | variable sample_aperture |
---|
438 | string unitssample_aperture |
---|
439 | string typesample_aperture |
---|
440 | |
---|
441 | //SASdetector <SASdetector> |
---|
442 | string detector_name |
---|
443 | variable offset_angle |
---|
444 | string unitsoffset_angle |
---|
445 | variable SDD |
---|
446 | string unitsSDD |
---|
447 | variable beamcenter_X |
---|
448 | string unitsbeamcenter_X |
---|
449 | variable beamcenter_Y |
---|
450 | string unitsbeamcenter_Y |
---|
451 | // variable pixel_sizeX |
---|
452 | // string unitspixel_sizeX |
---|
453 | // variable pixel_sizeY |
---|
454 | // string unitspixel_sizeY |
---|
455 | // string detectortype |
---|
456 | |
---|
457 | // <SASprocess name="NCNR-IGOR"> |
---|
458 | string nameSASprocess |
---|
459 | string SASprocessnote |
---|
460 | // string SASprocessdate |
---|
461 | // string average_type |
---|
462 | // string SAM_file |
---|
463 | // string BKD_file |
---|
464 | // string EMP_file |
---|
465 | // string DIV_file |
---|
466 | // string MASK_file |
---|
467 | // string ABS_parameters |
---|
468 | // variable TSTAND |
---|
469 | // variable DSTAND |
---|
470 | // string unitsDSTAND |
---|
471 | // variable IZERO |
---|
472 | // variable XSECT |
---|
473 | // string unitsXSECT |
---|
474 | string SASnote |
---|
475 | Endstructure |
---|
476 | |
---|
477 | |
---|
478 | //Function to write NIST canSAS XML files |
---|
479 | //Minimalist XML file - AJJ Dec 2008 |
---|
480 | function writeNISTXML(fileName, NISTfile) |
---|
481 | String fileName |
---|
482 | Struct NISTXMLfile &NISTfile |
---|
483 | |
---|
484 | variable fileID |
---|
485 | |
---|
486 | //create the sasXML file with SASroot |
---|
487 | //no namespace, no prefix |
---|
488 | fileID = xmlcreatefile(fileName,"SASroot","cansas1d/1.0","") |
---|
489 | |
---|
490 | //create a version attribute for the root element |
---|
491 | xmlsetAttr(fileID,"/SASroot","","version","1.0") |
---|
492 | xmlsetAttr(fileID,"/SASroot","","xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") |
---|
493 | xmlsetAttr(fileID,"/SASroot","","xsi:schemaLocation","cansas1d/1.0 http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd") |
---|
494 | |
---|
495 | |
---|
496 | //create the SASentry node |
---|
497 | xmladdnode(fileID,"/SASroot","","SASentry","",1) |
---|
498 | |
---|
499 | //create the Title node |
---|
500 | xmladdnode(fileID,"/SASroot/SASentry","","Title",NISTfile.Title,1) |
---|
501 | |
---|
502 | //create the Run node |
---|
503 | xmladdnode(fileID,"/SASroot/SASentry","","Run",NISTfile.Run,1) |
---|
504 | |
---|
505 | //create the SASdata node |
---|
506 | xmladdnode(fileID,"/SASroot/SASentry","","SASdata","",1) |
---|
507 | |
---|
508 | variable ii |
---|
509 | |
---|
510 | if (WaveExists(NISTfile.dQl) == 1) |
---|
511 | for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1) |
---|
512 | xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1) |
---|
513 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1) |
---|
514 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ) |
---|
515 | |
---|
516 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1) |
---|
517 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI) |
---|
518 | |
---|
519 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1) |
---|
520 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev) |
---|
521 | |
---|
522 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.dQl[ii]),1) |
---|
523 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsdQl) |
---|
524 | endfor |
---|
525 | else |
---|
526 | for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1) |
---|
527 | xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1) |
---|
528 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1) |
---|
529 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ) |
---|
530 | |
---|
531 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1) |
---|
532 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI) |
---|
533 | |
---|
534 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1) |
---|
535 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev) |
---|
536 | |
---|
537 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qdev",num2str(NISTfile.Qdev[ii]),1) |
---|
538 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qdev","","unit",NISTfile.unitsQdev) |
---|
539 | |
---|
540 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qmean",num2str(NISTfile.Qmean[ii]),1) |
---|
541 | xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qmean","","unit",NISTfile.unitsQmean) |
---|
542 | |
---|
543 | xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Shadowfactor",num2str(NISTfile.shadowfactor[ii]),1) |
---|
544 | endfor |
---|
545 | endif |
---|
546 | |
---|
547 | //SASsample node |
---|
548 | xmladdnode(fileID,"/SASroot/SASentry","","SASsample","",1) |
---|
549 | xmladdnode(fileID,"/SASroot/SASentry/SASsample","","ID",NISTfile.sample_ID,1) |
---|
550 | |
---|
551 | //SASInstrument node |
---|
552 | xmladdnode(fileID,"/SASroot/SASentry","","SASinstrument","",1) |
---|
553 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","name",NISTfile.nameSASinstrument,1) |
---|
554 | |
---|
555 | //SASsource |
---|
556 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASsource","",1) |
---|
557 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","radiation",NISTfile.radiation,1) |
---|
558 | |
---|
559 | //SAScollimation |
---|
560 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SAScollimation","",1) |
---|
561 | |
---|
562 | //SASdetector |
---|
563 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASdetector","",1) |
---|
564 | xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","name",NISTfile.detector_name,1) |
---|
565 | |
---|
566 | |
---|
567 | //SASprocess |
---|
568 | xmladdnode(fileID,"/SASroot/SASentry","","SASprocess","",1) |
---|
569 | xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess","","name",NISTfile.nameSASprocess) |
---|
570 | xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SASprocessnote",NISTfile.SASprocessnote,1) |
---|
571 | |
---|
572 | //SASnote |
---|
573 | xmladdnode(fileID,"/SASroot/SASentry","","SASnote",NISTfile.SASnote,1) |
---|
574 | |
---|
575 | xmlsavefile(fileID) |
---|
576 | xmlclosefile(fileID,0) |
---|
577 | |
---|
578 | end |
---|
579 | |
---|
580 | Function convertNISTtoNISTXML(fileStr) |
---|
581 | String fileStr |
---|
582 | |
---|
583 | Struct NISTXMLfile nf |
---|
584 | |
---|
585 | Variable rr,gg,bb,refnum,dQv |
---|
586 | SetDataFolder root: |
---|
587 | |
---|
588 | if (cmpStr(fileStr,"") == 0) |
---|
589 | //No filename given, open dialog |
---|
590 | Open/D/R refnum |
---|
591 | if (cmpstr(S_filename,"") == 0) |
---|
592 | return 0 |
---|
593 | else |
---|
594 | fileStr = S_filename |
---|
595 | endif |
---|
596 | endif |
---|
597 | |
---|
598 | //Load the waves, using default waveX names |
---|
599 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
---|
600 | LoadWave/G/D/A/Q fileStr |
---|
601 | String fileNamePath = S_Path+S_fileName |
---|
602 | String basestr = CleanupName(ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0),0) |
---|
603 | // String baseStr = CleanupName(S_fileName,0) |
---|
604 | // print "basestr :"+basestr |
---|
605 | String fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) |
---|
606 | // print "filename :"+filename |
---|
607 | Variable numCols = V_flag |
---|
608 | String outfileName = S_Path+basestr+".xml" |
---|
609 | |
---|
610 | |
---|
611 | if(numCols==3) //simple 3-column data with no resolution information |
---|
612 | |
---|
613 | Wave nf.Q = $(StringFromList(0, S_waveNames ,";" )) |
---|
614 | Wave nf.I = $(StringFromList(1, S_waveNames ,";" )) |
---|
615 | Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" )) |
---|
616 | |
---|
617 | //Set units |
---|
618 | nf.unitsQ = "1/A" |
---|
619 | nf.unitsI = "1/cm" |
---|
620 | nf.unitsIdev = "1/cm" |
---|
621 | |
---|
622 | endif //3-col data |
---|
623 | |
---|
624 | if(numCols == 6) //6-column SANS or USANS data that has resolution information |
---|
625 | |
---|
626 | // put the names of the (default named) loaded waves into local names |
---|
627 | Wave nf.Q = $(StringFromList(0, S_waveNames ,";" )) |
---|
628 | Wave nf.I = $(StringFromList(1, S_waveNames ,";" )) |
---|
629 | Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" )) |
---|
630 | |
---|
631 | //Set units |
---|
632 | nf.unitsQ = "1/A" |
---|
633 | nf.unitsI = "1/cm" |
---|
634 | nf.unitsIdev = "1/cm" |
---|
635 | |
---|
636 | WAVE resTest = $(StringFromList(3, S_waveNames ,";" )) |
---|
637 | |
---|
638 | // need to switch based on SANS/USANS |
---|
639 | if (isSANSResolution(resTest[0])) //checks to see if the first point of the wave is <0] |
---|
640 | Wave nf.Qdev = $(StringFromList(3, S_waveNames ,";" )) |
---|
641 | Wave nf.Qmean = $(StringFromList(4, S_waveNames ,";" )) |
---|
642 | Wave nf.Shadowfactor = $(StringFromList(5, S_waveNames ,";" )) |
---|
643 | |
---|
644 | //Set units |
---|
645 | nf.unitsQdev = "1/A" |
---|
646 | nf.unitsQmean = "1/A" |
---|
647 | else |
---|
648 | Wave nf.dQl = $(StringFromList(3, S_waveNames ,";" )) |
---|
649 | |
---|
650 | //Set units |
---|
651 | nf.unitsdQl = "1/A" |
---|
652 | |
---|
653 | endif |
---|
654 | |
---|
655 | //Tidy up |
---|
656 | Variable i = 0 |
---|
657 | do |
---|
658 | WAVE wv= $(StringFromList(i,S_waveNames,";")) |
---|
659 | if( WaveExists(wv) == 0 ) |
---|
660 | break |
---|
661 | endif |
---|
662 | KillWaves wv |
---|
663 | i += 1 |
---|
664 | while (1) // exit is via break statement |
---|
665 | |
---|
666 | |
---|
667 | endif //6-col data |
---|
668 | |
---|
669 | //Get file header |
---|
670 | setmetadataFromASCHeader(fileStr,nf) |
---|
671 | |
---|
672 | //Set required metadata that we can't get from these files |
---|
673 | nf.detector_name = "Ordela 128x128" |
---|
674 | nf.nameSASinstrument = "NIST NG3/NG7 SANS" |
---|
675 | nf.radiation = "neutron" |
---|
676 | nf.sample_ID = nf.title |
---|
677 | nf.nameSASProcess = "NIST Data Converter" |
---|
678 | nf.sasnote = "Data converted from previous NIST format. SASProcessnote contains header from original text file." |
---|
679 | |
---|
680 | writeNISTXML(outfileName, nf) |
---|
681 | |
---|
682 | end |
---|
683 | |
---|
684 | function setmetadataFromASCHeader(fileStr,NISTfile) |
---|
685 | String fileStr |
---|
686 | Struct NISTXMLfile &NISTfile |
---|
687 | |
---|
688 | String hdr="",buffer="" |
---|
689 | Variable lineNum = 0, fileref |
---|
690 | Variable num |
---|
691 | |
---|
692 | Open/R fileref as fileStr |
---|
693 | do |
---|
694 | FReadLine fileref, buffer |
---|
695 | if (stringmatch(buffer,"*The 6 columns are*") == 1) |
---|
696 | break |
---|
697 | endif |
---|
698 | buffer = RemoveEnding(buffer) |
---|
699 | print buffer |
---|
700 | //Get run value |
---|
701 | if (stringmatch(buffer,"*file:*") == 1) |
---|
702 | NISTfile.run = TrimWS(StringFromList(0,StringFromList(1, buffer, ":"),"C")) |
---|
703 | elseif (stringmatch(buffer,"combined file*") == 1) |
---|
704 | NISTfile.run = "Combined Data" |
---|
705 | endif |
---|
706 | |
---|
707 | //Get title value |
---|
708 | if (stringmatch(buffer,"*FIRST File LABEL:*") == 1) |
---|
709 | NISTfile.title = TrimWS(StringFromList(1,buffer, ":")) |
---|
710 | elseif(stringmatch(buffer,"*LABEL:*") == 1) |
---|
711 | NISTfile.title = TrimWS(StringFromList(1,buffer, ":")) |
---|
712 | endif |
---|
713 | |
---|
714 | hdr += buffer+"\n" |
---|
715 | while(strlen(buffer) > 0) |
---|
716 | |
---|
717 | if (strlen(NISTfile.title) == 0) |
---|
718 | NISTfile.title = CleanupName(ParseFilePath(3,ParseFilePath(5,fileStr,":",0,0),":",0,0),0) |
---|
719 | endif |
---|
720 | if (strlen(NISTfile.run) == 0) |
---|
721 | NISTfile.run = "Unknown" |
---|
722 | endif |
---|
723 | |
---|
724 | NISTfile.sasprocessnote = RemoveEnding(hdr) |
---|
725 | |
---|
726 | end |
---|
727 | |
---|
728 | //for writing out data (q-i-s) from the "type" folder, and including reduction information |
---|
729 | //if fullpath is a complete HD path:filename, no dialog will be presented |
---|
730 | //if fullpath is just a filename, the save dialog will be presented |
---|
731 | //if dialog = 1, a dialog will always be presented |
---|
732 | // |
---|
733 | // root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol |
---|
734 | // |
---|
735 | //AJJ Nov 2009 : This version of the function currently only works for Circular, Sector and Rectangular averages |
---|
736 | //i.e. anything that produces I vs Q. Need to add ability to handle Annular (I vs theta) but that requires namespace addition to XML format |
---|
737 | //and handling on load. |
---|
738 | Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) |
---|
739 | String type,fullpath |
---|
740 | Variable dialog //=1 will present dialog for name |
---|
741 | |
---|
742 | Struct NISTXMLfile nf |
---|
743 | |
---|
744 | String destStr="" |
---|
745 | destStr = "root:Packages:NIST:"+type |
---|
746 | |
---|
747 | Variable refNum |
---|
748 | // String fname,ave="C",hdrStr1="",hdrStr2="" |
---|
749 | // Variable step=1 |
---|
750 | |
---|
751 | //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** |
---|
752 | WAVE intw=$(destStr + ":integersRead") |
---|
753 | WAVE rw=$(destStr + ":realsRead") |
---|
754 | WAVE/T textw=$(destStr + ":textRead") |
---|
755 | WAVE qvals =$(destStr + ":qval") |
---|
756 | WAVE inten=$(destStr + ":aveint") |
---|
757 | WAVE sig=$(destStr + ":sigave") |
---|
758 | WAVE qbar = $(destStr + ":QBar") |
---|
759 | WAVE sigmaq = $(destStr + ":SigmaQ") |
---|
760 | WAVE fsubs = $(destStr + ":fSubS") |
---|
761 | |
---|
762 | |
---|
763 | SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr |
---|
764 | Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr) |
---|
765 | |
---|
766 | |
---|
767 | //check each wave |
---|
768 | If(!(WaveExists(intw))) |
---|
769 | Abort "intw DNExist BinaryWrite_W_Protocol()" |
---|
770 | Endif |
---|
771 | If(!(WaveExists(rw))) |
---|
772 | Abort "rw DNExist BinaryWrite_W_Protocol()" |
---|
773 | Endif |
---|
774 | If(!(WaveExists(textw))) |
---|
775 | Abort "textw DNExist BinaryWrite_W_Protocol()" |
---|
776 | Endif |
---|
777 | If(!(WaveExists(qvals))) |
---|
778 | Abort "qvals DNExist BinaryWrite_W_Protocol()" |
---|
779 | Endif |
---|
780 | If(!(WaveExists(inten))) |
---|
781 | Abort "inten DNExist BinaryWrite_W_Protocol()" |
---|
782 | Endif |
---|
783 | If(!(WaveExists(sig))) |
---|
784 | Abort "sig DNExist BinaryWrite_W_Protocol()" |
---|
785 | Endif |
---|
786 | If(!(WaveExists(qbar))) |
---|
787 | Abort "qbar DNExist BinaryWrite_W_Protocol()" |
---|
788 | Endif |
---|
789 | If(!(WaveExists(sigmaq))) |
---|
790 | Abort "sigmaq DNExist BinaryWrite_W_Protocol()" |
---|
791 | Endif |
---|
792 | If(!(WaveExists(fsubs))) |
---|
793 | Abort "fsubs DNExist BinaryWrite_W_Protocol()" |
---|
794 | Endif |
---|
795 | If(!(WaveExists(proto))) |
---|
796 | Abort "current protocol wave DNExist BinaryWrite_W_Protocol()" |
---|
797 | Endif |
---|
798 | |
---|
799 | if(dialog) |
---|
800 | PathInfo/S catPathName |
---|
801 | fullPath = DoSaveFileDialog("Save data as") |
---|
802 | If(cmpstr(fullPath,"")==0) |
---|
803 | //user cancel, don't write out a file |
---|
804 | Close/A |
---|
805 | Abort "no data file was written" |
---|
806 | Endif |
---|
807 | //Print "dialog fullpath = ",fullpath |
---|
808 | Endif |
---|
809 | |
---|
810 | SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") |
---|
811 | //actually open the file here |
---|
812 | //Open refNum as fullpath |
---|
813 | |
---|
814 | //Data |
---|
815 | Wave nf.Q = qvals |
---|
816 | nf.unitsQ = "1/A" |
---|
817 | Wave nf.I = inten |
---|
818 | nf.unitsI = "1/cm" |
---|
819 | Wave nf.Idev = sig |
---|
820 | nf.unitsIdev = "1/cm" |
---|
821 | Wave nf.Qdev = sigmaq |
---|
822 | nf.unitsQdev = "1/A" |
---|
823 | Wave nf.Qmean = qbar |
---|
824 | nf.unitsQmean = "1/A" |
---|
825 | Wave nf.Shadowfactor = fSubS |
---|
826 | nf.unitsShadowfactor = "none" |
---|
827 | |
---|
828 | |
---|
829 | //write out the standard header information |
---|
830 | //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] |
---|
831 | |
---|
832 | //AJJ to fix with sensible values |
---|
833 | nf.run = "Test" |
---|
834 | String acct = textw[3] |
---|
835 | nf.nameSASinstrument = acct[1,3] |
---|
836 | nf.SASnote = "" |
---|
837 | // |
---|
838 | nf.sample_ID = textw[6] |
---|
839 | nf.title = textw[6] |
---|
840 | nf.radiation = "neutron" |
---|
841 | nf.wavelength = rw[26] |
---|
842 | nf.unitswavelength = "A" |
---|
843 | nf.offset_angle = rw[19] |
---|
844 | nf.unitsoffset_angle = "cm" |
---|
845 | nf.SDD = rw[18] |
---|
846 | nf.unitsSDD = "m" |
---|
847 | nf.sample_transmission = rw[4] |
---|
848 | nf.sample_thickness = rw[5] |
---|
849 | nf.unitssample_thickness = "mm" |
---|
850 | |
---|
851 | nf.beamcenter_X = rw[16] |
---|
852 | nf.beamcenter_Y = rw[17] |
---|
853 | nf.unitsbeamcenter_X = "pixels" |
---|
854 | nf.unitsbeamcenter_Y = "pixels" |
---|
855 | nf.source_aperture = rw[23] |
---|
856 | nf.typesource_aperture = "pinhole" |
---|
857 | nf.unitssource_aperture = "mm" |
---|
858 | nf.sample_aperture = rw[24] |
---|
859 | nf.typesample_aperture = "pinhole" |
---|
860 | nf.unitssample_aperture = "mm" |
---|
861 | //nf.collimation_length = total length - rw[25] |
---|
862 | nf.wavelength_spread = rw[27] |
---|
863 | nf.unitswavelength_spread = "percent" |
---|
864 | //Do something with beamstop (rw[21]) |
---|
865 | nf.detector_name = textW[9] |
---|
866 | // fprintf refnum,"MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP\r\n" |
---|
867 | // fprintf refnum,hdrStr1 |
---|
868 | |
---|
869 | // fprintf refnum,"BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP \r\n" |
---|
870 | // fprintf refnum,hdrStr2 |
---|
871 | |
---|
872 | //insert protocol information here |
---|
873 | //-1 list of sample files |
---|
874 | //0 - bkg |
---|
875 | //1 - emp |
---|
876 | //2 - div |
---|
877 | //3 - mask |
---|
878 | //4 - abs params c2-c5 |
---|
879 | //5 - average params |
---|
880 | nf.SASprocessnote = "SAM: "+samFiles+"\n" |
---|
881 | nf.SASprocessnote += "BGD: "+proto[0]+"\n" |
---|
882 | nf.SASprocessnote += "EMP: "+Proto[1]+"\n" |
---|
883 | nf.SASprocessnote += "DIV: "+Proto[2]+"\n" |
---|
884 | nf.SASprocessnote += "MASK: "+Proto[3]+"\n" |
---|
885 | nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n" |
---|
886 | nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n" |
---|
887 | |
---|
888 | nf.nameSASProcess = "NIST IGOR" |
---|
889 | |
---|
890 | //Close refnum |
---|
891 | |
---|
892 | writeNISTXML(fullpath, nf) |
---|
893 | |
---|
894 | SetDataFolder root: //(redundant) |
---|
895 | |
---|
896 | //write confirmation of write operation to history area |
---|
897 | Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) |
---|
898 | KillWaves/Z tempShortProto |
---|
899 | Return(0) |
---|
900 | End |
---|
901 | |
---|
902 | Function WriteNSORTedXMLFile(qw,iw,sw,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) |
---|
903 | Wave qw,iw,sw,res |
---|
904 | String firstFileName,secondFileName,thirdFileName,normTo |
---|
905 | Variable norm12,norm23 |
---|
906 | |
---|
907 | Variable err=0,refNum,numCols |
---|
908 | String fullPath="",formatStr="" |
---|
909 | //check each wave - else REALLY FATAL error when writing file |
---|
910 | If(!(WaveExists(qw))) |
---|
911 | err = 1 |
---|
912 | return err |
---|
913 | Endif |
---|
914 | If(!(WaveExists(iw))) |
---|
915 | err = 1 |
---|
916 | return err |
---|
917 | Endif |
---|
918 | If(!(WaveExists(sw))) |
---|
919 | err = 1 |
---|
920 | return err |
---|
921 | Endif |
---|
922 | |
---|
923 | if(WaveExists(res)) |
---|
924 | numCols = 6 |
---|
925 | else |
---|
926 | numCols = 3 |
---|
927 | endif |
---|
928 | |
---|
929 | Variable dialog = 1 |
---|
930 | if(dialog) |
---|
931 | PathInfo/S catPathName |
---|
932 | fullPath = DoSaveFileDialog("Save data as") //won't actually open the file |
---|
933 | If(cmpstr(fullPath,"")==0) |
---|
934 | //user cancel, don't write out a file |
---|
935 | Close/A |
---|
936 | Abort "no data file was written" |
---|
937 | Endif |
---|
938 | //Print "dialog fullpath = ",fullpath |
---|
939 | Endif |
---|
940 | |
---|
941 | Struct NISTxmlfile nf |
---|
942 | |
---|
943 | //Data |
---|
944 | Wave nf.Q = qw |
---|
945 | nf.unitsQ = "1/A" |
---|
946 | Wave nf.I = iw |
---|
947 | nf.unitsI = "1/cm" |
---|
948 | Wave nf.Idev = sw |
---|
949 | nf.unitsIdev = "1/cm" |
---|
950 | |
---|
951 | //write out the standard header information |
---|
952 | //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] |
---|
953 | |
---|
954 | //AJJ to fix with sensible values |
---|
955 | nf.run = "" |
---|
956 | nf.nameSASinstrument = "NIST IGOR" |
---|
957 | nf.SASnote = "" |
---|
958 | // |
---|
959 | nf.sample_ID = ParseFilePath(3, fullPath, ":", 0, 0) |
---|
960 | nf.title = ParseFilePath(3, fullPath, ":", 0, 0) |
---|
961 | nf.radiation = "neutron" |
---|
962 | //Do something with beamstop (rw[21]) |
---|
963 | nf.detector_name = "NSORTed Data" |
---|
964 | nf.nameSASProcess = "NIST IGOR" |
---|
965 | |
---|
966 | nf.sasProcessNote = "COMBINED FILE CREATED: "+date()+"\n" |
---|
967 | nf.sasProcessNote += "NSORT-ed : " +firstFileName+";"+secondFileName+";"+thirdFileName+"\n" |
---|
968 | nf.sasProcessNote += "normalized to "+normTo+"\n" |
---|
969 | fprintf refNum, "multiplicative factor 1-2 = "+num2str(norm12)+" multiplicative factor 2-3 = "+num2str(norm23)+"\n" |
---|
970 | |
---|
971 | if (numCols == 3) |
---|
972 | writeNISTXML(fullpath,nf) |
---|
973 | elseif (numCols == 6) |
---|
974 | Make/O/N=(dimsize(res,0)) sigq = res[p][0] |
---|
975 | Make/O/N=(dimsize(res,0)) qbar = res[p][1] |
---|
976 | Make/O/N=(dimsize(res,0)) fs = res[p][2] |
---|
977 | |
---|
978 | Wave nf.Qdev = sigQ |
---|
979 | nf.unitsQdev = "1/A" |
---|
980 | Wave nf.Qmean = qbar |
---|
981 | nf.unitsQmean = "1/A" |
---|
982 | Wave nf.Shadowfactor = fs |
---|
983 | nf.unitsShadowfactor = "none" |
---|
984 | |
---|
985 | writeNISTXML(fullpath,nf) |
---|
986 | |
---|
987 | Killwaves/Z sigq,qbar,fs |
---|
988 | endif |
---|
989 | |
---|
990 | Return err |
---|
991 | End |
---|
992 | |
---|
993 | |
---|
994 | |
---|
995 | |
---|
996 | |
---|
997 | End |
---|
998 | |
---|
999 | /// See WriteModelData_v40.ipf for 6 column equivalent |
---|
1000 | Function ReWrite1DXMLData(folderStr) |
---|
1001 | String folderStr |
---|
1002 | |
---|
1003 | String fullpath="" |
---|
1004 | Variable dialog=1 |
---|
1005 | String dataSetFolderParent,basestr,fullBase |
---|
1006 | |
---|
1007 | Struct NISTXMLfile nf |
---|
1008 | |
---|
1009 | //Abuse ParseFilePath to get path without folder name |
---|
1010 | dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0) |
---|
1011 | //Abuse ParseFilePath to get basestr |
---|
1012 | basestr = ParseFilePath(0,folderStr,":",1,0) |
---|
1013 | |
---|
1014 | SetDataFolder $(dataSetFolderParent+basestr) |
---|
1015 | WAVE/Z qw = $(baseStr+"_q") |
---|
1016 | WAVE/Z iw = $(baseStr+"_i") |
---|
1017 | WAVE/Z sw = $(baseStr+"_s") |
---|
1018 | WAVE/Z resw = $(baseStr+"_res") |
---|
1019 | |
---|
1020 | if(WaveExists(qw) == 0) |
---|
1021 | Abort "q is missing" |
---|
1022 | endif |
---|
1023 | if(WaveExists(iw) == 0) |
---|
1024 | Abort "i is missing" |
---|
1025 | endif |
---|
1026 | if(WaveExists(sw) == 0) |
---|
1027 | Abort "s is missing" |
---|
1028 | endif |
---|
1029 | if(WaveExists(resw) == 0) |
---|
1030 | Abort "Resolution information is missing." |
---|
1031 | endif |
---|
1032 | |
---|
1033 | Duplicate/O qw qbar,sigQ,fs |
---|
1034 | |
---|
1035 | |
---|
1036 | |
---|
1037 | //Data |
---|
1038 | Wave nf.Q = qw |
---|
1039 | nf.unitsQ = "1/A" |
---|
1040 | Wave nf.I = iw |
---|
1041 | nf.unitsI = "1/cm" |
---|
1042 | Wave nf.Idev = sw |
---|
1043 | nf.unitsIdev = "1/cm" |
---|
1044 | Wave nf.Qdev = sigQ |
---|
1045 | nf.unitsQdev = "1/A" |
---|
1046 | Wave nf.Qmean = qbar |
---|
1047 | nf.unitsQmean = "1/A" |
---|
1048 | Wave nf.Shadowfactor = fs |
---|
1049 | nf.unitsShadowfactor = "none" |
---|
1050 | |
---|
1051 | |
---|
1052 | //write out the standard header information |
---|
1053 | //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] |
---|
1054 | |
---|
1055 | //AJJ to fix with sensible values |
---|
1056 | nf.run = "" |
---|
1057 | nf.nameSASinstrument = "NIST IGOR Procedures" |
---|
1058 | nf.SASnote = "" |
---|
1059 | // |
---|
1060 | nf.sample_ID = baseStr |
---|
1061 | nf.title = baseStr |
---|
1062 | nf.radiation = "neutron" |
---|
1063 | //Do something with beamstop (rw[21]) |
---|
1064 | nf.detector_name = "Re-written data" |
---|
1065 | |
---|
1066 | nf.SASprocessnote = "Modified data written from folder "+baseStr+" on "+(date()+" "+time()) |
---|
1067 | |
---|
1068 | nf.nameSASProcess = "NIST IGOR" |
---|
1069 | |
---|
1070 | //Close refnum |
---|
1071 | |
---|
1072 | if(dialog) |
---|
1073 | PathInfo/S catPathName |
---|
1074 | fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".xml") |
---|
1075 | If(cmpstr(fullPath,"")==0) |
---|
1076 | //user cancel, don't write out a file |
---|
1077 | Close/A |
---|
1078 | Abort "no data file was written" |
---|
1079 | Endif |
---|
1080 | //Print "dialog fullpath = ",fullpath |
---|
1081 | Endif |
---|
1082 | |
---|
1083 | |
---|
1084 | writeNISTXML(fullpath,nf) |
---|
1085 | //write confirmation of write operation to history area |
---|
1086 | Print "XML File written: ", GetFileNameFromPathNoSemi(fullPath) |
---|
1087 | KillWaves/Z tempShortProto |
---|
1088 | Return(0) |
---|
1089 | End |
---|
1090 | |
---|
1091 | |
---|
1092 | |
---|
1093 | |
---|
1094 | #else // if( Exists("XmlOpenFile") ) |
---|
1095 | // No XMLutils XOP: provide dummy function so that IgorPro can compile dependent support code |
---|
1096 | FUNCTION LoadNISTXMLData(fileName,doPlot) |
---|
1097 | String fileName |
---|
1098 | Variable doPlot |
---|
1099 | Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" |
---|
1100 | RETURN(-6) |
---|
1101 | END |
---|
1102 | |
---|
1103 | |
---|
1104 | Function writeNISTXML(fileName, NISTfile) |
---|
1105 | String fileName, NISTfile |
---|
1106 | Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" |
---|
1107 | RETURN(-6) |
---|
1108 | End |
---|
1109 | |
---|
1110 | Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) |
---|
1111 | String type,fullpath |
---|
1112 | Variable dialog //=1 will present dialog for name |
---|
1113 | |
---|
1114 | Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" |
---|
1115 | return(-6) |
---|
1116 | end |
---|
1117 | |
---|
1118 | Function WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) |
---|
1119 | Wave q3,i3,sig3,res |
---|
1120 | String firstFileName,secondFileName,thirdFileName,normTo |
---|
1121 | Variable norm12,norm23 |
---|
1122 | |
---|
1123 | Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" |
---|
1124 | return(-6) |
---|
1125 | End |
---|
1126 | |
---|
1127 | Function ReWrite1DXMLData(folderStr) |
---|
1128 | String folderStr |
---|
1129 | |
---|
1130 | Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" |
---|
1131 | return(-6) |
---|
1132 | end |
---|
1133 | #endif |
---|
1134 | |
---|
1135 | // if( Exists("XmlOpenFile") |
---|
1136 | //Needed to test whether file is XML. The load routine will then either give an error if XMLutils is not present or load the file if it is. |
---|
1137 | function isXML(filestr) |
---|
1138 | String filestr |
---|
1139 | |
---|
1140 | String line |
---|
1141 | Variable fileref |
---|
1142 | |
---|
1143 | Open/R fileref as filestr |
---|
1144 | FReadLine fileref, line |
---|
1145 | Close fileref |
---|
1146 | |
---|
1147 | //Hopefully this will distinguish between other formats and the XML |
---|
1148 | //Previous string match would match normal files that have a .xml file as their progenitor... |
---|
1149 | return GrepString(line, "(?iU).*\<.*xml.*") |
---|
1150 | |
---|
1151 | end |
---|