- Timestamp:
- Jan 30, 2010 12:00:09 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/USANS/WriteUSANSData.ipf
r587 r624 198 198 Return(0) 199 199 End 200 201 /////////XML Routines//////// 202 ///AJJ Jan 2010 203 ///Have to put these here, annoyingly, because we depend on USANS specific functions 204 ///Need to think about consolidation of functions. 205 206 #if( Exists("XmlOpenFile") ) 207 208 Function WriteXMLUSANSWaves(type,fullpath,lo,hi,dialog) 209 String type,fullpath 210 Variable lo,hi,dialog //=1 will present dialog for name 211 212 SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder 213 214 Struct NISTXMLfile nf 215 216 String termStr="\r\n" //VAX uses only <CR> as terminator, but only CRLF seems to FTP correctly to VAX 217 String destStr="",formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr 218 destStr = USANSFolder+":"+type 219 220 Variable refNum,integer,realval 221 222 223 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 224 WAVE qvals =$(destStr + ":Qvals") 225 WAVE inten=$(destStr + ":DetCts") 226 WAVE sig=$(destStr + ":ErrDetCts") 227 228 //check each wave 229 If(!(WaveExists(qvals))) 230 Abort "qvals DNExist in WriteUSANSWaves()" 231 Endif 232 If(!(WaveExists(inten))) 233 Abort "inten DNExist in WriteUSANSWaves()" 234 Endif 235 If(!(WaveExists(sig))) 236 Abort "sig DNExist in WriteUSANSWaves()" 237 Endif 238 239 //Use the evil extra column. Should probably switch to using slit_length in collimation. 240 Duplicate/O qvals,dumWave 241 NVAR DQv=$(USANSFolder+":Globals:MainPanel:gDQv") 242 dumWave = - DQv 243 /// 244 245 if(dialog) 246 PathInfo/S catPathName 247 fullPath = DoSaveFileDialog("Save data as") 248 If(cmpstr(fullPath,"")==0) 249 //user cancel, don't write out a file 250 Close/A 251 Abort "no data file was written" 252 Endif 253 //Print "dialog fullpath = ",fullpath 254 Endif 255 256 SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") 257 //actually open the file here 258 //Open refNum as fullpath 259 260 //Data 261 Wave nf.Q = qvals 262 nf.unitsQ = "1/A" 263 Wave nf.I = inten 264 nf.unitsI = "1/cm" 265 Wave nf.Idev = sig 266 nf.unitsIdev = "1/cm" 267 Wave nf.dQl = sigmaq 268 nf.unitsdQl= "1/A" 269 270 271 //write out the standard header information 272 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 273 274 //tailor the output given the type of data written out... 275 WAVE inten_EMP=$(USANSFolder+":EMP:DetCts") 276 String samStr="",empStr="",dateStr="",samLabelStr="",paramStr="",empLevStr="",bkgLevStr="" 277 String pkStr="" 278 NVAR TransWide = $(USANSFolder+":Globals:MainPanel:gTransWide") 279 NVAR TransRock = $(USANSFolder+":Globals:MainPanel:gTransRock") 280 NVAR empCts = $(USANSFolder+":Globals:MainPanel:gEmpCts") 281 NVAR bkgCts = $(USANSFolder+":Globals:MainPanel:gBkgCts") 282 NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick") 283 284 strswitch(type) 285 case "SAM": 286 samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 287 empStr = "Uncorrected SAM data" 288 empLevStr = "Uncorrected SAM data" 289 bkgLevStr = "Uncorrected SAM data" 290 paramStr = "Uncorrected SAM data" 291 pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 292 break 293 case "EMP": 294 samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 295 empStr = "Uncorrected EMP data" 296 empLevStr = "Uncorrected EMP data" 297 bkgLevStr = "Uncorrected EMP data" 298 paramStr = "Uncorrected EMP data" 299 pkStr += "EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 300 break 301 default: //"COR" is the default 302 samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 303 empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";") 304 empLevStr = "EMP LEVEL: " + num2str(empCts) 305 bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) 306 paramStr = "Ds = "+num2str(thick)+" cm ; " 307 paramStr += "Twide = "+num2Str(TransWide)+" ; " 308 paramStr += "Trock = "+num2str(TransRock) 309 pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 310 pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 311 endswitch 312 313 314 //AJJ to fix with sensible values 315 nf.run = "Test" 316 nf.nameSASinstrument = "BT5 USANS" 317 nf.SASnote = "" 318 // 319 nf.sample_ID = "" 320 nf.title = StringByKey("LABEL",note(inten),":",";") 321 nf.radiation = "neutron" 322 nf.wavelength = 2.38 323 nf.unitswavelength = "A" 324 nf.sample_thickness = thick 325 nf.unitssample_thickness = "cm" 326 327 //Do something with beamstop (rw[21]) 328 nf.detector_name = "BT5 DETECTOR ARRAY" 329 330 nf.SASprocessnote = samStr+"\n" 331 nf.SASprocessnote += dateStr+"\n" 332 nf.SASprocessnote += samLabelStr+"\n" 333 nf.SASprocessnote += empStr+"\n" 334 nf.SASprocessnote += paramStr+"\n" 335 nf.SASprocessnote += pkStr+"\n" 336 nf.SASprocessnote += empLevStr + " ; "+bkglevStr+"\n" 337 338 nf.nameSASProcess = "NIST IGOR" 339 340 //Close refnum 341 342 writeNISTXML(fullpath, nf) 343 344 SetDataFolder root: //(redundant) 345 346 //write confirmation of write operation to history area 347 Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 348 KillWaves/Z tempShortProto 349 Return(0) 350 End 351 352 Function WriteXMLUSANSDesmeared(fullpath,lo,hi,dialog) 353 String fullpath 354 Variable lo,hi,dialog //=1 will present dialog for name 355 356 SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder 357 358 Struct NISTXMLfile nf 359 360 String termStr="\r\n" 361 String destStr = USANSFolder+":DSM:" 362 String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr 363 364 Variable refNum,integer,realval 365 366 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 367 WAVE Q_dsm =$(destStr + "Q_dsm") 368 WAVE I_dsm=$(destStr + "I_dsm") 369 WAVE S_dsm=$(destStr + "S_dsm") 370 371 //check each wave 372 If(!(WaveExists(Q_dsm))) 373 Abort "Q_dsm DNExist in WriteUSANSDesmeared()" 374 Endif 375 If(!(WaveExists(I_dsm))) 376 Abort "I_dsm DNExist in WriteUSANSDesmeared()" 377 Endif 378 If(!(WaveExists(S_dsm))) 379 Abort "S_dsm DNExist in WriteUSANSDesmeared()" 380 Endif 381 382 // 06 FEB 06 SRK 383 // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns 384 // 385 Duplicate/O Q_dsm,res1,res2,res3 386 res3 = 1 // "fake" beamstop shadowing 387 res1 /= 100 //make the sigmaQ so small that there is no smearing 388 389 if(dialog) 390 Open/D refnum as fullpath+".dsm" //won't actually open the file 391 If(cmpstr(S_filename,"")==0) 392 //user cancel, don't write out a file 393 Close/A 394 Abort "no data file was written" 395 Endif 396 fullpath = S_filename 397 Endif 398 399 //write out partial set? 400 Duplicate/O Q_dsm,tq,ti,te 401 ti=I_dsm 402 te=S_dsm 403 if( (lo!=hi) && (lo<hi)) 404 redimension/N=(hi-lo+1) tq,ti,te,res1,res2,res3 //lo to hi, inclusive 405 tq=Q_dsm[p+lo] 406 ti=I_dsm[p+lo] 407 te=S_dsm[p+lo] 408 endif 409 410 //Data 411 Wave nf.Q = tq 412 nf.unitsQ = "1/A" 413 Wave nf.I = ti 414 nf.unitsI = "1/cm" 415 Wave nf.Idev = te 416 nf.unitsIdev = "1/cm" 417 Wave nf.Qdev = res1 418 nf.unitsQdev = "1/A" 419 Wave nf.Qmean = res2 420 nf.unitsQmean = "1/A" 421 Wave nf.Shadowfactor = res3 422 nf.unitsShadowfactor = "none" 423 424 //tailor the output given the type of data written out... 425 String samStr="",dateStr="",str1,str2 426 427 NVAR m = $(USANSFolder+":DSM:gPowerM") // power law exponent 428 NVAR chiFinal = $(USANSFolder+":DSM:gChi2Final") //chi^2 final 429 NVAR iter = $(USANSFolder+":DSM:gIterations") //total number of iterations 430 431 //get the number of spline passes from the wave note 432 String noteStr 433 Variable boxPass,SplinePass 434 noteStr=note(I_dsm) 435 BoxPass = NumberByKey("BOX", noteStr, "=", ";") 436 splinePass = NumberByKey("SPLINE", noteStr, "=", ";") 437 438 samStr = fullpath 439 dateStr="CREATED: "+date()+" at "+time() 440 sprintf str1,"Chi^2 = %g PowerLaw m = %4.2f Iterations = %d",chiFinal,m,iter 441 sprintf str2,"%d box smooth passes and %d smoothing spline passes",boxPass,splinePass 442 443 //AJJ to fix with sensible values 444 nf.run = "Test" 445 nf.nameSASinstrument = "BT5 USANS" 446 nf.SASnote = "" 447 // 448 nf.sample_ID = "" 449 nf.title = samstr 450 nf.radiation = "neutron" 451 nf.wavelength = 2.38 452 nf.unitswavelength = "A" 453 454 //Do something with beamstop (rw[21]) 455 nf.detector_name = "BT5 DETECTOR ARRAY" 456 457 nf.SASprocessnote = samStr+"\n" 458 nf.SASprocessnote += str1+"\n" 459 nf.SASprocessnote += str2+"\n" 460 nf.SASprocessnote += datestr+"\n" 461 462 463 nf.nameSASProcess = "NIST IGOR" 464 465 //Close refnum 466 467 writeNISTXML(fullpath, nf) 468 469 SetDataFolder root: //(redundant) 470 471 Return(0) 472 End 473 474 475 #else // if( Exists("XmlOpenFile") ) 476 // No XMLutils XOP: provide dummy function so that IgorPro can compile dependent support code 477 478 479 Function WriteXMLUSANSWaves(type,fullpath,lo,hi,dialog) 480 String type,fullpath 481 Variable lo,hi,dialog //=1 will present dialog for name 482 483 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)" 484 return(-6) 485 end 486 487 Function WriteXMLUSANSDesmeared(type,fullpath,lo,hi,dialog) 488 String type,fullpath 489 Variable lo,hi,dialog //=1 will present dialog for name 490 491 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)" 492 return(-6) 493 end 494 495 496 497 #endif
Note: See TracChangeset
for help on using the changeset viewer.