Ignore:
Timestamp:
May 31, 2007 12:58:47 PM (16 years ago)
Author:
ajj
Message:

Merged kline_29MAR07 branch (Separation of NCNR specific code) r66:115 into the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/Transmission.ipf

    r47 r116  
    250250        String fname,sname 
    251251         
    252         Variable isTrans, xTol= -5 
    253  
    254         String textstr,temp,labelStr,date_time,suffix,assoc 
    255         Variable ctime,lambda,sdd,detcnt,cntrate,refNum,trans,thick,xcenter,ycenter,numatten 
    256         Variable lastPoint, beamstop, Whole 
    257  
    258         isTrans = CheckIfBeamstopOut(fname, xTol) 
     252        Variable isTrans 
     253 
     254        Variable lastPoint 
     255 
     256        isTrans = isTransFile(fname) 
    259257        // decalre the correct set of waves 
    260258        // S_Whole is only a place holder so the waves are of equal length 
     
    283281        lastPoint = numpnts(GLambda) 
    284282         
    285         Open/R refNum as fname 
    286          
    287283        InsertPoints lastPoint,1,G_TRANS_Filenames 
    288284        G_TRANS_Filenames[lastPoint]="" 
     
    292288         
    293289        //read the file suffix 
    294         FSetPos refNum,19 
    295         FReadLine/N=4 refNum,suffix 
    296         //print suffix 
    297290        InsertPoints lastPoint,1,GSuffix 
    298         GSuffix[lastPoint]=suffix 
     291        GSuffix[lastPoint]=getSuffix(fname) 
    299292 
    300293        //read any suffix that this file is associated with 
    301         //FSetPos refNum,91             //wrong position 
    302         FSetPos refNum,404 
    303         FReadLine/N=4 refNum,assoc 
    304         //print isTrans, assoc 
    305294        InsertPoints lastPoint,1,GSuffices 
    306         GSuffices[lastPoint]=assoc 
     295        GSuffices[lastPoint]=getAssociatedFileSuffix(fname) 
    307296             
    308297        // read the sample.label text field 
    309         FSetPos refNum,98               //will start reading at byte 99 
    310         FReadLine/N=60 refNum,labelStr 
    311298        InsertPoints lastPoint,1,GLabels 
    312         GLabels[lastPoint]=labelStr 
    313  
    314         Close refNum 
     299        GLabels[lastPoint]=getSampleLabel(fname) 
    315300             
    316         //read the reals with GBLoadWave 
    317         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    318         String strToExecute 
    319          
     301 
    320302        //Transmission 
    321         strToExecute = GBLoadStr + "/S=158/U=1" + "\"" + fname + "\"" 
    322         Execute strToExecute 
    323         Wave w=$"tempGBWave0" 
    324         trans = w[0] 
    325303        InsertPoints lastPoint,1,GTransmission 
    326         GTransmission[lastPoint]=trans 
    327          
    328         //Whole Transmission 
    329         strToExecute = GBLoadStr + "/S=392/U=1" + "\"" + fname + "\"" 
    330         Execute strToExecute 
    331         Wave w=$"tempGBWave0" 
    332         Whole = w[0] 
     304        GTransmission[lastPoint]=getSampleTrans(fname) 
     305         
     306        //Whole detector Transmission 
    333307        InsertPoints lastPoint,1,GWhole 
    334         GWhole[lastPoint]=Whole 
     308        GWhole[lastPoint]=getSampleTransWholeDetector(fname) 
    335309             
    336310        //SDD 
    337         strToExecute = GBLoadStr + "/S=260/U=1" + "\"" + fname + "\"" 
    338         Execute strToExecute 
    339         sdd = w[0] 
    340311        InsertPoints lastPoint,1,GSDD 
    341         GSDD[lastPoint]=sdd 
     312        GSDD[lastPoint]=getSDD(fname) 
    342313             
    343314        //wavelength 
    344         strToExecute = GBLoadStr + "/S=292/U=1" + "\"" + fname + "\"" 
    345         Execute strToExecute 
    346         lambda = w[0] 
    347315        InsertPoints lastPoint,1,GLambda 
    348         GLambda[lastPoint]=lambda 
    349          
    350 //      InsertPoints lastPoint,1,GWhole 
    351 //      GWhole[lastPoint]=1 
    352          
    353         KillWaves/Z w 
    354  
     316        GLambda[lastPoint]=getWavelength(fname) 
     317         
     318        return(0) 
    355319End 
    356320 
     
    533497                                        suffix=T_GSuffix[jj] 
    534498                                        filename = pathname + T_GFilenames[ii] 
    535                                         Open/A/T="????TEXT" refnum as filename 
    536                                         //FSetPos refnum,91             //wrong position 
    537                                         FSetPos refnum,404 
    538                                         FBinWrite refnum, suffix 
    539                                         FStatus refnum 
    540                                         FSetPos refnum,V_logEOF 
    541                                         Close refnum 
     499                                        WriteAssocFileSuffixToHeader(filename,suffix) 
    542500                                endif 
    543501                                jj+=1 
     
    556514                                        suffix=T_GSuffix[jj] 
    557515                                        filename = pathname + S_GFilenames[ii] 
    558                                         Open/A/T="????TEXT" refnum as filename 
    559                                         //FSetPos refnum,91             //wrong position 
    560                                         FSetPos refnum,404 
    561                                         FBinWrite refnum, suffix 
    562                                         FStatus refnum 
    563                                         FSetPos refnum,V_logEOF 
    564                                         Close refnum 
     516                                        WriteAssocFileSuffixToHeader(filename,suffix) 
    565517                                endif 
    566518                                jj+=1 
     
    601553                                        suffix=T_GSuffix[jj] 
    602554                                        filename = pathname + T_GFilenames[ii] 
    603                                         Open/A/T="????TEXT" refnum as filename 
    604                                         //FSetPos refnum,91             //wrong position 
    605                                         FSetPos refnum,404 
    606                                         FBinWrite refnum, suffix 
    607                                         FStatus refnum 
    608                                         FSetPos refnum,V_logEOF 
    609                                         Close refnum 
     555                                        WriteAssocFileSuffixToHeader(filename,suffix) 
    610556                                endif 
    611557                                jj+=1 
     
    662608                         
    663609                        // write in zeros for the box coordinates 
    664                         Open/A/T="????TEXT" refnum as filename 
    665                         FSetPos refnum,478 
    666                         FBinWrite/F=3/B=3 refNum, zero 
    667                         FBinWrite/F=3/B=3 refNum, zero 
    668                         FBinWrite/F=3/B=3 refNum, zero 
    669                         FBinWrite/F=3/B=3 refNum, zero 
    670                         FStatus refnum                                  //move to the end of the file before closing 
    671                         FSetPos refnum,V_logEOF 
    672                         Close refnum 
    673          
     610                        WriteXYBoxToHeader(filename,0,0,0,0) 
     611                         
    674612                        // write in a null suffix 
    675                         Open/A/T="????TEXT" refnum as filename 
    676                         FSetPos refnum,404                      //suffix start byte is 404 
    677                         FBinWrite refnum, suffix 
    678                         FStatus refnum 
    679                         FSetPos refnum,V_logEOF 
    680                         Close refnum 
     613                        WriteAssocFileSuffixToHeader(filename,suffix) 
    681614                         
    682                         //write a trans==1 to the file header of the raw data (open/close done in function) 
    683                         ReWriteReal(filename,1,158)             //transmission start byte is 158 
    684                         ReWriteReal(filename,1,392)             //WholeTrans start byte is 392 
     615                        //write a trans==1 to the file header of the raw data 
     616                        WriteTransmissionToHeader(filename,1)           //sample trans 
     617                         
     618                        WriteWholeTransToHeader(filename,1)             //WholeTrans start byte is 392 
    685619                         
    686620                        //then update the table that is displayed 
     
    693627        endif 
    694628         
    695 //      // Write suffix of empty beam file into transmission files 
    696 //      ii= 0 
    697 //      do 
    698 //              if (cmpstr(T_EMP_Filenames[ii],"")!=0) 
    699 //                      jj=0 
    700 //                      do 
    701 //                              if (cmpstr(T_EMP_Filenames[ii],T_GFilenames[jj])==0) 
    702 //                                      suffix=T_GSuffix[jj] 
    703 //                                      filename = pathname + T_GFilenames[ii] 
    704 //                                      Open/A/T="????TEXT" refnum as filename 
    705 //                                      //FSetPos refnum,91             //wrong position 
    706 //                                      FSetPos refnum,404 
    707 //                                      FBinWrite refnum, suffix 
    708 //                                      FStatus refnum 
    709 //                                      FSetPos refnum,V_logEOF 
    710 //                                      Close refnum 
    711 //                              endif 
    712 //                              jj+=1 
    713 //                      while(jj<num_t_files) 
    714 //              endif 
    715 //      ii+=1 
    716 //      while(ii<num_t_files) 
    717629  
    718630        if(target == 1) 
     
    721633                do 
    722634                        filename = pathname + S_GFilenames[ii] 
    723                         Open/A/T="????TEXT" refnum as filename 
    724                         //FSetPos refnum,91             //wrong position 
    725                         FSetPos refnum,404 
    726                         FBinWrite refnum, suffix 
    727                         FStatus refnum 
    728                         FSetPos refnum,V_logEOF 
    729                         Close refnum 
     635                        // write in a null suffix 
     636                        WriteAssocFileSuffixToHeader(filename,suffix) 
    730637                         
    731638                        //write a trans==1 to the file header of the raw data (open/close done in function) 
    732                         ReWriteReal(filename,1,158)             //transmission start byte is 158 
     639                        WriteTransmissionToHeader(filename,1)           //sample trans 
    733640                         
    734641                        //then update the table that is displayed 
     
    742649        return(0) 
    743650End 
    744  
    745  
    746 // assigns both the empty file to the trans file 
    747 // and the trans file to the scattering file 
    748 // - writes out 4 characters to the file headers @ byte 404 
    749 // 
    750 // assignments are only permanently made when the transmissions 
    751 // are actually calculated 
    752 // 
    753 // NOT USED - AssignSelTransFilestoData(first,last) has been generalized to take a range 
    754 // 3/31/04 SRK 
    755 //Function AssignTransFilesToData() 
    756 // 
    757 //      Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" 
    758 //      Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices" 
    759 //      Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" 
    760 //      Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" 
    761 //       
    762 //      Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" 
    763 //      Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" 
    764 //      Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" 
    765 //      Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" 
    766 //       
    767 //      Variable num_s_files, num_t_files, ii, jj 
    768 //      Variable refnum 
    769 //      num_t_files = numpnts(T_GFilenames) 
    770 //      num_s_files = numpnts(S_GFilenames) 
    771 //      String suffix = "" 
    772 //      PathInfo catPathName 
    773 //      String pathname = S_path 
    774 //      String filename 
    775 // 
    776 //      // Write suffix of empty beam file into transmission files 
    777 //      ii= 0 
    778 //      do 
    779 //              if (cmpstr(T_EMP_Filenames[ii],"")!=0) 
    780 //                      jj=0 
    781 //                      do 
    782 //                              if (cmpstr(T_EMP_Filenames[ii],T_GFilenames[jj])==0) 
    783 //                                      suffix=T_GSuffix[jj] 
    784 //                                      filename = pathname + T_GFilenames[ii] 
    785 //                                      Open/A/T="????TEXT" refnum as filename 
    786 //                                      //FSetPos refnum,91             //wrong position 
    787 //                                      FSetPos refnum,404 
    788 //                                      FBinWrite refnum, suffix 
    789 //                                      FStatus refnum 
    790 //                                      FSetPos refnum,V_logEOF 
    791 //                                      Close refnum 
    792 //                              endif 
    793 //                      jj+=1 
    794 //                      while(jj<num_t_files) 
    795 //              endif 
    796 //              ii+=1 
    797 //      while(ii<num_t_files) 
    798 //  
    799 //      // Write suffix of transmission files into scattering files 
    800 //      ii= 0 
    801 //      do 
    802 //              if (cmpstr(S_TRANS_Filenames[ii],"")!=0) 
    803 //                      jj=0 
    804 //                      do 
    805 //                              if (cmpstr(S_TRANS_Filenames[ii],T_GFilenames[jj])==0) 
    806 //                                      suffix=T_GSuffix[jj] 
    807 //                                      filename = pathname + S_GFilenames[ii] 
    808 //                                      Open/A/T="????TEXT" refnum as filename 
    809 //                                      //FSetPos refnum,91             //wrong position 
    810 //                                      FSetPos refnum,404 
    811 //                                      FBinWrite refnum, suffix 
    812 //                                      FStatus refnum 
    813 //                                      FSetPos refnum,V_logEOF 
    814 //                                      Close refnum 
    815 //                              endif 
    816 //                              jj+=1 
    817 //                      while(jj<num_t_files) 
    818 //              endif 
    819 //              ii+=1 
    820 //      while(ii<num_s_files) 
    821 // 
    822 //      return(0) 
    823 //End 
    824  
    825  
    826  
    827 // NOT USED --- CalcSelTransFromHeader(first,last) has been generalized to accept a selection 
    828 // and modified to account for different attenuation factors. 3/31/04 SRK 
    829 // 
    830 //Function CalcTransFromHeader() 
    831 //      String filename 
    832 //      Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" 
    833 //      Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" 
    834 //       
    835 //      Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" 
    836 //      Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" 
    837 //      Wave S_GTransmission =  $"root:myGlobals:TransHeaderInfo:S_Transmission" 
    838 //       
    839 //      Variable num_s_files, num_t_files, ii, jj 
    840 //      Variable refnum, transCts, emptyCts 
    841 //      num_t_files = numpnts(T_GFilenames) 
    842 //      num_s_files = numpnts(S_GFilenames) 
    843 //      String suffix = "" 
    844 //      PathInfo catPathName 
    845 //      String pathname = S_path 
    846 //      String textStr="",abortStr="" 
    847 //      String emptyFile, transFile 
    848 //       
    849 //      ii= 0 
    850 //      do 
    851 //              if (cmpstr(S_TRANS_Filenames[ii],"")!=0) 
    852 //                      jj=0 
    853 //                      do 
    854 //                              if (cmpstr(S_TRANS_Filenames[ii],T_GFilenames[jj])==0) 
    855 //                              //Look for an empty beam for the transmission then 
    856 //                                      if (cmpstr(T_EMP_Filenames[jj],"")!=0)//Do the transmission calculation 
    857 //                                              textStr = "" 
    858 //                                              filename=pathname+S_GFilenames[ii] 
    859 //                                              emptyFile = pathname+T_EMP_Filenames[jj] 
    860 //                                              transFile = pathname+T_GFilenames[jj] 
    861 //                                              ////////// 
    862 //                                              // check the empty beam file for previously selected coordinates 
    863 //                                              //if they exist, set the xy string , save the normalized counts somewhere 
    864 //                                              //the value was written to an unused r*4 header analysis.factor (@b494) 
    865 //                                              Variable x1,x2,y1,y2,err 
    866 //                                              Open/R refnum as emptyFile 
    867 //                                              FSetPos refnum,478 
    868 //                                              FBinRead/F=3/B=3 refnum, x1 
    869 //                                              FBinRead/F=3/B=3 refnum, x2 
    870 //                                              FBinRead/F=3/B=3 refnum, y1 
    871 //                                              FBinRead/F=3/B=3 refnum, y2 
    872 //                                              Close refnum 
    873 //                                              //read the real count value 
    874 //                                              String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    875 //                                              String strToExecute 
    876 //                                              strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + emptyFile + "\"" 
    877 //                                              Execute strToExecute 
    878 //                                              Wave w=$"tempGBWave0" 
    879 //                                              Variable/G root:myGlobals:Patch:gTransCts = w[0] 
    880 //                                              emptyCts = w[0] 
    881 //                       
    882 //                                              // 
    883 //                                              if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction 
    884 //                                                      //no region selected     
    885 //                                                      //prompt user to select box w/marquee 
    886 //                                                      DoWindow/F TransFileTable 
    887 //                                                      Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+T_EMP_Filenames[jj] 
    888 //                                                      //from here the Marquee menu selection must handle the task of setting the box 
    889 //                                                      //and updating the information in the file header 
    890 //                                              Endif 
    891 //               
    892 //                                              //read in trans file to add to SAM 
    893 //                                              ReadHeaderAndData(transFile) 
    894 //                                              //adds to SAM 
    895 //                                              err = Raw_to_work("SAM") 
    896 //                                              //sum region in SAM 
    897 //                                              transCts =  SumCountsInBox(x1,x2,y1,y2,"SAM") 
    898 //                                               
    899 //                                              //calculate trans based on empty beam value 
    900 //                                              Variable trans= transCts/emptyCts 
    901 //                                               
    902 //                                              //write out counts and transmission 
    903 //                                              textstr += "  Trans counts = "+num2str(transCts) + "   Trans = "+num2str(trans) 
    904 //                                              Print S_GFilenames[ii], textstr 
    905 //                                              //Print ii,jj 
    906 //                                              //Print  "Empty counts = ",emptycts, "Trans counts = "+num2str(transCts) + "   Trans = "+num2str(trans) 
    907 //                                               
    908 //                                              //write the trans to the file header of the raw data (open/close done in function) 
    909 //                                              Variable start = 158            //transmission start byte 
    910 //                                              ReWriteReal(filename,trans,start) 
    911 //                                               
    912 //                                              //then update the global that is displayed 
    913 //                                              S_GTransmission[ii] = trans 
    914 //       
    915 //                                      else  // There is no empty assigned 
    916 //                                               abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj] 
    917 //                                               Print abortStr 
    918 //                                               //Abort abortStr 
    919 //                                               return(1) 
    920 //                                      endif 
    921 //                              endif 
    922 //                              jj+=1 
    923 //                      while(jj<num_t_files) 
    924 //              else //no transmission file 
    925 //                      abortStr = "Transmission beam file not assigned properly for " + S_GFilenames[ii] 
    926 //                      Print abortStr 
    927 //              endif 
    928 //              ii+=1 
    929 //      while(ii<num_s_files) 
    930 //      print "done" 
    931 //      return(0) 
    932 //End 
    933  
    934  
    935651 
    936652//given a selection of scattering files, calculates the transmission 
     
    997713                                                //if they exist, set the xy string , save the normalized counts somewhere 
    998714                                                //the value was written to an unused r*4 header analysis.factor (@b494) 
    999                                                 Open/R refnum as emptyFile 
    1000                                                 FSetPos refnum,478 
    1001                                                 FBinRead/F=3/B=3 refnum, x1 
    1002                                                 FBinRead/F=3/B=3 refnum, x2 
    1003                                                 FBinRead/F=3/B=3 refnum, y1 
    1004                                                 FBinRead/F=3/B=3 refnum, y2 
    1005                                                 Close refnum 
     715                                                GetXYBoxFromFile(emptyFile,x1,x2,y1,y2) 
     716                                                 
    1006717                                                //read the real count value 
    1007                                                 strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + emptyFile + "\"" 
    1008                                                 Execute strToExecute 
    1009                                                 Wave w=$"tempGBWave0" 
    1010                                         //      Variable/G root:myGlobals:Patch:gTransCts = w[0] 
    1011                                                 emptyCts = w[0] 
     718                                                emptyCts = getBoxCounts(emptyFile) 
    1012719                                                // read the attenuator number of the empty beam file 
    1013                                                 strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + emptyFile + "\"" 
    1014                                                 Execute strToExecute 
    1015                                                 attenEmp = w[3] 
     720                                                attenEmp = getAttenNumber(emptyFile) 
    1016721                                                // 
    1017722                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction 
     
    1046751                                                endif 
    1047752                                                //write the trans to the file header of the raw data (open/close done in function) 
    1048                                                 ReWriteReal(filename,trans,158)         //transmission start byte is 158 
     753                                                WriteTransmissionToHeader(filename,trans) 
    1049754                                                 
    1050755                                                //then update the global that is displayed 
     
    1117822                                                //if they exist, set the xy string , save the normalized counts somewhere 
    1118823                                                //the value was written to an unused r*4 header analysis.factor (@b494) 
    1119                                                 Open/R refnum as emptyFile 
    1120                                                 FSetPos refnum,478 
    1121                                                 FBinRead/F=3/B=3 refnum, x1 
    1122                                                 FBinRead/F=3/B=3 refnum, x2 
    1123                                                 FBinRead/F=3/B=3 refnum, y1 
    1124                                                 FBinRead/F=3/B=3 refnum, y2 
    1125                                                 Close refnum 
     824                                                getXYBoxFromFile(emptyFile,x1,x2,y1,y2) 
     825                                                 
    1126826                                                //read the real count value 
    1127                                                 strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + emptyFile + "\"" 
    1128                                                 Execute strToExecute 
    1129                                                 Wave w=$"tempGBWave0" 
    1130                                         //      Variable/G root:myGlobals:Patch:gTransCts = w[0] 
    1131                                                 emptyCts = w[0] 
     827                                                emptyCts = getBoxCounts(emptyFile) 
    1132828                                                // read the attenuator number of the empty beam file 
    1133                                                 strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + emptyFile + "\"" 
    1134                                                 Execute strToExecute 
    1135                                                 attenEmp = w[3] 
     829                                                attenEmp = getAttenNumber(emptyFile) 
    1136830                                                // 
    1137831                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction 
     
    1168862                                                endif 
    1169863                                                //write the trans to the file header of the raw data (open/close done in function) 
    1170                                                 ReWriteReal(filename,trans,158)         //transmission start byte is 158 
     864                                                WriteTransmissionToHeader(filename,trans)               //transmission start byte is 158 
    1171865                                                 
    1172866                                                //then update the global that is displayed 
     
    1195889// For the calculation of the Transmission using only the whole detector 
    1196890// Used to compute the transmission for the TransmissionFiles table using 
    1197 // the entire computer. For comparison with the "box" trans 
    1198 // updated: 5/11/2006 bo Bryan Greenwald 
     891// the entire detector. For comparison with the "box" trans 
     892// updated: 5/11/2006 by Bryan Greenwald 
    1199893Function CalcWholeTrans(startRow,endRow) 
    1200894        Variable startRow,endRow 
    1201895//      GetSelection table,ScatterFileTable,1 
    1202896 
     897        NVAR pixelsX = root:myGlobals:gNPixelsX 
     898        NVAR pixelsY = root:myGlobals:gNPixelsY 
     899         
    1203900        String filename 
    1204901        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" 
     
    1239936                                                //if they exist, set the xy string , save the normalized counts somewhere 
    1240937                                                //the value was written to an unused r*4 header analysis.factor (@b494) 
    1241                                                 Open/R refnum as emptyFile 
    1242                                                 FSetPos refnum,478 
    1243                                                 FBinRead/F=3/B=3 refnum, x1 
    1244                                                 FBinRead/F=3/B=3 refnum, x2 
    1245                                                 FBinRead/F=3/B=3 refnum, y1 
    1246                                                 FBinRead/F=3/B=3 refnum, y2 
    1247                                                 Close refnum 
     938                                                 
     939                                                getXYBoxFromFile(emptyFile,x1,x2,y1,y2) 
    1248940                                                //read the real count value 
    1249                                                 strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + emptyFile + "\"" 
    1250                                                 Execute strToExecute 
    1251                                                 Wave w=$"tempGBWave0" 
    1252                                         //      Variable/G root:myGlobals:Patch:gTransCts = w[0] 
    1253                                                 emptyCts = w[0] 
     941                                                emptyCts = getBoxCounts(emptyFile) 
    1254942                                                // read the attenuator number of the empty beam file 
    1255                                                 strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + emptyFile + "\"" 
    1256                                                 Execute strToExecute 
    1257                                                 attenEmp = w[3] 
     943                                                attenEmp = getAttenNumber(emptyFile) 
    1258944                                                // 
    1259945                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction 
     
    1269955                                                err = Raw_to_work("SAM") 
    1270956                                                //sum region in SAM 
    1271                                                 transCts =  SumTotalCounts("SAM")        
     957                                                transCts =  SumCountsInBox(0,pixelsX-1,0,pixelsY-1,"SAM")        
    1272958                                                // get the attenuator, lambda, and sample string (to get the instrument) 
    1273959                                                WAVE/T samText = $"root:SAM:textRead" 
     
    1295981                                                endif 
    1296982                                                //write the trans to the file header of the raw data (open/close done in function) 
    1297                                                 ReWriteReal(filename,trans,392)         //WholeTrans start byte is 392 
     983                                                WriteWholeTransToHeader(filename,trans) 
    1298984                                                 
    1299985                                                //then update the global that is displayed 
     
    14801166        //the value was written to an unused r*4 header analysis.factor (@b494) 
    14811167        Variable refnum,x1,x2,y1,y2,err 
    1482         Open/R refnum as filename 
    1483         FSetPos refnum,478 
    1484         FBinRead/F=3/B=3 refnum, x1 
    1485         FBinRead/F=3/B=3 refnum, x2 
    1486         FBinRead/F=3/B=3 refnum, y1 
    1487         FBinRead/F=3/B=3 refnum, y2 
    1488         Close refnum 
    1489         //read the real count value 
    1490         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    1491         String strToExecute 
    1492         strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + filename + "\"" 
    1493         Execute strToExecute 
    1494         Wave w=$"tempGBWave0" 
    1495         Variable/G root:myGlobals:gTransCts = w[0]                      //***NOTE this is NOT in the Trans sub-folder 
     1168        getXYBoxFromFile(filename,x1,x2,y1,y2) 
     1169         
     1170        //read the real count value, assign to a global 
     1171        Variable/G root:myGlobals:gTransCts = getBoxCounts(filename)                    //***NOTE this is NOT in the Trans sub-folder 
    14961172        // 
    14971173        if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction 
     
    15441220         
    15451221        UpdateBoxCoordinates() 
    1546         KillWaves/Z w 
    15471222        Return (0) 
    15481223End 
     
    16101285End 
    16111286 
    1612 // b BGtoFix -comment to describe the workings of the function 
    1613 // since it's different than calculating the regular transmission 
    16141287// 
    16151288// I am not sure what the difference is inthe function of CalcTotalTrans and CalcWholeTrans ?  
    16161289// do they really do anything different? 
     1290// is it a useful calculation at all? 
    16171291//  
    16181292Function TotalTrans(ctrlName) : ButtonControl 
     
    16201294  
    16211295   Variable transTableExists 
    1622    transTableExists = WinType("ScatterFileTable")               // b BGtoFix -checking for the existence of the wrong table 
     1296   transTableExists = WinType("TransFileTable") 
    16231297   if (transTableExists != 0) 
    16241298                GetSelection table,transFileTable,1 
     
    16291303                        CalcWholeTrans(V_StartRow,V_EndRow) 
    16301304                Else 
    1631                         DoAlert 0,"No selection from Scattering Files table"                    // b BGtoFix - really looking for files from the Trans Table... 
     1305                        DoAlert 0,"No selection from Trans Files table" 
    16321306                Endif 
    16331307   Else 
    1634                 DoAlert 0,"No file selected from Scattering Files table or no Scattering Files table available"  // b BGtoFix - really looking for files from the Trans Table... 
     1308                DoAlert 0,"No file selected from Trans Files table or no Trans Files table available" 
    16351309   Endif 
    16361310End 
     
    16521326End 
    16531327 
    1654  
    1655 //function to check the header of a raw data file (full path specified by fname) 
    1656 //checks the field of the x-position of the beamstop during data collection 
    1657 //if the x-position is more negatice (farther to the left) than xTol(input) 
    1658 //the the beamstop is "out" and the file is a transmission run and not a scattering run 
    1659 //xtol typically set at -5 (cm) - trans runs have bs(x) at -10 to -15 cm  
    1660 // function returns 1 if beamstop is out, 0 if beamstop is in 
    1661 // 
    1662 Function CheckIfBeamstopOut(fName,xTol) 
    1663         String fname 
    1664         Variable xTol 
    1665          
    1666         Variable refnum,xpos 
    1667         //pos = 369, read one real value 
    1668          
    1669         SetDataFolder root: 
    1670         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    1671         String strToExecute="" 
    1672         // 1 R*4 value 
    1673         strToExecute = GBLoadStr + "/S=368/U=1" + "\"" + fname + "\"" 
    1674         Execute strToExecute 
    1675         Wave w=$"root:tempGBWave0" 
    1676         xPos = w[0] 
    1677         KillWaves/Z w 
    1678         //Print "xPos = ",xpos 
    1679          
    1680         if(xpos<=xTol) 
    1681                 //xpos is farther left (more negative) than xtol (currently -5 cm) 
    1682                 Return(1) 
    1683         else 
    1684                 //some other file 
    1685                 Return(0) 
    1686         Endif 
    1687 End 
    16881328 
    16891329//function to update the box coordinates of the file selected as the  
     
    17111351         
    17121352        Variable refnum,x1,x2,y1,y2,err 
    1713         Open/R refnum as filename 
    1714         FSetPos refnum,478 
    1715         FBinRead/F=3/B=3 refnum, x1 
    1716         FBinRead/F=3/B=3 refnum, x2 
    1717         FBinRead/F=3/B=3 refnum, y1 
    1718         FBinRead/F=3/B=3 refnum, y2 
    1719         Close refnum 
    1720          
     1353        GetXYBoxFromFile(filename,x1,x2,y1,y2) 
     1354                 
    17211355        //and update the global string 
    17221356        String msgStr="" 
     
    18071441End 
    18081442 
    1809 //****************** 
    1810 //lookup tables for attenuator transmissions 
    1811 //NG3 and NG7 attenuators are physically different, so the transmissions are slightly different 
    1812 //NG1 - (8m SANS) is not supported 
    1813  
    1814 Proc MakeNG3AttenTable() 
    1815  
    1816         NewDataFolder/O root:myGlobals:Attenuators 
    1817         //do explicitly to avoid data folder problems, redundant, but it must work without fail 
    1818         Make/O/N=9 root:myGlobals:Attenuators:ng3att0 
    1819         Make/O/N=9 root:myGlobals:Attenuators:ng3att1 
    1820         Make/O/N=9 root:myGlobals:Attenuators:ng3att2 
    1821         Make/O/N=9 root:myGlobals:Attenuators:ng3att3 
    1822         Make/O/N=9 root:myGlobals:Attenuators:ng3att4 
    1823         Make/O/N=9 root:myGlobals:Attenuators:ng3att5 
    1824         Make/O/N=9 root:myGlobals:Attenuators:ng3att6 
    1825         Make/O/N=9 root:myGlobals:Attenuators:ng3att7 
    1826         Make/O/N=9 root:myGlobals:Attenuators:ng3att8 
    1827         Make/O/N=9 root:myGlobals:Attenuators:ng3att9 
    1828         Make/O/N=9 root:myGlobals:Attenuators:ng3att10 
    1829          
    1830         //each wave has 8 elements, the transmission of att# at the wavelengths  
    1831         //lambda = 5,6,7,8,10,12,14,17 
    1832         Make/O/N=9 root:myGlobals:Attenuators:ng3lambda={5,6,7,8,10,12,14,17,20} 
    1833         root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1,1 } 
    1834         root:myGlobals:Attenuators:ng3att1 = {0.421, 0.394, 0.371, 0.349, 0.316, 0.293, 0.274, 0.245,0.220} 
    1835         root:myGlobals:Attenuators:ng3att2 = {0.187, 0.164, 0.145, 0.130, 0.106, 0.0916, 0.0808, 0.0651,0.0531} 
    1836         root:myGlobals:Attenuators:ng3att3 = {0.0777, 0.0636, 0.0534, 0.0446, 0.0330, 0.0262, 0.0217, 0.0157 ,0.0116} 
    1837         root:myGlobals:Attenuators:ng3att4 = {0.0328, 0.0252, 0.0195, 0.0156, 0.0104, 7.68e-3, 5.98e-3, 3.91e-3,0.00262} 
    1838         root:myGlobals:Attenuators:ng3att5 = {0.0139, 9.94e-3, 7.34e-3, 5.44e-3, 3.29e-3, 2.25e-3, 1.66e-3, 9.95e-4, 6.12e-4} 
    1839         root:myGlobals:Attenuators:ng3att6 = {5.95e-3, 3.97e-3, 2.77e-3, 1.95e-3, 1.06e-3, 6.81e-4, 4.71e-4, 2.59e-4 , 1.45e-4} 
    1840         root:myGlobals:Attenuators:ng3att7 = {1.07e-3, 6.24e-4, 3.90e-4, 2.44e-4, 1.14e-4, 6.55e-5, 4.10e-5, 1.64e-5 , 7.26e-6} 
    1841         root:myGlobals:Attenuators:ng3att8 = {1.90e-4, 9.84e-5, 5.60e-5, 3.25e-5, 1.55e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 
    1842         root:myGlobals:Attenuators:ng3att9 = {3.61e-5, 1.74e-5, 9.90e-6, 6.45e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 
    1843         root:myGlobals:Attenuators:ng3att10 = {7.60e-6, 3.99e-6, 2.96e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9 , 8.60e-10} 
    1844  
    1845 End 
    1846  
    1847 Proc MakeNG7AttenTable() 
    1848  
    1849         NewDataFolder/O root:myGlobals:Attenuators 
    1850          
    1851         Make/O/N=9 root:myGlobals:Attenuators:ng7att0 
    1852         Make/O/N=9 root:myGlobals:Attenuators:ng7att1 
    1853         Make/O/N=9 root:myGlobals:Attenuators:ng7att2 
    1854         Make/O/N=9 root:myGlobals:Attenuators:ng7att3 
    1855         Make/O/N=9 root:myGlobals:Attenuators:ng7att4 
    1856         Make/O/N=9 root:myGlobals:Attenuators:ng7att5 
    1857         Make/O/N=9 root:myGlobals:Attenuators:ng7att6 
    1858         Make/O/N=9 root:myGlobals:Attenuators:ng7att7 
    1859         Make/O/N=9 root:myGlobals:Attenuators:ng7att8 
    1860         Make/O/N=9 root:myGlobals:Attenuators:ng7att9 
    1861         Make/O/N=9 root:myGlobals:Attenuators:ng7att10 
    1862          
    1863         //each wave has 8 elements, the transmission of att# at the wavelengths  
    1864         //lambda = 5,6,7,8,10,12,14,17 
    1865         Make/O/N=9 root:myGlobals:Attenuators:ng7lambda={5,6,7,8,10,12,14,17,20} 
    1866         root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1} 
    1867         root:myGlobals:Attenuators:ng7att1 = {0.418, 0.393, 0.369, 0.347, 0.313, 0.291, 0.271, 0.244, 0.219 } 
    1868         root:myGlobals:Attenuators:ng7att2 = {0.189, 0.167, 0.148, 0.132, 0.109, 0.0945, 0.0830, 0.0681, 0.0560} 
    1869         root:myGlobals:Attenuators:ng7att3 = {0.0784, 0.0651, 0.0541, 0.0456, 0.0340, 0.0273, 0.0223, 0.0164 , 0.0121} 
    1870         root:myGlobals:Attenuators:ng7att4 = {0.0328, 0.0256, 0.0200, 0.0159, 0.0107, 7.98e-3, 6.14e-3, 4.09e-3 , 0.00274} 
    1871         root:myGlobals:Attenuators:ng7att5 = {0.0139, 0.0101, 7.43e-3, 5.58e-3, 3.42e-3, 2.36e-3, 1.70e-3, 1.03e-3 , 6.27e-4} 
    1872         root:myGlobals:Attenuators:ng7att6 = {5.90e-3, 4.07e-3, 2.79e-3, 1.99e-3, 1.11e-3, 7.13e-4, 4.91e-4, 2.59e-4 , 1.42e-4} 
    1873         root:myGlobals:Attenuators:ng7att7 = {1.04e-3, 6.37e-4, 3.85e-4, 2.46e-4, 1.16e-4, 6.86e-5, 4.10e-5, 1.64e-5 ,7.02e-6} 
    1874         root:myGlobals:Attenuators:ng7att8 = {1.90e-4, 1.03e-4, 5.71e-5, 3.44e-5, 1.65e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 
    1875         root:myGlobals:Attenuators:ng7att9 = {3.58e-5, 1.87e-5, 1.05e-5, 7.00e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 
    1876         root:myGlobals:Attenuators:ng7att10 = {7.76e-6, 4.56e-6, 3.25e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9, 8.60e-10} 
    1877          
    1878 End 
    1879  
    1880 //returns the transmission of the attenuator (at NG3) given the attenuator number 
    1881 //which must be an integer(to select the wave) and given the wavelength. 
    1882 //the wavelength may be any value between 5 and 20 (A), and is interpolated 
    1883 //between calibrated wavelengths for a given attenuator 
    1884 Function LookupAttenNG3(lambda,attenNo) 
    1885         Variable lambda, attenNo 
    1886          
    1887         Variable trans 
    1888         String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(attenNo)) 
    1889         String lamStr = "root:myGlobals:Attenuators:ng3lambda" 
    1890          
    1891         if(attenNo == 0) 
    1892                 return (1)              //no attenuation, return trans == 1 
    1893         endif 
    1894          
    1895         if( (lambda < 5) || (lambda > 20 ) ) 
    1896                 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 
    1897         Endif 
    1898          
    1899         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1900                 Execute "MakeNG3AttenTable()" 
    1901         Endif 
    1902         //just in case creating the tables fails.... 
    1903         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1904                 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 
    1905         Endif 
    1906          
    1907         //lookup the value by interpolating the wavelength 
    1908         //the attenuator must always be an integer 
    1909         Wave att = $attStr 
    1910         Wave lam = $lamstr 
    1911         trans = interp(lambda,lam,att) 
    1912          
    1913 //      Print "trans = ",trans 
    1914          
    1915         return trans 
    1916 End 
    1917  
    1918 //returns the transmission of the attenuator (at NG7) given the attenuator number 
    1919 //which must be an integer(to select the wave) and given the wavelength. 
    1920 //the wavelength may be any value between 5 and 20 (A), and is interpolated 
    1921 //between calibrated wavelengths for a given attenuator 
    1922 // 
    1923 // this set of tables is also used for NG5 (NG1) SANS instrument - as the attenuator has yet to be calibrated 
    1924 Function LookupAttenNG7(lambda,attenNo) 
    1925         Variable lambda, attenNo 
    1926          
    1927         Variable trans 
    1928         String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(attenNo)) 
    1929         String lamStr = "root:myGlobals:Attenuators:ng7lambda" 
    1930          
    1931         if(attenNo == 0) 
    1932                 return (1)              //no attenuation, return trans == 1 
    1933         endif 
    1934          
    1935         if( (lambda < 5) || (lambda > 20 ) ) 
    1936                 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 
    1937         Endif 
    1938          
    1939         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1940                 Execute "MakeNG7AttenTable()" 
    1941         Endif 
    1942         //just in case creating the tables fails.... 
    1943         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1944                 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 
    1945         Endif 
    1946          
    1947         //lookup the value by interpolating the wavelength 
    1948         //the attenuator must always be an integer 
    1949         Wave att = $attStr 
    1950         Wave lam = $lamstr 
    1951         trans = interp(lambda,lam,att) 
    1952          
    1953         //Print "trans = ",trans 
    1954          
    1955         return trans 
    1956  
    1957 End 
    1958  
    1959 //returns the proper attenuation factor based on the instrument (NG3, NG5, or NG7) 
    1960 //NG5 values are taken from the NG7 tables (there is very little difference in the 
    1961 //values, and NG5 attenuators have not been calibrated (as of 8/01) 
    1962 //filestr as passed is textread[3], the default directory 
    1963 Function AttenuationFactor(fileStr,lam,attenNo) 
    1964         String fileStr 
    1965         Variable lam,attenNo 
    1966          
    1967         Variable attenFactor=1,loc 
    1968         String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) 
    1969          
    1970         strswitch(instr) 
    1971                 case "NG3": 
    1972                         attenFactor = LookupAttenNG3(lam,attenNo) 
    1973                         break 
    1974                 case "NG5": 
    1975                         //using NG7 lookup Table 
    1976                         attenFactor = LookupAttenNG7(lam,attenNo) 
    1977                         break 
    1978                 case "NG7": 
    1979                         attenFactor = LookupAttenNG7(lam,attenNo) 
    1980                         break 
    1981                 default:                                                         
    1982                         //return error? 
    1983                         attenFactor=1 
    1984         endswitch 
    1985 //      print "instr, lambda, attenNo,attenFactor = ",instr,lam,attenNo,attenFactor 
    1986         return(attenFactor) 
    1987 End 
     1443 
    19881444 
    19891445//******************* 
     
    20111467         
    20121468        Variable start 
    2013         //x-position starts after byte 368 
    2014         //ReWriteReal() takes care of open/close on its own 
    2015         start = 368      //BS x-position 
    2016         ReWriteReal(fname,xpos,start) 
     1469        //x-position starts after byte 368 in VAX files 
     1470        WriteBSXPosToHeader(fname,xpos) 
    20171471        return(0) 
    20181472End 
Note: See TracChangeset for help on using the changeset viewer.