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/Correct.ipf

    r47 r116  
    3131//******************************** 
    3232 
    33  
    3433//unused test procedure for Correct() function 
    3534//must be updated to include "mode" parameter before re-use 
     
    5756End 
    5857 
    59 //mode describes the type of subtraction that is to be done 
    60 //1 = both emp and bgd subtraction 
    61 //2 = only bgd subtraction 
    62 //3 = only emp subtraction 
    63 //4 = no subtraction (handled by ExecuteProtocol(), but implemented here as well) 
    64 // 
    65 // + 10 indicates that WORK.DRK is to be used 
    66 //**********unused*********** 
    67 //**worse yet, only partially converted to use DRK files!*********** 
    68 // 
    69 Function OLD_Correct(mode) 
    70         Variable mode 
    71          
    72         //Print "mode = ",mode 
    73         if(mode==4) 
    74                 Print "no subtraction required - Correct(mode) should not have been called" 
    75                 return(1)               //error - correct should not have been called 
    76         Endif 
    77          
    78         // always check for existence of data in SAM 
    79         // if the desired workfile doesn't exist, let the user know, and abort 
    80         String destPath 
    81         String type = "SAM" 
    82         //check for SAM 
    83         destPath = "root:"+Type + ":data" 
    84         if(WaveExists($destpath) == 0) 
    85                 Print "There is no work file in "+type+"--Aborting" 
    86                 Return(1)               //error condition 
    87         else 
    88                 //check for log-scaling of the "SAM" data and adjust if necessary 
    89                 ConvertFolderToLinearScale(type) 
    90                 Wave sam_data = $"root:SAM:data" 
    91         Endif 
    92          
    93         //check for BGD if mode = 1 or 2 or 11 or 12 
    94         if( (mode ==1) || (mode==2) || (mode==11) || (mode==12) ) 
    95                 type = "BGD" 
    96                 destPath =  "root:"+Type + ":data" 
    97                 if(WaveExists($destpath) == 0) 
    98                         Print "There is no work file in "+type+"--Aborting" 
    99                         Return(1)               //error condition 
    100                 else 
    101                         //check for log-scaling of the "BGD" data and adjust if necessary 
    102                         ConvertFolderToLinearScale(type) 
    103                         Wave bgd_data = $"root:BGD:data" 
    104                 Endif 
    105         Endif 
    106          
    107         // check for EMP data if type 3 or 1 or 13 or 11 
    108         if( (mode==1) || (mode==3) || (mode==11) || (mode==13) ) 
    109                 type = "EMP" 
    110                 destPath =  "root:"+Type + ":data" 
    111                 if(WaveExists($destpath) == 0) 
    112                         Print "There is no work file in "+type+"--Aborting" 
    113                         Return(1)               //error condition 
    114                 else 
    115                         //check for log-scaling of the "EMP" data and adjust if necessary 
    116                         ConvertFolderToLinearScale(type) 
    117                         Wave emp_data = $"root:EMP:data" 
    118                 Endif 
    119         Endif 
    120          
    121         // check for DRK data if type 11,12,13, or 14 
    122         if( (mode==11) || (mode==12) || (mode==13) || (mode==14) ) 
    123                 type = "DRK" 
    124                 destPath =  "root:"+Type + ":data" 
    125                 if(WaveExists($destpath) == 0) 
    126                         Print "There is no work file in "+type+"--Aborting" 
    127                         Return(1)               //error condition 
    128                 else 
    129                         //check for log-scaling of the "EMP" data and adjust if necessary 
    130                         ConvertFolderToLinearScale(type) 
    131                         Wave drk_data = $"root:DRK:data" 
    132                 Endif 
    133         Endif 
    134          
    135         //necessary files exist, proceed 
    136  
    137         //make needed wave references to other folders 
    138         //NOTE that these references MAY NOT EXIST, depending on the mode 
    139         WAVE sam_reals = $"root:SAM:realsread" 
    140         WAVE sam_ints = $"root:SAM:integersread" 
    141         WAVE/T sam_text = $"root:SAM:textread" 
    142         WAVE/Z emp_reals = $"root:EMP:realsread" 
    143         WAVE/Z emp_ints = $"root:EMP:integersread" 
    144         WAVE/T/Z emp_text = $"root:EMP:textread" 
    145         WAVE/Z bgd_reals = $"root:BGD:realsread" 
    146         WAVE/Z bgd_ints = $"root:BGD:integersread" 
    147         WAVE/T/Z bgd_text = $"root:BGD:textread" 
    148          
    149         //find the attenuation of the sample (if any) 
    150         Variable SamAttenFactor,lambda,attenNo,err=0 
    151         String samfileStr="" 
    152         samfileStr = sam_text[3] 
    153         lambda = sam_reals[26] 
    154         attenNo = sam_reals[3] 
    155         SamAttenFactor = AttenuationFactor(samFileStr,lambda,AttenNo) 
    156         //if sample trans is zero, do only SAM-BGD subtraction (notify the user) 
    157         Variable sam_trans = sam_reals[4] 
    158          
    159         //copy SAM information to COR, wiping out the old contents of the COR folder first 
    160         err = CopyWorkContents("SAM","COR")      
    161         if(err==1) 
    162                 Abort "No data in SAM, abort from Correct()" 
    163         endif 
    164          
    165         //now switch to COR folder 
    166         DestPath="root:COR" 
    167         //make appropriate wave references 
    168         WAVE data=$(destPath + ":data")                                 // these wave references point to the SAM data in COR 
    169         WAVE/T textread=$(destPath + ":textread")                       //that are to be directly operated on 
    170         WAVE integersread=$(destPath + ":integersread") 
    171         WAVE realsread=$(destPath + ":realsRead") 
    172  
    173         NVAR pixelsX = root:myGlobals:gNPixelsX 
    174         NVAR pixelsY = root:myGlobals:gNPixelsY 
    175          
    176         //Print "done copying data, starting the correct calculations" 
    177          
    178         // Start the actual "correct" step here 
    179         Variable wcen=0.001,numsam,tmonsam,tsam,rsam,csam,fsam 
    180         Variable tmonbgd,fbgd,xshift,yshift,rbgd,cbgd,sh_sum,ii,jj,trans,tmonemp,temp,femp 
    181         Variable cemp,remp 
    182         //make temporary waves to hold the intermediate results and the shifted arrays 
    183         Duplicate/O data cor1,cor2 
    184         cor1 = 0                //initialize to zero 
    185         cor2 = 0 
    186          
    187         //make needed wave references to other folders 
    188         Wave sam_reals = $"root:SAM:realsread" 
    189         Wave bgd_reals = $"root:BGD:realsread" 
    190         Wave emp_reals = $"root:EMP:realsread" 
    191          
    192         //get counts, trans, etc. from file headers 
    193         numsam = sam_ints[3]            //number of runs in SAM file 
    194         tmonsam = sam_reals[0]          //monitor count in SAM 
    195         tsam = sam_reals[4]             //SAM transmission 
    196         csam = sam_reals[16]            //x center 
    197         rsam = sam_reals[17]            //beam (x,y) define center of corrected field 
    198         //Print "rsam,csam = ",rsam,csam 
    199          
    200         // 
    201         //do sam-bgd subtraction if mode (1) or (2) 
    202         //else (mode 3), set cor1 = sam_data 
    203         if( (mode==1) || (mode==2) ) 
    204                 fsam = 1 
    205                 tmonbgd = bgd_reals[0]          //monitor count in BGD 
    206                 fbgd = tmonsam/tmonbgd  //this should be ==1 since normalized files 
    207          
    208                 //set up  center shift, relative to SAM 
    209                 cbgd = bgd_reals[16] 
    210                 rbgd = bgd_reals[17] 
    211                 //Print "rbgd,cbgd = ",rbgd,cbgd 
    212                 xshift = cbgd-csam 
    213                 yshift = rbgd-rsam 
    214                 if(abs(xshift) <= wcen) 
    215                         xshift = 0 
    216                 Endif 
    217                 if(abs(yshift) <= wcen) 
    218                         yshift = 0 
    219                 Endif 
    220                  
    221                 If((xshift != 0) || (yshift != 0)) 
    222                         DoAlert 1,"Do you want to ignore the beam center mismatch?" 
    223                         if(V_flag==1)           //yes -> just go on 
    224                                 xshift=0 
    225                                 yshift=0 
    226                         endif 
    227                 endif 
    228                 //do the sam-bgd subtraction,  deposit result in cor1[][] 
    229                 If((xshift == 0) && (yshift == 0)) 
    230                         //great, no shift required 
    231                         cor1 = fsam*sam_data - fbgd*bgd_data*SamAttenFactor 
    232                 else 
    233                         //shift required, very time-consuming 
    234                         Print "sam-bgd shift x,y = ",xshift,yshift 
    235                         Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
    236                         ii=0 
    237                         do 
    238                                 jj=0 
    239                                 do 
    240                                         //get the contribution of shifted data 
    241                                         sh_sum = ShiftSum(bgd_data,ii,jj,xshift,yshift,noadd) 
    242                                         if(noadd[0]) 
    243                                                 cor1[ii][jj]=0 
    244                                         else 
    245                                                 //add the sam_data + shifted sum  
    246                                                 cor1[ii][jj] = fsam*sam_data[ii][jj] - fbgd*sh_sum*SamAttenFactor 
    247                                         Endif 
    248                                         jj+=1 
    249                                 while(jj<pixelsY) 
    250                                 ii+=1 
    251                         while(ii<pixelsX) 
    252                 Endif 
    253         else                    //switch on mode 
    254                 cor1 = sam_data         //setup for just EMP subtraction 
    255         Endif 
    256          
    257         //Print "sam-bgd done" 
    258          
    259         if(mode == 2)           //just a BGD subtraction 
    260                 //we're done, get out w/no error 
    261                 //set the COR data to the result 
    262                 data = cor1 
    263                 //update COR header 
    264                 textread[1] = date() + " " + time()             //date + time stamp 
    265                 SetDataFolder root: 
    266                 KillWaves/Z cor1,cor2 
    267                 Return(0) 
    268         Endif 
    269          
    270         //if mode ==1 (ONLY choice left) do the empty-background subtraction 
    271         //else mode = 3, set cor2 to emp_data 
    272         if(mode==1)             //full subtraction 
    273                 trans = emp_reals[4]            //EMP transmission 
    274                 if(trans == 0) 
    275                         trans = 1 
    276                         DoAlert 0,"Empty cell transmission was zero. It has been reset to one for the calculation" 
    277                 endif 
    278                 tmonemp = emp_reals[0] 
    279                 femp = tmonsam/tmonemp 
    280                 temp = trans 
    281          
    282                 //set up center shift, relative to EMP 
    283                 cemp = emp_reals[16] 
    284                 remp = emp_reals[17] 
    285                 //Print "remp,cemp ",remp,cemp 
    286                 xshift = cbgd - cemp 
    287                 yshift = rbgd - remp 
    288                 if(abs(xshift) <= wcen ) 
    289                         xshift = 0 
    290                 endif 
    291                 if(abs(yshift) <= wcen) 
    292                         yshift = 0 
    293                 endif 
    294                  
    295                 If((xshift != 0) || (yshift != 0)) 
    296                         DoAlert 1,"Do you want to ignore the beam center mismatch?" 
    297                         if(V_flag==1) 
    298                                 xshift=0 
    299                                 yshift=0 
    300                         endif 
    301                 endif 
    302                 //do the emp-bgd subtraction,  deposit result in cor2[][] 
    303                 If((xshift == 0) && (yshift == 0)) 
    304                         //great, no shift required, DON'T scale this by the attenuation gfactor 
    305                         cor2 = femp*emp_data - fbgd*bgd_data 
    306                 else 
    307                         //shift required, very time-consuming 
    308                         Print "emp-bgd shift x,y = ",xshift,yshift 
    309                         Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
    310                         ii=0 
    311                         do 
    312                                 jj=0 
    313                                 do 
    314                                         //get the contribution of shifted data 
    315                                         sh_sum = ShiftSum(bgd_data,ii,jj,xshift,yshift,noadd) 
    316                                         if(noadd[0]) 
    317                                                 cor2[ii][jj]=0 
    318                                         else 
    319                                                 //add the sam_data + shifted sum  
    320                                                 cor2[ii][jj] = femp*emp_data[ii][jj] - fbgd*sh_sum 
    321                                         Endif 
    322                                         jj+=1 
    323                                 while(jj<pixelsY) 
    324                                 ii+=1 
    325                         while(ii<pixelsX) 
    326                 Endif 
    327         else            //switch on mode==1 for full subtraction 
    328                 cor2 = emp_data 
    329                 //be sure to set the empty center location... for the shift 
    330                 trans = emp_reals[4]            //EMP transmission 
    331                 if(trans == 0) 
    332                         trans = 1 
    333                         DoAlert 0,"Empty cell transmission was zero. It has been reset to one for the calculation" 
    334                 endif 
    335                 tmonemp = emp_reals[0] 
    336                 femp = tmonsam/tmonemp 
    337                 temp = trans 
    338          
    339                 //set up center shift, relative to EMP 
    340                 cemp = emp_reals[16] 
    341                 remp = emp_reals[17] 
    342         Endif 
    343          
    344         //Print "emp-bgd done" 
    345          
    346         //mode 2 exited, either 1 or 3 apply from here, and are setup properly. 
    347          
    348         //set up for final step, data(COR) = cor1 - Tsam/Temp*cor2 
    349         //set up shift, relative to SAM 
    350         xshift = cemp - csam 
    351         yshift = remp - rsam 
    352         if(abs(xshift) <= wcen ) 
    353                 xshift = 0 
    354         endif 
    355         if(abs(yshift) <= wcen) 
    356                 yshift = 0 
    357         endif 
    358          
    359         If((xshift != 0) || (yshift != 0)) 
    360                 DoAlert 1,"Do you want to ignore the beam center mismatch?" 
    361                 if(V_flag==1) 
    362                         xshift=0 
    363                         yshift=0 
    364                 endif 
    365         endif 
    366         //do the cor1-a*cor2 subtraction,  deposit result in data[][] (in the COR folder) 
    367         If((xshift == 0) && (yshift == 0)) 
    368                 //great, no shift required 
    369                 data = cor1 - (tsam/temp)*cor2*SamAttenFactor 
    370         else 
    371                 //shift required, very time-consuming 
    372                 Print "sam-emp shift x,y = ",xshift,yshift 
    373                 Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
    374                 ii=0 
    375                 do 
    376                         jj=0 
    377                         do 
    378                                 //get the contribution of shifted data 
    379                                 sh_sum = ShiftSum(cor2,ii,jj,xshift,yshift,noadd) 
    380                                 if(noadd[0]) 
    381                                         data[ii][jj]=0 
    382                                 else 
    383                                         //add the sam_data + shifted sum  
    384                                         data[ii][jj] = cor1[ii][jj] - (tsam/temp)*sh_sum*SamAttenFactor 
    385                                 Endif 
    386                                 jj+=1 
    387                         while(jj<pixelsY) 
    388                         ii+=1 
    389                 while(ii<pixelsX) 
    390         Endif 
    391          
    392         //Print "all done" 
    393          
    394         //update COR header 
    395         textread[1] = date() + " " + time()             //date + time stamp 
    396          
    397         //clean up 
    398         SetDataFolder root:COR 
    399         SetDataFolder root: 
    400         KillWaves/Z cor1,cor2,noadd 
    401  
    402         Return(0)               //all is ok, if you made it to this point 
    403 End 
    40458 
    40559//mode describes the type of subtraction that is to be done 
     
    13851039 
    13861040////////////////////////// 
     1041//**********unused*********** 
     1042//mode describes the type of subtraction that is to be done 
     1043//1 = both emp and bgd subtraction 
     1044//2 = only bgd subtraction 
     1045//3 = only emp subtraction 
     1046//4 = no subtraction (handled by ExecuteProtocol(), but implemented here as well) 
     1047// 
     1048// + 10 indicates that WORK.DRK is to be used 
     1049//**********unused*********** 
     1050//**worse yet, only partially converted to use DRK files!*********** 
     1051// 
     1052Function OLD_Correct(mode) 
     1053        Variable mode 
     1054         
     1055        //Print "mode = ",mode 
     1056        if(mode==4) 
     1057                Print "no subtraction required - Correct(mode) should not have been called" 
     1058                return(1)               //error - correct should not have been called 
     1059        Endif 
     1060         
     1061        // always check for existence of data in SAM 
     1062        // if the desired workfile doesn't exist, let the user know, and abort 
     1063        String destPath 
     1064        String type = "SAM" 
     1065        //check for SAM 
     1066        destPath = "root:"+Type + ":data" 
     1067        if(WaveExists($destpath) == 0) 
     1068                Print "There is no work file in "+type+"--Aborting" 
     1069                Return(1)               //error condition 
     1070        else 
     1071                //check for log-scaling of the "SAM" data and adjust if necessary 
     1072                ConvertFolderToLinearScale(type) 
     1073                Wave sam_data = $"root:SAM:data" 
     1074        Endif 
     1075         
     1076        //check for BGD if mode = 1 or 2 or 11 or 12 
     1077        if( (mode ==1) || (mode==2) || (mode==11) || (mode==12) ) 
     1078                type = "BGD" 
     1079                destPath =  "root:"+Type + ":data" 
     1080                if(WaveExists($destpath) == 0) 
     1081                        Print "There is no work file in "+type+"--Aborting" 
     1082                        Return(1)               //error condition 
     1083                else 
     1084                        //check for log-scaling of the "BGD" data and adjust if necessary 
     1085                        ConvertFolderToLinearScale(type) 
     1086                        Wave bgd_data = $"root:BGD:data" 
     1087                Endif 
     1088        Endif 
     1089         
     1090        // check for EMP data if type 3 or 1 or 13 or 11 
     1091        if( (mode==1) || (mode==3) || (mode==11) || (mode==13) ) 
     1092                type = "EMP" 
     1093                destPath =  "root:"+Type + ":data" 
     1094                if(WaveExists($destpath) == 0) 
     1095                        Print "There is no work file in "+type+"--Aborting" 
     1096                        Return(1)               //error condition 
     1097                else 
     1098                        //check for log-scaling of the "EMP" data and adjust if necessary 
     1099                        ConvertFolderToLinearScale(type) 
     1100                        Wave emp_data = $"root:EMP:data" 
     1101                Endif 
     1102        Endif 
     1103         
     1104        // check for DRK data if type 11,12,13, or 14 
     1105        if( (mode==11) || (mode==12) || (mode==13) || (mode==14) ) 
     1106                type = "DRK" 
     1107                destPath =  "root:"+Type + ":data" 
     1108                if(WaveExists($destpath) == 0) 
     1109                        Print "There is no work file in "+type+"--Aborting" 
     1110                        Return(1)               //error condition 
     1111                else 
     1112                        //check for log-scaling of the "EMP" data and adjust if necessary 
     1113                        ConvertFolderToLinearScale(type) 
     1114                        Wave drk_data = $"root:DRK:data" 
     1115                Endif 
     1116        Endif 
     1117         
     1118        //necessary files exist, proceed 
     1119 
     1120        //make needed wave references to other folders 
     1121        //NOTE that these references MAY NOT EXIST, depending on the mode 
     1122        WAVE sam_reals = $"root:SAM:realsread" 
     1123        WAVE sam_ints = $"root:SAM:integersread" 
     1124        WAVE/T sam_text = $"root:SAM:textread" 
     1125        WAVE/Z emp_reals = $"root:EMP:realsread" 
     1126        WAVE/Z emp_ints = $"root:EMP:integersread" 
     1127        WAVE/T/Z emp_text = $"root:EMP:textread" 
     1128        WAVE/Z bgd_reals = $"root:BGD:realsread" 
     1129        WAVE/Z bgd_ints = $"root:BGD:integersread" 
     1130        WAVE/T/Z bgd_text = $"root:BGD:textread" 
     1131         
     1132        //find the attenuation of the sample (if any) 
     1133        Variable SamAttenFactor,lambda,attenNo,err=0 
     1134        String samfileStr="" 
     1135        samfileStr = sam_text[3] 
     1136        lambda = sam_reals[26] 
     1137        attenNo = sam_reals[3] 
     1138        SamAttenFactor = AttenuationFactor(samFileStr,lambda,AttenNo) 
     1139        //if sample trans is zero, do only SAM-BGD subtraction (notify the user) 
     1140        Variable sam_trans = sam_reals[4] 
     1141         
     1142        //copy SAM information to COR, wiping out the old contents of the COR folder first 
     1143        err = CopyWorkContents("SAM","COR")      
     1144        if(err==1) 
     1145                Abort "No data in SAM, abort from Correct()" 
     1146        endif 
     1147         
     1148        //now switch to COR folder 
     1149        DestPath="root:COR" 
     1150        //make appropriate wave references 
     1151        WAVE data=$(destPath + ":data")                                 // these wave references point to the SAM data in COR 
     1152        WAVE/T textread=$(destPath + ":textread")                       //that are to be directly operated on 
     1153        WAVE integersread=$(destPath + ":integersread") 
     1154        WAVE realsread=$(destPath + ":realsRead") 
     1155 
     1156        NVAR pixelsX = root:myGlobals:gNPixelsX 
     1157        NVAR pixelsY = root:myGlobals:gNPixelsY 
     1158         
     1159        //Print "done copying data, starting the correct calculations" 
     1160         
     1161        // Start the actual "correct" step here 
     1162        Variable wcen=0.001,numsam,tmonsam,tsam,rsam,csam,fsam 
     1163        Variable tmonbgd,fbgd,xshift,yshift,rbgd,cbgd,sh_sum,ii,jj,trans,tmonemp,temp,femp 
     1164        Variable cemp,remp 
     1165        //make temporary waves to hold the intermediate results and the shifted arrays 
     1166        Duplicate/O data cor1,cor2 
     1167        cor1 = 0                //initialize to zero 
     1168        cor2 = 0 
     1169         
     1170        //make needed wave references to other folders 
     1171        Wave sam_reals = $"root:SAM:realsread" 
     1172        Wave bgd_reals = $"root:BGD:realsread" 
     1173        Wave emp_reals = $"root:EMP:realsread" 
     1174         
     1175        //get counts, trans, etc. from file headers 
     1176        numsam = sam_ints[3]            //number of runs in SAM file 
     1177        tmonsam = sam_reals[0]          //monitor count in SAM 
     1178        tsam = sam_reals[4]             //SAM transmission 
     1179        csam = sam_reals[16]            //x center 
     1180        rsam = sam_reals[17]            //beam (x,y) define center of corrected field 
     1181        //Print "rsam,csam = ",rsam,csam 
     1182         
     1183        // 
     1184        //do sam-bgd subtraction if mode (1) or (2) 
     1185        //else (mode 3), set cor1 = sam_data 
     1186        if( (mode==1) || (mode==2) ) 
     1187                fsam = 1 
     1188                tmonbgd = bgd_reals[0]          //monitor count in BGD 
     1189                fbgd = tmonsam/tmonbgd  //this should be ==1 since normalized files 
     1190         
     1191                //set up  center shift, relative to SAM 
     1192                cbgd = bgd_reals[16] 
     1193                rbgd = bgd_reals[17] 
     1194                //Print "rbgd,cbgd = ",rbgd,cbgd 
     1195                xshift = cbgd-csam 
     1196                yshift = rbgd-rsam 
     1197                if(abs(xshift) <= wcen) 
     1198                        xshift = 0 
     1199                Endif 
     1200                if(abs(yshift) <= wcen) 
     1201                        yshift = 0 
     1202                Endif 
     1203                 
     1204                If((xshift != 0) || (yshift != 0)) 
     1205                        DoAlert 1,"Do you want to ignore the beam center mismatch?" 
     1206                        if(V_flag==1)           //yes -> just go on 
     1207                                xshift=0 
     1208                                yshift=0 
     1209                        endif 
     1210                endif 
     1211                //do the sam-bgd subtraction,  deposit result in cor1[][] 
     1212                If((xshift == 0) && (yshift == 0)) 
     1213                        //great, no shift required 
     1214                        cor1 = fsam*sam_data - fbgd*bgd_data*SamAttenFactor 
     1215                else 
     1216                        //shift required, very time-consuming 
     1217                        Print "sam-bgd shift x,y = ",xshift,yshift 
     1218                        Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
     1219                        ii=0 
     1220                        do 
     1221                                jj=0 
     1222                                do 
     1223                                        //get the contribution of shifted data 
     1224                                        sh_sum = ShiftSum(bgd_data,ii,jj,xshift,yshift,noadd) 
     1225                                        if(noadd[0]) 
     1226                                                cor1[ii][jj]=0 
     1227                                        else 
     1228                                                //add the sam_data + shifted sum  
     1229                                                cor1[ii][jj] = fsam*sam_data[ii][jj] - fbgd*sh_sum*SamAttenFactor 
     1230                                        Endif 
     1231                                        jj+=1 
     1232                                while(jj<pixelsY) 
     1233                                ii+=1 
     1234                        while(ii<pixelsX) 
     1235                Endif 
     1236        else                    //switch on mode 
     1237                cor1 = sam_data         //setup for just EMP subtraction 
     1238        Endif 
     1239         
     1240        //Print "sam-bgd done" 
     1241         
     1242        if(mode == 2)           //just a BGD subtraction 
     1243                //we're done, get out w/no error 
     1244                //set the COR data to the result 
     1245                data = cor1 
     1246                //update COR header 
     1247                textread[1] = date() + " " + time()             //date + time stamp 
     1248                SetDataFolder root: 
     1249                KillWaves/Z cor1,cor2 
     1250                Return(0) 
     1251        Endif 
     1252         
     1253        //if mode ==1 (ONLY choice left) do the empty-background subtraction 
     1254        //else mode = 3, set cor2 to emp_data 
     1255        if(mode==1)             //full subtraction 
     1256                trans = emp_reals[4]            //EMP transmission 
     1257                if(trans == 0) 
     1258                        trans = 1 
     1259                        DoAlert 0,"Empty cell transmission was zero. It has been reset to one for the calculation" 
     1260                endif 
     1261                tmonemp = emp_reals[0] 
     1262                femp = tmonsam/tmonemp 
     1263                temp = trans 
     1264         
     1265                //set up center shift, relative to EMP 
     1266                cemp = emp_reals[16] 
     1267                remp = emp_reals[17] 
     1268                //Print "remp,cemp ",remp,cemp 
     1269                xshift = cbgd - cemp 
     1270                yshift = rbgd - remp 
     1271                if(abs(xshift) <= wcen ) 
     1272                        xshift = 0 
     1273                endif 
     1274                if(abs(yshift) <= wcen) 
     1275                        yshift = 0 
     1276                endif 
     1277                 
     1278                If((xshift != 0) || (yshift != 0)) 
     1279                        DoAlert 1,"Do you want to ignore the beam center mismatch?" 
     1280                        if(V_flag==1) 
     1281                                xshift=0 
     1282                                yshift=0 
     1283                        endif 
     1284                endif 
     1285                //do the emp-bgd subtraction,  deposit result in cor2[][] 
     1286                If((xshift == 0) && (yshift == 0)) 
     1287                        //great, no shift required, DON'T scale this by the attenuation gfactor 
     1288                        cor2 = femp*emp_data - fbgd*bgd_data 
     1289                else 
     1290                        //shift required, very time-consuming 
     1291                        Print "emp-bgd shift x,y = ",xshift,yshift 
     1292                        Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
     1293                        ii=0 
     1294                        do 
     1295                                jj=0 
     1296                                do 
     1297                                        //get the contribution of shifted data 
     1298                                        sh_sum = ShiftSum(bgd_data,ii,jj,xshift,yshift,noadd) 
     1299                                        if(noadd[0]) 
     1300                                                cor2[ii][jj]=0 
     1301                                        else 
     1302                                                //add the sam_data + shifted sum  
     1303                                                cor2[ii][jj] = femp*emp_data[ii][jj] - fbgd*sh_sum 
     1304                                        Endif 
     1305                                        jj+=1 
     1306                                while(jj<pixelsY) 
     1307                                ii+=1 
     1308                        while(ii<pixelsX) 
     1309                Endif 
     1310        else            //switch on mode==1 for full subtraction 
     1311                cor2 = emp_data 
     1312                //be sure to set the empty center location... for the shift 
     1313                trans = emp_reals[4]            //EMP transmission 
     1314                if(trans == 0) 
     1315                        trans = 1 
     1316                        DoAlert 0,"Empty cell transmission was zero. It has been reset to one for the calculation" 
     1317                endif 
     1318                tmonemp = emp_reals[0] 
     1319                femp = tmonsam/tmonemp 
     1320                temp = trans 
     1321         
     1322                //set up center shift, relative to EMP 
     1323                cemp = emp_reals[16] 
     1324                remp = emp_reals[17] 
     1325        Endif 
     1326         
     1327        //Print "emp-bgd done" 
     1328         
     1329        //mode 2 exited, either 1 or 3 apply from here, and are setup properly. 
     1330         
     1331        //set up for final step, data(COR) = cor1 - Tsam/Temp*cor2 
     1332        //set up shift, relative to SAM 
     1333        xshift = cemp - csam 
     1334        yshift = remp - rsam 
     1335        if(abs(xshift) <= wcen ) 
     1336                xshift = 0 
     1337        endif 
     1338        if(abs(yshift) <= wcen) 
     1339                yshift = 0 
     1340        endif 
     1341         
     1342        If((xshift != 0) || (yshift != 0)) 
     1343                DoAlert 1,"Do you want to ignore the beam center mismatch?" 
     1344                if(V_flag==1) 
     1345                        xshift=0 
     1346                        yshift=0 
     1347                endif 
     1348        endif 
     1349        //do the cor1-a*cor2 subtraction,  deposit result in data[][] (in the COR folder) 
     1350        If((xshift == 0) && (yshift == 0)) 
     1351                //great, no shift required 
     1352                data = cor1 - (tsam/temp)*cor2*SamAttenFactor 
     1353        else 
     1354                //shift required, very time-consuming 
     1355                Print "sam-emp shift x,y = ",xshift,yshift 
     1356                Make/O/N=1 noadd                //needed to get noadd condition back from ShiftSum() 
     1357                ii=0 
     1358                do 
     1359                        jj=0 
     1360                        do 
     1361                                //get the contribution of shifted data 
     1362                                sh_sum = ShiftSum(cor2,ii,jj,xshift,yshift,noadd) 
     1363                                if(noadd[0]) 
     1364                                        data[ii][jj]=0 
     1365                                else 
     1366                                        //add the sam_data + shifted sum  
     1367                                        data[ii][jj] = cor1[ii][jj] - (tsam/temp)*sh_sum*SamAttenFactor 
     1368                                Endif 
     1369                                jj+=1 
     1370                        while(jj<pixelsY) 
     1371                        ii+=1 
     1372                while(ii<pixelsX) 
     1373        Endif 
     1374         
     1375        //Print "all done" 
     1376         
     1377        //update COR header 
     1378        textread[1] = date() + " " + time()             //date + time stamp 
     1379         
     1380        //clean up 
     1381        SetDataFolder root:COR 
     1382        SetDataFolder root: 
     1383        KillWaves/Z cor1,cor2,noadd 
     1384 
     1385        Return(0)               //all is ok, if you made it to this point 
     1386End 
Note: See TracChangeset for help on using the changeset viewer.