| 1 | #pragma rtGlobals=1 // Use modern global access method. |
|---|
| 2 | #pragma version=4.00 |
|---|
| 3 | #pragma IgorVersion=6.0 |
|---|
| 4 | |
|---|
| 5 | // This is to be used with the Analysis packages ONLY |
|---|
| 6 | // there are a number of utility procedures here for loading |
|---|
| 7 | // data and generating valid lists of data files that are |
|---|
| 8 | // directly copied from the Reduction package |
|---|
| 9 | // -- There WILL be name conflicts if you mix the two... |
|---|
| 10 | // |
|---|
| 11 | // 16 DEC 05 SRK |
|---|
| 12 | // prepended function names with A_ to tag them for the |
|---|
| 13 | // "A"nalysis parckage, though nearly all are duplicate procedures |
|---|
| 14 | // so there will be no overlap with the reduction package |
|---|
| 15 | // |
|---|
| 16 | // |
|---|
| 17 | // these extra procedures are used by: |
|---|
| 18 | // Linearized fits (duplicated in Reduction - will need to handle gently) |
|---|
| 19 | // Invariant (no overlap with reduction) |
|---|
| 20 | // |
|---|
| 21 | // SRK MAR 2005 |
|---|
| 22 | |
|---|
| 23 | // create a KW=string; of model=coef correspondence as the models are plotted, rather than |
|---|
| 24 | // some other hard-wired solution |
|---|
| 25 | Function AddModelToStrings(funcStr,coefStr,suffix) |
|---|
| 26 | String funcStr,coefStr,suffix |
|---|
| 27 | |
|---|
| 28 | if(exists("root:Packages:NIST:coefKWStr")==0) |
|---|
| 29 | String/G root:Packages:NIST:coefKWStr="" |
|---|
| 30 | String/G root:Packages:NIST:suffixKWStr="" |
|---|
| 31 | endif |
|---|
| 32 | SVAR coefKWStr = root:Packages:NIST:coefKWStr |
|---|
| 33 | SVAR suffixKWStr = root:Packages:NIST:suffixKWStr |
|---|
| 34 | coefKWStr += funcStr+"="+coefStr+";" |
|---|
| 35 | suffixKWStr += coefStr+"="+suffix+";" |
|---|
| 36 | end |
|---|
| 37 | |
|---|
| 38 | // loads a 1-d (ascii) datafile and plots the data |
|---|
| 39 | // will overwrite existing data if user is OK with this |
|---|
| 40 | // - multiple datasets can be automatically plotted on the same graph |
|---|
| 41 | // |
|---|
| 42 | //substantially easier to write this as a Proc rather than a function... |
|---|
| 43 | |
|---|
| 44 | // |
|---|
| 45 | Proc A_LoadOneDData() |
|---|
| 46 | A_LoadOneDDataWithName("",1) //will prompt for file and plot data |
|---|
| 47 | End |
|---|
| 48 | |
|---|
| 49 | // load the data specified by fileStr (a full path:name) |
|---|
| 50 | // and plots if doPlot==1 |
|---|
| 51 | // if fileStr is null, a dialog is presented to select the file |
|---|
| 52 | // |
|---|
| 53 | // 3 cases (if) |
|---|
| 54 | // - 3 columns = QIS, no resolution |
|---|
| 55 | // - 6 columns = QSIG, SANS w/resolution |
|---|
| 56 | // - 5 columns = old-style desmeared USANS data (from VAX) |
|---|
| 57 | // |
|---|
| 58 | // This loader replaces the A_LoadOneDData() which was almost completely duplicated code |
|---|
| 59 | // |
|---|
| 60 | //new version, 19JUN07 that loads each data set into a separate data folder |
|---|
| 61 | // the data folder is given the "base name" of the data file as it's loaded |
|---|
| 62 | // |
|---|
| 63 | Proc A_LoadOneDDataWithName(fileStr,doPlot) |
|---|
| 64 | String fileStr |
|---|
| 65 | Variable doPlot |
|---|
| 66 | |
|---|
| 67 | Variable rr,gg,bb,refnum |
|---|
| 68 | String w0,w1,w2,n0,n1,n2 |
|---|
| 69 | String w3,w4,w5,n3,n4,n5 //3 extra waves to load |
|---|
| 70 | SetDataFolder root: //build sub-folders for each data set under root |
|---|
| 71 | |
|---|
| 72 | if (exists("root:Packages:NIST:USANS:Globals:MainPanel:gDQv")) |
|---|
| 73 | //Running from USANS reduction |
|---|
| 74 | Variable dQv = root:Packages:NIST:USANS:Globals:MainPanel:gDQv |
|---|
| 75 | endif |
|---|
| 76 | if(exists("root:Packages:NIST:USANS_gDQv")) |
|---|
| 77 | //Running from SANS Analysis |
|---|
| 78 | Variable dQv = root:Packages:NIST:USANS_gDQv |
|---|
| 79 | endif |
|---|
| 80 | |
|---|
| 81 | if (cmpStr(fileStr,"") == 0) |
|---|
| 82 | //No filename given, open dialog |
|---|
| 83 | Open/D/R refnum |
|---|
| 84 | if (cmpstr(S_filename,"") == 0) |
|---|
| 85 | return |
|---|
| 86 | else |
|---|
| 87 | fileStr = S_filename |
|---|
| 88 | endif |
|---|
| 89 | endif |
|---|
| 90 | |
|---|
| 91 | if (isXML(fileStr) == 1) |
|---|
| 92 | LoadNISTXMLData(fileStr,doPlot) |
|---|
| 93 | else |
|---|
| 94 | //Load the waves, using default waveX names |
|---|
| 95 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
|---|
| 96 | LoadWave/G/D/A/Q fileStr |
|---|
| 97 | String fileNamePath = S_Path+S_fileName |
|---|
| 98 | String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0) |
|---|
| 99 | print "basestr :"+basestr |
|---|
| 100 | String fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) |
|---|
| 101 | print "filename :"+filename |
|---|
| 102 | Variable numCols = V_flag |
|---|
| 103 | |
|---|
| 104 | if(numCols==3) //simple 3-column data with no resolution information |
|---|
| 105 | |
|---|
| 106 | // put the names of the three loaded waves into local names |
|---|
| 107 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 108 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 109 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 110 | |
|---|
| 111 | //remove the semicolon AND period from files from the VAX |
|---|
| 112 | w0 = CleanupName((basestr + "_q"),0) |
|---|
| 113 | w1 = CleanupName((basestr + "_i"),0) |
|---|
| 114 | w2 = CleanupName((basestr + "_s"),0) |
|---|
| 115 | |
|---|
| 116 | //String baseStr=w1[0,strlen(w1)-3] |
|---|
| 117 | if(DataFolderExists("root:"+baseStr)) |
|---|
| 118 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
|---|
| 119 | if(V_flag==2) //user selected No, don't load the data |
|---|
| 120 | SetDataFolder root: |
|---|
| 121 | KillWaves $n0,$n1,$n2 // kill the default waveX that were loaded |
|---|
| 122 | //if(DataFolderExists("root:Packages:NIST")) |
|---|
| 123 | // String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 124 | //endif |
|---|
| 125 | return //quits the macro |
|---|
| 126 | endif |
|---|
| 127 | SetDataFolder $("root:"+baseStr) |
|---|
| 128 | else |
|---|
| 129 | NewDataFolder/S $("root:"+baseStr) |
|---|
| 130 | endif |
|---|
| 131 | |
|---|
| 132 | ////overwrite the existing data, if it exists |
|---|
| 133 | Duplicate/O $("root:"+n0), $w0 |
|---|
| 134 | Duplicate/O $("root:"+n1), $w1 |
|---|
| 135 | Duplicate/O $("root:"+n2), $w2 |
|---|
| 136 | |
|---|
| 137 | // no resolution matrix to make |
|---|
| 138 | |
|---|
| 139 | SetScale d,0,0,"1/A",$w0 |
|---|
| 140 | SetScale d,0,0,"1/cm",$w1 |
|---|
| 141 | |
|---|
| 142 | endif //3-col data |
|---|
| 143 | |
|---|
| 144 | if(numCols == 6) //6-column SANS or USANS data that has resolution information |
|---|
| 145 | |
|---|
| 146 | // put the names of the (default named) loaded waves into local names |
|---|
| 147 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 148 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 149 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 150 | n3 = StringFromList(3, S_waveNames ,";" ) |
|---|
| 151 | n4 = StringFromList(4, S_waveNames ,";" ) |
|---|
| 152 | n5 = StringFromList(5, S_waveNames ,";" ) |
|---|
| 153 | |
|---|
| 154 | //remove the semicolon AND period from files from the VAX |
|---|
| 155 | w0 = CleanupName((basestr + "_q"),0) |
|---|
| 156 | w1 = CleanupName((basestr + "_i"),0) |
|---|
| 157 | w2 = CleanupName((basestr + "_s"),0) |
|---|
| 158 | w3 = CleanupName((basestr + "sq"),0) |
|---|
| 159 | w4 = CleanupName((basestr + "qb"),0) |
|---|
| 160 | w5 = CleanupName((basestr + "fs"),0) |
|---|
| 161 | |
|---|
| 162 | //String baseStr=w1[0,strlen(w1)-3] |
|---|
| 163 | if(DataFolderExists("root:"+baseStr)) |
|---|
| 164 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
|---|
| 165 | if(V_flag==2) //user selected No, don't load the data |
|---|
| 166 | SetDataFolder root: |
|---|
| 167 | KillWaves $n0,$n1,$n2,$n3,$n4,$n5 // kill the default waveX that were loaded |
|---|
| 168 | if(DataFolderExists("root:Packages:NIST")) |
|---|
| 169 | String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 170 | endif //set the last file loaded to the one NOT loaded |
|---|
| 171 | return //quits the macro |
|---|
| 172 | endif |
|---|
| 173 | SetDataFolder $("root:"+baseStr) |
|---|
| 174 | else |
|---|
| 175 | NewDataFolder/S $("root:"+baseStr) |
|---|
| 176 | endif |
|---|
| 177 | |
|---|
| 178 | ////overwrite the existing data, if it exists |
|---|
| 179 | Duplicate/O $("root:"+n0), $w0 |
|---|
| 180 | Duplicate/O $("root:"+n1), $w1 |
|---|
| 181 | Duplicate/O $("root:"+n2), $w2 |
|---|
| 182 | Duplicate/O $("root:"+n3), $w3 |
|---|
| 183 | Duplicate/O $("root:"+n4), $w4 |
|---|
| 184 | Duplicate/O $("root:"+n5), $w5 |
|---|
| 185 | |
|---|
| 186 | // need to switch based on SANS/USANS |
|---|
| 187 | if (isSANSResolution($w3[0])) //checks to see if the first point of the wave is <0] |
|---|
| 188 | // make a resolution matrix for SANS data |
|---|
| 189 | Variable np=numpnts($w0) |
|---|
| 190 | Make/D/O/N=(np,4) $(baseStr+"_res") |
|---|
| 191 | |
|---|
| 192 | $(baseStr+"_res")[][0] = $w3[p] //sigQ |
|---|
| 193 | $(baseStr+"_res")[][1] = $w4[p] //qBar |
|---|
| 194 | $(baseStr+"_res")[][2] = $w5[p] //fShad |
|---|
| 195 | $(baseStr+"_res")[][3] = $w0[p] //Qvalues |
|---|
| 196 | else |
|---|
| 197 | //the data is USANS data |
|---|
| 198 | // marix calculation here, but for now, just copy the waves |
|---|
| 199 | //$(baseStr+"_res")[][0] = $w3[p] //sigQ |
|---|
| 200 | //$(baseStr+"_res")[][1] = $w4[p] //qBar |
|---|
| 201 | //$(baseStr+"_res")[][2] = $w5[p] //fShad |
|---|
| 202 | //$(baseStr+"_res")[][3] = $w0[p] //Qvalues |
|---|
| 203 | dQv = -$w3[0] |
|---|
| 204 | |
|---|
| 205 | USANS_CalcWeights(baseStr,dQv) |
|---|
| 206 | |
|---|
| 207 | endif |
|---|
| 208 | Killwaves/Z $w3,$w4,$w5 //get rid of the resolution waves that are in the matrix |
|---|
| 209 | |
|---|
| 210 | SetScale d,0,0,"1/A",$w0 |
|---|
| 211 | SetScale d,0,0,"1/cm",$w1 |
|---|
| 212 | |
|---|
| 213 | endif //6-col data |
|---|
| 214 | |
|---|
| 215 | // Load ORNL data from Heller program |
|---|
| 216 | if(numCols == 4) //4-column SANS or USANS data that has resolution information |
|---|
| 217 | |
|---|
| 218 | // put the names of the (default named) loaded waves into local names |
|---|
| 219 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 220 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 221 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 222 | n3 = StringFromList(3, S_waveNames ,";" ) |
|---|
| 223 | |
|---|
| 224 | //remove the semicolon AND period from files from the VAX |
|---|
| 225 | w0 = CleanupName((basestr + "_q"),0) |
|---|
| 226 | w1 = CleanupName((basestr + "_i"),0) |
|---|
| 227 | w2 = CleanupName((basestr + "_s"),0) |
|---|
| 228 | w3 = CleanupName((basestr + "sq"),0) |
|---|
| 229 | w4 = CleanupName((basestr + "qb"),0) |
|---|
| 230 | w5 = CleanupName((basestr + "fs"),0) |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | //String baseStr=w1[0,strlen(w1)-3] |
|---|
| 234 | if(DataFolderExists("root:"+baseStr)) |
|---|
| 235 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
|---|
| 236 | if(V_flag==2) //user selected No, don't load the data |
|---|
| 237 | SetDataFolder root: |
|---|
| 238 | KillWaves $n0,$n1,$n2,$n3 // kill the default waveX that were loaded |
|---|
| 239 | if(DataFolderExists("root:Packages:NIST")) |
|---|
| 240 | String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 241 | endif //set the last file loaded to the one NOT loaded |
|---|
| 242 | return //quits the macro |
|---|
| 243 | endif |
|---|
| 244 | SetDataFolder $("root:"+baseStr) |
|---|
| 245 | else |
|---|
| 246 | NewDataFolder/S $("root:"+baseStr) |
|---|
| 247 | endif |
|---|
| 248 | |
|---|
| 249 | ////overwrite the existing data, if it exists |
|---|
| 250 | Duplicate/O $("root:"+n0), $w0 |
|---|
| 251 | Duplicate/O $("root:"+n1), $w1 |
|---|
| 252 | Duplicate/O $("root:"+n2), $w2 |
|---|
| 253 | Duplicate/O $("root:"+n3), $w3 |
|---|
| 254 | Duplicate/O $("root:"+n0), $w4 // Set qb wave to nominal measured Q values |
|---|
| 255 | Duplicate/O $("root:"+n0), $w5 // Make wave of appropriate length |
|---|
| 256 | $w5 = 1 // Set all shadowfactor to 1 |
|---|
| 257 | |
|---|
| 258 | // need to switch based on SANS/USANS |
|---|
| 259 | if (isSANSResolution($w3[0])) //checks to see if the first point of the wave is <0] |
|---|
| 260 | // make a resolution matrix for SANS data |
|---|
| 261 | Variable np=numpnts($w0) |
|---|
| 262 | Make/D/O/N=(np,4) $(baseStr+"_res") |
|---|
| 263 | |
|---|
| 264 | $(baseStr+"_res")[][0] = $w3[p] //sigQ |
|---|
| 265 | $(baseStr+"_res")[][1] = $w4[p] //qBar |
|---|
| 266 | $(baseStr+"_res")[][2] = $w5[p] //fShad |
|---|
| 267 | $(baseStr+"_res")[][3] = $w0[p] //Qvalues |
|---|
| 268 | else |
|---|
| 269 | //the data is USANS data |
|---|
| 270 | // marix calculation here, but for now, just copy the waves |
|---|
| 271 | //$(baseStr+"_res")[][0] = $w3[p] //sigQ |
|---|
| 272 | //$(baseStr+"_res")[][1] = $w4[p] //qBar |
|---|
| 273 | //$(baseStr+"_res")[][2] = $w5[p] //fShad |
|---|
| 274 | //$(baseStr+"_res")[][3] = $w0[p] //Qvalues |
|---|
| 275 | dQv = -$w3[0] |
|---|
| 276 | |
|---|
| 277 | USANS_CalcWeights(baseStr,dQv) |
|---|
| 278 | |
|---|
| 279 | endif |
|---|
| 280 | Killwaves/Z $w3,$w4,$w5 //get rid of the resolution waves that are in the matrix |
|---|
| 281 | |
|---|
| 282 | SetScale d,0,0,"1/A",$w0 |
|---|
| 283 | SetScale d,0,0,"1/cm",$w1 |
|---|
| 284 | |
|---|
| 285 | endif //4-col data |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | if(numCols==5) //this is the "old-style" VAX desmeared data format |
|---|
| 289 | |
|---|
| 290 | // put the names of the three loaded waves into local names |
|---|
| 291 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 292 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 293 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 294 | n3 = StringFromList(3, S_waveNames ,";" ) |
|---|
| 295 | n4 = StringFromList(4, S_waveNames ,";" ) |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | //remove the semicolon AND period from files from the VAX |
|---|
| 299 | w0 = CleanupName((basestr+"_q"),0) |
|---|
| 300 | w1 = CleanupName((basestr+"_i"),0) |
|---|
| 301 | w2 = CleanupName((basestr+"_s"),0) |
|---|
| 302 | w3 = CleanupName((basestr+"_ism"),0) |
|---|
| 303 | w4 = CleanupName((basestr+"_fit_ism"),0) |
|---|
| 304 | |
|---|
| 305 | //String baseStr=w1[0,strlen(w1)-3] |
|---|
| 306 | if(DataFolderExists("root:"+baseStr)) |
|---|
| 307 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
|---|
| 308 | if(V_flag==2) //user selected No, don't load the data |
|---|
| 309 | KillWaves $n0,$n1,$n2,$n3,$n4,$n5 // kill the default waveX that were loaded |
|---|
| 310 | //if(DataFolderExists("root:Packages:NIST")) |
|---|
| 311 | // String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 312 | //endif //set the last file loaded to the one NOT loaded |
|---|
| 313 | return //quits the macro |
|---|
| 314 | endif |
|---|
| 315 | SetDataFolder $("root:"+baseStr) |
|---|
| 316 | else |
|---|
| 317 | NewDataFolder/S $("root:"+baseStr) |
|---|
| 318 | endif |
|---|
| 319 | |
|---|
| 320 | ////overwrite the existing data, if it exists |
|---|
| 321 | Duplicate/O $("root:"+n0), $w0 |
|---|
| 322 | Duplicate/O $("root:"+n1), $w1 |
|---|
| 323 | Duplicate/O $("root:"+n2), $w2 |
|---|
| 324 | Duplicate/O $("root:"+n3), $w3 |
|---|
| 325 | Duplicate/O $("root:"+n4), $w4 |
|---|
| 326 | |
|---|
| 327 | // no resolution matrix |
|---|
| 328 | endif //5-col data |
|---|
| 329 | |
|---|
| 330 | ////// |
|---|
| 331 | if(DataFolderExists("root:Packages:NIST")) |
|---|
| 332 | String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 333 | endif |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | //plot if desired |
|---|
| 337 | if(doPlot) |
|---|
| 338 | // assign colors randomly |
|---|
| 339 | rr = abs(trunc(enoise(65535))) |
|---|
| 340 | gg = abs(trunc(enoise(65535))) |
|---|
| 341 | bb = abs(trunc(enoise(65535))) |
|---|
| 342 | |
|---|
| 343 | // if target window is a graph, and user wants to append, do so |
|---|
| 344 | DoWindow/B Plot_Manager |
|---|
| 345 | if(WinType("") == 1) |
|---|
| 346 | DoAlert 1,"Do you want to append this data to the current graph?" |
|---|
| 347 | if(V_Flag == 1) |
|---|
| 348 | AppendToGraph $w1 vs $w0 |
|---|
| 349 | ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1 |
|---|
| 350 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 351 | ModifyGraph tickUnit(left)=1 |
|---|
| 352 | else |
|---|
| 353 | //new graph |
|---|
| 354 | Display $w1 vs $w0 |
|---|
| 355 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
|---|
| 356 | ModifyGraph grid=1,mirror=2,standoff=0 |
|---|
| 357 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 358 | ModifyGraph tickUnit(left)=1 |
|---|
| 359 | Legend |
|---|
| 360 | endif |
|---|
| 361 | else |
|---|
| 362 | // graph window was not target, make new one |
|---|
| 363 | Display $w1 vs $w0 |
|---|
| 364 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
|---|
| 365 | ModifyGraph grid=1,mirror=2,standoff=0 |
|---|
| 366 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 367 | ModifyGraph tickUnit(left)=1 |
|---|
| 368 | Legend |
|---|
| 369 | endif |
|---|
| 370 | endif |
|---|
| 371 | |
|---|
| 372 | //go back to the root folder and clean up before leaving |
|---|
| 373 | SetDataFolder root: |
|---|
| 374 | KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5 |
|---|
| 375 | |
|---|
| 376 | endif |
|---|
| 377 | End |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | //procedure for loading NSE data in the format (4-columns) |
|---|
| 381 | // qvals - time - I(q,t) - dI(q,t) |
|---|
| 382 | // |
|---|
| 383 | // |
|---|
| 384 | // this does NOT load the data into separate folders... |
|---|
| 385 | // |
|---|
| 386 | Proc A_LoadNSEData() |
|---|
| 387 | A_LoadNSEDataWithName("",1) |
|---|
| 388 | End |
|---|
| 389 | |
|---|
| 390 | Proc A_LoadNSEDataWithName(fileStr,doPlot) |
|---|
| 391 | |
|---|
| 392 | //Load the waves, using default waveX names |
|---|
| 393 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
|---|
| 394 | LoadWave/G/D/A fileStr |
|---|
| 395 | String filename = S_fileName |
|---|
| 396 | |
|---|
| 397 | String w0,w1,w2,n0,n1,n2,wt,w3,n3 |
|---|
| 398 | Variable rr,gg,bb |
|---|
| 399 | |
|---|
| 400 | // put the names of the three loaded waves into local names |
|---|
| 401 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 402 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 403 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 404 | n3 = StringFromList(3, S_waveNames ,";" ) |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | //remove the semicolon AND period from files from the VAX |
|---|
| 408 | w0 = CleanupName(("qvals_"+S_fileName),0) |
|---|
| 409 | w1 = CleanupName(("time_"+S_fileName),0) |
|---|
| 410 | w2 = CleanupName(("iqt_"+S_fileName),0) |
|---|
| 411 | w3 = CleanupName(("iqterr_"+S_fileName),0) |
|---|
| 412 | |
|---|
| 413 | if(exists(w0) !=0) |
|---|
| 414 | DoAlert 0,"This file has already been loaded. Use Append to Graph..." |
|---|
| 415 | KillWaves $n0,$n1,$n2 // kill the default waveX that were loaded |
|---|
| 416 | return |
|---|
| 417 | endif |
|---|
| 418 | |
|---|
| 419 | // Rename to give nice names |
|---|
| 420 | Rename $n0, $w0 |
|---|
| 421 | Rename $n1, $w1 |
|---|
| 422 | Rename $n2, $w2 |
|---|
| 423 | Rename $n3, $w3 |
|---|
| 424 | |
|---|
| 425 | if(doPlot) |
|---|
| 426 | // assign colors randomly |
|---|
| 427 | rr = abs(trunc(enoise(65535))) |
|---|
| 428 | gg = abs(trunc(enoise(65535))) |
|---|
| 429 | bb = abs(trunc(enoise(65535))) |
|---|
| 430 | |
|---|
| 431 | // if target window is a graph, and user wants to append, do so |
|---|
| 432 | if(WinType("") == 1) |
|---|
| 433 | DoAlert 1,"Do you want to append this data to the current graph?" |
|---|
| 434 | if(V_Flag == 1) |
|---|
| 435 | AppendToGraph $w2 vs $w1 |
|---|
| 436 | ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
|---|
| 437 | ErrorBars $w2 Y,wave=($w3,$w3) |
|---|
| 438 | else |
|---|
| 439 | //new graph |
|---|
| 440 | Display $w2 vs $w1 |
|---|
| 441 | ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
|---|
| 442 | ErrorBars $w2 Y,wave=($w3,$w3) |
|---|
| 443 | Legend |
|---|
| 444 | endif |
|---|
| 445 | else |
|---|
| 446 | // graph window was not target, make new one |
|---|
| 447 | Display $w2 vs $w1 |
|---|
| 448 | ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
|---|
| 449 | ErrorBars $w2 Y,wave=($w3,$w3) |
|---|
| 450 | Legend |
|---|
| 451 | endif |
|---|
| 452 | endif //doPlot |
|---|
| 453 | |
|---|
| 454 | End |
|---|
| 455 | |
|---|
| 456 | //procedure for loading desmeared USANS data in the format (5-columns) |
|---|
| 457 | // qvals - I(q) - sig I - Ism(q) - fitted Ism(q) |
|---|
| 458 | //no weighting wave is created (not needed in IGOR 4) |
|---|
| 459 | // |
|---|
| 460 | // not really ever used... |
|---|
| 461 | // |
|---|
| 462 | Proc A_LoadUSANSData() |
|---|
| 463 | |
|---|
| 464 | //Load the waves, using default waveX names |
|---|
| 465 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
|---|
| 466 | LoadWave/G/D/A |
|---|
| 467 | String filename = S_fileName |
|---|
| 468 | |
|---|
| 469 | String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4 |
|---|
| 470 | Variable rr,gg,bb |
|---|
| 471 | |
|---|
| 472 | // put the names of the three loaded waves into local names |
|---|
| 473 | n0 = StringFromList(0, S_waveNames ,";" ) |
|---|
| 474 | n1 = StringFromList(1, S_waveNames ,";" ) |
|---|
| 475 | n2 = StringFromList(2, S_waveNames ,";" ) |
|---|
| 476 | n3 = StringFromList(3, S_waveNames ,";" ) |
|---|
| 477 | n4 = StringFromList(4, S_waveNames ,";" ) |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | //remove the semicolon AND period from files from the VAX |
|---|
| 481 | w0 = CleanupName((S_fileName+"_q"),0) |
|---|
| 482 | w1 = CleanupName((S_fileName+"_i"),0) |
|---|
| 483 | w2 = CleanupName((S_fileName+"_s"),0) |
|---|
| 484 | w3 = CleanupName((S_fileName+"_ism"),0) |
|---|
| 485 | w4 = CleanupName((S_fileName+"_fit_ism"),0) |
|---|
| 486 | |
|---|
| 487 | if(exists(w0) !=0) //the wave already exists |
|---|
| 488 | DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
|---|
| 489 | if(V_flag==2) //user selected No |
|---|
| 490 | KillWaves $n0,$n1,$n2,$n3,$n4 // kill the default waveX that were loaded |
|---|
| 491 | if(DataFolderExists("root:Packages:NIST")) |
|---|
| 492 | String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 493 | endif //set the last file loaded to the one NOT loaded |
|---|
| 494 | return //quits the macro |
|---|
| 495 | endif |
|---|
| 496 | endif |
|---|
| 497 | |
|---|
| 498 | ////overwrite the existing data, if it exists |
|---|
| 499 | Duplicate/O $n0, $w0 |
|---|
| 500 | Duplicate/O $n1, $w1 |
|---|
| 501 | Duplicate/O $n2, $w2 |
|---|
| 502 | Duplicate/O $n3, $w3 |
|---|
| 503 | Duplicate/O $n4, $w4 |
|---|
| 504 | KillWaves $n0,$n1,$n2,$n3,$n4 |
|---|
| 505 | |
|---|
| 506 | if(DataFolderExists("root:Packages:NIST")) |
|---|
| 507 | String/G root:Packages:NIST:gLastFileName = filename |
|---|
| 508 | endif |
|---|
| 509 | |
|---|
| 510 | // assign colors randomly |
|---|
| 511 | rr = abs(trunc(enoise(65535))) |
|---|
| 512 | gg = abs(trunc(enoise(65535))) |
|---|
| 513 | bb = abs(trunc(enoise(65535))) |
|---|
| 514 | |
|---|
| 515 | // if target window is a graph, and user wants to append, do so |
|---|
| 516 | if(WinType("") == 1) |
|---|
| 517 | DoAlert 1,"Do you want to append this data to the current graph?" |
|---|
| 518 | if(V_Flag == 1) |
|---|
| 519 | AppendToGraph $w1 vs $w0 |
|---|
| 520 | ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
|---|
| 521 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 522 | else |
|---|
| 523 | //new graph |
|---|
| 524 | Display $w1 vs $w0 |
|---|
| 525 | ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
|---|
| 526 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 527 | Legend |
|---|
| 528 | endif |
|---|
| 529 | else |
|---|
| 530 | // graph window was not target, make new one |
|---|
| 531 | Display $w1 vs $w0 |
|---|
| 532 | ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
|---|
| 533 | ErrorBars $w1 Y,wave=($w2,$w2) |
|---|
| 534 | Legend |
|---|
| 535 | endif |
|---|
| 536 | |
|---|
| 537 | End |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | //// Extra "Utility Procedures" |
|---|
| 541 | // to pick path, get a list of data files, and make sure that a valid filename |
|---|
| 542 | // is passed to LoadOneDDataWithName() |
|---|
| 543 | // |
|---|
| 544 | |
|---|
| 545 | //prompts user to choose the local folder that contains the SANS Data |
|---|
| 546 | //only one folder can be used, and its path is catPathName (and is a NAME, not a string) |
|---|
| 547 | //this will overwrite the path selection |
|---|
| 548 | //returns 1 if no path selected as error condition |
|---|
| 549 | Function A_PickPath() |
|---|
| 550 | |
|---|
| 551 | //set the global string to the selected pathname |
|---|
| 552 | NewPath/O/M="pick the SANS data folder" catPathName |
|---|
| 553 | PathInfo/S catPathName |
|---|
| 554 | String dum = S_path |
|---|
| 555 | String alertStr = "" |
|---|
| 556 | alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood" |
|---|
| 557 | //alertStr += " Please see the manual for details." |
|---|
| 558 | if (V_flag == 0) |
|---|
| 559 | //path does not exist - no folder selected |
|---|
| 560 | String/G root:Packages:NIST:gCatPathStr = "no folder selected" |
|---|
| 561 | return(1) |
|---|
| 562 | else |
|---|
| 563 | //set the global to the path (as a string) |
|---|
| 564 | // need 4 \ since it is the escape character |
|---|
| 565 | if(cmpstr("\\\\",dum[0,1])==0) //Windoze user going through network neighborhood |
|---|
| 566 | DoAlert 0,alertStr |
|---|
| 567 | KillPath catPathName |
|---|
| 568 | return(1) |
|---|
| 569 | endif |
|---|
| 570 | String/G root:Packages:NIST:gCatPathStr = dum |
|---|
| 571 | return(0) //no error |
|---|
| 572 | endif |
|---|
| 573 | End |
|---|
| 574 | |
|---|
| 575 | //Function attempts to find valid filename from partial name that has been stripped of |
|---|
| 576 | //the VAX version number. The partial name is tried first |
|---|
| 577 | //*** the PATH is hard-wired to catPathName (which is assumed to exist) |
|---|
| 578 | //version numers up to ;10 are tried |
|---|
| 579 | //only the "name;vers" is returned. the path is not prepended, hence the return string |
|---|
| 580 | //is not a complete specification of the file |
|---|
| 581 | // |
|---|
| 582 | // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary |
|---|
| 583 | // since from marquee, the filename field (textread[0]) must be used, and can be a mix of |
|---|
| 584 | // upper/lowercase letters, while the filename on the server (should) be all caps |
|---|
| 585 | // now makes repeated calls to ValidFileString() |
|---|
| 586 | // |
|---|
| 587 | Function/S A_FindValidFilename(partialName) |
|---|
| 588 | String PartialName |
|---|
| 589 | |
|---|
| 590 | String retStr="" |
|---|
| 591 | |
|---|
| 592 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
|---|
| 593 | retStr = A_ValidFileString(partialName) |
|---|
| 594 | if(cmpstr(retStr,"") !=0) |
|---|
| 595 | //non-null return |
|---|
| 596 | return(retStr) |
|---|
| 597 | Endif |
|---|
| 598 | |
|---|
| 599 | //if the partial name is derived from the file header, there can be spaces at the beginning |
|---|
| 600 | //or in the middle of the filename - depending on the prefix and initials used |
|---|
| 601 | // |
|---|
| 602 | //remove any leading spaces from the name before starting |
|---|
| 603 | partialName = A_RemoveAllSpaces(partialName) |
|---|
| 604 | |
|---|
| 605 | //try name with no spaces |
|---|
| 606 | retStr = A_ValidFileString(partialName) |
|---|
| 607 | if(cmpstr(retStr,"") !=0) |
|---|
| 608 | //non-null return |
|---|
| 609 | return(retStr) |
|---|
| 610 | Endif |
|---|
| 611 | |
|---|
| 612 | //try all UPPERCASE |
|---|
| 613 | partialName = UpperStr(partialName) |
|---|
| 614 | retStr = A_ValidFileString(partialName) |
|---|
| 615 | if(cmpstr(retStr,"") !=0) |
|---|
| 616 | //non-null return |
|---|
| 617 | return(retStr) |
|---|
| 618 | Endif |
|---|
| 619 | |
|---|
| 620 | //try all lowercase (ret null if failure) |
|---|
| 621 | partialName = LowerStr(partialName) |
|---|
| 622 | retStr = A_ValidFileString(partialName) |
|---|
| 623 | if(cmpstr(retStr,"") !=0) |
|---|
| 624 | //non-null return |
|---|
| 625 | return(retStr) |
|---|
| 626 | else |
|---|
| 627 | return(retStr) |
|---|
| 628 | Endif |
|---|
| 629 | End |
|---|
| 630 | |
|---|
| 631 | //function to test a binary file to see if it is a RAW binary SANS file |
|---|
| 632 | //first checks the total bytes in the file (which for raw data is 33316 bytes) |
|---|
| 633 | //**note that the "DIV" file will also show up as a raw file by the run field |
|---|
| 634 | //should be listed in CAT/SHORT and in patch windows |
|---|
| 635 | // |
|---|
| 636 | //Function then checks the file fname (full path:file) for "RAW" run.type field |
|---|
| 637 | //if not found, the data is not raw data and zero is returned |
|---|
| 638 | Function A_CheckIfRawData(fname) |
|---|
| 639 | String fname |
|---|
| 640 | |
|---|
| 641 | Variable refnum,totalBytes |
|---|
| 642 | String testStr="" |
|---|
| 643 | |
|---|
| 644 | Open/R/T="????TEXT" refNum as fname |
|---|
| 645 | //get the total number of bytes in the file, to avoid moving past EOF |
|---|
| 646 | FStatus refNum |
|---|
| 647 | totalBytes = V_logEOF |
|---|
| 648 | //Print totalBytes |
|---|
| 649 | if(totalBytes!=33316) |
|---|
| 650 | //can't possibly be a raw data file |
|---|
| 651 | Close refnum |
|---|
| 652 | return(0) //not a raw SANS file |
|---|
| 653 | Endif |
|---|
| 654 | FSetPos refNum,75 |
|---|
| 655 | FReadLine/N=3 refNum,testStr |
|---|
| 656 | Close refNum |
|---|
| 657 | |
|---|
| 658 | if(cmpstr(testStr,"RAW")==0) |
|---|
| 659 | //true, is raw data file |
|---|
| 660 | Return(1) |
|---|
| 661 | else |
|---|
| 662 | //some other file |
|---|
| 663 | Return(0) |
|---|
| 664 | Endif |
|---|
| 665 | End |
|---|
| 666 | |
|---|
| 667 | //list (input) is a list, typically returned from IndexedFile() |
|---|
| 668 | //which is semicolon-delimited, and may contain filesnames from the VAX |
|---|
| 669 | //that contain version numbers, where the version number appears as a separate list item |
|---|
| 670 | //(and also as a non-existent file) |
|---|
| 671 | //these numbers must be purged from the list, especially for display in a popup |
|---|
| 672 | //or list processing of filenames |
|---|
| 673 | //the function returns the list, cleaned of version numbers (up to 11) |
|---|
| 674 | //raw data files will typically never have a version number other than 1. |
|---|
| 675 | Function/S A_RemoveVersNumsFromList(list) |
|---|
| 676 | String list |
|---|
| 677 | |
|---|
| 678 | //get rid of version numbers first (up to 11) |
|---|
| 679 | Variable ii,num |
|---|
| 680 | String item |
|---|
| 681 | num = ItemsInList(list,";") |
|---|
| 682 | ii=1 |
|---|
| 683 | do |
|---|
| 684 | item = num2str(ii) |
|---|
| 685 | list = RemoveFromList(item, list ,";" ) |
|---|
| 686 | ii+=1 |
|---|
| 687 | while(ii<12) |
|---|
| 688 | |
|---|
| 689 | return (list) |
|---|
| 690 | End |
|---|
| 691 | |
|---|
| 692 | //Function attempts to find valid filename from partial name that has been stripped of |
|---|
| 693 | //the VAX version number. The partial name is tried first |
|---|
| 694 | //*** the PATH is hard-wired to catPathName (which is assumed to exist) |
|---|
| 695 | //version numers up to ;10 are tried |
|---|
| 696 | //only the "name;vers" is returned. the path is not prepended, hence the return string |
|---|
| 697 | //is not a complete specification of the file |
|---|
| 698 | // |
|---|
| 699 | Function/S A_ValidFileString(partialName) |
|---|
| 700 | String partialName |
|---|
| 701 | |
|---|
| 702 | String tempName = "",msg="" |
|---|
| 703 | Variable ii,refnum |
|---|
| 704 | |
|---|
| 705 | ii=0 |
|---|
| 706 | do |
|---|
| 707 | if(ii==0) |
|---|
| 708 | //first pass, try the partialName |
|---|
| 709 | tempName = partialName |
|---|
| 710 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
|---|
| 711 | if(V_flag == 0) |
|---|
| 712 | //file exists |
|---|
| 713 | Close refnum //YES needed, |
|---|
| 714 | break |
|---|
| 715 | endif |
|---|
| 716 | else |
|---|
| 717 | tempName = partialName + ";" + num2str(ii) |
|---|
| 718 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
|---|
| 719 | if(V_flag == 0) |
|---|
| 720 | //file exists |
|---|
| 721 | Close refnum |
|---|
| 722 | break |
|---|
| 723 | endif |
|---|
| 724 | Endif |
|---|
| 725 | ii+=1 |
|---|
| 726 | //print "ii=",ii |
|---|
| 727 | while(ii<11) |
|---|
| 728 | //go get the selected bits of information, using tempName, which exists |
|---|
| 729 | if(ii>=11) |
|---|
| 730 | //msg = partialName + " not found. is version number > 11?" |
|---|
| 731 | //DoAlert 0, msg |
|---|
| 732 | //PathInfo catPathName |
|---|
| 733 | //Print S_Path |
|---|
| 734 | Return ("") //use null string as error condition |
|---|
| 735 | Endif |
|---|
| 736 | |
|---|
| 737 | Return (tempName) |
|---|
| 738 | End |
|---|
| 739 | |
|---|
| 740 | //function to remove all spaces from names when searching for filenames |
|---|
| 741 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
|---|
| 742 | //but the text field in the header WILL, if less than 3 characters were used for the |
|---|
| 743 | //user's initials, and can have leading spaces if prefix was less than 5 characters |
|---|
| 744 | // |
|---|
| 745 | //returns a string identical to the original string, except with the interior spaces removed |
|---|
| 746 | // |
|---|
| 747 | Function/S A_RemoveAllSpaces(str) |
|---|
| 748 | String str |
|---|
| 749 | |
|---|
| 750 | String tempstr = str |
|---|
| 751 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
|---|
| 752 | ii=0 |
|---|
| 753 | do |
|---|
| 754 | len = strlen(tempStr) |
|---|
| 755 | spc = strsearch(tempStr," ",0) //is the last character a space? |
|---|
| 756 | if (spc == -1) |
|---|
| 757 | break //no more spaces found, get out |
|---|
| 758 | endif |
|---|
| 759 | str = tempstr |
|---|
| 760 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
|---|
| 761 | While(1) //should never be more than 2 or 3 |
|---|
| 762 | |
|---|
| 763 | If(strlen(tempStr) < 1) |
|---|
| 764 | tempStr = "" //be sure to return a null string if problem found |
|---|
| 765 | Endif |
|---|
| 766 | |
|---|
| 767 | //Print strlen(tempstr) |
|---|
| 768 | |
|---|
| 769 | Return(tempStr) |
|---|
| 770 | |
|---|
| 771 | End |
|---|
| 772 | |
|---|
| 773 | //AJJ Oct 2008 |
|---|
| 774 | //Moved from GaussUtils - makes more sense to have it here |
|---|
| 775 | |
|---|
| 776 | // utility used in the "PlotSmeared...() macros to get a list of data folders |
|---|
| 777 | // |
|---|
| 778 | //1: Waves. |
|---|
| 779 | //2: Numeric variables. |
|---|
| 780 | //3: String variables. |
|---|
| 781 | //4: Data folders. |
|---|
| 782 | Function/S GetAList(type) |
|---|
| 783 | Variable type |
|---|
| 784 | |
|---|
| 785 | SetDataFolder root: |
|---|
| 786 | |
|---|
| 787 | String objName,str="" |
|---|
| 788 | Variable index = 0 |
|---|
| 789 | do |
|---|
| 790 | objName = GetIndexedObjName(":", type, index) |
|---|
| 791 | if (strlen(objName) == 0) |
|---|
| 792 | break |
|---|
| 793 | endif |
|---|
| 794 | //Print objName |
|---|
| 795 | str += objName + ";" |
|---|
| 796 | index += 1 |
|---|
| 797 | while(1) |
|---|
| 798 | |
|---|
| 799 | // remove myGlobals, Packages from the folder list |
|---|
| 800 | if(type==4) |
|---|
| 801 | str = RemoveFromList("myGlobals", str , ";" ) |
|---|
| 802 | str = RemoveFromList("Packages", str, ";") |
|---|
| 803 | str = RemoveFromList("AutoFit", str, ";") |
|---|
| 804 | endif |
|---|
| 805 | |
|---|
| 806 | return(str) |
|---|
| 807 | End |
|---|