#pragma rtGlobals=1 // Use modern global access method. ///////// SRK - VERY SIMPLE batch converter has been added: see // // Function batchXML26ColConvert() // // Function batchGrasp26ColConvert() // // these both need a real interface, and a way to better define the name of the // converted output file. And some retention of the header would be nice too... // // Functions and interfaces to manage datasets now that they are in data folders // Planned interface // - Panel to select/load data and then select operation // Planned functions: // - Rename a data set - AJJ Done Nov 2009 // - Duplicate a data set - AJJ Done Nov 2009 // - Subtract one data set from another // - Add one data set to another // - Divide data sets // - Multiply data sets // - Save a data folder to file /////////////////// Data Management Panel /////////////////////////////////////////////////////// // Proc MakeDMPanel() DoWindow/F DataManagementPanel if(V_flag==0) fMakeDMPanel() endif End Proc fMakeDMPanel() PauseUpdate; Silent 1 // building window... NewPanel /W=(459,44,959,460)/N=DataManagementPanel/K=2 as "Data Set Management" ModifyPanel fixedSize=1,cbRGB=(30000,60000,60000) //Main bit of panel GroupBox grpBox_0,pos={20,10},size={460,150} GroupBox grpBox_1,pos={20,180},size={460,70} GroupBox grpBox_2,pos={20,270},size={460,40} GroupBox grpBox_3,pos={20,330},size={460,40} Button DS_button,title="Load 1D Data Set",pos={300,20},size={150,20} Button DS_button,proc=DM_LoadDataSetProc Button Unload_button,title="Unload 1D Data Set",pos={300,50},size={150,20} Button Unload_button,proc=DM_UnloadProc Button Save_button,title="Save 1D Data Set",pos={300,80},size={150,20} Button Save_button,proc=DM_SaveProc Button ReSort_button,title="Re-Sort 1D Data Set",pos={300,130},size={150,20} Button ReSort_button,proc=DM_ReSortProc PopupMenu DS_popup,pos={30,40},size={318,20},title="Data Set ",proc=DM_PopupProc PopupMenu DS_popup,mode=1,value= #"DM_DataSetPopupList()" CheckBox XMLStateCtrl,pos={30,82},size={124,14},title="XML Output Enabled (change in Preferences)" CheckBox XMLStateCtrl,help={"Default output format is canSAS XML rather than NIST 6 column"} CheckBox XMLStateCtrl,value= root:Packages:NIST:gXML_Write,disable=2 Button Rename_button,title="Rename",pos={75,220},size={150,20} Button Rename_button,proc=DM_RenameProc Button Duplicate_button,title="Duplicate",pos={275,220},size={150,20} Button Duplicate_button,proc=DM_DuplicateProc SetVariable NewName_setvar,title="New Name (max 25 characters)",pos={50,190},size={400,20} SetVariable NewName_setvar,fsize=12,value=_STR:"",proc=DMNameSetvarproc,live=1 Button SaveAsXML_button,title="Save as canSAS XML",pos={75,280},size={150,20} Button SaveAsXML_button,proc=DMSaveAsXMLproc Button SaveAs6col_button,title="Save as NIST 6 column",pos={275,280},size={160,20} Button SaveAs6col_button,proc=DMSaveAs6colproc Button BatchConvertData_button,title="Batch Convert Format of 1D Data Files",pos={75,340},size={350,20} Button BatchConvertData_button,proc=DMBatchConvertProc Button DMDone_button,title="Done",pos={360,370},size={60,20} Button DMDone_button,proc=DMDoneButtonProc Button DMHelp_button,title="?",pos={440,370},size={30,20} Button DMHelp_button,proc=DMHelpButtonProc ControlInfo/W=DataManagementPanel DS_popup if (cmpstr(S_Value,"No data loaded") == 0) SetVariable NewName_setvar,value=_STR:"dataset_copy" else //fake call to popup //// -- can't use STRUCT in a Proc, only a function // STRUCT WMPopupAction pa // pa.win = "DataManagementPanel" // pa.ctrlName = "DS_popup" // pa.eventCode = 2 // DM_PopupProc(pa) endif End Function DMSaveAs6colproc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode) case 2: ControlInfo/W=DataManagementPanel DS_popup String folderName = S_Value fReWrite1DData(folderName,"tab","CRLF") break endswitch return 0 End Function DMSaveAsXMLproc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode) case 2: ControlInfo/W=DataManagementPanel DS_popup String folderName = S_Value ReWrite1DXMLData(folderName) break endswitch return 0 End //Function SaveDataSetToFile(folderName) // String folderName // // String protoStr = "" // //Check for history string in folder // //If it doesn't exist then // // //Do saving of data file. // // NVAR gXML_Write = root:Packages:NIST:gXML_Write // // if (gXML_Write == 1) // ReWrite1DXMLData(folderName) // else // fReWrite1DData(folderName,"tab","CRLF") // endif // // //Include history string to record what was done? // //End Function DMBatchConvertProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode) case 2: Execute "MakeNCNRBatchConvertPanel()" break endswitch return 0 End Function DMNameSetvarproc(sva) : SetVariableControl STRUCT WMSetVariableAction &sva switch( sva.eventCode ) case 1: // mouse up case 2: // Enter key case 3: // Live update String sv = sva.sval if( strlen(sv) > 25 ) sv= sv[0,24] SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv ControlUpdate /W=$(sva.win) $(sva.ctrlName) Beep endif break endswitch return 0 End Function DM_RenameProc(ba) : ButtonControl STRUCT WMButtonAction &ba String DS,NewName ControlInfo/W=$(ba.win) DS_popup DS = S_Value ControlInfo/W=$(ba.win) NewName_setvar NewName = CleanupName(S_Value, 0 ) //clean up any bad characters, and put the cleaned string back SetVariable NewName_setvar,value=_STR:NewName switch (ba.eventcode) case 2: // mouse up RenameDataSet(DS,NewName) ControlUpdate /W=$(ba.win) DS_Popup break endswitch return 0 end Function DM_DuplicateProc(ba) : ButtonControl STRUCT WMButtonAction &ba String DS,NewName ControlInfo/W=$(ba.win) DS_popup DS = S_Value ControlInfo/W=$(ba.win) NewName_setvar NewName = CleanupName(S_Value, 0 ) //clean up any bad characters, and put the cleaned string back SetVariable NewName_setvar,value=_STR:NewName switch (ba.eventcode) case 2: // mouse up DuplicateDataSet(DS,NewName,0) ControlUpdate /W=$(ba.win) DS_Popup break endswitch return 0 end Function DM_SaveProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch(ba.eventCode) case 2: ControlInfo/W=$(ba.win) DS_popup SaveDataSetToFile(S_Value) break endswitch return 0 end Function DM_UnloadProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch (ba.eventcode) case 2: // mouse up String savDF=GetDataFolder(1) String DF ControlInfo /W=$(ba.win) DS_Popup DF = S_Value print DF //check for horrific null output from control if (cmpstr(DF,"") != 0) SetDataFolder DF KillVariables/A SetDataFolder savDF KillDataFolder/Z $DF ControlUpdate /W=$(ba.win) DS_Popup ControlInfo/W=DataManagementPanel DS_popup if (cmpstr(S_Value,"No data loaded") == 0) SetVariable NewName_setvar,value=_STR:"dataset_copy" else //fake call to popup STRUCT WMPopupAction pa pa.win = "DataManagementPanel" pa.ctrlName = "DS_popup" pa.eventCode = 2 DM_PopupProc(pa) endif endif break endswitch return 0 end Function DM_PopupProc(pa) : PopupMenuControl STRUCT WMPopupAction &pa String resultName switch( pa.eventCode) case 2: //print "Called by "+pa.ctrlname+" with value "+pa.popStr ControlInfo/W=$(pa.win) $(pa.ctrlName) String popStr = S_Value if (stringmatch(pa.ctrlname,"*DS*") == 1) resultName = stringfromlist(0,popStr,"_")+"_copy" SetVariable NewName_setvar win=$(pa.win), value=_STR:resultName endif break endswitch End //Must follow naming scheme to match buttons to popups //"Name_button" goes with "Name_popup" Function DM_LoadDataSetProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" Execute cmd SVAR gLastFileName = root:packages:NIST:gLastFileName String windowName = ba.win String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" ControlUpdate/W=$(windowName) $(popupName) //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow // convoluted method to find the right item and pop the menu. String list,folderStr Variable num folderStr = CleanupName(gLastFileName,0) list = DM_DataSetPopupList() num=WhichListItem(folderStr,list,";",0,0) if(num != -1) PopupMenu $(popupName),mode=num+1,win=$(windowName) ControlUpdate/W=$(windowName) $(popupName) if (cmpstr(popupName,"DS_popup") == 0) //send fake mouse action to popup to update old name if Struct WMPopupAction pa pa.eventCode = 2 //fake mouse up pa.win = windowName pa.ctrlName = "DS_popup" DM_PopupProc(pa) endif endif break endswitch return 0 End Function/S DMGetDSName(dsNum) Variable dsNum String ctrlName if (dsNum == 1) ctrlName = "DS1_popup" elseif (dsNum == 2) ctrlName = "DS2_popup" endif ControlInfo/W=DataManagementPanel $(ctrlName) Return S_Value End Function DMDoneButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba String win = ba.win switch (ba.eventCode) case 2: DoWindow/K DataManagementPanel break endswitch return 0 End Function DMHelpButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba String win = ba.win switch (ba.eventCode) case 2: // click code here DisplayHelpTopic/Z/K=1 "Data Set Management" if(V_flag !=0) DoAlert 0,"The Data Set Management Help file could not be found" endif break endswitch return 0 End Function DM_ReSortProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch(ba.eventCode) case 2: ControlInfo/W=$(ba.win) DS_popup ReSortDataSet(S_Value) break endswitch return 0 end /////////////////////// Batch Data Conversion Panel //////////////////////////////////// // // Proc MakeNCNRBatchConvertPanel() NCNRInitBatchConvert() DoWindow/F NCNRBatchConvertPanel if(V_flag==0) fMakeNCNRBatchConvertPanel() endif End Function NCNRInitBatchConvert() NewDataFolder/O/S root:Packages:NIST:BatchConvert Make/O/T/N=1 filewave="" Make/O/N=1 selWave=0 Variable/G ind=0,gRadioVal=1 SetDataFolder root: End Proc fMakeNCNRBatchConvertPanel() PauseUpdate; Silent 1 // building window... NewPanel /W=(658,347,1018,737)/N=NCNRBatchConvertPanel/K=2 as "Batch Convert 1D Data" // NewPanel /W=(658,347,1018,737)/N=NCNRBatchConvertPanel as "Batch Convert 1D Data" ModifyPanel cbRGB=(40000,50000,32896) ModifyPanel fixedSize=1 ListBox fileList,pos={13,11},size={206,179} ListBox fileList,listWave=root:Packages:NIST:BatchConvert:fileWave ListBox fileList,selWave=root:Packages:NIST:BatchConvert:selWave,mode= 4 Button button7,pos={238,20},size={100,20},proc=NCNRBatchConvertNewFolder,title="New Folder" Button button7,help={"Select a new data folder"} TitleBox msg0,pos={238,160},size={100,30},title="\JCShift-click to\rselect multiple files" TitleBox msg0,frame=0,fixedSize=1 GroupBox filterGroup,pos={13,200},size={206,60},title="Filter list by input file type" CheckBox filterCheck_1,pos={24,220},size={36,14},title="XML",value= 1,mode=1, proc=BC_filterCheckProc CheckBox filterCheck_2,pos={24,239},size={69,14},title="ABS or AVE",value= 0,mode=1, proc=BC_filterCheckProc CheckBox filterCheck_3,pos={100,220},size={69,14},title="none",value= 0,mode=1, proc=BC_filterCheckProc Button button8,pos={238,75},size={100,20},proc=NCNRBatchConvertHelpProc,title="Help" Button button9,pos={238,47},size={100,20},proc=NCNRBatchConvertRefresh,title="Refresh List" Button button10,pos={238,102},size={100,20},proc=NCNRBatchConvertSelectAll,title="Select All" Button button0,pos={238,130},size={100,20},proc=NCNRBatchConvertDone,title="Done" GroupBox outputGroup,pos={13,270},size={206,60},title="Output File Type" CheckBox outputCheck_1,pos={24,289},size={36,14},title="XML",value= 0,mode=1, proc=BC_outputCheckProc CheckBox outputCheck_2,pos={24,309},size={69,14},title="ABS or AVE",value= 1,mode=1, proc=BC_outputCheckProc Button button6,pos={13,350},size={206,20},proc=NCNRBatchConvertFiles,title="Convert File(s)" Button button6,help={"Converts the files to the format selected"} End Function BC_filterCheckProc(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked NVAR gRadioVal= root:Packages:NIST:BatchConvert:gRadioVal strswitch (ctrlName) case "filterCheck_1": gRadioVal= 1 break case "filterCheck_2": gRadioVal= 2 break case "filterCheck_3": gRadioVal= 3 break endswitch CheckBox filterCheck_1,value= gRadioVal==1 CheckBox filterCheck_2,value= gRadioVal==2 CheckBox filterCheck_3,value= gRadioVal==3 NCNRBatchConvertGetList() return(0) End Function BC_outputCheckProc(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked if(cmpstr("outputCheck_1",ctrlName)==0) CheckBox outputCheck_1,value=checked CheckBox outputCheck_2,value=!checked else CheckBox outputCheck_1,value=!checked CheckBox outputCheck_2,value=checked endif return(0) End Function NCNRBatchConvertFiles(ba) : ButtonControl STRUCT WMButtonAction &ba switch (ba.eventCode) case 2: //check the input/output as best I can (none may be the input filter) Variable inputType,outputType=1 NVAR gRadioVal= root:Packages:NIST:BatchConvert:gRadioVal inputType = gRadioVal ControlInfo outputCheck_1 if(V_value==1) outputType = 1 //xml else outputType = 2 //6-col endif if(inputType==outputType) DoAlert 0,"Input and output types are the same. Nothing will be converted" return(0) endif // input and output are different, proceed Wave/T fileWave=$"root:Packages:NIST:BatchConvert:fileWave" Wave sel=$"root:Packages:NIST:BatchConvert:selWave" String fname="",pathStr="",newFileName="" Variable ii,num PathInfo catPathName //this is where the files are pathStr=S_path // process the selected items num=numpnts(sel) ii=0 do if(sel[ii] == 1) fname=pathStr + fileWave[ii] if(outputType == 1) convertNISTtoNISTXML(fname) endif if(outputType == 2) convertNISTXMLtoNIST6Col(fname) endif endif ii+=1 while(ii 25 ) sv= sv[0,24] SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv ControlUpdate /W=$(sva.win) $(sva.ctrlName) Beep endif Button DASave_Button win=$(sva.win), disable=2 break endswitch return 0 End ////////////////////// Functions to do manipulations /////////////////////////////////// Function RenameDataSet(dataSetFolder, newName) String dataSetFolder String newName String dataSetFolderParent,basestr,objName Variable index = 0 //Abuse ParseFilePath to get path without folder name dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) //Abuse ParseFilePath to get basestr basestr = ParseFilePath(0,dataSetFolder,":",1,0) // try RenameDataFolder $(dataSetFolder) $(newName)//; AbortOnRTE SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE do objName = GetIndexedObjName("",1,index) if (strlen(objName) == 0) break endif Rename $(objName) $(ReplaceString(basestr,objName,newName)) index+=1 while(1) SetDataFolder root: // catch // Print "Aborted: " + num2str(V_AbortCode) // SetDataFolder root: // endtry End Function DuplicateDataSet(dataSetFolder, newName, forceoverwrite) String dataSetFolder String newName Variable forceoverwrite String dataSetFolderParent,basestr,objName Variable index = 0 //Abuse ParseFilePath to get path without folder name dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) //Abuse ParseFilePath to get basestr basestr = ParseFilePath(0,dataSetFolder,":",1,0) print "Duplicating "+dataSetFolder+" as "+newName SetDataFolder $(dataSetFolderParent) if (!DataFolderExists(newName)) NewDataFolder $(newName) else if (!forceoverwrite) DoAlert 1, "A dataset with the name "+newName+" already exists. Overwrite?" if (V_flag == 2) return 1 endif endif endif //If we are here, the folder (now) exists and the user has agreed to overwrite //either in the function call or from the alert. // here, GetIndexedObjectName copies all of the waves index = 0 do objName = GetIndexedObjName(basestr,1,index) if (strlen(objName) == 0) break endif objname = ":"+basestr+":"+objname Duplicate/O $(objName) $(ReplaceString(basestr,objName,newName)) index+=1 while(1) // -- for USANS data, we need the slit height. copy all of the "USANS_*" variables // may need to augment this for other situations index = 0 do objName = GetIndexedObjName(basestr,2,index) if (strlen(objName) == 0) break endif if(stringmatch(objName,"USANS*") == 1) objname = ":"+basestr+":"+objname NVAR tmp = $objName Variable/G $(ReplaceString(basestr,objName,newName))= tmp endif index+=1 while(1) SetDataFolder root: return 0 End // Subtract Set2 From Set1 // Use Result_I = Set1_I - f*Set2_I Function SubtractDataSets(set1Name,set2Name,set2Scale,resultName) String set1Name String set2Name Variable set2Scale String resultName String set1Path = "root:"+set1Name+":" String set2Path = "root:"+set2Name+":" String resultPath = "root:"+resultName+":" SetDataFolder root: //Create folder for result //UnloadDataSet(resultName) //Make the folder if (DuplicateDataSet(set1Path,resultName,0)) return 1 else //Do subtraction of I waves - including interpolation if necessary. Wave result_i = $(resultPath+resultName+"_i") Wave result_s = $(resultPath+resultName+"_s") Wave set1_i = $(set1Path+set1Name+"_i") Wave set1_q = $(set1Path+set1Name+"_q") Wave set1_s = $(set1Path+set1Name+"_s") Wave set2_i = $(set2Path+set2Name+"_i") Wave set2_q = $(set2Path+set2Name+"_q") Wave set2_s = $(set2Path+set2Name+"_s") result_i = set1_i - (set2Scale*interp(set1_q[p],set2_q,set2_i)) result_s = sqrt(set1_s^2 + (set2Scale*interp(set1_q[p],set2_q,set2_s))^2 ) //Calculate result error wave - can we produce corrected Q error? //Generate history string to record what was done? return 0 endif End // Add Set2 to Set1 // Use Result_I = Set1_I + f*Set2_I Function AddDataSets(set1Name,set2Name,set2Scale,resultName) String set1Name String set2Name Variable set2Scale String resultName String set1Path = "root:"+set1Name+":" String set2Path = "root:"+set2Name+":" String resultPath = "root:"+resultName+":" SetDataFolder root: //Create folder for result if(DuplicateDataSet(set1Path,resultName,0)) //User said no overwrite return 1 else //Do addition of I waves - including interpolation if necessary. Wave result_i = $(resultPath+resultName+"_i") Wave result_s = $(resultPath+resultName+"_s") Wave set1_i = $(set1Path+set1Name+"_i") Wave set1_q = $(set1Path+set1Name+"_q") Wave set1_s = $(set1Path+set1Name+"_s") Wave set2_i = $(set2Path+set2Name+"_i") Wave set2_q = $(set2Path+set2Name+"_q") Wave set2_s = $(set2Path+set2Name+"_s") result_i = set1_i + set2Scale*interp(set1_q[p],set2_q,set2_i) //Calculate result error wave (note that this is identical to subtraction) result_s = sqrt(set1_s^2 + (set2Scale*interp(set1_q[p],set2_q,set2_s))^2 ) // - can we produce corrected Q error? //Generate history string to record what was done? return 0 endif End // Multiply Set1 by Set2 // Use Result_I = Set1_I * (f*Set2_I) Function MultiplyDataSets(set1Name, set2Name, set2Scale, resultName) String set1Name String set2Name Variable set2Scale String resultName String set1Path = "root:"+set1Name+":" String set2Path = "root:"+set2Name+":" String resultPath = "root:"+resultName+":" SetDataFolder root: //Create folder for result //Make the folder if(DuplicateDataSet(set1Path,resultName,0)) //User said no overwrite return 1 else //Do multiplcation of I waves - including interpolation if necessary. Wave result_i = $(resultPath+resultName+"_i") Wave result_s = $(resultPath+resultName+"_s") Wave set1_i = $(set1Path+set1Name+"_i") Wave set1_q = $(set1Path+set1Name+"_q") Wave set1_s = $(set1Path+set1Name+"_s") Wave set2_i = $(set2Path+set2Name+"_i") Wave set2_q = $(set2Path+set2Name+"_q") Wave set2_s = $(set2Path+set2Name+"_s") result_i = set1_i*set2Scale*interp(set1_q[p],set2_q,set2_i) //Calculate result error wave // sum each of the relative errors, interpolating set 2 intensity and error as needed // then sqrt result_s = (set2Scale*interp(set1_q[p],set2_q,set2_i)*set1_s)^2 result_s += (set2Scale*set1_i*interp(set1_q[p],set2_q,set2_s))^2 result_s = sqrt(result_s) // - can we produce corrected Q error? //Generate history string to record what was done? return 0 endif End // Divide Set1 by Set2 // Use Result_I = Set1_I / (f*Set2_I) Function DivideDataSets(set1Name, set2Name, set2Scale, resultName) String set1Name String set2Name Variable set2Scale String resultName String set1Path = "root:"+set1Name+":" String set2Path = "root:"+set2Name+":" String resultPath = "root:"+resultName+":" SetDataFolder root: //Create folder for result //Make the folder if(DuplicateDataSet(set1Path,resultName,0)) //User said no overwrite return 1 else //Do division of I waves - including interpolation if necessary. Wave result_i = $(resultPath+resultName+"_i") Wave result_s = $(resultPath+resultName+"_s") Wave set1_i = $(set1Path+set1Name+"_i") Wave set1_q = $(set1Path+set1Name+"_q") Wave set1_s = $(set1Path+set1Name+"_s") Wave set2_i = $(set2Path+set2Name+"_i") Wave set2_q = $(set2Path+set2Name+"_q") Wave set2_s = $(set2Path+set2Name+"_s") result_i = set1_i/(set2Scale*interp(set1_q[p],set2_q,set2_i) ) //Calculate result error wave // sum each of the relative errors, interpolating set 2 intensity and error as needed // then sqrt result_s = (set1_s/set2Scale/interp(set1_q[p],set2_q,set2_i))^2 result_s += (interp(set1_q[p],set2_q,set2_s)*set1_i/set2Scale/interp(set1_q[p],set2_q,set2_i)^2)^2 result_s = sqrt(result_s) // - can we produce corrected Q error? //Generate history string to record what was done? return 0 endif End Function ReSortDataSet(set1name) String set1name String set1Path = "root:"+set1Name+":" String curPath = GetDataFolder(1) SetDataFolder set1Path //Check for resolution wave if (exists(set1name+"_res")) Wave reswave = $(set1name+"_res") //Check for USANS data - we won't resort these for the moment if (dimsize(reswave, 1) > 4 ) //USANS data, bail out print "Can't re-sort USANS data yet!" return 1 endif //Break out resolution wave into separate waves Make/O/N=(numpnts($(set1name+"_q"))) res0 = reswave[p][0] Make/O/N=(numpnts($(set1name+"_q"))) res1 = reswave[p][1] Make/O/N=(numpnts($(set1name+"_q"))) res2 = reswave[p][2] Make/O/N=(numpnts($(set1name+"_q"))) res3 = reswave[p][3] //sort print "Re-Sorting 4 or 6 Column Data Set with resolution information: "+set1Name sort $(set1name+"_q"),$(set1name+"_q"),$(set1name+"_i"),$(set1name+"_s"), res0, res1, res2, res3 //Put resolution contents back reswave[][0] = res0[p] reswave[][1]= res1[p] reswave[][2] = res2[p] reswave[][3] = res3[p] //cleanup Killwaves/Z res0, res1, res2, res3 else //3 Column only //sort print "Re-Sorting 3 Column Data Set: "+set1Name sort $(set1name+"_q"),$(set1name+"_q"),$(set1name+"_i"),$(set1name+"_s") endif SetDataFolder curPath return 0 End ///////////////////////////Other Utility functions //////////////////////////// Function SaveDataSetToFile(folderName) String folderName String protoStr = "" //Check for history string in folder //If it doesn't exist then //Do saving of data file. NVAR gXML_Write = root:Packages:NIST:gXML_Write if (gXML_Write == 1) ReWrite1DXMLData(folderName) else fReWrite1DData(folderName,"tab","CRLF") endif //Include history string to record what was done? End // still need to get the header information, and possibly the SASprocessnote from the XML load into the 6-column header // // start by looking in: // String xmlReaderFolder = "root:Packages:CS_XMLreader:" // for Title and Title_folder strings -> then the metadata (but the processnote is still not there // // may need to get it directly using the filename Function convertNISTXMLtoNIST6Col(fname) String fname String list, item,path Variable num,ii //load the XML LoadNISTXMLData(fname,"",0,0) //no plot, no force overwrite // Execute "A_LoadOneDDataWithName(\""+fname+"\",0)" //won't plot // then rewrite what is in the data folder that was just loaded String basestr = ParseFilePath(0, fname, ":", 1, 0) baseStr = CleanupName(baseStr,0) print fname print basestr fReWrite1DData_noPrompt(baseStr,"tab","CR") return(0) End ///////// SRK - VERY SIMPLE batch converter // no header information is preserved // file names are partially preserved // /// to use this: // -open the Plot Manager and set the path // -run this function // // it doesn't matter if the XML ouput flag is set - this overrides. Function batchXML26ColConvert() String list, item,path,fname Variable num,ii PathInfo CatPathName path = S_Path list = A_ReducedDataFileList("") num = itemsInList(list) Print num for(ii=0;ii 4) //it's USANS put -dQv back in the last 3 columns NVAR/Z dQv = USANS_dQv if(NVAR_Exists(dQv) == 0) Abort "It's USANS data, and I don't know what the slit height is." endif sigQ = -dQv qbar = -dQv fs = -dQv else //it's SANS sigQ = resw[p][0] qbar = resw[p][1] fs = resw[p][2] endif dialog=0 if(dialog) PathInfo/S catPathName // fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".txt") fullPath = DoSaveFileDialog("Save data as",fname=baseStr[0,strlen(BaseStr)-1]) Print fullPath If(cmpstr(fullPath,"")==0) //user cancel, don't write out a file Close/A Abort "no data file was written" Endif //Print "dialog fullpath = ",fullpath Endif PathInfo catPathName fullPath = S_Path + baseStr[0,strlen(BaseStr)-1] Open refnum as fullpath fprintf refnum,"Modified data written from folder %s on %s\r\n",baseStr,(date()+" "+time()) wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs Close refnum KillWaves/Z sigQ,qbar,fs SetDataFolder root: return(0) End ///////////end SRK ///// SRK ///// Rebinning // main entry procedure for subtraction panel // re-initializes necessary folders and waves Proc OpenRebin() DoWindow/F Rebin_Panel if(V_Flag==0) InitRebin() Rebin() //the panel // Plot_Sub1D() //the graph endif End Function InitRebin() NewDataFolder/O/S root:Packages:NIST:Rebin // Variable/G gPtsBeg1=0 // Variable/G gPtsEnd1=0 Variable/G binning=2 SetDataFolder root: End Proc Rebin() PauseUpdate; Silent 1 // building window... NewPanel /W=(658,347,920,562)/K=1 DoWindow/C Rebin_Panel ModifyPanel cbRGB=(65535,48662,45086),fixedSize=1 Button button0,pos={161,178},size={50,20},proc=Rebin_Done,title="Done" PopupMenu popup0,pos={11,50},size={211,20},title="Data in Memory" PopupMenu popup0,mode=1,value= #"A_OneDDataInMemory()" Button button1,pos={60,14},size={150,20},proc=Rebin_Load,title="Load Data From File" Button button2,pos={118,84},size={100,20},proc=Rebin_Append,title="Append Data" Button button3,pos={11,84},size={80,20},proc=Rebin_newGraph,title="New Graph" Button button6,pos={11,138},size={70,20},proc=Rebin_by,title="Rebin by" Button button_8,pos={160,138},size={90,20},proc=SaveResultBin,title="Save Result" Button button_9,pos={20,178},size={30,20},proc=Rebin_Help,title="?" SetVariable end_3,pos={97,140},size={40,14},title=" ",Font="Arial",fsize=10 SetVariable end_3,limits={1,10,1},value= root:Packages:NIST:Rebin:binning EndMacro Function Rebin_Help(ba) : ButtonControl STRUCT WMButtonAction &ba String win = ba.win switch (ba.eventCode) case 2: // click code here DisplayHelpTopic/Z/K=1 "Re-Bin Data" if(V_flag !=0) DoAlert 0,"The ReBin Help file could not be found" endif break endswitch return 0 End Function Rebin_Done(ctrlName) : ButtonControl String ctrlName DoWindow/K Rebin_Panel End Proc Rebin_Load(ctrlName) : ButtonControl String ctrlName A_LoadOneDData() ControlUpdate/W=Rebin_Panel popup0 End Function Rebin_Append(ctrlName) : ButtonControl String ctrlName //appends data set from memory /// joindre String iStr,qStr,eStr Variable rr,gg,bb //get the current selection ControlInfo popup0 if(strlen(S_Value)==0) Abort "You must load data from a file into memory before appending the data" Endif A_PM_doAppend(S_Value) DoWindow/F Rebin_Panel End Function Rebin_newGraph(ctrlName) : ButtonControl String ctrlName //get the current selection ControlInfo popup0 if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0) Abort "You must load data from a file into memory before plotting the data" Endif A_PM_doNewGraph(S_Value) DoWindow/F Rebin_Panel End Function Rebin_by (ctrlName) : ButtonControl String ctrlName Variable len Variable ii,jj, helplp,kk String iStr,qStr,eStr,sqStr,qbStr,fsStr,wtStr,folderStr Variable rr,gg,bb NVAR binpts = root:Packages:NIST:Rebin:binning ControlInfo popup0 if(strlen(S_Value)==0) Abort "You must load data from a file into memory before plotting the data" Endif folderStr = S_Value SetDataFolder $("root:"+folderStr) Wave w0 = $(folderStr+"_q") Wave w1 = $(folderStr+"_i") Wave w2 = $(folderStr+"_s") Wave resW = $(folderStr+"_res") len = numpnts(w0) Make/O/D/N=(len) w3,w4,w5 w3 = resW[p][0] //std dev of resolution fn w4 = resW[p][1] //mean q-value w5 = resW[p][2] //beamstop shadow factor Make/O/D/N=(round((len-1)/binpts)) qbin,Ibin,sigbin,sqbin,qbbin,fsbin,helpTemp qbin = 0 Ibin = 0 sigbin = 0 sqbin = 0 qbbin = 0 fsbin = 0 helptemp = 0 ii=0 do qBin = qBin + w0[binpts*p+ii]/binpts iBin = iBin + w1[binpts*p+ii]/binpts helptemp = helptemp + w2[binpts*p+ii]^2 sqBin = sqBin + w3[binpts*p+ii]/binpts qbBin = qbBin + w4[binpts*p+ii]/binpts fsBin = fsBin + w5[binpts*p+ii]/binpts ii+=1 while (ii