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