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

Last change on this file since 480 was 477, checked in by srkline, 14 years ago

Added save/restore buttons to SimpleGlobal? fit to be able to restore the state of the checkboxes if possible. Checkboxes are reset when new data sets are selected.

Typos in SANSRedn help file have been corrected.

Error bar styles have been changed to /T=0, a vertical line with no horizontal bar. My preference - I got tired of seeing more of the horizontal bar than the actual data.

File size: 10.8 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
8// The function is called "LoadNISTXMLData" but is actually more generic
9// and will load any canSAS XML v1 dataset
10// Dec 2008 :
11//                       Caveats - Assumes Q in /A and I in /cm
12function LoadNISTXMLData(filestr,doPlot)
13        String filestr
14        Variable doPlot
15       
16       
17        Variable rr,gg,bb
18        NVAR dQv = root:Packages:NIST:USANS_dQv
19
20               
21        Print "Trying to load canSAS XML format data"
22        Variable result = CS_XMLReader(filestr)
23       
24        String xmlReaderFolder = "root:Packages:CS_XMLreader:"
25       
26        if (result == 0)
27                        SetDataFolder xmlReaderFolder
28                                               
29                        Variable i,j,numDataSets
30                        Variable np
31                       
32                        String w0,w1,w2,basestr,fileName
33                        String xmlDataFolder,xmlDataSetFolder
34                       
35                       
36                       
37                        for (i = 0; i < CountObjects(xmlReaderFolder,4); i+=1)
38                                                               
39                                xmlDataFolder = xmlReaderFolder+GetIndexedObjName(xmlReaderFolder,4,i)+":"
40                                numDataSets = CountObjects(xmlDataFolder,4)
41                                if (numDataSets > 0)
42                                        //Multiple SASData sets in this SASEntry
43                                        for (j = 0; j < numDataSets; j+=1)
44                                               
45                                                xmlDataSetFolder = xmlDataFolder+GetIndexedObjName(xmlDataFolder,4,j)+":"
46                                               
47                                                SetDataFolder xmlDataSetFolder
48                                       
49                                                basestr = CleanupName(getXMLDataSetTitle(xmlDataSetFolder,j),0)
50                                                //String basestr = ParseFilePath(3, ParseFilePath(5,filestr,":",0,0),":",0,0)                           
51                                                fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
52                                                       
53                                                //print "In NIST XML Loader"
54                                                //print "fileStr: ",fileStr
55                                                //print "basestr: ",basestr
56                                                //print "fileName: ",fileName
57                                                //remove the semicolon AND period from files from the VAX
58                                                w0 = basestr + "_q"
59                                                w1 = basestr + "_i"
60                                                w2 = basestr + "_s"
61                                               
62                                                if(DataFolderExists("root:"+baseStr))
63                                                                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?"
64                                                                if(V_flag==2)   //user selected No, don't load the data
65                                                                        SetDataFolder root:
66                                                                        if(DataFolderExists("root:Packages:NIST"))
67                                                                                String/G root:Packages:NIST:gLastFileName = filename
68                                                                        endif           //set the last file loaded to the one NOT loaded
69                                                                        return  0       //quits the macro
70                                                                endif
71                                                                SetDataFolder $("root:"+baseStr)
72                                                else
73                                                        NewDataFolder/S $("root:"+baseStr)
74                                                endif
75                       
76                                                Duplicate/O $(xmlDataSetFolder+"Qsas") $w0
77                                                Duplicate/O $(xmlDataSetFolder+"Isas") $w1
78                                                Duplicate/O $(xmlDataSetFolder+"Idev") $w2
79               
80               
81                                                       
82                                                if (exists(xmlDataSetFolder+"Qdev"))
83                                                        Wave Qsas = $(xmlDataSetFolder+"Qsas")
84                                                        Wave Qdev = $(xmlDataSetFolder+"Qdev")
85                                               
86                                                // make a resolution matrix for SANS data
87                                                         np=numpnts($w0)
88                                                        Make/D/O/N=(np,4) $(baseStr+"_res")
89                                                        Wave reswave =  $(baseStr+"_res")
90                                                       
91                                                        reswave[][0] = Qdev[p]          //sigQ
92                                                        reswave[][3] = Qsas[p]  //Qvalues
93                                                        if(exists(xmlDataSetFolder+"Qmean"))
94                                                                Wave Qmean = $(xmlDataSetFolder+"Qmean")
95                                                                reswave[][1] = Qmean[p]         //qBar
96                                                        endif
97                                                        if(exists(xmlDataSetFolder+"Shadowfactor"))
98                                                                Wave Shadowfactor = $(xmlDataSetFolder+"Shadowfactor")
99                                                                reswave[][2] = Shadowfactor[p]          //fShad
100                                                        endif
101                                                elseif(exists(xmlDataSetFolder+"dQl"))
102                                                        //USAS Data
103                                                        Wave dQl = $(xmlDataSetFolder+"dQl")
104                                                        dQv = dQl[0]
105                                               
106                                                        USANS_CalcWeights(baseStr,dQv)
107                                                else
108                                                        //No resolution data
109                                                endif
110                                                        //get rid of the resolution waves that are in the matrix
111                                       
112                                                        SetScale d,0,0,"1/A",$w0
113                                                        SetScale d,0,0,"1/cm",$w1
114                                               
115                                                       
116                               
117                                                //////
118                                                if(DataFolderExists("root:Packages:NIST"))
119                                                        String/G root:Packages:NIST:gLastFileName = filename
120                                                endif
121                                       
122                                               
123                                                //plot if desired
124                                                if(doPlot)
125                                                        // assign colors randomly
126                                                        rr = abs(trunc(enoise(65535)))
127                                                        gg = abs(trunc(enoise(65535)))
128                                                        bb = abs(trunc(enoise(65535)))
129                                                       
130                                                        // if target window is a graph, and user wants to append, do so
131                                                   DoWindow/B Plot_Manager
132                                                        if(WinType("") == 1)
133                                                                DoAlert 1,"Do you want to append this data to the current graph?"
134                                                                if(V_Flag == 1)
135                                                                        AppendToGraph $w1 vs $w0
136                                                                        ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1
137                                                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
138                                                                        ModifyGraph tickUnit(left)=1
139                                                                else
140                                                                //new graph
141                                                                        Display $w1 vs $w0
142                                                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
143                                                                        ModifyGraph grid=1,mirror=2,standoff=0
144                                                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
145                                                                        ModifyGraph tickUnit(left)=1
146                                                                        Legend
147                                                                endif
148                                                        else
149                                                        // graph window was not target, make new one
150                                                                Display $w1 vs $w0
151                                                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
152                                                                ModifyGraph grid=1,mirror=2,standoff=0
153                                                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
154                                                                ModifyGraph tickUnit(left)=1
155                                                                Legend
156                                                        endif
157                                                endif
158                                       
159                                        endfor
160                                       
161                                       
162                                else
163                                        //No multiple SASData sets for this SASEntry
164                                        SetDataFolder xmlDataFolder
165                                       
166                                        basestr = CleanupName(getXMLDataSetTitle(xmlDataFolder,0),0)
167                                        //String basestr = ParseFilePath(3, ParseFilePath(5,filestr,":",0,0),":",0,0)                           
168                                        fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
169                                               
170                                        //print "In NIST XML Loader"
171                                        //print "fileStr: ",fileStr
172                                        //print "basestr: ",basestr
173                                        //print "fileName: ",fileName
174                                        w0 = basestr + "_q"
175                                        w1 = basestr + "_i"
176                                        w2 = basestr + "_s"
177                                       
178                                        if(DataFolderExists("root:"+baseStr))
179                                                        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?"
180                                                        if(V_flag==2)   //user selected No, don't load the data
181                                                                SetDataFolder root:
182                                                                if(DataFolderExists("root:Packages:NIST"))
183                                                                        String/G root:Packages:NIST:gLastFileName = filename
184                                                                endif           //set the last file loaded to the one NOT loaded
185                                                                return  0       //quits the macro
186                                                        endif
187                                                        SetDataFolder $("root:"+baseStr)
188                                        else
189                                                NewDataFolder/S $("root:"+baseStr)
190                                        endif
191               
192                                        Duplicate/O $(xmlDataFolder+"Qsas") $w0
193                                        Duplicate/O $(xmlDataFolder+"Isas") $w1
194                                        Duplicate/O $(xmlDataFolder+"Idev") $w2
195       
196       
197                                               
198                                        if (exists(xmlDataFolder+"Qdev"))
199                                                Wave Qsas = $(xmlDataFolder+"Qsas")
200                                                Wave Qdev = $(xmlDataFolder+"Qdev")
201                                       
202                                        // make a resolution matrix for SANS data
203                                                np=numpnts($w0)
204                                                Make/D/O/N=(np,4) $(baseStr+"_res")
205                                                Wave reswave =  $(baseStr+"_res")
206                                               
207                                                reswave[][0] = Qdev[p]          //sigQ
208                                                reswave[][3] = Qsas[p]  //Qvalues
209                                                if(exists(xmlDataFolder+"Qmean"))
210                                                        Wave Qmean = $(xmlDataFolder+"Qmean")
211                                                        reswave[][1] = Qmean[p]         //qBar
212                                                endif
213                                                if(exists(xmlDataFolder+"Shadowfactor"))
214                                                        Wave Shadowfactor = $(xmlDataFolder+"Shadowfactor")
215                                                        reswave[][2] = Shadowfactor[p]          //fShad
216                                                endif
217                                        elseif(exists(xmlDataFolder+"dQl"))
218                                                //USAS Data
219                                                Wave dQl = $(xmlDataFolder+"dQl")
220                                                dQv = dQl[0]
221                                       
222                                                USANS_CalcWeights(baseStr,dQv)
223                                        else
224                                                //No resolution data
225                                        endif
226                                                //get rid of the resolution waves that are in the matrix
227                               
228                                                SetScale d,0,0,"1/A",$w0
229                                                SetScale d,0,0,"1/cm",$w1
230                                       
231                                               
232                       
233                                        //////
234                                        if(DataFolderExists("root:Packages:NIST"))
235                                                String/G root:Packages:NIST:gLastFileName = filename
236                                        endif
237                               
238                                       
239                                        //plot if desired
240                                        if(doPlot)
241                                                // assign colors randomly
242                                                rr = abs(trunc(enoise(65535)))
243                                                gg = abs(trunc(enoise(65535)))
244                                                bb = abs(trunc(enoise(65535)))
245                                               
246                                                // if target window is a graph, and user wants to append, do so
247                                           DoWindow/B Plot_Manager
248                                                if(WinType("") == 1)
249                                                        DoAlert 1,"Do you want to append this data to the current graph?"
250                                                        if(V_Flag == 1)
251                                                                AppendToGraph $w1 vs $w0
252                                                                ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1
253                                                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
254                                                                ModifyGraph tickUnit(left)=1
255                                                        else
256                                                        //new graph
257                                                                Display $w1 vs $w0
258                                                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
259                                                                ModifyGraph grid=1,mirror=2,standoff=0
260                                                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
261                                                                ModifyGraph tickUnit(left)=1
262                                                                Legend
263                                                        endif
264                                                else
265                                                // graph window was not target, make new one
266                                                        Display $w1 vs $w0
267                                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
268                                                        ModifyGraph grid=1,mirror=2,standoff=0
269                                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
270                                                        ModifyGraph tickUnit(left)=1
271                                                        Legend
272                                                endif
273                                        endif
274                               
275                                endif
276                        endfor
277        endif
278
279        //go back to the root folder and clean up before leaving
280        SetDataFolder root:
281        //KillDataFolder xmlReaderFolder
282       
283
284end
285
286
287function/S getXMLDataSetTitle(xmlDF,dsNum)
288        String xmlDF
289        Variable dsNum
290
291        SVAR title = root:myGlobals:gXMLLoader_Title
292
293
294        String mdstring = xmlDF+"metadata"
295
296        Wave/T meta = $mdstring
297        //Check for value when there are multiple datasets
298        FindValue/TEXT="Title"/TXOP=4/Z meta
299        title = meta[V_Value][1]
300
301         //Check for Run value
302         FindValue/TEXT="Run_"+num2str(dsNum)/TXOP=4/Z meta
303        if (V_Value >= 0)
304                title = title+" "+meta[V_Value][1]
305        else
306                FindValue/TEXT="Run"/TXOP=4/Z meta
307                title = title+" "+meta[V_Value][1]     
308        endif
309
310        if (strlen(title) > 28)
311                //Prompt title, "Set New Sample Name"
312                //DoPrompt "Sample Name Is Too Long", title
313                do
314                        Execute "getXMLShorterTitle()"
315                while (strlen(title) > 28)                     
316        endif
317       
318        return title
319end
320
321function isXML(filestr)
322        String filestr
323       
324        String line
325        Variable fileref
326       
327        Open/R fileref as filestr
328        FReadLine fileref,  line
329        Close fileref
330       
331        //Hopefully this will distinguish between other formats and the XML
332        return stringmatch(line, "*xml*")       
333
334end
335
336
337Proc getXMLShorterTitle()
338       
339         //NVAR title = root:myGlobals:gXMLLoader_Title
340       
341        DoWindow/K getNewTitle
342        getNewTitle()
343
344        PauseforUser getNewTitle
345end
346
347Window getNewTitle()
348
349        PauseUpdate; Silent 1           // building window...
350        NewPanel /W=(166,90,666,230) as "Sample Title Too Long!"
351        SetDrawLayer UserBack
352        DrawText 11,22,"The sample title is too long."
353        DrawText 11,42,"Please enter a new one with a maximum length 28 characters"
354        DrawText 11,72,"Current Sample Title:"
355        GroupBox group0 pos={8,55},size={484,50}
356        TitleBox tb_CurrentTitle,pos={150,57}, variable=:myGlobals:gXMLLoader_Title,fSize=12,frame=0   
357        SetVariable sv_NewTitle,pos={11,77},size={476,18},title="New Sample Title"
358        SetVariable sv_NewTitle,fSize=12,value=root:myGlobals:gXMLLoader_Title
359        Button btn_SetNewTitle title="Set New Title",pos={150,110},size={200,20}
360        Button btn_SetNewTitle proc=SetNewTitleButtonProc
361
362EndMacro
363
364
365Proc SetNewTitleButtonProc(ctrlName) : ButtonControl
366        String ctrlName
367
368        DoWindow/K getNewTitle
369
370End
Note: See TracBrowser for help on using the repository browser.