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

Last change on this file since 429 was 420, checked in by ajj, 14 years ago

PlotManager? fixes for common use

File size: 4.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=1.00
3#pragma IgorVersion=6.0
4
5#include "cansasXML_v11", version >= 1.10
6
7
8function LoadNISTXMLData(filestr,doPlot)
9        String filestr
10        Variable doPlot
11       
12       
13        Variable rr,gg,bb
14        NVAR dQv = root:Packages:NIST:USANS_dQv
15
16               
17        Print "Trying to load canSAS XML format data"
18        Variable result = CS_XMLReader(filestr)
19       
20        String xmlReaderFolder = "root:Packages:CS_XMLreader:"
21       
22        if (result == 0)
23                        SetDataFolder xmlReaderFolder
24                                               
25                        Variable i
26                       
27                        for (i = 0; i < CountObjects(xmlReaderFolder,4); i+=1)
28                               
29                                String xmlDataFolder = xmlReaderFolder+GetIndexedObjName(xmlReaderFolder,4,i)+":"
30                                                               
31                                SetDataFolder xmlDataFolder
32                                                                               
33                                String w0,w1,w2
34                       
35                                String basestr = CleanupName(getXMLDataSetTitle(xmlDataFolder),0)
36                                //String basestr = ParseFilePath(3, ParseFilePath(5,filestr,":",0,0),":",0,0)                           
37                                String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
38                                       
39                                //print "In NIST XML Loader"
40                                //print "fileStr: ",fileStr
41                                //print "basestr: ",basestr
42                                //print "fileName: ",fileName
43                                //remove the semicolon AND period from files from the VAX
44                                w0 = basestr + "_q"
45                                w1 = basestr + "_i"
46                                w2 = basestr + "_s"
47                               
48                                if(DataFolderExists("root:"+baseStr))
49                                                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?"
50                                                if(V_flag==2)   //user selected No, don't load the data
51                                                        SetDataFolder root:
52                                                        if(DataFolderExists("root:Packages:NIST"))
53                                                                String/G root:Packages:NIST:gLastFileName = filename
54                                                        endif           //set the last file loaded to the one NOT loaded
55                                                        return  0       //quits the macro
56                                                endif
57                                                SetDataFolder $("root:"+baseStr)
58                                else
59                                        NewDataFolder/S $("root:"+baseStr)
60                                endif
61       
62                                Duplicate/O $(xmlDataFolder+"Qsas") $w0
63                                Duplicate/O $(xmlDataFolder+"Isas") $w1
64                                Duplicate/O $(xmlDataFolder+"Idev") $w2
65
66
67                                       
68                                if (exists(xmlDataFolder+"Qdev"))
69                                        Wave Qsas = $(xmlDataFolder+"Qsas")
70                                        Wave Qdev = $(xmlDataFolder+"Qdev")
71                               
72                                // make a resolution matrix for SANS data
73                                        Variable np=numpnts($w0)
74                                        Make/D/O/N=(np,4) $(baseStr+"_res")
75                                        Wave reswave =  $(baseStr+"_res")
76                                       
77                                        reswave[][0] = Qdev[p]          //sigQ
78                                        reswave[][3] = Qsas[p]  //Qvalues
79                                        if(exists(xmlDataFolder+"Qmean"))
80                                                Wave Qmean = $(xmlDataFolder+"Qmean")
81                                                reswave[][1] = Qmean[p]         //qBar
82                                        endif
83                                        if(exists(xmlDataFolder+"Shadowfactor"))
84                                                Wave Shadowfactor = $(xmlDataFolder+"Shadowfactor")
85                                                reswave[][2] = Shadowfactor[p]          //fShad
86                                        endif
87                                elseif(exists(xmlDataFolder+"dQl"))
88                                        //USAS Data
89                                        Wave dQl = $(xmlDataFolder+"dQl")
90                                        dQv = dQl[0]
91                               
92                                        USANS_CalcWeights(baseStr,dQv)
93                                else
94                                        //No resolution data
95                                endif
96                                        //get rid of the resolution waves that are in the matrix
97                       
98                                        SetScale d,0,0,"1/A",$w0
99                                        SetScale d,0,0,"1/cm",$w1
100                               
101                                       
102               
103                                //////
104                                if(DataFolderExists("root:Packages:NIST"))
105                                        String/G root:Packages:NIST:gLastFileName = filename
106                                endif
107                       
108                               
109                                //plot if desired
110                                if(doPlot)
111                                        // assign colors randomly
112                                        rr = abs(trunc(enoise(65535)))
113                                        gg = abs(trunc(enoise(65535)))
114                                        bb = abs(trunc(enoise(65535)))
115                                       
116                                        // if target window is a graph, and user wants to append, do so
117                                   DoWindow/B Plot_Manager
118                                        if(WinType("") == 1)
119                                                DoAlert 1,"Do you want to append this data to the current graph?"
120                                                if(V_Flag == 1)
121                                                        AppendToGraph $w1 vs $w0
122                                                        ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1
123                                                        ErrorBars $w1 Y,wave=($w2,$w2)
124                                                        ModifyGraph tickUnit(left)=1
125                                                else
126                                                //new graph
127                                                        Display $w1 vs $w0
128                                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
129                                                        ModifyGraph grid=1,mirror=2,standoff=0
130                                                        ErrorBars $w1 Y,wave=($w2,$w2)
131                                                        ModifyGraph tickUnit(left)=1
132                                                        Legend
133                                                endif
134                                        else
135                                        // graph window was not target, make new one
136                                                Display $w1 vs $w0
137                                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
138                                                ModifyGraph grid=1,mirror=2,standoff=0
139                                                ErrorBars $w1 Y,wave=($w2,$w2)
140                                                ModifyGraph tickUnit(left)=1
141                                                Legend
142                                        endif
143                                endif
144                        endfor
145        endif
146
147        //go back to the root folder and clean up before leaving
148        SetDataFolder root:
149        //KillDataFolder xmlReaderFolder
150       
151
152end
153
154
155function/S getXMLDataSetTitle(xmlDF)
156        String xmlDF
157
158        String mdstring = xmlDF+"metadata"
159        print mdstring
160
161        Wave/T meta = $mdstring
162        FindValue/TEXT="Run"/TXOP=4/Z meta
163
164        String title = meta[V_Value][1]
165       
166        return title
167end
168
169function isXML(filestr)
170        String filestr
171       
172        String line
173        Variable fileref
174       
175        Open/R fileref as filestr
176        FReadLine fileref,  line
177        Close fileref
178       
179        //Hopefully this will distinguish between other formats and the XML
180        return stringmatch(line, "*xml*")       
181
182end
Note: See TracBrowser for help on using the repository browser.