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

Last change on this file since 794 was 739, checked in by srkline, 13 years ago

Now, the XML writer writes out + dQv to the dQl field for each point. Since this field in the XML file identifies the data as USANS, it is used as the flag. Upon loading the global USANS_dQv is set to abs(dQv)

our old 6-column format still writes out the last three columns as -(dQv) and keys on the negative number to flag it as USANS.

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