#pragma rtGlobals=1 // Use modern global access method. #pragma Version=2.20 #pragma IgorVersion=6.1 ////////////// //for writing out data (q-i-s-dum-dum-dum) from the "type" folder //if fullpath is a complete HD path:filename, no dialog will be presented //if fullpath is just a filename, the save dialog will be presented (forced if dialog =1) //lo,hi are an (optional) range of the data[lo,hi] to save (in points) //if lo=hi=0, all of the data is written out // //////// 27 OCT 04 // now writes 6-column data such that the last three columns are the divergence // = a constant value, set in Init_MainUSANS() // Function WriteUSANSWaves(type,fullpath,lo,hi,dialog) String type,fullpath Variable lo,hi,dialog //=1 will present dialog for name SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder String termStr="\r\n" //VAX uses only as terminator, but only CRLF seems to FTP correctly to VAX String destStr="",formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr destStr = USANSFolder+":"+type Variable refNum,integer,realval //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** WAVE qvals =$(destStr + ":Qvals") WAVE inten=$(destStr + ":DetCts") WAVE sig=$(destStr + ":ErrDetCts") //check each wave If(!(WaveExists(qvals))) Abort "qvals DNExist in WriteUSANSWaves()" Endif If(!(WaveExists(inten))) Abort "inten DNExist in WriteUSANSWaves()" Endif If(!(WaveExists(sig))) Abort "sig DNExist in WriteUSANSWaves()" Endif // 27 OCT 04 SRK // make a dummy wave to hold the divergence, and write it as the last 3 columns // and make the value negative as a flag for the analysis software // Duplicate/O qvals,dumWave NVAR DQv=$(USANSFolder+":Globals:MainPanel:gDQv") dumWave = - DQv /// if(dialog) PathInfo/S savePathName fullPath = DoSaveFileDialog("Save data as") If(cmpstr(fullPath,"")==0) //user cancel, don't write out a file Close/A Abort "no data file was written" Endif //Print "dialog fullpath = ",fullpath Endif //write out partial set? Duplicate/O qvals,tq,ti,te ti=inten te=sig if( (lo!=hi) && (lo as terminator, but only CRLF seems to FTP correctly to VAX String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr String newFName="",suffix="_6col.cor",fullpath="" Variable refNum_old,refnum_new,integer,realval // 08 NOV 04 SRK Variable ii,dQv = -0.037 //hard-wired value for divergence (pre- NOV 2004 value) /// Open/R/D/M="Select the 3-column data file"/T="????" refnum_old //won't actually open the file If(cmpstr(S_filename,"")==0) //user cancel, don't write out a file Close/A Abort "no data file was written" Endif fullpath = S_filename newFname = fullpath[0,strlen(fullpath)-5]+suffix Print fullpath Print newFname String tmpStr String extraStr="" sprintf extraStr,"%15.6g %15.6g %15.6g",dQv,dQv,dQv extraStr += termStr //actually open each of the files Open/R refNum_old as fullpath Open refNum_new as newFname //7 header lines for(ii=0;ii<7;ii+=1) FReadLine refNum_old, tmpStr //returns only CR fprintf refnum_new,tmpStr+"\n" // add LF so file has CRLF endfor do FReadLine refNum_old, tmpStr if(strlen(tmpStr)==0) break endif fprintf refnum_new,tmpStr[0,strlen(tmpStr)-2]+extraStr while(1) Close refnum_old Close refnum_new Return(0) End /////////XML Routines//////// ///AJJ Jan 2010 ///Have to put these here, annoyingly, because we depend on USANS specific functions ///Need to think about consolidation of functions. #if( Exists("XmlOpenFile") ) Function WriteXMLUSANSWaves(type,fullpath,lo,hi,dialog) String type,fullpath Variable lo,hi,dialog //=1 will present dialog for name SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder Struct NISTXMLfile nf String termStr="\r\n" //VAX uses only as terminator, but only CRLF seems to FTP correctly to VAX String destStr="",formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr destStr = USANSFolder+":"+type Variable refNum,integer,realval //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** WAVE qvals =$(destStr + ":Qvals") WAVE inten=$(destStr + ":DetCts") WAVE sig=$(destStr + ":ErrDetCts") //check each wave If(!(WaveExists(qvals))) Abort "qvals DNExist in WriteUSANSWaves()" Endif If(!(WaveExists(inten))) Abort "inten DNExist in WriteUSANSWaves()" Endif If(!(WaveExists(sig))) Abort "sig DNExist in WriteUSANSWaves()" Endif //Use the evil extra column. Should probably switch to using slit_length in collimation. Duplicate/O qvals,dumWave NVAR DQv=$(USANSFolder+":Globals:MainPanel:gDQv") dumWave = - DQv /// if(dialog) PathInfo/S catPathName fullPath = DoSaveFileDialog("Save data as") If(cmpstr(fullPath,"")==0) //user cancel, don't write out a file Close/A Abort "no data file was written" Endif //Print "dialog fullpath = ",fullpath Endif SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") //actually open the file here //Open refNum as fullpath //Data Wave nf.Q = qvals nf.unitsQ = "1/A" Wave nf.I = inten nf.unitsI = "1/cm" Wave nf.Idev = sig nf.unitsIdev = "1/cm" Wave nf.dQl = sigmaq nf.unitsdQl= "1/A" //write out the standard header information //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] //tailor the output given the type of data written out... WAVE inten_EMP=$(USANSFolder+":EMP:DetCts") String samStr="",empStr="",dateStr="",samLabelStr="",paramStr="",empLevStr="",bkgLevStr="" String pkStr="" NVAR TransWide = $(USANSFolder+":Globals:MainPanel:gTransWide") NVAR TransRock = $(USANSFolder+":Globals:MainPanel:gTransRock") NVAR empCts = $(USANSFolder+":Globals:MainPanel:gEmpCts") NVAR bkgCts = $(USANSFolder+":Globals:MainPanel:gBkgCts") NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick") strswitch(type) case "SAM": samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") empStr = "Uncorrected SAM data" empLevStr = "Uncorrected SAM data" bkgLevStr = "Uncorrected SAM data" paramStr = "Uncorrected SAM data" pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) break case "EMP": samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") empStr = "Uncorrected EMP data" empLevStr = "Uncorrected EMP data" bkgLevStr = "Uncorrected EMP data" paramStr = "Uncorrected EMP data" pkStr += "EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) break default: //"COR" is the default samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";") empLevStr = "EMP LEVEL: " + num2str(empCts) bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) paramStr = "Ds = "+num2str(thick)+" cm ; " paramStr += "Twide = "+num2Str(TransWide)+" ; " paramStr += "Trock = "+num2str(TransRock) pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) endswitch //AJJ to fix with sensible values nf.run = "Test" nf.nameSASinstrument = "BT5 USANS" nf.SASnote = "" // nf.sample_ID = "" nf.title = StringByKey("LABEL",note(inten),":",";") nf.radiation = "neutron" nf.wavelength = 2.38 nf.unitswavelength = "A" nf.sample_thickness = thick nf.unitssample_thickness = "cm" //Do something with beamstop (rw[21]) nf.detector_name = "BT5 DETECTOR ARRAY" nf.SASprocessnote = samStr+"\n" nf.SASprocessnote += dateStr+"\n" nf.SASprocessnote += samLabelStr+"\n" nf.SASprocessnote += empStr+"\n" nf.SASprocessnote += paramStr+"\n" nf.SASprocessnote += pkStr+"\n" nf.SASprocessnote += empLevStr + " ; "+bkglevStr+"\n" nf.nameSASProcess = "NIST IGOR" //Close refnum writeNISTXML(fullpath, nf) SetDataFolder root: //(redundant) //write confirmation of write operation to history area Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) KillWaves/Z tempShortProto Return(0) End Function WriteXMLUSANSDesmeared(fullpath,lo,hi,dialog) String fullpath Variable lo,hi,dialog //=1 will present dialog for name SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder Struct NISTXMLfile nf String termStr="\r\n" String destStr = USANSFolder+":DSM:" String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr Variable refNum,integer,realval //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** WAVE Q_dsm =$(destStr + "Q_dsm") WAVE I_dsm=$(destStr + "I_dsm") WAVE S_dsm=$(destStr + "S_dsm") //check each wave If(!(WaveExists(Q_dsm))) Abort "Q_dsm DNExist in WriteUSANSDesmeared()" Endif If(!(WaveExists(I_dsm))) Abort "I_dsm DNExist in WriteUSANSDesmeared()" Endif If(!(WaveExists(S_dsm))) Abort "S_dsm DNExist in WriteUSANSDesmeared()" Endif // 06 FEB 06 SRK // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns // Duplicate/O Q_dsm,res1,res2,res3 res3 = 1 // "fake" beamstop shadowing res1 /= 100 //make the sigmaQ so small that there is no smearing if(dialog) Open/D refnum as fullpath+".dsm" //won't actually open the file If(cmpstr(S_filename,"")==0) //user cancel, don't write out a file Close/A Abort "no data file was written" Endif fullpath = S_filename Endif //write out partial set? Duplicate/O Q_dsm,tq,ti,te ti=I_dsm te=S_dsm if( (lo!=hi) && (lo