Ignore:
Timestamp:
May 18, 2018 10:32:22 AM (5 years ago)
Author:
srkline
Message:

Significant restructuring of V_ExecuteProtocol to make the logic of the flow more tractable and adaptable in the future.

Added major change to VSANS event mode reduction panel to allow F and M binned events to be saved to a copy of the correspondng data file. A new data reduction panel for multiple slice reduction is now presented for Event data. This allows reduction of a single slice (all 8 F,M panels, back ignored), or all of the slices.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_EventMode_Utils.ipf

    r1060 r1100  
    11#pragma TextEncoding = "MacRoman" 
    22#pragma rtGlobals=3             // Use modern global access method and strict wave access. 
     3 
     4 
     5 
     6 
    37 
    48 
     
    556560        return(0) 
    557561End 
    558  
    559  
    560  
    561  
    562  
    563  
    564562 
    565563 
     
    881879End 
    882880 
    883  
     881// 
     882/////// to copy a sliced data set to a folder to save 
     883// 
     884 
     885 
     886// load event file from RAW data loaded 
     887        // pick either the front or middle carriage 
     888        // pick the "mode" of loading data (osc, stream, etc.) 
     889// process the event data 
     890// split to panels 
     891// move slices to "export" location 
     892// move bin details to export location 
     893// repeat load + process + move with the 2nd carriage, using the same time binning 
     894// 
     895// save the data file, giving a new name to not overwrite the original data file 
     896// 
     897 
     898 
     899// 
     900// root:Packages:NIST:VSANS:RAW:gFileList               //name of the data file(s) in raw (take 1st from semi-list) 
     901// 
     902 
     903Function V_DuplicateRAWForExport() 
     904        KillDataFolder/Z root:export 
     905        DuplicateDataFolder root:Packages:NIST:VSANS:RAW: root:export 
     906        return(0) 
     907end 
     908 
     909Function V_CopySlicesForExport(detStr) 
     910        String detStr 
     911         
     912        if(cmpstr(detStr,"M") == 0) 
     913                Duplicate/O root:Packages:NIST:VSANS:Event:slices_B root:export:entry:instrument:detector_MB:slices 
     914                Duplicate/O root:Packages:NIST:VSANS:Event:slices_T root:export:entry:instrument:detector_MT:slices 
     915                Duplicate/O root:Packages:NIST:VSANS:Event:slices_L root:export:entry:instrument:detector_ML:slices 
     916                Duplicate/O root:Packages:NIST:VSANS:Event:slices_R root:export:entry:instrument:detector_MR:slices 
     917        else 
     918                Duplicate/O root:Packages:NIST:VSANS:Event:slices_B root:export:entry:instrument:detector_FB:slices 
     919                Duplicate/O root:Packages:NIST:VSANS:Event:slices_T root:export:entry:instrument:detector_FT:slices 
     920                Duplicate/O root:Packages:NIST:VSANS:Event:slices_L root:export:entry:instrument:detector_FL:slices 
     921                Duplicate/O root:Packages:NIST:VSANS:Event:slices_R root:export:entry:instrument:detector_FR:slices 
     922        endif 
     923         
     924        Duplicate/O root:Packages:NIST:VSANS:Event:binEndTime root:export:entry:reduction:binEndTime 
     925        Duplicate/O root:Packages:NIST:VSANS:Event:timeWidth root:export:entry:reduction:timeWidth       
     926         
     927        return(0) 
     928end 
     929 
     930// 
     931// data is intact in the file so that it can still be read in as a regular raw data file. 
     932// 
     933Proc V_SaveExportedEvents() 
     934 
     935        String filename = root:Packages:NIST:VSANS:RAW:gFileList                //name of the data file(s) in raw (take 1st from semi-list) 
     936        String saveName 
     937 
     938        saveName = StringFromList(0, fileName) 
     939        Save_VSANS_file("root:export", "Events_"+saveName) 
     940 
     941End 
     942 
     943 
     944 
     945 
     946////////////////////////////////////////////////////////////// 
     947// 
     948// 
     949// Panel for reducing event data 
     950// 
     951// 
     952// 
     953//              Panel to have readout/buttons for: 
     954//                      # slices 
     955//                      timing information (table, graph) 
     956//                      protocol to use (popup) 
     957//                      Event_ file (popup) 
     958// 
     959//                      Manually advance slice and display in RAW (for testing) 
     960// 
     961// 
     962 
     963// 
     964//              Save the total monitor count 
     965//              Save the total count time 
     966//              Save the sample label 
     967// 
     968//              ? Don't need to save the original detector data (I can sum the slices) 
     969// 
     970// 
     971// for each slice(N) 
     972//              find the binWidth -> bin fraction 
     973//              adjust count time 
     974//      adjust monitor count 
     975//              ? adjust integrated detector count 
     976//      adjust sample label (mark as slice(N)?) 
     977// 
     978//              copy slice(N) to each detector panel (ignore B) 
     979// 
     980//              Process through reduction protocol 
     981// 
     982//              give appropriate output name (N) 
     983// 
     984// 
     985 
     986 
     987//************************* 
     988// 
     989// Procedures to allow batch reduction of Event data files 
     990// 
     991//****note that much of this file is becoming obsolete as improved methods for  
     992//reducing multiple files are introduced. Some of these procedures may not last long*** 
     993// 
     994//************************** 
     995 
     996// 
     997//panel to allow reduction of a series of files using a selected  protocol 
     998// 
     999//main entry procedure to open the panel, initializing if necessary 
     1000Macro V_ReduceEventFiles() 
     1001         
     1002        DoWindow/F V_Event_Reduce_Panel 
     1003        If(V_flag == 0) 
     1004                V_InitializeEventReducePanel() 
     1005                //draw panel 
     1006                V_Event_Reduce_Panel() 
     1007                //pop the protocol list 
     1008                V_EVR_ProtoPopMenuProc("",1,"") 
     1009                //then update the popup list 
     1010                V_EVR_RedPopMenuProc("ERFilesPopup",1,"") 
     1011        Endif 
     1012End 
     1013 
     1014//create the global variables needed to run the MReduce Panel 
     1015//all are kept in root:Packages:NIST:VSANS:Globals:MRED 
     1016// 
     1017Proc V_InitializeEventReducePanel() 
     1018 
     1019        If(DataFolderExists("root:Packages:NIST:VSANS:Globals:EVRED")) 
     1020                //ok, do nothing 
     1021        else 
     1022                //no, create the folder and the globals 
     1023                NewDataFolder/O root:Packages:NIST:VSANS:Globals:EVRED 
     1024//              String/G root:Packages:NIST:VSANS:Globals:MRED:gMRedMatchStr = "*" 
     1025                PathInfo catPathName 
     1026                If(V_flag==1) 
     1027                        String dum = S_path 
     1028                        String/G root:Packages:NIST:VSANS:Globals:EVRED:gCatPathStr = dum 
     1029                else 
     1030                        String/G root:Packages:NIST:VSANS:Globals:EVRED:gCatPathStr = "no path selected" 
     1031                endif 
     1032                String/G root:Packages:NIST:VSANS:Globals:EVRED:gMRedList = "none" 
     1033                String/G root:Packages:NIST:VSANS:Globals:EVRED:gMRProtoList = "none" 
     1034                String/G root:Packages:NIST:VSANS:Globals:EVRED:gFileNumList="" 
     1035                Variable/G root:Packages:NIST:VSANS:Globals:EVRED:gNumSlices=1 
     1036                Variable/G root:Packages:NIST:VSANS:Globals:EVRED:gCurSlice=1 
     1037 
     1038 
     1039        Endif  
     1040End 
     1041 
     1042 
     1043// 
     1044// borrows some of the basic functions from the MRED panel 
     1045// 
     1046Window V_Event_Reduce_Panel() 
     1047        PauseUpdate; Silent 1           // building window... 
     1048        NewPanel /W=(535,72,951,288) /K=1 as "Event File File Reduction" 
     1049        ModifyPanel cbRGB=(60535,51151,51490) 
     1050        ModifyPanel fixedSize=1 
     1051        SetDrawLayer UserBack 
     1052        DrawLine 7,30,422,30 
     1053        SetVariable PathDisplay,pos={77,7},size={300,13},title="Path" 
     1054        SetVariable PathDisplay,help={"This is the path to the folder that will be used to find the SANS data while reducing. If no files appear in the popup, make sure that this folder is set correctly"} 
     1055        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:EVRED:gCatPathStr 
     1056        Button PathButton,pos={3,3},size={70,20},proc=V_PickEVRPathButton,title="Pick Path" 
     1057        Button PathButton,help={"Select the folder containing the raw SANS data files"} 
     1058        Button helpButton,pos={385,3},size={25,20},proc=V_ShowEVRHelp,title="?" 
     1059        Button helpButton,help={"Show the help file for reducing event files"} 
     1060        PopupMenu ERFilesPopup,pos={3,45},size={167,19},proc=V_EVR_RedPopMenuProc,title="File to Reduce" 
     1061        PopupMenu ERFilesPopup,help={"The displayed file is the one that will be reduced."} 
     1062        PopupMenu ERFilesPopup,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:EVRED:gMRedList" 
     1063 
     1064        SetVariable ERSlices,pos={3,75},size={100,15},title="# of slices" 
     1065        SetVariable ERSlices,limits={0,1000,0},value=root:Packages:NIST:VSANS:Globals:EVRED:gNumSlices 
     1066         
     1067        SetVariable ERSelSlice,pos={150,75},size={100,15},title="current slice" 
     1068        SetVariable ERSelSlice,limits={0,1000,1},value=root:Packages:NIST:VSANS:Globals:EVRED:gCurSlice 
     1069        SetVariable ERSelSlice,proc=V_ChangeSliceViewSetVar 
     1070 
     1071        Button ToSTOButton,pos={305,45},size={100,20},proc=V_EVR_LoadAndSTO,title="to STO" 
     1072        Button ToSTOButton,help={"Load the event file and copy to STO"} 
     1073 
     1074        Button TimeBinButton,pos={305,75},size={100,20},proc=V_EVR_TimeBins,title="Time Bins" 
     1075        Button TimeBinButton,help={"Display the time bins"} 
     1076                                 
     1077//      SetVariable ERList,pos={3,48},size={350,13},proc=V_FileNumberListProc,title="File number list: " 
     1078//      SetVariable ERList,help={"Enter a comma delimited list of file numbers to reduce. Ranges can be entered using a dash."} 
     1079//      SetVariable ERList,limits={-Inf,Inf,1},value= root:Packages:NIST:VSANS:Globals:EVRED:gFileNumList 
     1080 
     1081        PopupMenu ERProto_pop,pos={3,118},size={119,19},proc=V_EVR_ProtoPopMenuProc,title="Protocol " 
     1082        PopupMenu ERProto_pop,help={"All of the data files in the popup will be reduced using this protocol"} 
     1083        PopupMenu ERProto_pop,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:EVRED:gMRProtoList" 
     1084        Button ReduceAllButton,pos={3,178},size={180,20},proc=V_EVR_ReduceAllSlices,title="Reduce All Slices" 
     1085        Button ReduceAllButton,help={"This will reduce all slices."} 
     1086        Button ReduceOneButton,pos={3,148},size={180,20},proc=V_EVR_ReduceTopSlice,title="Reduce Selected Slice" 
     1087        Button ReduceOneButton,help={"This will reduce the selected slice."} 
     1088         
     1089        Button DoneButton,pos={290,178},size={110,20},proc=V_EVR_DoneButtonProc,title="Done Reducing" 
     1090        Button DoneButton,help={"When done reducing files, this will close this control panel."} 
     1091EndMacro 
     1092 
     1093 
     1094//allows the user to set the path to the local folder that contains the SANS data 
     1095//2 global strings are reset after the path "catPathName" is reset in the function PickPath() 
     1096// this path is the only one, the globals are simply for convenience 
     1097// 
     1098Function V_PickEVRPathButton(PathButton) : ButtonControl 
     1099        String PathButton 
     1100         
     1101        V_PickPath()            //sets the main global path string for catPathName 
     1102         
     1103        //then update the "local" copy in the MRED subfolder 
     1104        PathInfo/S catPathName 
     1105        String dum = S_path 
     1106        if (V_flag == 0) 
     1107                //path does not exist - no folder selected 
     1108                String/G root:Packages:NIST:VSANS:Globals:EVRED:gCatPathStr = "no folder selected" 
     1109        else 
     1110                String/G root:Packages:NIST:VSANS:Globals:EVRED:gCatPathStr = dum 
     1111        endif 
     1112         
     1113        //Update the pathStr variable box 
     1114        ControlUpdate/W=V_Event_Reduce_Panel $"PathDisplay" 
     1115         
     1116        //then update the popup list 
     1117        V_EVR_RedPopMenuProc("ERFilesPopup",1,"") 
     1118End 
     1119 
     1120// 
     1121// loads the file in the popup (to RAW as usual) 
     1122// then copies the data to STO 
     1123// 
     1124//      updates the total number of slices 
     1125// 
     1126// resets the slice view to 0 
     1127//              changes the limits on the SetVar control {0,n,1} 
     1128// 
     1129Function V_EVR_LoadAndSTO(PathButton) : ButtonControl 
     1130        String PathButton 
     1131 
     1132        String fileName 
     1133        Variable err 
     1134 
     1135        ControlInfo ERFilesPopup 
     1136        fileName = S_Value 
     1137         
     1138        err = V_LoadHDF5Data(FileName,"RAW") 
     1139        if(!err)                //directly from, and the same steps as DisplayMainButtonProc(ctrlName) 
     1140                SVAR hdfDF = root:file_name                     // last file loaded, may not be the safest way to pass 
     1141                String folder = StringFromList(0,hdfDF,".") 
     1142                 
     1143                // this (in SANS) just passes directly to fRawWindowHook() 
     1144                V_UpdateDisplayInformation("RAW")               // plot the data in whatever folder type 
     1145                                                                 
     1146                // set the global to display ONLY if the load was called from here, not from the  
     1147                // other routines that load data (to read in values) 
     1148                SVAR gLast = root:Packages:NIST:VSANS:Globals:gLastLoadedFile 
     1149                gLast = hdfDF 
     1150                                                 
     1151        endif 
     1152         
     1153        // now copy RAW to STO for safe keeping... 
     1154        //V_CopyHDFToWorkFolder(oldtype,newtype) 
     1155        V_CopyHDFToWorkFolder("RAW","STO") 
     1156 
     1157        // read the number of slices from FL 
     1158        WAVE/Z w = root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:slices 
     1159        NVAR num = root:Packages:NIST:VSANS:Globals:EVRED:gNumSlices 
     1160         
     1161        num = DimSize(w, 2) 
     1162         
     1163        //change the slice view to slice 0 
     1164        SetVariable ERSelSlice,win=V_Event_Reduce_Panel,limits={0,(num-1),1} 
     1165        NVAR value=root:Packages:NIST:VSANS:Globals:EVRED:gCurSlice 
     1166        value=0 
     1167        V_ChangeSliceViewSetVar("",0,"","") 
     1168         
     1169        return(0) 
     1170End 
     1171 
     1172// given a file already loaded into RAW (and copied to STO) 
     1173// display a selected slice (8 panels) 
     1174// rescale the monitor count 
     1175// rescale the count time 
     1176// update the sample label 
     1177// 
     1178// TODO -- and I missing anything that is done at the normal RAW load time 
     1179// that I am not doing here simply by copying over 
     1180// -- like... data error, nonlinear corrections, etc. 
     1181// the nonlinear corrections need only be done once, since the detector is the same for all slices. 
     1182// 
     1183Function V_ChangeSliceViewSetVar(ctrlName,varNum,varStr,varName) : SetVariableControl 
     1184        String ctrlName 
     1185        Variable varNum 
     1186        String varStr 
     1187        String varName 
     1188         
     1189        Variable ii 
     1190        String detStr,fname      
     1191        // varNum is the only meaningful input, the slice number 
     1192         
     1193        // copy STO to RAW 
     1194        V_CopyHDFToWorkFolder("STO","RAW") 
     1195         
     1196         
     1197        // switch data to point to the correct slice 
     1198        string tmpStr = "root:Packages:NIST:VSANS:RAW:entry:instrument:"  
     1199 
     1200        fname="RAW" 
     1201        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1) 
     1202                detStr = StringFromList(ii, ksDetectorListNoB, ";") 
     1203                Wave data = V_getDetectorDataW(fname,detStr) 
     1204                 
     1205                WAVE/Z slices = $("root:Packages:NIST:VSANS:RAW:entry:instrument:detector_"+detStr+":slices") 
     1206                data = slices[p][q][varNum] 
     1207                V_MakeDataError(tmpStr+"detector_"+detStr)              //update the error wave to match the slice 
     1208        endfor 
     1209                 
     1210        // TODO: update the times and counts 
     1211        // use a special "put", not "write" so it is written to the RAW folder, not the file 
     1212        // 
     1213        wave binEnd = root:Packages:NIST:VSANS:RAW:entry:reduction:binEndTime 
     1214        wave timeWidth = root:Packages:NIST:VSANS:RAW:entry:reduction:timeWidth 
     1215         
     1216        Variable timeFract,num 
     1217        num = numpnts(binEnd) 
     1218        timeFract = timeWidth[varNum]/binEnd[num-1] 
     1219 
     1220// get values from STO 
     1221        Variable mon_STO,ctTime_STO 
     1222        String label_STO 
     1223 
     1224        ctTime_STO = V_getCount_time("STO") 
     1225        mon_STO = V_getBeamMonNormData("STO") 
     1226        label_STO = V_getSampleDescription("STO") 
     1227         
     1228// mon ct 
     1229        V_putBeamMonNormData("RAW",mon_STO*timeFract) 
     1230// ct time 
     1231        V_putCount_time("RAW",ctTime_STO*timeFract) 
     1232// label 
     1233        V_putSampleDescription("RAW",label_STO+" slice "+num2str(varNum)) 
     1234         
     1235        return(0) 
     1236End 
     1237 
     1238 
     1239// 
     1240// locates the time bins and shows the time bin table (and plot?) 
     1241// 
     1242Function V_EVR_TimeBins(PathButton) : ButtonControl 
     1243        String PathButton 
     1244 
     1245        wave binEnd = root:Packages:NIST:VSANS:RAW:entry:reduction:binEndTime 
     1246        wave timeWidth = root:Packages:NIST:VSANS:RAW:entry:reduction:timeWidth 
     1247 
     1248        edit binEnd,timeWidth 
     1249         
     1250        return(0) 
     1251End 
     1252 
     1253Proc V_ShowEVRHelp(ctrlName) : ButtonControl 
     1254        String ctrlName 
     1255 
     1256        DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Reduce Event Files]" 
     1257        if(V_flag !=0) 
     1258                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found" 
     1259        endif 
     1260End 
     1261 
     1262 
     1263 
     1264 
     1265// 
     1266// 
     1267// 
     1268Function V_EVR_RedPopMenuProc(ERFilesPopup,popNum,popStr) : PopupMenuControl 
     1269        String ERFilesPopup 
     1270        Variable popNum 
     1271        String popStr 
     1272 
     1273        String list = V_GetValidEVRedPopupList() 
     1274//       
     1275        SVAR str= root:Packages:NIST:VSANS:Globals:EVRED:gMredList 
     1276        str=list 
     1277        ControlUpdate ERFilesPopup 
     1278        return(0) 
     1279End 
     1280 
     1281// get a  list of all of the sample files, based on intent 
     1282// 
     1283// 
     1284// only accepts files in the list that are purpose=scattering 
     1285// 
     1286Function/S V_GetValidEVRedPopupList() 
     1287 
     1288        String semiList="" 
     1289 
     1290        semiList = V_GetSAMList() 
     1291        return(semiList) 
     1292 
     1293End 
     1294 
     1295//returns a list of the available protocol waves in the protocols folder 
     1296//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist) 
     1297//since these waves do not contain valid protocol instructions 
     1298// 
     1299// also removes Base and DoAll since for event file reduction, speed is of the essence 
     1300// and there is no provision in the protocol for "asking" for the files to be identified 
     1301// 
     1302Function V_EVR_ProtoPopMenuProc(ERProto_pop,popNum,popStr) : PopupMenuControl 
     1303        String ERProto_pop 
     1304        Variable popNum 
     1305        String popStr 
     1306 
     1307        //get list of currently valid protocols, and put it in the popup (the global list) 
     1308        //excluding "tempProtocol" and "CreateNew" if they exist 
     1309        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols 
     1310        String list = WaveList("*",";","") 
     1311        SetDataFolder root: 
     1312         
     1313        //remove items from the list (list is unchanged if the items are not present) 
     1314        list = RemoveFromList("CreateNew", list, ";") 
     1315        list = RemoveFromList("tempProtocol", list, ";") 
     1316        list = RemoveFromList("fakeProtocol", list, ";") 
     1317        list = RemoveFromList("PanelNameW", list, ";") 
     1318        list = RemoveFromList("Beg_pts", list, ";") 
     1319        list = RemoveFromList("End_pts", list, ";") 
     1320        list = RemoveFromList("trimUpdate", list, ";") 
     1321        list = RemoveFromList("Base", list, ";") 
     1322        list = RemoveFromList("DoAll", list, ";") 
     1323         
     1324        String/G root:Packages:NIST:VSANS:Globals:EVRED:gMRProtoList = list 
     1325        ControlUpdate ERProto_pop 
     1326 
     1327End 
     1328 
     1329// 
     1330//button procedure to close the panel,  
     1331// 
     1332Function V_EVR_DoneButtonProc(ctrlName) : ButtonControl 
     1333        String ctrlName 
     1334 
     1335        // this button will make sure all files are closed  
     1336        //and close the panel 
     1337 
     1338        Close/A 
     1339        DoWindow/K V_Event_Reduce_Panel 
     1340         
     1341        KillDataFolder root:Packages:NIST:VSANS:Globals:EVRED 
     1342End 
     1343 
     1344 
     1345 
     1346 
     1347// 
     1348// reduce just the selected slice 
     1349// 
     1350// Assumes that: 
     1351// - the event data file has been loaded and copied to STO for repeated access 
     1352// - the protocol has been properly and completely defined (test one slice first!) 
     1353// 
     1354// 
     1355Function V_EVR_ReduceTopSlice(ctrlName) : ButtonControl 
     1356        String ctrlName 
     1357 
     1358        //get the selected protocol 
     1359        ControlInfo ERProto_pop 
     1360        String protocolNameStr = S_Value 
     1361         
     1362        //also set this as the current protocol, for the function that writes the averaged waves 
     1363        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr 
     1364         
     1365        // get the file name from the popup 
     1366        ControlInfo ERFilesPopup 
     1367        String samStr = S_Value 
     1368         
     1369        // get the current slice number 
     1370        NVAR curSlice = root:Packages:NIST:VSANS:Globals:EVRED:gCurSlice 
     1371        // get the total number of slices 
     1372        NVAR totalSlices = root:Packages:NIST:VSANS:Globals:EVRED:gNumSlices 
     1373         
     1374        //reduce all the files in the list here, using the global protocol(the full reference) 
     1375        //see -- DoReduceList is found in MultipleReduce.ipf 
     1376         
     1377//      V_DoReduceList(commaList) 
     1378        Variable skipLoad = 0 
     1379        V_ExecuteProtocol_Event(protocolNameStr,samStr,curSlice,skipLoad) 
     1380         
     1381        Return 0 
     1382End 
     1383 
     1384 
     1385 
     1386// 
     1387// reduce all slices 
     1388// 
     1389Function V_EVR_ReduceAllSlices(ctrlName) : ButtonControl 
     1390        String ctrlName 
     1391 
     1392        //get the selected protocol 
     1393        ControlInfo ERProto_pop 
     1394        String protocolNameStr = S_Value 
     1395         
     1396        //also set this as the current protocol, for the function that writes the averaged waves 
     1397        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr 
     1398         
     1399        // get the file name from the popup 
     1400        ControlInfo ERFilesPopup 
     1401        String samStr = S_Value 
     1402         
     1403        // get the total number of slices 
     1404        NVAR totalSlices = root:Packages:NIST:VSANS:Globals:EVRED:gNumSlices 
     1405         
     1406         
     1407        Variable skipLoad = 0 
     1408        Variable curSlice = 0 
     1409        // do the first one (slice 0) 
     1410        V_ExecuteProtocol_Event(protocolNameStr,samStr,curSlice,skipLoad) 
     1411         
     1412        skipLoad = 1 
     1413        for(curSlice = 1;curSlice<totalSlices; curSlice +=1) 
     1414                V_ExecuteProtocol_Event(protocolNameStr,samStr,curSlice,skipLoad) 
     1415        endfor 
     1416         
     1417         
     1418        Return 0 
     1419End 
     1420 
     1421 
     1422 
     1423////////////////////////////////// 
     1424// 
     1425// This is the Event-equivalent version of ExecuteProtocol 
     1426// with special handling for shuffling the event slices from STO to RAW->SAM 
     1427// -skips repetitive loads 
     1428// -adjusts timing 
     1429// -names slices 
     1430 
     1431//protStr is the full path to the selected protocol wave 
     1432//samStr is the name of the event data file "Event_sansNNNN.nxs.ngv" 
     1433// SliceNum is the number of slice to reduce (copy it from STO) 
     1434// skipLoad is a flag (0|1) to allow skip of loading EMP, BGD, etc. on repeated passes 
     1435Function V_ExecuteProtocol_Event(protStr,samStr,sliceNum,skipLoad) 
     1436        String protStr,samStr 
     1437        Variable sliceNum 
     1438        Variable skipLoad 
     1439 
     1440        String protoPath = "root:Packages:NIST:VSANS:Globals:Protocols:" 
     1441        WAVE/T prot = $(protoPath+protStr) 
     1442//      SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols 
     1443         
     1444        Variable filesOK,err,notDone 
     1445        String activeType, msgStr, junkStr, pathStr="" 
     1446        PathInfo catPathName                    //this is where the files are 
     1447        pathStr=S_path 
     1448         
     1449//      NVAR useXMLOutput = root:Packages:NIST:gXML_Write 
     1450         
     1451        //Parse the instructions in the prot wave 
     1452        //0 - bkg 
     1453        //1 - emp 
     1454        //2 - div 
     1455        //3 - mask 
     1456        //4 - abs params c2-c5 
     1457        //5 - average params 
     1458        //6 = DRK file (**out of sequence) 
     1459        //7 = beginning trim points 
     1460        //8 = end trim points 
     1461        //9 = unused 
     1462        //10 = unused 
     1463        //11 = unused 
     1464 
     1465////////////////////////////// 
     1466// DIV 
     1467////////////////////////////// 
     1468// for VSANS, DIV is used on each data file as it is converted to WORK, so it needs to be 
     1469//  the first thing in place, before any data or backgrounds are loaded 
     1470 
     1471        //check for work.div file (prot[2]) 
     1472        //load in if needed 
     1473        // no math is done here, DIV is applied as files are converted to WORK (the first operation in VSANS) 
     1474        // 
     1475                // save the state of the DIV preference 
     1476        NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor 
     1477        Variable saved_gDoDIVCor = gDoDIVCor 
     1478         
     1479        if(!skipLoad) 
     1480                 
     1481                err = V_Proto_LoadDIV(prot[2]) 
     1482                 
     1483                if(err) 
     1484                        SetDataFolder root: 
     1485                        Abort "No file selected, data reduction aborted" 
     1486                endif 
     1487        endif 
     1488         
     1489////////////////////////////// 
     1490// SAM 
     1491////////////////////////////// 
     1492 
     1493        // move the selected slice number to RAW, then to SAM 
     1494        V_ChangeSliceViewSetVar("",sliceNum,"","") 
     1495         
     1496        //Execute "V_Convert_to_Workfile()" 
     1497        err = V_Raw_to_work("SAM") 
     1498         
     1499        //always update 
     1500        activeType = "SAM" 
     1501        V_UpdateDisplayInformation(ActiveType) 
     1502 
     1503 
     1504////////////////////////////// 
     1505// BGD 
     1506////////////////////////////// 
     1507         
     1508        //check for BGD file  -- "ask" might not fail - "ask?" will - ? not allowed in VAX filenames 
     1509        // add if needed 
     1510        //use a "case" statement 
     1511        if(!skipLoad) 
     1512         
     1513                msgStr = "Select background file" 
     1514                activeType = "BGD" 
     1515                 
     1516                err = V_Proto_LoadFile(prot[0],activeType,msgStr) 
     1517                if(err) 
     1518                        PathInfo/S catPathName 
     1519                        SetDataFolder root: 
     1520                        Abort "No file selected, data reduction aborted" 
     1521                endif 
     1522         
     1523        //      //Loader is in charge of updating, since it knows if data was loaded 
     1524        //      V_UpdateDisplayInformation(ActiveType) 
     1525        endif 
     1526 
     1527////////////////////////////// 
     1528// EMP 
     1529//////////////////////////////   
     1530         
     1531        //check for emp file (prot[1]) 
     1532        // add if needed 
     1533        if(!skipLoad) 
     1534 
     1535                msgStr = "Select empty cell data" 
     1536                activeType = "EMP" 
     1537                 
     1538                err = V_Proto_LoadFile(prot[1],activeType,msgStr) 
     1539                if(err) 
     1540                        PathInfo/S catPathName 
     1541                        SetDataFolder root: 
     1542                        Abort "No file selected, data reduction aborted" 
     1543                endif 
     1544         
     1545        //      //Loader is in charge of updating, since it knows if data was loaded 
     1546        //      V_UpdateDisplayInformation(ActiveType) 
     1547        endif 
     1548 
     1549////////////////////////////// 
     1550// CORRECT 
     1551////////////////////////////// 
     1552 
     1553        //do the CORRECT step based on the answers to emp and bkg subtraction 
     1554        //by setting the proper"mode" 
     1555        //1 = both emp and bgd subtraction 
     1556        //2 = only bgd subtraction 
     1557        //3 = only emp subtraction 
     1558        //4 = no subtraction  
     1559        //additional modes 091301 
     1560        //11 = emp, bgd, drk 
     1561        //12 = bgd and drk 
     1562        //13 = emp and drk 
     1563        //14 = no subtractions 
     1564        //work.drk is from proto[6] 
     1565        // 
     1566        //subtracting just the DRK data is NOT an option - it doesnt' really make any physical sense 
     1567        // - in this case, DRK is skipped (equivalent to mode==4) 
     1568        // automatically accounts for attenuators given the lookup tables and the  
     1569        //desired subtractions 
     1570        //Attenuator lookup tables are alredy implemented (NG1 = NG7) 
     1571        // 
     1572 
     1573 
     1574/////// DRK is SKIPPED 
     1575         
     1576//      //read in the DRK data if necessary 
     1577//      //only one file, assumed to be RAW data 
     1578//      // 
     1579//      String fname="",drkStr="" 
     1580//      drkStr=StringByKey("DRK",prot[6],"=",",") 
     1581//      if(cmpstr(drkStr,"none") != 0) 
     1582//              err = ReadHeaderAndData( (pathStr+drkStr) ) 
     1583//              if(err) 
     1584//                      PathInfo/S catPathName 
     1585//                      Abort "reduction sequence aborted" 
     1586//              endif 
     1587//              err = V_Raw_to_Work_NoNorm("DRK") 
     1588//      endif 
     1589 
     1590        //dispatch to the proper "mode" of Correct() 
     1591//      V_Dispatch_to_Correct(bgdStr,empStr,drkStr) 
     1592        V_Dispatch_to_Correct(prot[0],prot[1],prot[6]) 
     1593         
     1594        if(err) 
     1595                PathInfo/S catPathName 
     1596                SetDataFolder root: 
     1597                Abort "error in Correct, called from executeprotocol, normal cor" 
     1598        endif 
     1599        activeType = "COR" 
     1600 
     1601// always update - COR will always be generated 
     1602        V_UpdateDisplayInformation(ActiveType)           
     1603 
     1604 
     1605////////////////////////////// 
     1606//  ABSOLUTE SCALE 
     1607////////////////////////////// 
     1608 
     1609        err = V_Proto_ABS_Scale(prot[4],activeType) 
     1610         
     1611        if(err) 
     1612                SetDataFolder root: 
     1613                Abort "Error in V_Absolute_Scale(), called from V_ExecuteProtocol" 
     1614        endif 
     1615//      activeType = "ABS" 
     1616 
     1617 
     1618////////////////////////////// 
     1619// MASK 
     1620////////////////////////////// 
     1621// 
     1622// DONE 
     1623//              x- fill in the "ask" step 
     1624//  x- none is OK, except if the kill fails for any reason 
     1625// x- the regular case of the file name specified by the protocol works correctly 
     1626// x- don't create a null mask if not used, it will handle the error and print out that the mask is missing 
     1627// 
     1628//mask data if desired (mask is applied when the data is binned to I(q)) and is 
     1629//not done explicitly here 
     1630         
     1631        //check for mask 
     1632        //doesn't change the activeType 
     1633        if(!skipLoad) 
     1634 
     1635                V_Proto_ReadMask(prot[3]) 
     1636        endif 
     1637         
     1638////////////////////////////// 
     1639// AVERAGING 
     1640////////////////////////////// 
     1641 
     1642        // average/save data as specified 
     1643        //Parse the keyword=<Value> string as needed, based on AVTYPE 
     1644         
     1645        //average/plot first  
     1646        String av_type = StringByKey("AVTYPE",prot[5],"=",";") 
     1647        If(cmpstr(av_type,"none") != 0) 
     1648                If (cmpstr(av_type,"")==0)              //if the key could not be found... (if "ask" the string) 
     1649                        //get the averaging parameters from the user, as if the set button was hit in the panel 
     1650                        V_SetAverageParamsButtonProc("dummy")           //from "ProtocolAsPanel" 
     1651                        SVAR tempAveStr = root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr 
     1652                        av_type = StringByKey("AVTYPE",tempAveStr,"=",";") 
     1653                else 
     1654                        //there is info in the string, use the protocol 
     1655                        //set the global keyword-string to prot[5] 
     1656                        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = prot[5] 
     1657                Endif 
     1658        Endif 
     1659 
     1660 
     1661        String detGroup = StringByKey("DETGROUP",prot[5],"=",";")               //only for annular, null if not present 
     1662 
     1663         
     1664//convert the folder to linear scale before averaging, then revert by calling the window hook 
     1665// (not needed for VSANS, data is always linear scale) 
     1666 
     1667// 
     1668// (DONE) 
     1669// -x this generates a "Bin Type Not Found" error if reducing only to a 2D level (like for DIV) 
     1670//              because binTypeStr is null 
     1671        String binTypeStr = StringByKey("BINTYPE",prot[5],"=",";") 
     1672        // plotting is not really necessary, and the graph may not be open - so skip for now? 
     1673        Variable binType 
     1674        // only get the binning type if user asks for averaging 
     1675        If(cmpstr(av_type,"none") != 0) 
     1676                binType = V_BinTypeStr2Num(binTypeStr) 
     1677                if(binType == 0) 
     1678                                Abort "Binning mode not found in V_QBinAllPanels() "// when no case matches 
     1679                endif 
     1680        endif 
     1681 
     1682 
     1683// identify the collimation type 
     1684// this will be a string used to determine how the resolution information is to be calculated 
     1685// and written to the reduced data file 
     1686// 
     1687// possible values are: 
     1688// 
     1689// pinhole 
     1690// pinhole_whiteBeam 
     1691// narrowSlit 
     1692// narrowSlit_whiteBeam 
     1693// convergingPinholes 
     1694// 
     1695 
     1696        String collimationStr 
     1697        collimationStr = V_IdentifyCollimation(activeType) 
     1698         
     1699 
     1700//////////////////////////////////////// 
     1701// DISPATCH TO AVERAGING 
     1702///////////////////////////////////////// 
     1703// 
     1704// TODO: 
     1705// -- do I calculate the proper resolution here?, YES, I've already decoded the binning type 
     1706//   and the averaging type has been specified by the protocol. 
     1707// 
     1708// so currently, the resolution is calculated every time that the data is averaged (in VC_fDoBinning_QxQy2D) 
     1709// 
     1710// -- if I calculate the resolution here, then the Trimming routines must be updated 
     1711//    to trim the resolution waves also. This will work for the columns present in 
     1712//    pinhole resolution, but anything using the matrix method - it won't work - and I'll need  
     1713//    a different solution 
     1714// 
     1715 
     1716        V_Proto_doAverage(prot[5],av_type,activeType,binType,collimationStr) 
     1717 
     1718 
     1719 
     1720//////////////////////// 
     1721// PLOT THE DATA 
     1722//////////////////////// 
     1723 
     1724        V_Proto_doPlot(prot[5],av_type,activeType,binType,detGroup) 
     1725         
     1726         
     1727 
     1728////////////////////     
     1729// SAVE THE DATA 
     1730//////////////////// 
     1731 
     1732//  
     1733// x- how do I get the sample file name? 
     1734//    local variable samFileLoaded is the file name loaded (contains the extension) 
     1735// 
     1736// V_Proto_SaveFile(avgStr,activeType,samFileLoaded,av_type,binType,detGroup,trimBegStr,trimEndStr) 
     1737 
     1738        prot[9] = collimationStr 
     1739        String outputFileName 
     1740        outputFileName = RemoveEnding(samStr,".nxs.ngv") + "_SL"+num2str(sliceNum) 
     1741        //? remove the "Events_" from the beginning? some other naming scheme entirely? 
     1742         
     1743        V_Proto_SaveFile(prot[5],activeType,outputFileName,av_type,binType,detGroup,prot[7],prot[8]) 
     1744         
     1745////////////////////////////// 
     1746// DONE WITH THE PROTOCOL 
     1747//////////////////////////////   
     1748         
     1749        // reset any global preferences that I had changed 
     1750        gDoDIVCor = saved_gDoDIVCor 
     1751         
     1752         
     1753        Return(0) 
     1754End 
     1755 
     1756 
     1757 
Note: See TracChangeset for help on using the changeset viewer.