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

Last change on this file since 877 was 845, checked in by ajj, 11 years ago

Fix to the canSAS XML reader to put in sane values if Qmean and Shadowfactor are missing.

File size: 36.2 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//AJJ 12/5/08
396
397//Define struct for file contents
398Structure NISTXMLfile
399//      string filename
400        string Run
401        string title
402
403        //<SASdata>
404        Wave Q,I,Idev,Qdev,Qmean,Shadowfactor,dQl
405        string unitsQ,unitsI,unitsIdev,unitsQdev,unitsQmean,unitsShadowfactor,unitsdQl
406
407//      Variable flux_monitor
408//      string Q_resolution
409
410        //<SASsample>
411        string sample_ID
412        variable sample_thickness
413        string unitssample_thickness
414        variable sample_transmission
415
416        //SASinstrument
417        string nameSASinstrument
418        // SASinstrument/SASsource
419        string radiation
420//      string beam_shape
421        variable wavelength
422        string unitswavelength
423        variable wavelength_spread
424        string unitswavelength_spread
425 
426        //<SAScollimation>
427//      variable collimation_length
428//      string unitscollimation_length
429        variable source_aperture
430        string unitssource_aperture
431        string typesource_aperture
432        variable sample_aperture
433        string unitssample_aperture
434        string typesample_aperture
435
436        //SASdetector         <SASdetector>
437        string detector_name
438        variable offset_angle
439        string unitsoffset_angle
440        variable  SDD
441        string unitsSDD
442        variable beamcenter_X
443        string unitsbeamcenter_X
444        variable beamcenter_Y
445        string unitsbeamcenter_Y
446//      variable pixel_sizeX
447//      string unitspixel_sizeX
448//      variable pixel_sizeY
449//      string unitspixel_sizeY
450//      string detectortype
451
452        // <SASprocess name="NCNR-IGOR">
453        string nameSASprocess
454        string SASprocessnote
455//      string SASprocessdate
456//      string average_type
457//      string SAM_file
458//      string BKD_file
459//      string EMP_file
460//      string DIV_file
461//      string MASK_file
462//      string ABS_parameters
463//      variable TSTAND
464//      variable DSTAND
465//      string unitsDSTAND
466//      variable IZERO
467//      variable XSECT
468//      string unitsXSECT
469        string SASnote
470Endstructure
471
472
473//Function to write NIST canSAS XML files
474//Minimalist XML file - AJJ Dec 2008
475function writeNISTXML(fileName, NISTfile)
476        String fileName
477        Struct NISTXMLfile &NISTfile
478
479        variable fileID
480       
481        //create the sasXML file with SASroot
482        //no namespace, no prefix
483        fileID = xmlcreatefile(fileName,"SASroot","cansas1d/1.0","")
484
485        //create a version attribute for the root element
486        xmlsetAttr(fileID,"/SASroot","","version","1.0")
487        xmlsetAttr(fileID,"/SASroot","","xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
488        xmlsetAttr(fileID,"/SASroot","","xsi:schemaLocation","cansas1d/1.0 http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd")
489
490
491        //create the SASentry node
492        xmladdnode(fileID,"/SASroot","","SASentry","",1)
493               
494        //create the Title node
495        xmladdnode(fileID,"/SASroot/SASentry","","Title",NISTfile.Title,1)
496
497        //create the Run node
498        xmladdnode(fileID,"/SASroot/SASentry","","Run",NISTfile.Run,1)
499       
500        //create the SASdata node
501        xmladdnode(fileID,"/SASroot/SASentry","","SASdata","",1)
502
503        variable ii
504       
505        if (WaveExists(NISTfile.dQl) == 1)
506                for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1)
507                        xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1)
508                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1)
509                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ)
510       
511                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1)
512                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI)
513       
514                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1)
515                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev)     
516       
517                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","dQl",num2str(NISTfile.dQl[ii]),1)
518                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/dQl","","unit",NISTfile.unitsdQl)               
519                endfor
520        else
521                for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1)
522                        xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1)
523                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1)
524                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ)
525       
526                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1)
527                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI)
528       
529                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1)
530                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev)
531       
532                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qdev",num2str(NISTfile.Qdev[ii]),1)
533                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qdev","","unit",NISTfile.unitsQdev)
534       
535                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qmean",num2str(NISTfile.Qmean[ii]),1)
536                        xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qmean","","unit",NISTfile.unitsQmean)
537       
538                        xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Shadowfactor",num2str(NISTfile.shadowfactor[ii]),1)
539                endfor
540        endif
541
542        //SASsample node
543        xmladdnode(fileID,"/SASroot/SASentry","","SASsample","",1)
544        xmladdnode(fileID,"/SASroot/SASentry/SASsample","","ID",NISTfile.sample_ID,1)
545
546        //SASInstrument node
547        xmladdnode(fileID,"/SASroot/SASentry","","SASinstrument","",1)
548        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","name",NISTfile.nameSASinstrument,1)
549       
550        //SASsource
551        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASsource","",1)
552        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","radiation",NISTfile.radiation,1)
553
554        //SAScollimation
555        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SAScollimation","",1)
556
557        //SASdetector
558        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASdetector","",1)
559        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","name",NISTfile.detector_name,1)
560
561
562        //SASprocess
563        xmladdnode(fileID,"/SASroot/SASentry","","SASprocess","",1)
564        xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess","","name",NISTfile.nameSASprocess)     
565        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SASprocessnote",NISTfile.SASprocessnote,1)
566       
567        //SASnote
568        xmladdnode(fileID,"/SASroot/SASentry","","SASnote",NISTfile.SASnote,1)
569       
570        xmlsavefile(fileID)
571        xmlclosefile(fileID,0)
572       
573end
574
575//
576// !!! nf.Sample_ID is not set correctly here, since it's not read in from the NIST 6-col data file
577// and SASprocessnote does not get set either!
578//
579Function convertNISTtoNISTXML(fileStr)
580        String fileStr
581       
582        Struct NISTXMLfile nf
583       
584        Variable rr,gg,bb,refnum,dQv
585        SetDataFolder root:     
586       
587        if (cmpStr(fileStr,"") == 0)
588                //No filename given, open dialog
589                Open/D/R  refnum
590                if (cmpstr(S_filename,"") == 0)
591                        return 0
592                else
593                        fileStr = S_filename
594                endif
595        endif
596
597        //Load the waves, using default waveX names
598        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
599        LoadWave/G/D/A/Q fileStr
600        String fileNamePath = S_Path+S_fileName
601        String basestr = CleanupName(ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0),0)
602//      String baseStr = CleanupName(S_fileName,0)
603//              print "basestr :"+basestr
604        String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
605//              print "filename :"+filename
606        Variable numCols = V_flag
607        String outfileName = S_Path+basestr+".xml"
608
609       
610        if(numCols==3)          //simple 3-column data with no resolution information
611               
612                Wave nf.Q = $(StringFromList(0, S_waveNames ,";" ))
613                Wave nf.I = $(StringFromList(1, S_waveNames ,";" ))
614                Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" ))
615                               
616                //Set units
617                nf.unitsQ = "1/A"
618                nf.unitsI = "1/cm"
619                nf.unitsIdev = "1/cm"
620                               
621        endif           //3-col data
622       
623        if(numCols == 6)                //6-column SANS or USANS data that has resolution information
624               
625                // put the names of the (default named) loaded waves into local names
626                Wave nf.Q = $(StringFromList(0, S_waveNames ,";" ))
627                Wave nf.I  = $(StringFromList(1, S_waveNames ,";" ))
628                Wave nf.Idev  = $(StringFromList(2, S_waveNames ,";" ))
629
630                //Set units
631                nf.unitsQ = "1/A"
632                nf.unitsI = "1/cm"
633                nf.unitsIdev = "1/cm"
634
635                WAVE resTest = $(StringFromList(3, S_waveNames ,";" ))
636
637                // need to switch based on SANS/USANS
638                if (isSANSResolution(resTest[0]))               //checks to see if the first point of the wave is <0]
639                        Wave nf.Qdev  = $(StringFromList(3, S_waveNames ,";" ))
640                        Wave nf.Qmean  = $(StringFromList(4, S_waveNames ,";" ))
641                        Wave nf.Shadowfactor  = $(StringFromList(5, S_waveNames ,";" ))
642                       
643                        //Set units
644                        nf.unitsQdev = "1/A"
645                        nf.unitsQmean = "1/A"
646                else
647                        Wave nf.dQl = $(StringFromList(3, S_waveNames ,";" ))
648                       
649                        //Set units
650                        nf.unitsdQl = "1/A"
651                       
652                endif
653       
654        endif   //6-col data
655
656        //Get file header
657        setmetadataFromASCHeader(fileStr,nf)
658
659        //Set required metadata that we can't get from these files
660        nf.detector_name = "Ordela 128x128"
661        nf.nameSASinstrument = "NIST NG3/NG7 SANS"
662        nf.radiation = "neutron"
663        nf.sample_ID = nf.title
664        nf.nameSASProcess = "NIST Data Converter"
665        nf.sasnote = "Data converted from previous NIST format. SASProcessnote contains header from original text file."
666
667        writeNISTXML(outfileName, nf)
668
669        //Tidy up AFTER we're all done, since STRUCT points to wave0,wave1, etc.
670        Variable i = 0
671        do
672                WAVE/Z wv= $(StringFromList(i,S_waveNames,";"))
673                if( WaveExists(wv) == 0 )
674                        break
675                endif
676                KillWaves wv
677                i += 1
678        while (1)       // exit is via break statement
679
680end
681
682function setmetadataFromASCHeader(fileStr,NISTfile)
683        String fileStr
684        Struct NISTXMLfile &NISTfile
685
686        String hdr="",buffer=""
687        Variable lineNum = 0, fileref
688        Variable num
689       
690        Open/R fileref as fileStr
691        do
692                FReadLine fileref, buffer
693                if (stringmatch(buffer,"*The 6 columns are*") == 1)
694                        break
695                endif
696                buffer = RemoveEnding(buffer)
697//              print buffer
698                //Get run value
699                if (stringmatch(buffer,"*file:*") == 1)
700                        NISTfile.run = TrimWS(StringFromList(0,StringFromList(1, buffer, ":"),"C"))
701                elseif (stringmatch(buffer,"combined file*") == 1)
702                        NISTfile.run = "Combined Data"
703                endif
704               
705                //Get title value
706                if (stringmatch(buffer,"*FIRST File LABEL:*") == 1)
707                        NISTfile.title = TrimWS(StringFromList(1,buffer, ":"))
708                endif
709                if(stringmatch(buffer,"*LABEL:*") == 1)
710                        NISTfile.title = TrimWS(StringFromList(1,buffer, ":"))
711                endif
712                if(stringmatch(buffer,"NSORT*") == 1)
713                        NISTfile.title = buffer
714                endif
715               
716                hdr += buffer+"\n"
717        while(strlen(buffer) > 0)
718       
719        if (strlen(NISTfile.title) == 0)
720                NISTfile.title = CleanupName(ParseFilePath(3,ParseFilePath(5,fileStr,":",0,0),":",0,0),0)
721        endif
722        if (strlen(NISTfile.run) == 0)
723                NISTfile.run = "Unknown"
724        endif
725       
726        NISTfile.sasprocessnote = RemoveEnding(hdr)
727       
728end
729
730//for writing out data (q-i-s) from the "type" folder, and including reduction information
731//if fullpath is a complete HD path:filename, no dialog will be presented
732//if fullpath is just a filename, the save dialog will be presented
733//if dialog = 1, a dialog will always be presented
734//
735// root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol
736//
737//AJJ Nov 2009 : This version of the function currently only works for Circular, Sector and Rectangular averages
738//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
739//and handling on load.
740Function WriteXMLWaves_W_Protocol(type,fullpath,dialog)
741        String type,fullpath
742        Variable dialog         //=1 will present dialog for name
743       
744        Struct NISTXMLfile nf
745       
746        String destStr=""
747        destStr = "root:Packages:NIST:"+type
748       
749        Variable refNum
750//      String fname,ave="C",hdrStr1="",hdrStr2=""
751//      Variable step=1
752       
753        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
754        WAVE intw=$(destStr + ":integersRead")
755        WAVE rw=$(destStr + ":realsRead")
756        WAVE/T textw=$(destStr + ":textRead")
757        WAVE qvals =$(destStr + ":qval")
758        WAVE inten=$(destStr + ":aveint")
759        WAVE sig=$(destStr + ":sigave")
760        WAVE qbar = $(destStr + ":QBar")
761        WAVE sigmaq = $(destStr + ":SigmaQ")
762        WAVE fsubs = $(destStr + ":fSubS")
763
764
765        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr
766        Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)
767
768       
769        //check each wave
770        If(!(WaveExists(intw)))
771                Abort "intw DNExist BinaryWrite_W_Protocol()"
772        Endif
773        If(!(WaveExists(rw)))
774                Abort "rw DNExist BinaryWrite_W_Protocol()"
775        Endif
776        If(!(WaveExists(textw)))
777                Abort "textw DNExist BinaryWrite_W_Protocol()"
778        Endif
779        If(!(WaveExists(qvals)))
780                Abort "qvals DNExist BinaryWrite_W_Protocol()"
781        Endif
782        If(!(WaveExists(inten)))
783                Abort "inten DNExist BinaryWrite_W_Protocol()"
784        Endif
785        If(!(WaveExists(sig)))
786                Abort "sig DNExist BinaryWrite_W_Protocol()"
787        Endif
788        If(!(WaveExists(qbar)))
789                Abort "qbar DNExist BinaryWrite_W_Protocol()"
790        Endif
791        If(!(WaveExists(sigmaq)))
792                Abort "sigmaq DNExist BinaryWrite_W_Protocol()"
793        Endif
794        If(!(WaveExists(fsubs)))
795                Abort "fsubs DNExist BinaryWrite_W_Protocol()"
796        Endif
797        If(!(WaveExists(proto)))
798                Abort "current protocol wave DNExist BinaryWrite_W_Protocol()"
799        Endif
800       
801        if(dialog)
802                PathInfo/S catPathName
803                fullPath = DoSaveFileDialog("Save data as")
804                If(cmpstr(fullPath,"")==0)
805                        //user cancel, don't write out a file
806                        Close/A
807                        Abort "no data file was written"
808                Endif
809                //Print "dialog fullpath = ",fullpath
810        Endif
811       
812        SVAR samFiles = $("root:Packages:NIST:"+type+":fileList")
813        //actually open the file here
814        //Open refNum as fullpath
815       
816        //Data
817        Wave nf.Q = qvals
818        nf.unitsQ = "1/A"
819        Wave nf.I = inten
820        nf.unitsI = "1/cm"
821        Wave nf.Idev = sig
822        nf.unitsIdev = "1/cm"
823        Wave nf.Qdev = sigmaq
824        nf.unitsQdev = "1/A"
825        Wave nf.Qmean = qbar
826        nf.unitsQmean = "1/A"
827        Wave nf.Shadowfactor = fSubS
828        nf.unitsShadowfactor = "none"
829       
830       
831        //write out the standard header information
832        //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]
833       
834        //AJJ to fix with sensible values
835        nf.run = "Test"
836        String acct = textw[3]
837        nf.nameSASinstrument = acct[1,3]
838        nf.SASnote = ""
839        //
840        nf.sample_ID = textw[6]
841        nf.title = textw[6]
842        nf.radiation = "neutron"
843        nf.wavelength = rw[26]
844        nf.unitswavelength = "A"
845        nf.offset_angle = rw[19]
846        nf.unitsoffset_angle = "cm"
847        nf.SDD = rw[18]
848        nf.unitsSDD = "m"
849        nf.sample_transmission = rw[4]
850        nf.sample_thickness = rw[5]
851        nf.unitssample_thickness = "mm"
852       
853        nf.beamcenter_X = rw[16] 
854        nf.beamcenter_Y = rw[17]
855        nf.unitsbeamcenter_X = "pixels"
856        nf.unitsbeamcenter_Y = "pixels"
857        nf.source_aperture = rw[23]
858        nf.typesource_aperture = "pinhole"
859        nf.unitssource_aperture = "mm"
860        nf.sample_aperture = rw[24]
861        nf.typesample_aperture = "pinhole"
862        nf.unitssample_aperture = "mm"
863        //nf.collimation_length = total length - rw[25]
864        nf.wavelength_spread = rw[27]
865        nf.unitswavelength_spread = "percent"
866        //Do something with beamstop (rw[21])
867        nf.detector_name = textW[9]
868//      fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n"
869//      fprintf refnum,hdrStr1
870
871//      fprintf refnum,"BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP \r\n"
872//      fprintf refnum,hdrStr2
873
874        //insert protocol information here
875        //-1 list of sample files
876        //0 - bkg
877        //1 - emp
878        //2 - div
879        //3 - mask
880        //4 - abs params c2-c5
881        //5 - average params
882        nf.SASprocessnote =  "SAM: "+samFiles+"\n"
883        nf.SASprocessnote += "BGD: "+proto[0]+"\n"
884        nf.SASprocessnote += "EMP: "+Proto[1]+"\n"
885        nf.SASprocessnote += "DIV: "+Proto[2]+"\n"
886        nf.SASprocessnote += "MASK: "+Proto[3]+"\n"
887        nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n"
888        nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n"
889       
890        nf.nameSASProcess = "NIST IGOR"
891
892        //Close refnum
893       
894        writeNISTXML(fullpath, nf)
895       
896        SetDataFolder root:             //(redundant)
897       
898        //write confirmation of write operation to history area
899        Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath)
900        KillWaves/Z tempShortProto
901        Return(0)
902End
903
904Function WriteNSORTedXMLFile(qw,iw,sw,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res])
905        Wave qw,iw,sw,res
906        String firstFileName,secondFileName,thirdFileName,normTo
907        Variable norm12,norm23
908
909        Variable err=0,refNum,numCols,dialog=1
910        String fullPath="",formatStr="",str2
911        //check each wave - else REALLY FATAL error when writing file
912        If(!(WaveExists(qw)))
913                err = 1
914                return err
915        Endif
916        If(!(WaveExists(iw)))
917                err = 1
918                return err
919        Endif
920        If(!(WaveExists(sw)))
921                err = 1
922                return err
923        Endif
924       
925        if(WaveExists(res))
926                numCols = 6
927        else
928                numCols = 3
929        endif
930       
931// 05SEP05 SRK -- added to automatically combine files from a table - see the end of NSORT.ipf for details
932// - use the flag set in DoCombineFiles() to decide if the table entries should be used
933//Ê Êroot:myGlobals:CombineTable:useTable= (1) (0)
934//if(exists("root:myGlobals:CombineTable:SaveName"))
935        NVAR/Z useTable = root:myGlobals:CombineTable:useTable
936        if(NVAR_Exists(useTable) && useTable==1)
937                SVAR str=root:myGlobals:CombineTable:SaveNameStr        //messy, but pass in as a global
938                fullPath = str
939//              str2 = "Is the file name "+str+" correct?"
940//              DoAlert 1,str2
941//              if(V_flag==1)
942                        dialog=0                //bypass the dialog if the name is good (assumed, since DoAlert is bypassed)
943//              endif
944        endif
945
946        if(dialog)
947                PathInfo/S catPathName
948                fullPath = DoSaveFileDialog("Save XML data as",fname="",suffix=".ABSx")         //won't actually open the file
949                If(cmpstr(fullPath,"")==0)
950                        //user cancel, don't write out a file
951                        Close/A
952                        Abort "no data file was written"
953                Endif
954                //Print "dialog fullpath = ",fullpath
955        Endif
956
957        Struct NISTxmlfile nf
958       
959        //Data
960        Wave nf.Q = qw
961        nf.unitsQ = "1/A"
962        Wave nf.I = iw
963        nf.unitsI = "1/cm"
964        Wave nf.Idev = sw
965        nf.unitsIdev = "1/cm"
966
967        //write out the standard header information
968        //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]
969       
970        //AJJ to fix with sensible values
971        nf.run = ""
972        nf.nameSASinstrument = "NIST IGOR"
973        nf.SASnote = ""
974        //
975        nf.sample_ID = ParseFilePath(3, fullPath, ":", 0, 0)
976        nf.title = ParseFilePath(3, fullPath, ":", 0, 0)
977        nf.radiation = "neutron"
978        //Do something with beamstop (rw[21])
979        nf.detector_name = "NSORTed Data"       
980        nf.nameSASProcess = "NIST IGOR"
981       
982        nf.sasProcessNote = "COMBINED FILE CREATED: "+date()+"\n"
983        nf.sasProcessNote += "NSORT-ed : " +firstFileName+";"+secondFileName+";"+thirdFileName+"\n"
984        nf.sasProcessNote += "normalized to  "+normTo+"\n"
985        fprintf refNum, "multiplicative factor 1-2 = "+num2str(norm12)+" multiplicative factor 2-3 = "+num2str(norm23)+"\n"
986
987        if (numCols == 3)
988                writeNISTXML(fullpath,nf)
989        elseif (numCols == 6)
990                Make/O/N=(dimsize(res,0)) sigq = res[p][0]
991                Make/O/N=(dimsize(res,0)) qbar = res[p][1]
992                Make/O/N=(dimsize(res,0)) fs = res[p][2]
993       
994                Wave nf.Qdev = sigQ
995                nf.unitsQdev = "1/A"
996                Wave nf.Qmean = qbar
997                nf.unitsQmean = "1/A"
998                Wave nf.Shadowfactor = fs
999                nf.unitsShadowfactor = "none"
1000       
1001                writeNISTXML(fullpath,nf)
1002       
1003                Killwaves/Z sigq,qbar,fs
1004        endif
1005
1006        Return err
1007End
1008
1009
1010
1011/// See WriteModelData_v40.ipf for 6 column equivalent
1012//
1013// will abort if resolution wave is missing
1014// switches for USANS data if the proper global is found, otheriwse treats as SANS data
1015//
1016Function ReWrite1DXMLData(folderStr)
1017        String folderStr
1018
1019        String fullpath=""
1020        Variable dialog=1
1021        String dataSetFolderParent,basestr,fullBase
1022       
1023        Struct NISTXMLfile nf
1024
1025        //Abuse ParseFilePath to get path without folder name
1026        dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
1027        //Abuse ParseFilePath to get basestr
1028        basestr = ParseFilePath(0,folderStr,":",1,0)
1029
1030        SetDataFolder $(dataSetFolderParent+basestr)
1031        WAVE/Z qw = $(baseStr+"_q")
1032        WAVE/Z iw = $(baseStr+"_i")
1033        WAVE/Z sw = $(baseStr+"_s")
1034        WAVE/Z resw = $(baseStr+"_res")
1035       
1036        if(WaveExists(qw) == 0)
1037                Abort "q is missing"
1038        endif
1039        if(WaveExists(iw) == 0)
1040                Abort "i is missing"
1041        endif
1042        if(WaveExists(sw) == 0)
1043                Abort "s is missing"
1044        endif
1045        if(WaveExists(resw) == 0)
1046                Abort "Resolution information is missing."
1047        endif
1048       
1049       
1050        // if (USANS)
1051        // else (SANS is assumed)
1052        // endif
1053        NVAR/Z dQv = USANS_dQv          // in current DF
1054        if (NVAR_Exists(dQv))
1055                //USANS data, proceed
1056                //Use the evil extra column for the resolution "information". Should probably switch to using slit_length in collimation.
1057                Duplicate/O qw,dumWave
1058                dumWave = dQv                   //written out as a positive value, since the column is identified by its label, dQl
1059               
1060                //Data
1061                Wave nf.Q = qw
1062                nf.unitsQ = "1/A"
1063                Wave nf.I = iw
1064                nf.unitsI = "1/cm"
1065                Wave nf.Idev = sw
1066                nf.unitsIdev = "1/cm"
1067                // for slit-smeared USANS, set only a 4th column to  -dQv
1068                Wave nf.dQl = dumWave
1069                nf.unitsdQl= "1/A"
1070       
1071                //AJJ to fix with sensible values
1072                nf.run = ""
1073                nf.nameSASinstrument = "NIST IGOR Procedures"
1074                nf.SASnote = ""
1075                //
1076                nf.sample_ID = baseStr
1077                nf.title = baseStr
1078                nf.radiation = "neutron"
1079                //Do something with beamstop (rw[21])
1080                nf.detector_name = "Re-written USANS data"
1081       
1082                nf.SASprocessnote =  "Modified data written from folder "+baseStr+" on "+(date()+" "+time())
1083               
1084                nf.nameSASProcess = "NIST IGOR"
1085               
1086        else
1087                //assume SANS data
1088                Duplicate/O qw qbar,sigQ,fs
1089                sigq = resw[p][0]
1090                qbar = resw[p][1]
1091                fs = resw[p][2]
1092       
1093                       
1094                //Data
1095                Wave nf.Q = qw
1096                nf.unitsQ = "1/A"
1097                Wave nf.I = iw
1098                nf.unitsI = "1/cm"
1099                Wave nf.Idev = sw
1100                nf.unitsIdev = "1/cm"
1101                Wave nf.Qdev = sigQ
1102                nf.unitsQdev = "1/A"
1103                Wave nf.Qmean = qbar
1104                nf.unitsQmean = "1/A"
1105                Wave nf.Shadowfactor = fs
1106                nf.unitsShadowfactor = "none"
1107               
1108               
1109                //write out the standard header information
1110                //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]
1111               
1112                //AJJ to fix with sensible values
1113                nf.run = ""
1114                nf.nameSASinstrument = "NIST IGOR Procedures"
1115                nf.SASnote = ""
1116                //
1117                nf.sample_ID = baseStr
1118                nf.title = baseStr
1119                nf.radiation = "neutron"
1120                //Do something with beamstop (rw[21])
1121                nf.detector_name = "Re-written data"
1122       
1123                nf.SASprocessnote =  "Modified data written from folder "+baseStr+" on "+(date()+" "+time())
1124               
1125                nf.nameSASProcess = "NIST IGOR"
1126
1127        endif
1128
1129       
1130        if(dialog)
1131                PathInfo/S catPathName
1132                fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".xml")
1133                If(cmpstr(fullPath,"")==0)
1134                        //user cancel, don't write out a file
1135                        Close/A
1136                        Abort "no data file was written"
1137                Endif
1138                //Print "dialog fullpath = ",fullpath
1139        Endif
1140       
1141       
1142        writeNISTXML(fullpath,nf)
1143        //write confirmation of write operation to history area
1144        Print "XML File written: ", GetFileNameFromPathNoSemi(fullPath)
1145        KillWaves/Z tempShortProto
1146       
1147        SetDataFolder root:
1148
1149        Return(0)
1150End
1151
1152
1153
1154
1155#else   // if( Exists("XmlOpenFile") )
1156        // No XMLutils XOP: provide dummy function so that IgorPro can compile dependent support code
1157        FUNCTION LoadNISTXMLData(fileName,doPlot)
1158            String fileName
1159            Variable doPlot
1160            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)"
1161            RETURN(-6)
1162        END
1163       
1164
1165        Function writeNISTXML(fileName, NISTfile)
1166                String fileName, NISTfile
1167                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)"
1168                RETURN(-6)
1169        End
1170       
1171        Function WriteXMLWaves_W_Protocol(type,fullpath,dialog)
1172                String type,fullpath
1173                Variable dialog         //=1 will present dialog for name
1174       
1175            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)"
1176                return(-6)
1177        end
1178       
1179        Function WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res])
1180                Wave q3,i3,sig3,res
1181                String firstFileName,secondFileName,thirdFileName,normTo
1182                Variable norm12,norm23
1183
1184                 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)"
1185                return(-6)
1186        End
1187
1188        Function ReWrite1DXMLData(folderStr)
1189                String folderStr
1190       
1191                 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)"
1192                return(-6)
1193        end
1194#endif
1195
1196        // if( Exists("XmlOpenFile")
1197//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.
1198function isXML(filestr)
1199        String filestr
1200       
1201        String line
1202        Variable fileref
1203       
1204        Open/R/Z fileref as filestr
1205        FReadLine fileref,  line
1206        Close fileref
1207       
1208        //Hopefully this will distinguish between other formats and the XML
1209        //Previous string match would match normal files that have a .xml file as their progenitor...
1210        return GrepString(line, "(?iU).*\<.*xml.*")     
1211
1212end
Note: See TracBrowser for help on using the repository browser.