Ignore:
Timestamp:
Sep 15, 2009 5:25:35 PM (13 years ago)
Author:
srkline
Message:

Moved the NIST-specific XML writer to NIST_XML.ipf file, also so that it can be conditionally compiled without error if the XML XOP is not present. Wrote a dummy function to compile if XOP is not present.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Common/NIST_XML_v40.ipf

    r555 r556  
    689689end 
    690690 
     691//for writing out data (q-i-s) from the "type" folder, and including reduction information 
     692//if fullpath is a complete HD path:filename, no dialog will be presented 
     693//if fullpath is just a filename, the save dialog will be presented 
     694//if dialog = 1, a dialog will always be presented 
     695// 
     696// root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol 
     697// 
     698Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) 
     699        String type,fullpath 
     700        Variable dialog         //=1 will present dialog for name 
     701         
     702        Struct NISTXMLfile nf 
     703         
     704        String destStr="" 
     705        destStr = "root:Packages:NIST:"+type 
     706         
     707        Variable refNum 
     708        String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" 
     709        String fname,ave="C",hdrStr1="",hdrStr2="" 
     710        Variable step=1 
     711         
     712        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
     713        WAVE intw=$(destStr + ":integersRead") 
     714        WAVE rw=$(destStr + ":realsRead") 
     715        WAVE/T textw=$(destStr + ":textRead") 
     716        WAVE qvals =$(destStr + ":qval") 
     717        WAVE inten=$(destStr + ":aveint") 
     718        WAVE sig=$(destStr + ":sigave") 
     719        WAVE qbar = $(destStr + ":QBar") 
     720        WAVE sigmaq = $(destStr + ":SigmaQ") 
     721        WAVE fsubs = $(destStr + ":fSubS") 
     722 
     723 
     724        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr 
     725        Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr) 
     726 
     727         
     728        //check each wave 
     729        If(!(WaveExists(intw))) 
     730                Abort "intw DNExist BinaryWrite_W_Protocol()" 
     731        Endif 
     732        If(!(WaveExists(rw))) 
     733                Abort "rw DNExist BinaryWrite_W_Protocol()" 
     734        Endif 
     735        If(!(WaveExists(textw))) 
     736                Abort "textw DNExist BinaryWrite_W_Protocol()" 
     737        Endif 
     738        If(!(WaveExists(qvals))) 
     739                Abort "qvals DNExist BinaryWrite_W_Protocol()" 
     740        Endif 
     741        If(!(WaveExists(inten))) 
     742                Abort "inten DNExist BinaryWrite_W_Protocol()" 
     743        Endif 
     744        If(!(WaveExists(sig))) 
     745                Abort "sig DNExist BinaryWrite_W_Protocol()" 
     746        Endif 
     747        If(!(WaveExists(qbar))) 
     748                Abort "qbar DNExist BinaryWrite_W_Protocol()" 
     749        Endif 
     750        If(!(WaveExists(sigmaq))) 
     751                Abort "sigmaq DNExist BinaryWrite_W_Protocol()" 
     752        Endif 
     753        If(!(WaveExists(fsubs))) 
     754                Abort "fsubs DNExist BinaryWrite_W_Protocol()" 
     755        Endif 
     756        If(!(WaveExists(proto))) 
     757                Abort "current protocol wave DNExist BinaryWrite_W_Protocol()" 
     758        Endif 
     759         
     760        if(dialog) 
     761                PathInfo/S catPathName 
     762                fullPath = DoSaveFileDialog("Save data as") 
     763                If(cmpstr(fullPath,"")==0) 
     764                        //user cancel, don't write out a file 
     765                        Close/A 
     766                        Abort "no data file was written" 
     767                Endif 
     768                //Print "dialog fullpath = ",fullpath 
     769        Endif 
     770         
     771        SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") 
     772        //actually open the file here 
     773        //Open refNum as fullpath 
     774         
     775        //Data 
     776        Wave nf.Q = qvals 
     777        nf.unitsQ = "1/A" 
     778        Wave nf.I = inten 
     779        nf.unitsI = "1/cm" 
     780        Wave nf.Idev = sig 
     781        nf.unitsIdev = "1/cm" 
     782        Wave nf.Qdev = sigmaq 
     783        nf.unitsQdev = "1/A" 
     784        Wave nf.Qmean = qbar 
     785        nf.unitsQmean = "1/A" 
     786        Wave nf.Shadowfactor = fSubS 
     787        nf.unitsShadowfactor = "none" 
     788         
     789         
     790        //write out the standard header information 
     791        //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 
     792         
     793        //AJJ to fix with sensible values 
     794        nf.run = "Test" 
     795        String acct = textw[3] 
     796        nf.nameSASinstrument = acct[1,3] 
     797        nf.SASnote = "" 
     798        // 
     799        nf.sample_ID = textw[6] 
     800        nf.title = textw[6] 
     801        nf.radiation = "neutron" 
     802        nf.wavelength = rw[26] 
     803        nf.unitswavelength = "A" 
     804        nf.offset_angle = rw[19] 
     805        nf.unitsoffset_angle = "cm" 
     806        nf.SDD = rw[18] 
     807        nf.unitsSDD = "m" 
     808        nf.sample_transmission = rw[4] 
     809        nf.sample_thickness = rw[5] 
     810        nf.unitssample_thickness = "mm" 
     811         
     812        nf.beamcenter_X = rw[16]   
     813        nf.beamcenter_Y = rw[17] 
     814        nf.unitsbeamcenter_X = "pixels" 
     815        nf.unitsbeamcenter_Y = "pixels" 
     816        nf.source_aperture = rw[23] 
     817        nf.typesource_aperture = "pinhole" 
     818        nf.unitssource_aperture = "mm" 
     819        nf.sample_aperture = rw[24] 
     820        nf.typesample_aperture = "pinhole" 
     821        nf.unitssample_aperture = "mm" 
     822        //nf.collimation_length = total length - rw[25] 
     823        nf.wavelength_spread = rw[27] 
     824        nf.unitswavelength_spread = "percent" 
     825        //Do something with beamstop (rw[21]) 
     826        nf.detector_name = textW[9] 
     827//      fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n" 
     828//      fprintf refnum,hdrStr1 
     829 
     830//      fprintf refnum,"BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP \r\n" 
     831//      fprintf refnum,hdrStr2 
     832 
     833        //insert protocol information here 
     834        //-1 list of sample files 
     835        //0 - bkg 
     836        //1 - emp 
     837        //2 - div 
     838        //3 - mask 
     839        //4 - abs params c2-c5 
     840        //5 - average params 
     841        nf.SASprocessnote =  "SAM: "+samFiles+"\n" 
     842        nf.SASprocessnote += "BGD: "+proto[0]+"\n" 
     843        nf.SASprocessnote += "EMP: "+Proto[1]+"\n" 
     844        nf.SASprocessnote += "DIV: "+Proto[2]+"\n" 
     845        nf.SASprocessnote += "MASK: "+Proto[3]+"\n" 
     846        nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n" 
     847        nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n" 
     848         
     849        nf.nameSASProcess = "NIST IGOR" 
     850 
     851        //Close refnum 
     852         
     853        writeNISTXML(fullpath, nf) 
     854         
     855        SetDataFolder root:             //(redundant) 
     856         
     857        //write confirmation of write operation to history area 
     858        Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 
     859        KillWaves/Z tempShortProto 
     860        Return(0) 
     861End 
    691862 
    692863#else   // if( Exists("XmlOpenFile") ) 
     
    700871         
    701872 
    702         function writeNISTXML(fileName, NISTfile) 
    703             String fileName, NISTfile 
     873        Function writeNISTXML(fileName, NISTfile) 
     874                String fileName, NISTfile 
     875                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)" 
     876                RETURN(-6) 
     877        End 
     878         
     879        Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) 
     880                String type,fullpath 
     881                Variable dialog         //=1 will present dialog for name 
     882         
    704883            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)" 
    705          RETURN(-6) 
    706          
    707          
    708 #endif  // if( Exists("XmlOpenFile")  
     884                return(-6) 
     885        end 
     886#endif 
     887 
     888        // if( Exists("XmlOpenFile")  
    709889//Needed to test whether file is XML. The load routine will then either give an error if XMLutils is not present or load the file if it is. 
    710890function isXML(filestr) 
Note: See TracChangeset for help on using the changeset viewer.