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