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

Last change on this file since 1239 was 1228, checked in by srkline, 3 years ago

correction to the conditional compilation of the XML utilities to ensure that VSANS will always compile correctly.

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