source: sans/Dev/trunk/NCNR_User_Procedures/Common/NIST_XML_v40.ipf @ 1036

Last change on this file since 1036 was 994, checked in by srkline, 7 years ago

more changes, lots of files.

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