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.

Location:
sans/Dev/trunk/NCNR_User_Procedures
Files:
2 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) 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WriteQIS.ipf

    r555 r556  
    860860 
    861861 
    862 //for writing out data (q-i-s) from the "type" folder, and including reduction information 
    863 //if fullpath is a complete HD path:filename, no dialog will be presented 
    864 //if fullpath is just a filename, the save dialog will be presented 
    865 //if dialog = 1, a dialog will always be presented 
    866 // 
    867 // root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol 
    868 // 
    869 Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) 
    870         String type,fullpath 
    871         Variable dialog         //=1 will present dialog for name 
    872          
    873         Struct NISTXMLfile nf 
    874          
    875         String destStr="" 
    876         destStr = "root:Packages:NIST:"+type 
    877          
    878         Variable refNum 
    879         String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" 
    880         String fname,ave="C",hdrStr1="",hdrStr2="" 
    881         Variable step=1 
    882          
    883         //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
    884         WAVE intw=$(destStr + ":integersRead") 
    885         WAVE rw=$(destStr + ":realsRead") 
    886         WAVE/T textw=$(destStr + ":textRead") 
    887         WAVE qvals =$(destStr + ":qval") 
    888         WAVE inten=$(destStr + ":aveint") 
    889         WAVE sig=$(destStr + ":sigave") 
    890         WAVE qbar = $(destStr + ":QBar") 
    891         WAVE sigmaq = $(destStr + ":SigmaQ") 
    892         WAVE fsubs = $(destStr + ":fSubS") 
    893  
    894  
    895         SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr 
    896         Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr) 
    897  
    898          
    899         //check each wave 
    900         If(!(WaveExists(intw))) 
    901                 Abort "intw DNExist BinaryWrite_W_Protocol()" 
    902         Endif 
    903         If(!(WaveExists(rw))) 
    904                 Abort "rw DNExist BinaryWrite_W_Protocol()" 
    905         Endif 
    906         If(!(WaveExists(textw))) 
    907                 Abort "textw DNExist BinaryWrite_W_Protocol()" 
    908         Endif 
    909         If(!(WaveExists(qvals))) 
    910                 Abort "qvals DNExist BinaryWrite_W_Protocol()" 
    911         Endif 
    912         If(!(WaveExists(inten))) 
    913                 Abort "inten DNExist BinaryWrite_W_Protocol()" 
    914         Endif 
    915         If(!(WaveExists(sig))) 
    916                 Abort "sig DNExist BinaryWrite_W_Protocol()" 
    917         Endif 
    918         If(!(WaveExists(qbar))) 
    919                 Abort "qbar DNExist BinaryWrite_W_Protocol()" 
    920         Endif 
    921         If(!(WaveExists(sigmaq))) 
    922                 Abort "sigmaq DNExist BinaryWrite_W_Protocol()" 
    923         Endif 
    924         If(!(WaveExists(fsubs))) 
    925                 Abort "fsubs DNExist BinaryWrite_W_Protocol()" 
    926         Endif 
    927         If(!(WaveExists(proto))) 
    928                 Abort "current protocol wave DNExist BinaryWrite_W_Protocol()" 
    929         Endif 
    930          
    931         if(dialog) 
    932                 PathInfo/S catPathName 
    933                 fullPath = DoSaveFileDialog("Save data as") 
    934                 If(cmpstr(fullPath,"")==0) 
    935                         //user cancel, don't write out a file 
    936                         Close/A 
    937                         Abort "no data file was written" 
    938                 Endif 
    939                 //Print "dialog fullpath = ",fullpath 
    940         Endif 
    941          
    942         SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") 
    943         //actually open the file here 
    944         //Open refNum as fullpath 
    945          
    946         //Data 
    947         Wave nf.Q = qvals 
    948         nf.unitsQ = "1/A" 
    949         Wave nf.I = inten 
    950         nf.unitsI = "1/cm" 
    951         Wave nf.Idev = sig 
    952         nf.unitsIdev = "1/cm" 
    953         Wave nf.Qdev = sigmaq 
    954         nf.unitsQdev = "1/A" 
    955         Wave nf.Qmean = qbar 
    956         nf.unitsQmean = "1/A" 
    957         Wave nf.Shadowfactor = fSubS 
    958         nf.unitsShadowfactor = "none" 
    959          
    960          
    961         //write out the standard header information 
    962         //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 
    963          
    964         //AJJ to fix with sensible values 
    965         nf.run = "Test" 
    966         String acct = textw[3] 
    967         nf.nameSASinstrument = acct[1,3] 
    968         nf.SASnote = "" 
    969         // 
    970         nf.sample_ID = textw[6] 
    971         nf.title = textw[6] 
    972         nf.radiation = "neutron" 
    973         nf.wavelength = rw[26] 
    974         nf.unitswavelength = "A" 
    975         nf.offset_angle = rw[19] 
    976         nf.unitsoffset_angle = "cm" 
    977         nf.SDD = rw[18] 
    978         nf.unitsSDD = "m" 
    979         nf.sample_transmission = rw[4] 
    980         nf.sample_thickness = rw[5] 
    981         nf.unitssample_thickness = "mm" 
    982          
    983         nf.beamcenter_X = rw[16]   
    984         nf.beamcenter_Y = rw[17] 
    985         nf.unitsbeamcenter_X = "pixels" 
    986         nf.unitsbeamcenter_Y = "pixels" 
    987         nf.source_aperture = rw[23] 
    988         nf.typesource_aperture = "pinhole" 
    989         nf.unitssource_aperture = "mm" 
    990         nf.sample_aperture = rw[24] 
    991         nf.typesample_aperture = "pinhole" 
    992         nf.unitssample_aperture = "mm" 
    993         //nf.collimation_length = total length - rw[25] 
    994         nf.wavelength_spread = rw[27] 
    995         nf.unitswavelength_spread = "percent" 
    996         //Do something with beamstop (rw[21]) 
    997         nf.detector_name = textW[9] 
    998 //      fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n" 
    999 //      fprintf refnum,hdrStr1 
    1000  
    1001 //      fprintf refnum,"BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP \r\n" 
    1002 //      fprintf refnum,hdrStr2 
    1003  
    1004         //insert protocol information here 
    1005         //-1 list of sample files 
    1006         //0 - bkg 
    1007         //1 - emp 
    1008         //2 - div 
    1009         //3 - mask 
    1010         //4 - abs params c2-c5 
    1011         //5 - average params 
    1012         nf.SASprocessnote =  "SAM: "+samFiles+"\n" 
    1013         nf.SASprocessnote += "BGD: "+proto[0]+"\n" 
    1014         nf.SASprocessnote += "EMP: "+Proto[1]+"\n" 
    1015         nf.SASprocessnote += "DIV: "+Proto[2]+"\n" 
    1016         nf.SASprocessnote += "MASK: "+Proto[3]+"\n" 
    1017         nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n" 
    1018         nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n" 
    1019          
    1020         nf.nameSASProcess = "NIST IGOR" 
    1021  
    1022         //Close refnum 
    1023          
    1024         writeNISTXML(fullpath, nf) 
    1025          
    1026         SetDataFolder root:             //(redundant) 
    1027          
    1028         //write confirmation of write operation to history area 
    1029         Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 
    1030         KillWaves/Z tempShortProto 
    1031         Return(0) 
    1032 End 
Note: See TracChangeset for help on using the changeset viewer.