source: trunk/User Procedures/Irena/IR3_DataManipulationIII.ipf @ 1218

Last change on this file since 1218 was 1218, checked in by ilavsky, 5 months ago

Fix liberal names saving in Data Man III

  • Property svn:eol-style set to native
File size: 59.8 KB
Line 
1#pragma TextEncoding = "UTF-8"
2#pragma rtGlobals=3                             // Use modern global access method and strict wave access
3#pragma DefaultTab={3,20,4}             // Set default tab width in Igor Pro 9 and later
4#pragma version=1.03
5
6
7constant IR3DMversionNumber = 1.02                      //Data Manipulation III panel version number
8
9
10//Version notes:
11//1.03 fix IR3DM_AverageSaveData to be able to save liiberal names data (e.g., starting with numbers)
12//1.02 fix Process data - trim
13//1.01 add handling of USAXS M_... waves
14//1.00 first usable version.
15//
16/////******************************************************************************************
17/////******************************************************************************************
18
19
20Menu "TracePopup", dynamic
21      IN2G_MenuItemForGraph("Remove wave and recalculate","IR3DM_DataManIIIDataDisplay"),/Q, IN3DM_AverageRemoveData()
22End
23
24Function IN3DM_AverageRemoveData()
25
26        GetLastUserMenuInfo
27        Print S_graphName, S_traceName
28        String topGraph = S_graphName
29        Wave Wv=TraceNameToWaveRef(S_graphName, S_traceName)
30        RemoveFromGraph /W=$(S_graphName) /Z $(S_traceName)
31        IR3DM_AverageDataFunction()
32end
33
34/////******************************************************************************************
35/////******************************************************************************************
36Function IR3DM_DataManipulationIII()
37
38        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
39        IN2G_CheckScreenSize("width",1200)
40        DoWIndow IR3DM_DataManIIIPanel
41        if(V_Flag)
42                DoWindow/F IR3DM_DataManIIIPanel
43        else
44                //DoAlert /T="This is not finished yet" 0, "This tool is really not finished yet. It needs lot more work, so use the other Data Manipulation tools, please. "
45                IR3DM_InitDMIII()
46                IR3DM_DataManIIIPanelFnct()
47                ING2_AddScrollControl()
48                IR1_UpdatePanelVersionNumber("IR3DM_DataManIIIPanel", IR3DMversionNumber,1)
49                IR3C_MultiUpdListOfAvailFiles("Irena:DataManIII")       
50        endif
51        IR3DM_CreateDM3Graphs()
52end
53////************************************************************************************************************
54Function IR3DM_MainCheckVersion()       
55        DoWindow IR3DM_DataManIIIPanel
56        if(V_Flag)
57                if(!IR1_CheckPanelVersionNumber("IR3DM_DataManIIIPanel", IR3DMversionNumber))
58                        DoAlert /T="The Data manipulation 3 panel was created by incorrect version of Irena " 1, "Data manipulation needs to be restarted to work properly. Restart now?"
59                        if(V_flag==1)
60                                KillWIndow/Z IR3DM_DataManIIIPanel
61                                KillWindow/Z IR3DM_DataManIIIDataDisplay
62                                IR3DM_DataManipulationIII()
63                        else            //at least reinitialize the variables so we avoid major crashes...
64                                IR3DM_InitDMIII()
65                        endif
66                endif
67        endif
68end
69//
70////************************************************************************************************************
71////************************************************************************************************************
72////************************************************************************************************************
73////************************************************************************************************************
74Function IR3DM_DataManIIIPanelFnct()
75        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
76        PauseUpdate             // building window...
77        NewPanel /K=1 /W=(2.25,43.25,530,800) as "Data Manipulation"
78        DoWIndow/C IR3DM_DataManIIIPanel
79        TitleBox MainTitle title="Data Manipulation III",pos={140,2},frame=0,fstyle=3, fixedSize=1,font= "Times New Roman", size={360,30},fSize=22,fColor=(0,0,52224)
80        string UserDataTypes=""
81        string UserNameString=""
82        string XUserLookup=""
83        string EUserLookup=""
84        IR2C_AddDataControls("Irena:DataManIII","IR3DM_DataManIIIPanel","DSM_Int;M_DSM_Int;SMR_Int;M_SMR_Int;","AllCurrentlyAllowedTypes",UserDataTypes,UserNameString,XUserLookup,EUserLookup, 0,1, DoNotAddControls=1)
85        IR3C_MultiAppendControls("Irena:DataManIII","IR3DM_DataManIIIPanel", "IR3DM_CopyAndAppendData","",1,0)
86        //hide what is not needed
87        checkbox UseResults, disable=0
88        //OK, that is done
89       
90        //now controls in some locagical order...
91        SetVariable DataFolderName,noproc,title=" ",pos={250,100},size={270,17},frame=0, fstyle=1,valueColor=(0,0,65535)
92        Setvariable DataFolderName, variable=root:Packages:Irena:DataManIII:DataFolderName, noedit=1
93
94        CheckBox ProcessData,pos={280,120},size={90,14},proc=IR3DM_CheckProc,title="Process data"
95        CheckBox ProcessData,variable= root:Packages:Irena:DataManIII:ProcessData, help={"Check, if you want to process data somehow"}
96        CheckBox AverageData,pos={280,140},size={90,14},proc=IR3DM_CheckProc,title="Average multiple data"
97        CheckBox AverageData,variable= root:Packages:Irena:DataManIII:AverageData, help={"Check, if you want to average multiple data together"}
98        CheckBox DeleteData,pos={420,120},size={90,14},proc=IR3DM_CheckProc,title="Delete data"
99        CheckBox DeleteData,variable= root:Packages:Irena:DataManIII:DeleteData, help={"Check, if you want to delete data"}
100                        //      PopupMenu ManipulationSelected,pos={250,125},size={200,20},fStyle=2,proc=IR3DM_PopMenuProc,title="Function : "
101                        //      SVAR ManipulationSelected = root:Packages:Irena:DataManIII:ManipulationSelected
102                        //      PopupMenu ManipulationSelected,mode=1,popvalue=ManipulationSelected,value= #"root:Packages:Irena:DataManIII:ListOfManipulations"
103
104        CheckBox ProcessTrim,variable= root:Packages:Irena:DataManIII:ProcessData, help={"Check, if you want to process data somehow"}
105        CheckBox ProcessTrim,pos={330,170},size={90,14},proc=IR3DM_CheckProc,title="Trim data"
106        CheckBox ProcessTrim,variable= root:Packages:Irena:DataManIII:ProcessTrim, help={"Check, if you want to trim Q range"}
107        SetVariable DataQEnd,pos={290,190},size={190,15}, proc=IR3DM_SetVarProc,title="Q max "
108        Setvariable DataQEnd, variable=root:Packages:Irena:DataManIII:DataQEnd, limits={-inf,inf,0}
109        SetVariable DataQstart,pos={290,210},size={190,15}, proc=IR3DM_SetVarProc,title="Q min  "
110        Setvariable DataQstart, variable=root:Packages:Irena:DataManIII:DataQstart, limits={-inf,inf,0}
111
112        CheckBox ProcessSubtractData,pos={330,250},size={90,14},proc=IR3DM_CheckProc,title="Subtract data"
113        CheckBox ProcessSubtractData,variable= root:Packages:Irena:DataManIII:ProcessSubtractData, help={"Check, if you want to subtract a data set"}
114
115        PopupMenu SelectFolderToSubtract,pos={262,270},size={180,20},fStyle=2,proc=IR3DM_PopMenuProc,title=" "
116        SVAR SelectedFolderToSubtract = root:Packages:Irena:DataManIII:SelectedFolderToSubtract
117        PopupMenu SelectFolderToSubtract,mode=1,popvalue=SelectedFolderToSubtract,value= IR3DM_ListAllData()
118        //function buttons...
119        Button AddManyDataBTN,pos={290,190},size={180,18}, proc=IR3DM_ButtonProc,title="Clear & Add selected", help={"This will clear the tool, add all selected data and average"}
120        //Button AddManyDataBTN fColor=(65535,0,0)
121
122        SetVariable SaveDataToFolder,pos={260,430},size={260,15}, noproc,title="Save as:"
123        Setvariable SaveDataToFolder, variable=root:Packages:Irena:DataManIII:SaveDataToFolder
124        SetVariable AppendModifier,pos={380,400},size={120,15}, noproc,title="Append :"
125        Setvariable AppendModifier, variable=root:Packages:Irena:DataManIII:AppendModifier
126
127        Button DoManipulationBTN,pos={290,490},size={200,20}, proc=IR3DM_ButtonProc,title=" ", help={"This will run selected data manipulation"}
128        Button DoManipulationBTN fColor=(65535,0,0)
129
130        Button ClearTheToolBTN,pos={290,550},size={200,20}, proc=IR3DM_ButtonProc,title="Clear data", help={"This will remove all data from this tool"}
131        Button SaveManipulationsBTN,pos={290,550},size={200,20}, proc=IR3DM_ButtonProc,title="Save data", help={"This will save results from manipulation"}
132
133
134
135
136        Button SelectAll,pos={200,680},size={80,15}, proc=IR3DM_ButtonProc,title="SelectAll", help={"Select All data in Listbox"}
137//
138        Button GetHelp,pos={430,50},size={80,15},fColor=(65535,32768,32768), proc=IR3DM_ButtonProc,title="Get Help", help={"Open www manual page for this tool"}
139//
140//     
141//      //and fix which controls are displayed:
142//     
143        IR3DM_SetupControlsOnMainpanel()
144end
145
146
147
148//*****************************************************************************************************************
149//*****************************************************************************************************************
150
151static Function IR3DM_SetupControlsOnMainpanel()
152       
153        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
154        //SVAR ManipulationSelected = root:Packages:Irena:DataManIII:ManipulationSelected
155        DoWindow IR3DM_DataManIIIPanel
156        if(V_Flag)
157                NVAR DeleteData = root:Packages:Irena:DataManIII:DeleteData             
158                NVAR ProcessData = root:Packages:Irena:DataManIII:ProcessData
159                NVAR AverageData = root:Packages:Irena:DataManIII:AverageData
160                SVAR AppendModifier = root:Packages:Irena:DataManIII:AppendModifier
161                if(DeleteData+ProcessData+AverageData != 1)
162                        DeleteData = 0
163                        ProcessData = 1
164                        AverageData = 0
165                endif
166                NVAR ProcessTrim = root:Packages:Irena:DataManIII:ProcessTrim
167                NVAR ProcessSubtractData = root:Packages:Irena:DataManIII:ProcessSubtractData
168
169
170                //Button DeleteDataBTN  win=IR3DM_DataManIIIPanel, disable=(ProcessData||AverageData)
171                SetVariable DataQEnd    win=IR3DM_DataManIIIPanel, disable=!(ProcessData*ProcessTrim)
172                SetVariable DataQstart  win=IR3DM_DataManIIIPanel, disable=!(ProcessData*ProcessTrim)
173                CheckBox ProcessTrim    win=IR3DM_DataManIIIPanel, disable= (DeleteData||AverageData)
174                CheckBox ProcessSubtractData    win=IR3DM_DataManIIIPanel, disable=(DeleteData||AverageData)
175                PopupMenu SelectFolderToSubtract        win=IR3DM_DataManIIIPanel, disable=!(ProcessData*ProcessSubtractData)
176                SetVariable SaveDataToFolder    win=IR3DM_DataManIIIPanel, disable=(DeleteData)
177                SetVariable AppendModifier      win=IR3DM_DataManIIIPanel, disable=(DeleteData)
178                Button AddManyDataBTN   win=IR3DM_DataManIIIPanel, disable=(DeleteData || ProcessData)
179               
180                if(DeleteData)
181                        Button DoManipulationBTN  win=IR3DM_DataManIIIPanel, title="Delete data"
182                        AppendModifier=""
183                elseif(ProcessData)
184                        Button DoManipulationBTN  win=IR3DM_DataManIIIPanel, title="Process data"
185                        AppendModifier="_mod"
186                elseif(AverageData)
187                        Button DoManipulationBTN  win=IR3DM_DataManIIIPanel, title="Save averaged data"
188                        AppendModifier="_ave"
189                else
190                        Button DoManipulationBTN  win=IR3DM_DataManIIIPanel, title=""
191                endif
192                Button ClearTheToolBTN          win=IR3DM_DataManIIIPanel, disable= (!AverageData)     
193                Button SaveManipulationsBTN             win=IR3DM_DataManIIIPanel, disable= (!ProcessData)     
194               
195               
196        endif
197end
198
199//*****************************************************************************************************************
200//*****************************************************************************************************************
201Function IR3DM_CheckProc(cba) : CheckBoxControl
202        STRUCT WMCheckboxAction &cba
203
204        switch( cba.eventCode )
205                case 2: // mouse up
206                        Variable checked = cba.checked
207                       
208                        NVAR DeleteData = root:Packages:Irena:DataManIII:DeleteData             
209                        NVAR ProcessData = root:Packages:Irena:DataManIII:ProcessData
210                        NVAR ProcessTrim = root:Packages:Irena:DataManIII:ProcessTrim
211                        NVAR AverageData = root:Packages:Irena:DataManIII:AverageData
212                        KillWIndow/Z IR3DM_DataManIIIDataDisplay
213                        if(stringmatch(cba.ctrlName,"DeleteData"))
214                                ProcessData  = !DeleteData
215                                AverageData =  0
216                                if(!DeleteData)
217                                        IR3DM_CreateDM3Graphs()
218                                endif
219                                IR3DM_SetupControlsOnMainpanel()
220                        endif
221                        if(stringmatch(cba.ctrlName,"AverageData"))
222                                DeleteData  = 0
223                                ProcessData =  !AverageData
224                                if(!DeleteData)
225                                        IR3DM_CreateDM3Graphs()
226                                endif
227                                IR3DM_SetupControlsOnMainpanel()
228                        endif
229
230                        if(stringmatch(cba.ctrlName,"ProcessData"))
231                                DeleteData  = 0
232                                AverageData =  !ProcessData
233                                if(!DeleteData)
234                                        IR3DM_CreateDM3Graphs()
235                                endif
236                                IR3DM_SetupControlsOnMainpanel()
237                        endif
238                        if(stringmatch(cba.ctrlName,"ProcessTrim"))
239                                IR3DM_SetupControlsOnMainpanel()
240                        endif
241                        if(stringmatch(cba.ctrlName,"ProcessSubtractData"))
242                                IR3DM_SetupControlsOnMainpanel()
243                                IR3DM_AppendProcessDataToGraphLogLog()
244                        endif
245                       
246                        break
247                case -1: // control being killed
248                        break
249        endswitch
250
251        return 0
252End
253//**********************************************************************************************************
254//**********************************************************************************************************
255
256Function IR3DM_ButtonProc(ba) : ButtonControl
257        STRUCT WMButtonAction &ba
258
259        switch( ba.eventCode )
260                case 2: // mouse up
261                        // click code here
262                        if(stringmatch(ba.ctrlName,"DoManipulationBTN"))                //this function depends on what we are doing
263                                NVAR DeleteData = root:Packages:Irena:DataManIII:DeleteData             
264                                NVAR ProcessData = root:Packages:Irena:DataManIII:ProcessData
265                                NVAR ProcessTrim = root:Packages:Irena:DataManIII:ProcessTrim
266                                NVAR AverageData = root:Packages:Irena:DataManIII:AverageData
267                                if(DeleteData)                  //this is Delete data button now
268                                        DoAlert /T="This will REALLY delete data, are you sure?" 1, "Choose \"Yes\" to delete selected data type for ALL selected folders in the table. Are you sure you want to delete the data?"
269                                        if(V_Flag==1)
270                                                IR3DM_ProcessSequenceOfData("DeleteData")
271                                        endif
272                                elseif(AverageData)             //this is save data button now
273                                        IR3DM_AverageSaveData()
274                                elseif(ProcessData)             //this is process or save, we need to figure this out...
275                                        IR3DM_ProcessSequenceOfData("ProcessData")
276                                endif
277                               
278                        endif
279                        if(stringmatch(ba.ctrlName,"SaveManipulationsBTN"))             //Save results of manipulations
280                                IR3DM_SaveProcessDataFnct()
281                        endif
282                        if(stringmatch(ba.ctrlName,"SelectAll"))
283                                Wave/Z SelectionOfAvailableData = root:Packages:Irena:DataManIII:SelectionOfAvailableData
284                                if(WaveExists(SelectionOfAvailableData))
285                                        SelectionOfAvailableData=1
286                                endif
287                        endif
288                        if(stringmatch(ba.ctrlName,"ClearTheToolBTN"))
289                                KillWIndow/Z IR3DM_DataManIIIDataDisplay
290                                NVAR DeleteData = root:Packages:Irena:DataManIII:DeleteData     
291                                SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
292                                if(!DeleteData)
293                                        IR3DM_CreateDM3Graphs()
294                                        SaveDataToFolder = ""
295                                endif
296                                Wave/Z wv1=root:Packages:Irena:DataManIII:Averaged_Data:AverageIntensity
297                                Wave/Z wv2=root:Packages:Irena:DataManIII:Averaged_Data:AverageQvector
298                                Wave/Z wv3=root:Packages:Irena:DataManIII:Averaged_Data:AverageErrors
299                                KillWaves/Z wv1, wv2, wv3
300                        endif
301
302                        if(stringmatch(ba.ctrlName,"AddManyDataBTN"))
303                                KillWIndow/Z IR3DM_DataManIIIDataDisplay
304                                NVAR DeleteData = root:Packages:Irena:DataManIII:DeleteData     
305                                SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
306                                if(!DeleteData)
307                                        IR3DM_CreateDM3Graphs()
308                                        SaveDataToFolder = ""
309                                endif
310                                Wave/Z SelectionOfAvailableData = root:Packages:Irena:DataManIII:SelectionOfAvailableData
311                                if(WaveExists(SelectionOfAvailableData))
312                                        Wave/T ListOfAvailableData = root:Packages:Irena:DataManIII:ListOfAvailableData
313                                        variable i
314                                        string FolderNameStr
315                                                For(i=0;i<numpnts(ListOfAvailableData);i+=1)
316                                                        IF(SelectionOfAvailableData[i]>0.5)
317                                                                FolderNameStr = ListOfAvailableData[i]
318                                                                IR3DM_CopyAndAppendData(FolderNameStr)
319                                                        endif
320                                                endfor
321                                endif
322                        endif
323
324
325                        if(stringmatch(ba.ctrlName,"GetHelp"))
326                                IN2G_OpenWebManual("Irena/bioSAXS.html#basic-fits")                             //fix me!!                     
327                        endif
328
329                       
330                        break
331                case -1: // control being killed
332                        break
333        endswitch
334
335        return 0
336End
337//**************************************************************************************
338//**************************************************************************************
339//cannot be static, called from panel.
340Function/T IR3DM_ListAllData()
341
342        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
343        String AllDataFolders
344        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
345        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSData
346        NVAR  UseResults=  root:Packages:Irena:DataManIII:UseResults
347        NVAR  UseUserDefinedData=  root:Packages:Irena:DataManIII:UseUserDefinedData
348        NVAR  UseModelData = root:Packages:Irena:DataManIII:UseModelData
349        SVAR StartFolderName=root:Packages:Irena:DataManIII:DataStartFolder
350        SVAR DataMatchString= root:Packages:Irena:DataManIII:DataMatchString
351        NVAR InvertGrepSearch=root:Packages:Irena:DataManIII:InvertGrepSearch
352       
353        AllDataFolders=IR3C_MultiGenStringOfFolders("Irena:DataManIII", StartFolderName,UseIndra2Data, UseQRSData,UseResults, 0,1)
354        AllDataFolders = GrepList(AllDataFolders, "Packages", 1)
355        if(strlen(DataMatchString)>0)
356                AllDataFolders = GrepList(AllDataFolders, DataMatchString, InvertGrepSearch)
357        endif
358        AllDataFolders = ReplaceString(StartFolderName, AllDataFolders,"")
359        //SVAR BufferMatchString=root:Packages:Irena:BioSAXSDataMan:BufferMatchString
360        //select only Averaged data.
361        //if(strlen(BufferMatchString)>0)
362        //      AllDataFolders = GrepList(AllDataFolders, BufferMatchString, 0)
363        //endif
364        return AllDataFolders
365end
366//**********************************************************************************************************
367//**********************************************************************************************************
368//**********************************************************************************************************
369//**********************************************************************************************************
370
371static Function IR3DM_ProcessSequenceOfData(WhatToDO)
372                string WhatToDO
373               
374                //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
375                //NVAR DelayBetweenProcessing=root:Packages:Irena:DataManIII:DelayBetweenProcessing
376                Wave SelectionOfAvailableData = root:Packages:Irena:DataManIII:SelectionOfAvailableData
377                Wave/T ListOfAvailableData = root:Packages:Irena:DataManIII:ListOfAvailableData
378                variable i, imax, HowMany
379                imax = numpnts(ListOfAvailableData)
380                HowMany = sum(SelectionOfAvailableData)
381                For(i=0;i<imax;i+=1)
382                        if(SelectionOfAvailableData[i]>0.5)             //data set selected
383                                if(StringMatch(WhatToDO, "DeleteData"))
384                                        IR3DM_DeleteData(ListOfAvailableData[i])
385                                elseif(StringMatch(WhatToDO, "ProcessData"))
386                                        IR3DM_CopyAndAppendData(ListOfAvailableData[i])
387                                        IR3DM_ProcessDataFunction(HowMany)
388                                endif
389                        endif
390                endfor
391                //IR3J_CleanUnusedParamWaves()
392                print "all selected data processed"
393                IR3C_MultiUpdListOfAvailFiles("Irena:DataManIII")
394
395end
396//**********************************************************************************************************
397//**************************************************************************************
398//**************************************************************************************
399Function IR3DM_DeleteData(FolderNameStr)
400        string FolderNameStr
401       
402        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
403        DFref oldDf= GetDataFolderDFR()
404        SetDataFolder root:Packages:Irena:DataManIII                                    //go into the folder
405                SVAR DataStartFolder=root:Packages:Irena:DataManIII:DataStartFolder
406                SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
407                SVAR IntensityWaveName=root:Packages:Irena:DataManIII:IntensityWaveName
408                SVAR QWavename=root:Packages:Irena:DataManIII:QWavename
409                SVAR ErrorWaveName=root:Packages:Irena:DataManIII:ErrorWaveName
410                SVAR dQWavename=root:Packages:Irena:DataManIII:dQWavename
411                NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
412                NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
413                //these are variables used by the control procedure
414                NVAR  UseResults=  root:Packages:Irena:DataManIII:UseResults
415                NVAR  UseUserDefinedData=  root:Packages:Irena:DataManIII:UseUserDefinedData
416                NVAR  UseModelData = root:Packages:Irena:DataManIII:UseModelData
417                SVAR DataFolderName  = root:Packages:Irena:DataManIII:DataFolderName
418                SVAR IntensityWaveName = root:Packages:Irena:DataManIII:IntensityWaveName
419                SVAR QWavename = root:Packages:Irena:DataManIII:QWavename
420                SVAR ErrorWaveName = root:Packages:Irena:DataManIII:ErrorWaveName
421                UseUserDefinedData = 0
422                UseModelData = 0
423                string ListOfItems
424                //get the names of waves, assume this tool actually works. May not under some conditions. In that case this tool will not work.
425                IR3C_SelectWaveNamesData("Irena:DataManIII", FolderNameStr)                     //this routine will preset names in strings as needed,         
426                Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
427                Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName(QWavename))
428                Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName(ErrorWaveName))
429                Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName(dQWavename))
430                if(!WaveExists(SourceIntWv) &&  !WaveExists(SourceQWv) && UseIndra2Data)                //may be we heve M_... data here?
431                        Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName("M_"+IntensityWaveName))
432                        Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName("M_"+QWavename))
433                        Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName("M_"+ErrorWaveName))
434                        Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName("M_"+dQWavename))
435                endif
436                CheckDisplayed /A SourceIntWv, SourceQWv, SourceErrorWv, SourcedQWv
437                if(V_Flag>0)
438                        Abort "Data from "+DataFolderName+" are in use in graph or table. Close all tables and graphs using it and try again."
439                else
440                        print "Deleted Data from folder : "+DataFolderName
441                        KillWaves/Z SourceIntWv, SourceQWv, SourceErrorWv, SourcedQWv
442                        print "Deleted following waves: "+IntensityWaveName+", "+QWavename+", "+ErrorWaveName+", "+dQWavename
443                        //now check if the DataFOlder is empty, and if yes, delete the folder also
444                        if(CountObjects(DataFolderName, 1 )+CountObjects(DataFolderName, 2)+CountObjects(DataFolderName, 3)<1)
445                                KillDataFolder /Z DataFolderName
446                                print "Folder :"+DataFolderName+" was empty after deleting the data therefore it was deleted."
447                        else
448                                print "Folder :"+DataFolderName+" was not empty after deleting the data therefore it was not deleted."
449                        endif
450                endif
451        SetDataFolder oldDf
452end
453//**********************************************************************************************************
454//**********************************************************************************************************
455//**********************************************************************************************************
456//**************************************************************************************
457//**************************************************************************************
458
459Function IR3DM_SetVarProc(sva) : SetVariableControl
460        STRUCT WMSetVariableAction &sva
461
462        variable tempP
463        switch( sva.eventCode )
464                case 1: // mouse up
465                case 2: // Enter key
466                        NVAR DataQstart=root:Packages:Irena:DataManIII:DataQstart
467                        NVAR DataQEnd=root:Packages:Irena:DataManIII:DataQEnd
468                        NVAR DataQEndPoint = root:Packages:Irena:DataManIII:DataQEndPoint
469                        NVAR DataQstartPoint = root:Packages:Irena:DataManIII:DataQstartPoint
470                       
471                        if(stringmatch(sva.ctrlName,"DataQEnd"))
472                                WAVE Original_Q = root:Packages:Irena:DataManIII:Original_Q
473                                tempP = BinarySearch(Original_Q, DataQEnd )
474                                if(tempP<1)
475                                        print "Wrong Q value set, Data Q max must be at most 1 point before the end of Data"
476                                        tempP = numpnts(Original_Q)-2
477                                        DataQEnd = Original_Q[tempP]
478                                endif
479                                DataQEndPoint = tempP   
480                                //set cursor
481                                Cursor /W=IR3DM_DataManIIIDataDisplay /P B  Original_Intensity  DataQEndPoint           
482                                IR3DM_SyncCursorsTogether("Original_Intensity","B",tempP)
483                        endif
484                        if(stringmatch(sva.ctrlName,"DataQstart"))
485                                WAVE Original_Q = root:Packages:Irena:DataManIII:Original_Q
486                                tempP = BinarySearch(Original_Q, DataQstart )
487                                if(tempP<1)
488                                        print "Wrong Q value set, Data Q min must be at least 1 point from the start of Data"
489                                        tempP = 1
490                                        DataQstart = Original_Q[tempP]
491                                endif
492                                DataQstartPoint=tempP
493                                Cursor /W=IR3DM_DataManIIIDataDisplay /P A  Original_Intensity  DataQstartPoint         
494                                IR3DM_SyncCursorsTogether("Original_Intensity","A",tempP)
495                endif
496                        break
497
498                case 3: // live update
499                        break
500                case -1: // control being killed
501                        break
502        endswitch
503
504        return 0
505End
506//*****************************************************************************************************************
507//*****************************************************************************************************************
508
509Function IR3DM_PopMenuProc(pa) : PopupMenuControl
510        STRUCT WMPopupAction &pa
511
512        switch( pa.eventCode )
513                case 2: // mouse up
514                        Variable popNum = pa.popNum
515                        String popStr = pa.popStr
516//                      if(StringMatch(pa.ctrlName, "ManipulationSelected" ))
517//                              SVAR ManipulationSelected = root:Packages:Irena:DataManIII:ManipulationSelected
518//                              ManipulationSelected = popStr
519//                              KillWindow/Z IR3DM_DataManIIIDataDisplay
520//                              IR3DM_CreateDM3Graphs()
521//                      endif
522                        if(StringMatch(pa.ctrlName, "SelectFolderToSubtract" ))
523                                SVAR SelectedFolderToSubtract = root:Packages:Irena:DataManIII:SelectedFolderToSubtract
524                                SelectedFolderToSubtract = popStr
525                                IR3DM_CopyAndAppendDataToSubtract(SelectedFolderToSubtract)
526                        endif
527                        break
528                case -1: // control being killed
529                        break
530        endswitch
531
532        return 0
533End
534
535
536//**************************************************************************************
537//**************************************************************************************
538
539Function IR3DM_CopyAndAppendDataToSubtract(FolderNameStr)
540        string FolderNameStr
541       
542        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
543        DFref oldDf= GetDataFolderDFR()
544        SetDataFolder root:Packages:Irena:DataManIII                                    //go into the folder
545
546        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
547        SVAR IntensityWaveName=root:Packages:Irena:DataManIII:IntensityWaveName
548        SVAR QWavename=root:Packages:Irena:DataManIII:QWavename
549        SVAR ErrorWaveName=root:Packages:Irena:DataManIII:ErrorWaveName
550        SVAR dQWavename=root:Packages:Irena:DataManIII:dQWavename
551        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
552        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
553        string OldFOlderName=DataFolderName
554        IR3C_SelectWaveNamesData("Irena:DataManIII", FolderNameStr)                     //this routine will preset names in strings as needed   
555        SVAR SelectedFolderToSubtract = SelectedFolderToSubtract
556        SelectedFolderToSubtract =      FolderNameStr
557        Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
558        Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName(QWavename))
559        Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName(ErrorWaveName))
560        Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName(dQWavename))
561        if(!WaveExists(SourceIntWv) &&  !WaveExists(SourceQWv) && UseIndra2Data)                //may be we heve M_... data here?
562                Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName("M_"+IntensityWaveName))
563                Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName("M_"+QWavename))
564                Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName("M_"+ErrorWaveName))
565                Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName("M_"+dQWavename))
566        endif
567        if(!WaveExists(SourceIntWv)||   !WaveExists(SourceQWv))                         //||!WaveExists(SourceErrorWv))
568                Abort "Data selection failed for Data in routine IR3DM_CopyAndAppendDataToSubtract"
569        endif
570        Duplicate/O SourceIntWv, OrigIntToSubtractWave
571        Duplicate/O SourceQWv, OrigQToSubtractWave
572        if(WaveExists(SourceErrorWv))
573                Duplicate/O SourceErrorWv, OrigErrorToSubtractWave
574        else
575                Duplicate/O SourceIntWv, OrigErrorToSubtractWave
576                OrigErrorToSubtractWave = 0
577        endif
578        if(WaveExists(SourcedQWv))
579                Duplicate/O SourcedQWv, OrigdQToSubtractWave
580        else
581                Duplicate/O SourceIntWv, OrigdQToSubtractWave
582                OrigdQToSubtractWave = 0
583        endif
584        print "Added Data from folder for subtraction : "+DataFolderName
585        IR3C_SelectWaveNamesData("Irena:DataManIII", OldFolderName)                     //this routine will preset names in strings as needed           
586        IR3DM_AppendProcessDataToGraphLogLog()
587        SetDataFolder oldDf
588end
589
590//**************************************************************************************
591Function IR3DM_CopyAndAppendData(FolderNameStr)
592        string FolderNameStr
593       
594        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
595        DFref oldDf= GetDataFolderDFR()
596        SetDataFolder root:Packages:Irena:DataManIII                                    //go into the folder
597        IR3DM_CreateDM3Graphs()
598                //OK, now we need to do what user wants.
599                //If Delete data, skip rest and do what user wants.
600                NVAR DeleteData= root:Packages:Irena:DataManIII:DeleteData
601                NVAR AverageData= root:Packages:Irena:DataManIII:AverageData
602                NVAR ProcessData= root:Packages:Irena:DataManIII:ProcessData
603                if(DeleteData)
604                        NVAR WarnUserDeleteData=root:Packages:Irena:DataManIII:WarnUserDeleteData
605                        if(WarnUserDeleteData<0.5)
606                                DoAlert /T="This will REALLY delete data, are you sure?" 1, "Choose \"Yes\" to delete selected data type for ALL selected folders in the table. Are you sure you want to delete the data?"
607                                if(V_Flag==1)
608                                        WarnUserDeleteData = 1
609                                else
610                                        WarnUserDeleteData = 0
611                                endif
612                        endif
613                        if(WarnUserDeleteData)
614                                IR3DM_ProcessSequenceOfData("DeleteData")
615                                IR3C_MultiUpdListOfAvailFiles("Irena:DataManIII")
616                        endif
617                elseif(ProcessData)                                                                                                                     //Add one data set to graph and process
618                        //remove any data from AverageData below
619                        KillWaves/Z AverageIntensity, AverageQvector, AverageErrors
620                        variable i
621                        For(i=0;i<50;i+=1)
622                                KillWaves/Z $("Original_Intensity"+num2str(i)), $("Original_Q"+num2str(i)), $("Original_Errors"+num2str(i)), $("Original_dQ"+num2str(i))
623                        endfor
624                        SVAR DataStartFolder=root:Packages:Irena:DataManIII:DataStartFolder
625                        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
626                        SVAR IntensityWaveName=root:Packages:Irena:DataManIII:IntensityWaveName
627                        SVAR QWavename=root:Packages:Irena:DataManIII:QWavename
628                        SVAR ErrorWaveName=root:Packages:Irena:DataManIII:ErrorWaveName
629                        SVAR dQWavename=root:Packages:Irena:DataManIII:dQWavename
630                        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
631                        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
632                        //these are variables used by the control procedure
633                        NVAR  UseResults=  root:Packages:Irena:DataManIII:UseResults
634                        NVAR  UseUserDefinedData=  root:Packages:Irena:DataManIII:UseUserDefinedData
635                        NVAR  UseModelData = root:Packages:Irena:DataManIII:UseModelData
636                        SVAR DataFolderName  = root:Packages:Irena:DataManIII:DataFolderName
637                        SVAR IntensityWaveName = root:Packages:Irena:DataManIII:IntensityWaveName
638                        SVAR QWavename = root:Packages:Irena:DataManIII:QWavename
639                        SVAR ErrorWaveName = root:Packages:Irena:DataManIII:ErrorWaveName
640                        SVAR AddExtension=root:Packages:Irena:DataManIII:AppendModifier
641                        SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
642                        SVAR SaveDataToFolderFull = root:Packages:Irena:DataManIII:SaveDataToFolderFull
643                        UseUserDefinedData = 0
644                        UseModelData = 0
645                        //get the names of waves, assume this tool actually works. May not under some conditions. In that case this tool will not work.
646                        IR3C_SelectWaveNamesData("Irena:DataManIII", FolderNameStr)                     //this routine will preset names in strings as needed,         
647                        Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
648                        Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName(QWavename))
649                        Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName(ErrorWaveName))
650                        Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName(dQWavename))
651                        if(!WaveExists(SourceIntWv) &&  !WaveExists(SourceQWv) && UseIndra2Data)                //may be we heve M_... data here?
652                                Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName("M_"+IntensityWaveName))
653                                Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName("M_"+QWavename))
654                                Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName("M_"+ErrorWaveName))
655                                Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName("M_"+dQWavename))
656                        endif
657                        if(!WaveExists(SourceIntWv)||   !WaveExists(SourceQWv))//||!WaveExists(SourceErrorWv))
658                                Abort "Data selection failed for Data in routine IR3DM_CopyAndAppendData"
659                        endif
660                        string OutputWaveNameMain
661                        OutputWaveNameMain = RemoveEnding(IN2G_removeExtraQuote(DataFolderName,1,1), ":")  + AddExtension+":"
662                        //if(strlen(SaveDataToFolder)<1)
663                        SaveDataToFolder = OutputWaveNameMain
664                        //endif
665
666                        //this one is using only one data set at time...
667                        Duplicate/O SourceIntWv, Original_Intensity
668                        Duplicate/O SourceQWv, Original_Q
669                        if(WaveExists(SourceErrorWv))
670                                Duplicate/O SourceErrorWv, Original_Errors
671                        else
672                                Duplicate/O SourceIntWv, Original_Errors
673                                Original_Errors = 0
674                        endif
675                        if(WaveExists(SourcedQWv))
676                                Duplicate/O SourcedQWv, Original_dQ
677                        else
678                                Duplicate/O SourceQWv, Original_dQ
679                                WAVE Original_dQ
680                                Original_dQ = 0
681                        endif
682                        IR3DM_AppendProcessDataToGraphLogLog()
683                        print "Added Data from folder : "+DataFolderName               
684                elseif(AverageData)                                                                                                                     //Add many data sets to graph and average
685                        //remove any data from Process data above
686                        killwaves/Z Modified_Intensity, Modified_Q  , Modified_Errors, Modified_dQ
687                        Wave/Z Original_Intensity
688                        Wave/Z Original_Q
689                        Wave/Z Original_Errors
690                        Wave/Z Original_dQ
691                        KillWaves/Z Original_Intensity, Original_Q, Original_Errors, Original_dQ
692                        SVAR DataStartFolder=root:Packages:Irena:DataManIII:DataStartFolder
693                        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
694                        SVAR IntensityWaveName=root:Packages:Irena:DataManIII:IntensityWaveName
695                        SVAR QWavename=root:Packages:Irena:DataManIII:QWavename
696                        SVAR ErrorWaveName=root:Packages:Irena:DataManIII:ErrorWaveName
697                        SVAR dQWavename=root:Packages:Irena:DataManIII:dQWavename
698                        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
699                        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
700                        //these are variables used by the control procedure
701                        NVAR  UseResults=  root:Packages:Irena:DataManIII:UseResults
702                        NVAR  UseUserDefinedData=  root:Packages:Irena:DataManIII:UseUserDefinedData
703                        NVAR  UseModelData = root:Packages:Irena:DataManIII:UseModelData
704                        SVAR DataFolderName  = root:Packages:Irena:DataManIII:DataFolderName
705                        SVAR IntensityWaveName = root:Packages:Irena:DataManIII:IntensityWaveName
706                        SVAR QWavename = root:Packages:Irena:DataManIII:QWavename
707                        SVAR ErrorWaveName = root:Packages:Irena:DataManIII:ErrorWaveName
708                        UseUserDefinedData = 0
709                        UseModelData = 0
710                        //get the names of waves, assume this tool actually works. May not under some conditions. In that case this tool will not work.
711                        IR3C_SelectWaveNamesData("Irena:DataManIII", FolderNameStr)                     //this routine will preset names in strings as needed,         
712                        Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
713                        Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName(QWavename))
714                        Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName(ErrorWaveName))
715                        Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName(dQWavename))
716                        if(!WaveExists(SourceIntWv) &&  !WaveExists(SourceQWv) && UseIndra2Data)                //may be we heve M_... data here?
717                                Wave/Z SourceIntWv=$(DataFolderName+possiblyQUoteName("M_"+IntensityWaveName))
718                                Wave/Z SourceQWv=$(DataFolderName+possiblyQUoteName("M_"+QWavename))
719                                Wave/Z SourceErrorWv=$(DataFolderName+possiblyQUoteName("M_"+ErrorWaveName))
720                                Wave/Z SourcedQWv=$(DataFolderName+possiblyQUoteName("M_"+dQWavename))
721                        endif
722                        if(!WaveExists(SourceIntWv)||   !WaveExists(SourceQWv))//||!WaveExists(SourceErrorWv))
723                                Abort "Data selection failed for Data in routine IR3DM_CopyAndAppendData"
724                        endif
725                        IR3DM_AppendAveDataToGraphLogLog()
726                        IR3DM_AverageDataFunction()
727                        print "Added Data from folder : "+DataFolderName
728                endif
729        SetDataFolder oldDf
730end
731//**********************************************************************************************************
732//**********************************************************************************************************
733//**********************************************************************************************************
734//************************************************************************************************************
735
736Function IR3DM_ProcessDataFunction(HowMany)
737        variable HowMany
738       
739        doWIndow IR3DM_DataManIIIDataDisplay
740        if(V_Flag==0)
741                return 0
742        endif
743        DoWIndow/F IR3DM_DataManIIIDataDisplay
744        DfRef OldDf=GetDataFolderDFR()
745        setDataFolder root:Packages:Irena:DataManIII
746        variable i, numTraces
747        string TraceNames, NewNote
748        SVAR AddExtension=root:Packages:Irena:DataManIII:AppendModifier
749        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
750        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
751        NVAR UseResults=  root:Packages:Irena:DataManIII:UseResults
752        SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
753        SVAR SaveDataToFolderFull = root:Packages:Irena:DataManIII:SaveDataToFolderFull
754        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
755        //let's trim if asked for...
756        NVAR TrimSelected=root:Packages:Irena:DataManIII:ProcessTrim
757        NVAR Subtract = root:Packages:Irena:DataManIII:ProcessSubtractData
758
759        Wave Original_Intensity
760        Wave Original_Q
761        Wave Original_Errors
762        Wave Original_dQ
763
764        NewNote = "Processed Data;"+date()+";"+time()+";"
765        NVAR Qmax=root:Packages:Irena:DataManIII:DataQEnd
766        NVAR Qmin=root:Packages:Irena:DataManIII:DataQstart
767        variable StartP, EndP
768        if(TrimSelected)
769                StartP= BinarySearch(Original_Q, Qmin )
770                EndP= BinarySearch(Original_Q, Qmax )
771                EndP = (EndP<numpnts(Original_Q)&&EndP>0) ? EndP : (numpnts(Original_Q)-1)
772                StartP = (StartP>=0) ? StartP : 0
773                Duplicate/O/R=[StartP,EndP] Original_Intensity, Modified_Intensity
774                Duplicate/O/R=[StartP,EndP] Original_Q, Modified_Q
775                Duplicate/O/R=[StartP,EndP] Original_Errors, Modified_Errors
776                Duplicate/O/R=[StartP,EndP] Original_dQ, Modified_dQ
777                NewNote = "Data trimmed;StartQ="+num2str(Qmin)+";EndQ="+num2str(Qmax)+";"
778        else
779                Duplicate/O Original_Intensity, Modified_Intensity
780                Duplicate/O Original_Q, Modified_Q
781                Duplicate/O Original_Errors, Modified_Errors
782                Duplicate/O Original_dQ, Modified_dQ
783        endif
784       
785        Wave Modified_Intensity = root:Packages:Irena:DataManIII:Modified_Intensity
786        Wave Modified_Q = root:Packages:Irena:DataManIII:Modified_Q
787        Wave Modified_Errors = root:Packages:Irena:DataManIII:Modified_Errors
788        Note /K/NOCR Modified_Intensity, NewNote
789        Note /K/NOCR Modified_Q, NewNote
790        Note /K/NOCR Modified_Errors, NewNote
791
792        RemoveFromGraph /W=IR3DM_DataManIIIDataDisplay /Z Modified_Intensity
793        IN2G_ColorTopGrphRainbow(topGraphStr="IR3DM_DataManIIIDataDisplay")
794
795        AppendToGraph /W=IR3DM_DataManIIIDataDisplay  Modified_Intensity  vs Modified_Q
796        ErrorBars/T=2/L=2 /W=IR3DM_DataManIIIDataDisplay $(NameOfWave(Modified_Intensity)) Y,wave=(Modified_Errors,Modified_Errors)
797        ModifyGraph /W=IR3DM_DataManIIIDataDisplay lstyle($(NameOfWave(Modified_Intensity)))=3,lsize($(NameOfWave(Modified_Intensity)))=3,rgb($(NameOfWave(Modified_Intensity)))=(0,0,0)
798        ReorderTraces/W=IR3DM_DataManIIIDataDisplay _back_, {$(NameOfWave(Modified_Intensity))}
799        IN2G_LegendTopGrphFldr(str2num(IN2G_LkUpDfltVar("LegendSize")), 20, 0, 1, topGraphStr="IR3DM_DataManIIIDataDisplay")
800        DoUpdate
801        if(HowMany>1)   //processign many data sets, need to save the data here also.
802                IR3DM_SaveProcessDataFnct()
803        endif
804       
805        setDataFOlder oldDf
806
807end
808
809//**********************************************************************************************************
810
811//************************************************************************************************************
812
813Function IR3DM_SaveProcessDataFnct()
814       
815        doWIndow IR3DM_DataManIIIDataDisplay
816        if(V_Flag==0)
817                return 0
818        endif
819        DoWIndow/F IR3DM_DataManIIIDataDisplay
820        DfRef OldDf=GetDataFolderDFR()
821        setDataFolder root:Packages:Irena:DataManIII
822        variable i, numTraces
823        string TraceNames, NewNote
824        SVAR AddExtension=root:Packages:Irena:DataManIII:AppendModifier
825        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
826        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
827        NVAR UseResults=  root:Packages:Irena:DataManIII:UseResults
828        SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
829        SVAR SaveDataToFolderFull = root:Packages:Irena:DataManIII:SaveDataToFolderFull
830        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
831
832        Wave Original_Intensity
833        Wave Original_Q
834        Wave Original_Errors
835        Wave Original_dQ
836        Wave/Z Modified_Intensity = root:Packages:Irena:DataManIII:Modified_Intensity
837        Wave/Z Modified_Q = root:Packages:Irena:DataManIII:Modified_Q
838        Wave/Z Modified_Errors = root:Packages:Irena:DataManIII:Modified_Errors
839        SVAR IntensityWaveName = root:Packages:Irena:DataManIII:IntensityWaveName
840        SVAR QWavename = root:Packages:Irena:DataManIII:QWavename
841        SVAR ErrorWaveName = root:Packages:Irena:DataManIII:ErrorWaveName
842
843        if(WaveExists(Modified_Intensity)&&WaveExists(Modified_Q)&&WaveExists(Modified_Errors))
844                //SetDataFOlder $(RemoveListItem(ItemsInList(SaveDataToFolderFull,":")-1, SaveDataToFolderFull, ":"))
845                SetDataFOlder $(SaveDataToFolderFull)
846                //print GetDataFOlder(1)
847                NewDataFolder/O/S $(StringFromList(ItemsInList(SaveDataToFolder,":")-1, SaveDataToFolder, ":"))
848                print "Data saved in folder: "+GetDataFOlder(1)
849                Duplicate/O Modified_Intensity, $(IN2G_removeExtraQuote(IntensityWaveName,1,1) + AddExtension)
850                Duplicate/O Modified_Q, $(IN2G_removeExtraQuote(QWavename,1,1) + AddExtension)
851                Duplicate/O Modified_Errors, $(IN2G_removeExtraQuote(ErrorWaveName,1,1) + AddExtension)
852        else
853                Print "No data to save in IR3DM_SaveProcessDataFnct"
854        endif
855        setDataFolder root:Packages:Irena:DataManIII
856
857end//************************************************************************************************************
858//************************************************************************************************************
859
860Function IR3DM_AverageDataFunction()
861       
862        doWIndow IR3DM_DataManIIIDataDisplay
863        if(V_Flag==0)
864                return 0
865        endif
866        DoWIndow/F IR3DM_DataManIIIDataDisplay
867        DfRef OldDf=GetDataFolderDFR()
868        setDataFolder root:Packages:Irena:DataManIII
869        variable i, numTraces
870        string TraceNames, NewNote
871        SVAR AddExtension=root:Packages:Irena:DataManIII:AppendModifier
872        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
873        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
874        NVAR UseResults=  root:Packages:Irena:DataManIII:UseResults
875        SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
876        SVAR SaveDataToFolderFull = root:Packages:Irena:DataManIII:SaveDataToFolderFull
877       
878        TraceNames= TraceNameList("IR3DM_DataManIIIDataDisplay",";",3)
879        TraceNames=GrepList(TraceNames, "AverageIntensity",1 , ";" )                                                                                    //this removes any _ave waves which user may have generated by multiple push of the button.
880        NewNote = "Averaged Data;"+date()+";"+time()+";List of Data waves="+TraceNames
881        numTraces = ItemsInList(TraceNames)
882        //create needed lists first...
883        make/Free/T/N=(numTraces) FldrNamesTWv
884        make/Free/N=(numTraces) SelFldrs
885        SelFldrs = 1
886        string TempStrName
887        string Xtmplt,Ytmplt,Etmplt,OutFldrNm,OutXWvNm, OutYWvNm,OutEWvNm
888        variable UseStdDev,UseSEM, UseMinMax, PropagateErrors
889
890        //build the lists of folders...
891        make/WAVE/N=(numTraces)/Free  wr
892        For(i=0;i<numTraces;i+=1)
893                wr[i] = TraceNameToWaveRef("IR3DM_DataManIIIDataDisplay", StringFromList(i,TraceNames))
894        endfor
895        FldrNamesTWv = GetWavesDataFolder(wr[p], 1)
896        //take first folder name, append the user appendix and create new strings here...
897        string FirstFolderShortName=StringFromList(ItemsInList(FldrNamesTWv[0], ":")-1, FldrNamesTWv[0], ":")
898        //string OutputWaveNameMain = RemoveListItem(ItemsInList(FirstFolderShortName,"_")-1, FirstFolderShortName, "_") +AddExtension
899        SaveDataToFolderFull = RemoveListItem(ItemsInList(FldrNamesTWv[0],":")-1, FldrNamesTWv[0], ":")
900        string OutputWaveNameMain = IN2G_removeExtraQuote(FirstFolderShortName,1,1) + AddExtension
901        if(strlen(SaveDataToFolder)<1)
902                SaveDataToFolder = OutputWaveNameMain
903        endif
904        if(UseQRSdata) 
905                Xtmplt = "(?i)q_"
906                Ytmplt = "(?i)r_"
907                Etmplt = "(?i)s_"
908        elseif(UseIndra2Data)
909                Xtmplt = "DSM_Qvec"
910                Ytmplt = "DSM_Int"
911                Etmplt = "DSM_Error"
912        elseif(UseResults)
913                abort "No idea how to average results yet, fix IR3DM_AverageDataFunction"
914        else
915                Xtmplt = ""
916                Ytmplt = ""
917                Etmplt = ""
918        endif
919       
920        UseStdDev = 1
921        UseSEM = 0
922        PropagateErrors = 0
923        UseMinMax = 0
924        IR3M_AverageMultipleWaves(FldrNamesTWv,SelFldrs,Xtmplt,Ytmplt,Etmplt,UseStdDev,UseSEM, UseMinMax, PropagateErrors)     
925        Wave AveragedDataXwave = root:Packages:DataManipulationII:AveragedDataXwave
926        Wave AveragedDataYwave = root:Packages:DataManipulationII:AveragedDataYwave
927        Wave AveragedDataEwave = root:Packages:DataManipulationII:AveragedDataEwave
928        //NVAR Overwrite=root:Packages:Irena:BioSAXSDataMan:OverwriteExistingData
929        NewDataFOlder/O Averaged_Data
930        Duplicate/O AveragedDataYwave, root:Packages:Irena:DataManIII:Averaged_Data:AverageIntensity
931        Duplicate/O AveragedDataXwave, root:Packages:Irena:DataManIII:Averaged_Data:AverageQvector
932        Duplicate/O AveragedDataEwave, root:Packages:Irena:DataManIII:Averaged_Data:AverageErrors
933        Wave AverageIntensity = root:Packages:Irena:DataManIII:Averaged_Data:AverageIntensity
934        Wave AverageQvector = root:Packages:Irena:DataManIII:Averaged_Data:AverageQvector
935        Wave AverageErrors = root:Packages:Irena:DataManIII:Averaged_Data:AverageErrors
936        Note /K/NOCR AverageIntensity, NewNote
937        Note /K/NOCR AverageQvector, NewNote
938        Note /K/NOCR AverageErrors, NewNote
939
940        RemoveFromGraph /W=IR3DM_DataManIIIDataDisplay /Z AverageIntensity
941        IN2G_ColorTopGrphRainbow(topGraphStr="IR3DM_DataManIIIDataDisplay")
942        //CheckDisplayed /W=IR3DM_DataManIIIDataDisplay AverageIntensity
943        //if(V_Flag!=1)
944        AppendToGraph /W=IR3DM_DataManIIIDataDisplay  AverageIntensity  vs AverageQvector
945        ErrorBars/T=2/L=2 /W=IR3DM_DataManIIIDataDisplay $(NameOfWave(AverageIntensity)) Y,wave=(AverageErrors,AverageErrors)
946        ModifyGraph /W=IR3DM_DataManIIIDataDisplay lstyle($(NameOfWave(AverageIntensity)))=3,lsize($(NameOfWave(AverageIntensity)))=3,rgb($(NameOfWave(AverageIntensity)))=(0,0,0)
947        ReorderTraces/W=IR3DM_DataManIIIDataDisplay _back_, {$(NameOfWave(AverageIntensity))}
948        //endif
949        IN2G_LegendTopGrphFldr(str2num(IN2G_LkUpDfltVar("LegendSize")), 20, 1, 0, topGraphStr="IR3DM_DataManIIIDataDisplay")
950//      //NVAR DisplayErrorBars = root:Packages:Irena:BioSAXSDataMan:DisplayErrorBars
951//      //IN2G_ShowHideErrorBars(DisplayErrorBars, topGraphStr="IRB1_DataManipulationPanel#LogLogDataDisplay")
952        DoUpdate
953        setDataFOlder oldDf
954
955end
956
957//**********************************************************************************************************
958//************************************************************************************************************
959
960Function IR3DM_AverageSaveData()
961
962
963        DfRef OldDf=GetDataFolderDFR()
964        setDataFolder root:Packages:Irena:DataManIII
965        variable i, numTraces
966        string TraceNames, NewNote
967        SVAR AddExtension=root:Packages:Irena:DataManIII:AppendModifier
968        NVAR UseIndra2Data=root:Packages:Irena:DataManIII:UseIndra2Data
969        NVAR UseQRSdata=root:Packages:Irena:DataManIII:UseQRSdata
970        NVAR UseResults=  root:Packages:Irena:DataManIII:UseResults
971        SVAR SaveDataToFolder = root:Packages:Irena:DataManIII:SaveDataToFolder
972        SVAR SaveDataToFolderFull = root:Packages:Irena:DataManIII:SaveDataToFolderFull
973
974        Wave/Z AverageIntensity = root:Packages:Irena:DataManIII:Averaged_Data:AverageIntensity
975        Wave/Z AverageQvector = root:Packages:Irena:DataManIII:Averaged_Data:AverageQvector
976        Wave/Z AverageErrors = root:Packages:Irena:DataManIII:Averaged_Data:AverageErrors
977       
978        if(!WaveExists(AverageIntensity) ||!WaveExists(AverageQvector) ||!WaveExists(AverageErrors))
979                return 0
980        endif
981        string Xtmplt,Ytmplt,Etmplt,OutFldrNm,OutXWvNm, OutYWvNm,OutEWvNm
982
983        if(UseQRSdata) 
984                OutYWvNm = "r_"+SaveDataToFolder
985                OutEWvNm = "s_"+SaveDataToFolder
986                OutXWvNm = "q_"+SaveDataToFolder
987        elseif(UseIndra2Data)
988                OutXWvNm = "DSM_Qvec"
989                OutYWvNm = "DSM_Int"
990                OutEWvNm = "DSM_Error"
991        elseif(UseResults)
992                abort "No idea how to average results yet, fix IR3DM_AverageDataFunction"
993        else
994                Xtmplt = ""
995                Ytmplt = ""
996                Etmplt = ""
997        endif
998        //and now I need to save the data
999        variable Overwrite = 0
1000        OutFldrNm=SaveDataToFolderFull+possiblyQuoteName(SaveDataToFolder)
1001        if(DataFolderExists(OutFldrNm)&&!Overwrite)
1002                DoAlert /T="Folder for Average data exists" 1, "Folder "+OutFldrNm+" exists, do you want to overwrite?"
1003                if(V_Flag!=1)
1004                        abort
1005                endif
1006        endif
1007        NewDataFolder/O/S $(RemoveEnding(OutFldrNm , ":") )
1008        Duplicate/O AverageQvector, $(OutXWvNm)
1009        Duplicate/O AverageIntensity, $(OutYWvNm)
1010        Duplicate/O AverageErrors, $(OutEWvNm)
1011        Wave NewAveXWave = $(OutXWvNm)
1012        Wave NewAveYWave = $(OutYWvNm)
1013        Wave NewAveEWave = $(OutEWvNm)
1014        Print "Saved averaged data set into folder :"+OutFldrNm
1015       
1016        setDataFOlder oldDf
1017
1018end
1019//**********************************************************************************************************
1020//************************************************************************************************************
1021
1022Function IR3DM_AppendAveDataToGraphLogLog()
1023       
1024        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1025        variable WhichLegend=0
1026        string Shortname1, SubtractShortName, legendText
1027
1028        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
1029        SVAR IntensityWaveName=root:Packages:Irena:DataManIII:IntensityWaveName
1030        SVAR QWavename=root:Packages:Irena:DataManIII:QWavename
1031        SVAR ErrorWaveName=root:Packages:Irena:DataManIII:ErrorWaveName
1032        SVAR dQWavename=root:Packages:Irena:DataManIII:dQWavename
1033
1034        Wave/Z AddIntWv=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
1035        Wave/Z AddQWv=$(DataFolderName+possiblyQUoteName(QWavename))
1036        Wave/Z AddErrorWv=$(DataFolderName+possiblyQUoteName(ErrorWaveName))
1037        Wave/Z AdddQWv=$(DataFolderName+possiblyQUoteName(dQWavename))
1038
1039        if(!WaveExists(AddIntWv))
1040                return 0
1041        endif
1042        //check if this data is already displayed in the graph.
1043        CheckDisplayed /W=IR3DM_DataManIIIDataDisplay AddIntWv
1044        if(!V_flag)
1045                AppendToGraph /W=IR3DM_DataManIIIDataDisplay  AddIntWv  vs AddQWv
1046                ModifyGraph /W=IR3DM_DataManIIIDataDisplay log=1, mirror(bottom)=1
1047                Label /W=IR3DM_DataManIIIDataDisplay left "\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"Intensity"
1048                Label /W=IR3DM_DataManIIIDataDisplay bottom "\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"Q[A\\S-1\\M"+"\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"]"
1049                //ErrorBars /W=IR3DM_DataManIIIDataDisplay $nameOfWave(AddIntWv) Y,wave=(AddErrorWv,AddErrorWv)         
1050        endif
1051        //IN2G_LegendTopGrphFldr(str2num(IN2G_LkUpDfltVar("LegendSize")), 20, 1, 0, topGraphStr = "IR3DM_DataManIIIDataDisplay")
1052        //IN2G_ColorTopGrphRainbow(topGraphStr="IR3DM_DataManIIIDataDisplay")
1053//      NVAR DisplayErrorBars = root:Packages:Irena:BioSAXSDataMan:DisplayErrorBars
1054//      IN2G_ShowHideErrorBars(DisplayErrorBars, topGraphStr="IRB1_DataManipulationPanel#LogLogDataDisplay")
1055
1056end
1057//**********************************************************************************************************
1058//**********************************************************************************************************
1059//************************************************************************************************************
1060//**********************************************************************************************************
1061
1062
1063Function IR3DM_AppendProcessDataToGraphLogLog()
1064       
1065        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1066        variable WhichLegend=0
1067        string Shortname1, SubtractShortName, legendText
1068        Wave/Z Original_Intensity=root:Packages:Irena:DataManIII:Original_Intensity
1069        Wave/Z Original_Q=root:Packages:Irena:DataManIII:Original_Q
1070        Wave/Z Original_Errors=root:Packages:Irena:DataManIII:Original_Errors
1071        if(!WaveExists(Original_Intensity))
1072                return 0
1073        endif
1074        DoWIndow IR3DM_DataManIIIDataDisplay
1075        if(V_Flag==0)
1076                IR3DM_CreateDM3Graphs()
1077        endif
1078       
1079        CheckDisplayed /W=IR3DM_DataManIIIDataDisplay Original_Intensity
1080        if(!V_flag)
1081                AppendToGraph /W=IR3DM_DataManIIIDataDisplay  Original_Intensity  vs Original_Q
1082                ModifyGraph /W=IR3DM_DataManIIIDataDisplay log=1, mirror(bottom)=1
1083                Label /W=IR3DM_DataManIIIDataDisplay left "\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"Intensity"
1084                Label /W=IR3DM_DataManIIIDataDisplay bottom "\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"Q[A\\S-1\\M"+"\\Z"+IN2G_LkUpDfltVar("AxisLabelSize")+"]"
1085                ErrorBars /W=IR3DM_DataManIIIDataDisplay Original_Intensity Y,wave=(Original_Errors,Original_Errors)           
1086        endif
1087        NVAR DataQEnd = root:Packages:Irena:DataManIII:DataQEnd
1088        NVAR DataQstart = root:Packages:Irena:DataManIII:DataQstart
1089        NVAR DataQEndPoint = root:Packages:Irena:DataManIII:DataQEndPoint
1090        NVAR DataQstartPoint = root:Packages:Irena:DataManIII:DataQstartPoint
1091        if(DataQstart>0)                        //old Q min already set.
1092                DataQstartPoint = BinarySearch(Original_Q, DataQstart)
1093        endif
1094        if(DataQstartPoint<1)   //Qmin not set or not found. Set to point 2 on that wave.
1095                DataQstart = Original_Q[1]
1096                DataQstartPoint = 1
1097        endif
1098        if(DataQEnd>0)                  //old Q max already set.
1099                DataQEndPoint = BinarySearch(Original_Q, DataQEnd)
1100        endif
1101        if(DataQEndPoint<1)     //Qmax not set or not found. Set to last point-1 on that wave.
1102                DataQEnd = Original_Q[numpnts(Original_Q)-2]
1103                DataQEndPoint = numpnts(Original_Q)-2
1104        endif
1105        SetWindow IR3DM_DataManIIIDataDisplay, hook(DM3LogCursorMoved) = $""
1106        cursor /W=IR3DM_DataManIIIDataDisplay B, Original_Intensity, DataQEndPoint
1107        cursor /W=IR3DM_DataManIIIDataDisplay A, Original_Intensity, DataQstartPoint
1108        SetWindow IR3DM_DataManIIIDataDisplay, hook(DM3LogCursorMoved) = IR3DM_GraphWindowHook
1109
1110
1111        NVAR ProcessSubtractData = root:Packages:Irena:DataManIII:ProcessSubtractData
1112        Wave/Z OriginalSubtractIntWave=root:Packages:Irena:DataManIII:OrigIntToSubtractWave
1113        Wave/Z OriginalSubtractQWave=root:Packages:Irena:DataManIII:OrigQToSubtractWave
1114        Wave/Z OriginalSubtractErrorWave=root:Packages:Irena:DataManIII:OrigErrorToSubtractWave
1115        if(ProcessSubtractData)
1116                if(WaveExists(OriginalSubtractIntWave) && WaveExists(OriginalSubtractQWave))
1117                        CheckDisplayed /W=IR3DM_DataManIIIDataDisplay OriginalSubtractIntWave
1118                        if(!V_flag)
1119                                AppendToGraph /W=IR3DM_DataManIIIDataDisplay  OriginalSubtractIntWave  vs OriginalSubtractQWave
1120                                ModifyGraph /W=IR3DM_DataManIIIDataDisplay rgb($(nameofWave(OriginalSubtractIntWave)))=(0,0,0)
1121                                //ErrorBars /W=IR3DM_DataManIIIDataDisplay $(nameofWave(OriginalSubtractIntWave)) Y,wave=(OriginalSubtractErrorWave,OriginalSubtractErrorWave)         
1122                        endif
1123                endif
1124        else
1125                if(WaveExists(OriginalSubtractIntWave) && WaveExists(OriginalSubtractQWave))
1126                        RemoveFromGraph /W=IR3DM_DataManIIIDataDisplay /Z $(nameofWave(OriginalSubtractIntWave))
1127                endif
1128        endif
1129
1130        SVAR DataFolderName=root:Packages:Irena:DataManIII:DataFolderName
1131        SVAR SelectedFolderToSubtract  = root:Packages:Irena:DataManIII:SelectedFolderToSubtract
1132        Shortname1 = StringFromList(ItemsInList(DataFolderName, ":")-1, DataFolderName  ,":")
1133        SubtractShortName = StringFromList(ItemsInList(SelectedFolderToSubtract, ":")-1, SelectedFolderToSubtract  ,":")
1134        if(ProcessSubtractData)
1135                SubtractShortName = "\\s("+nameofWave(OriginalSubtractIntWave)+") Subtract wave : "+ SubtractShortName
1136                legendText = "\\s(Original_Intensity) "+Shortname1+"\r"+ SubtractShortName
1137                Legend/W=IR3DM_DataManIIIDataDisplay /C/N=text0/J/A=LB legendText
1138        else
1139                Legend/W=IR3DM_DataManIIIDataDisplay /C/N=text0/J/A=LB "\\s(Original_Intensity) "+Shortname1
1140        endif
1141        //IN2G_LegendTopGrphFldr(IN2G_LkUpDfltVar("LegendSize"), 20, 1, 0, topGraphStr = "IR3DM_DataManIIIDataDisplay")
1142        //IN2G_ColorTopGrphRainbow(topGraphStr="IR3DM_DataManIIIDataDisplay")
1143end
1144//**********************************************************************************************************
1145//**********************************************************************************************************
1146
1147Function IR3DM_GraphWindowHook(s)
1148        STRUCT WMWinHookStruct &s
1149
1150        Variable hookResult = 0
1151
1152        switch(s.eventCode)
1153                case 0:                         // Activate
1154                        // Handle activate
1155                        break
1156
1157                case 1:                         // Deactivate
1158                        // Handle deactivate
1159                        break
1160                case 7:                         //coursor moved
1161                        IR3DM_SyncCursorsTogether(s.traceName,s.cursorName,s.pointNumber)
1162                        hookResult = 1
1163                // And so on . . .
1164        endswitch
1165
1166        return hookResult       // 0 if nothing done, else 1
1167End
1168//**********************************************************************************************************
1169//**********************************************************************************************************
1170
1171static Function IR3DM_SyncCursorsTogether(traceName,CursorName,PointNumber)
1172        string traceName,CursorName
1173        variable PointNumber
1174
1175        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1176        IR3DM_CreateDM3Graphs()
1177        NVAR DataQEnd = root:Packages:Irena:DataManIII:DataQEnd
1178        NVAR DataQstart = root:Packages:Irena:DataManIII:DataQstart
1179        NVAR DataQEndPoint = root:Packages:Irena:DataManIII:DataQEndPoint
1180        NVAR DataQstartPoint = root:Packages:Irena:DataManIII:DataQstartPoint
1181        Wave Original_Q=root:Packages:Irena:DataManIII:Original_Q
1182        Wave Original_Intensity=root:Packages:Irena:DataManIII:Original_Intensity
1183        variable tempMaxQ, tempMaxQY, tempMinQY, maxY, minY
1184        //check if user removed cursor from graph, in which case do nothing for now...
1185        if(numtype(PointNumber)==0)
1186                if(stringmatch(CursorName,"A"))         //moved cursor A, which is start of Q range
1187                        DataQstartPoint = PointNumber
1188                        DataQstart = Original_Q[PointNumber]
1189                endif
1190                if(stringmatch(CursorName,"B"))         //moved cursor B, which is end of Q range
1191                        DataQEndPoint = PointNumber
1192                        DataQEnd = Original_Q[PointNumber]
1193                endif
1194        endif
1195end
1196//**********************************************************************************************************
1197//**********************************************************************************************************
1198
1199//**********************************************************************************************************
1200//**********************************************************************************************************
1201//**********************************************************************************************************
1202Function IR3DM_CreateDM3Graphs()
1203       
1204        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1205        variable exists1=0
1206        NVAR DeleteData= root:Packages:Irena:DataManIII:DeleteData
1207        if(DeleteData)
1208                KillWindow/Z IR3DM_DataManIIIDataDisplay
1209        else
1210                DoWIndow IR3DM_DataManIIIDataDisplay
1211                if(V_Flag)
1212                        DoWIndow/hide=? IR3DM_DataManIIIDataDisplay
1213                        if(V_Flag==2)
1214                                DoWIndow/F IR3DM_DataManIIIDataDisplay
1215                        endif
1216                else
1217                        Display /W=(521,10,1383,750)/K=1 /N=IR3DM_DataManIIIDataDisplay
1218                        ShowInfo/W=IR3DM_DataManIIIDataDisplay
1219                        exists1=1
1220                endif
1221                AutoPositionWindow/M=0/R=IR3DM_DataManIIIPanel IR3DM_DataManIIIDataDisplay     
1222        endif
1223end
1224
1225//**********************************************************************************************************
1226//**********************************************************************************************************
1227
1228//**********************************************************************************************************
1229//**********************************************************************************************************
1230
1231Function IR3DM_InitDMIII()     
1232
1233
1234        //IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1235        DFref oldDf= GetDataFolderDFR()
1236        string ListOfVariables
1237        string ListOfStrings
1238        variable i
1239               
1240        if (!DataFolderExists("root:Packages:Irena:DataManIII"))                //create folder
1241                NewDataFolder/O root:Packages
1242                NewDataFolder/O root:Packages:Irena
1243                NewDataFolder/O root:Packages:Irena:DataManIII
1244        endif
1245        SetDataFolder root:Packages:Irena:DataManIII                                    //go into the folder
1246
1247        //here define the lists of variables and strings needed, separate names by ;...
1248        ListOfStrings="DataFolderName;IntensityWaveName;QWavename;ErrorWaveName;dQWavename;DataUnits;"
1249        ListOfStrings+="DataStartFolder;DataMatchString;FolderSortString;FolderSortStringAll;"
1250        ListOfStrings+="UserMessageString;SavedDataMessage;SelectedFolderToSubtract;"
1251        ListOfStrings+="SaveDataToFolder;SaveDataToFolderFull;AppendModifier;"
1252
1253        ListOfVariables="UseIndra2Data1;UseQRSdata1;DataQEnd;DataQStart;DataQEndPoint;DataQstartPoint;"
1254        ListOfVariables+="DeleteData;ProcessData;AverageData;WarnUserDeleteData;"
1255        ListOfVariables+="ProcessTrim;ProcessRebin;ProcessSubtractValue;ProcessSubtractData;"
1256        ListOfVariables+="ProcessRebinTarget;ProcessSubtractValueNumber;"
1257        ListOfVariables+="ProcessAverageAllData;"
1258
1259        //and here we create them
1260        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
1261                IN2G_CreateItem("variable",StringFromList(i,ListOfVariables))
1262        endfor         
1263                                                               
1264        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1265                IN2G_CreateItem("string",StringFromList(i,ListOfStrings))
1266        endfor 
1267
1268        ListOfStrings="DataFolderName;IntensityWaveName;QWavename;ErrorWaveName;dQWavename;"
1269        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1270                SVAR teststr=$(StringFromList(i,ListOfStrings))
1271                teststr =""
1272        endfor         
1273        ListOfStrings="DataMatchString;FolderSortString;FolderSortStringAll;"
1274        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1275                SVAR teststr=$(StringFromList(i,ListOfStrings))
1276                if(strlen(teststr)<1)
1277                        teststr =""
1278                endif
1279        endfor         
1280        ListOfStrings="DataStartFolder;"
1281        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1282                SVAR teststr=$(StringFromList(i,ListOfStrings))
1283                if(strlen(teststr)<1)
1284                        teststr ="root:"
1285                endif
1286        endfor         
1287        SVAR SelectedFolderToSubtract
1288        SelectedFolderToSubtract = ""
1289//      SVAR ListOfManipulations
1290//      ListOfManipulations="TrimData;RebinData;SmoothData;DeleteData;"
1291//      SVAR ManipulationSelected
1292//      if(strlen(ManipulationSelected)<1)
1293//              ManipulationSelected="TrimData"
1294//      endif
1295        NVAR DeleteData
1296        NVAR ProcessData
1297        NVAR AverageData
1298        ProcessData = 1
1299        DeleteData = 0
1300        AverageData = 0
1301        NVAR WarnUserDeleteData
1302        WarnUserDeleteData = 0
1303        SVAR SaveDataToFolder
1304        SVAR AppendModifier
1305        SaveDataToFolder=""
1306        AppendModifier=""
1307       
1308        Make/O/T/N=(0) ListOfAvailableData
1309        Make/O/N=(0) SelectionOfAvailableData
1310        SetDataFolder oldDf
1311
1312end
1313//**************************************************************************************
1314//**************************************************************************************
1315//**************************************************************************************
Note: See TracBrowser for help on using the repository browser.