source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/MultipleReduce.ipf @ 72

Last change on this file since 72 was 41, checked in by srkline, 16 years ago

change to UNIX line endings

File size: 25.8 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//*************************
6// Vers. 1.2 092101
7//
8// Procedures for the MRED panel to allow quick batch reduction of data files
9// -as of 8/01, use the new method of requiring only run numbers to select the datafiles
10//              and these data failes need not be consecutively numbered
11//
12//****note that much of this file is becoming obsolete as improved methods for
13//reducing multiple files are introduced. Some of these procedures may not last long***
14//
15//**************************
16
17
18//simple procedure to bring the CAT TABLE to the front if it is present
19//alerts user, but does nothing else if CAT TABLE is not present
20//called by several panels
21//
22Proc ShowCATWindow()
23        DoWindow/F CatVSTable
24        if(V_flag==0)
25                DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
26        Endif
27End
28
29
30//function takes a list of filenames (just the name, no path , no extension)
31//that is COMMA delimited, and creates a new list that is also COMMA delimited
32//and contains the full path:file;vers for each file in the list
33//and ensures that files in returned list are RAW data , and can be found on disk
34//
35Function/S  FullNameListFromFileList(list)
36        String list
37       
38        String newList="",pathStr="",sepStr=","
39        PathInfo catPathName
40        if(V_flag==0)
41                Abort "CatPath does not exist - use Pick Path to select the data folder"
42        else
43                pathStr = S_Path
44        Endif
45       
46        Variable ii,num,ok
47        String fullName="",partialName="",tempName="",str
48         
49        num = ItemsInList(list,",")
50        ii=0
51        do
52                //take each item, and try to find the file (extensions for raw data should be ;1)
53                partialName = StringFromList(ii,list,",")       //COMMA separated list
54                if(strlen(partialName)!=0)              //null string items will be skipped
55                        tempName = FindValidFilename(partialName)               //will add the version # if needed     
56                        fullName = pathStr + tempName                                           //prepend the path (CAT)
57                       
58                        //discard strings that are not filenames (print the non-files)
59                        //make sure the file is really a RAW data file
60                        ok = CheckIfRawData(fullName)           // 1 if RAW, 0 if unknown type
61                        if (!ok)
62                                //write to cmd window that file was not a RAW SANS file
63                                str = "This file is not recognized as a RAW SANS data file: "+tempName+"\r"
64                                Print str
65                        else
66                                //yes, a valid file:path;ext that is RAW SANS
67                                //add the full path:file;ext +"," to the newList
68                                newList += fullName + sepStr
69                        Endif
70                endif           //partialName from original list != ""
71                ii+=1
72        while(ii<num)   //process all items in list
73       
74        Return(newList)
75End
76
77//takes a COMMA delimited list of files (full path:name;vers output of FullNameListFromFileList()
78//function and reduces each of the files in the list
79//the protocol is from the global string (wich is NOt in the MRED folder, but in the Protocols folder
80//
81Function DoReduceList(list)
82        String list
83       
84        //selected protocol is in a temporary global variable so that it can be used with execute
85        SVAR gMredProtoStr = root:myGlobals:Protocols:gMredProtoStr
86        //input list is a comma delimited list of individual sample files to be reduced using the
87        //given protocol - based on WM proc "ExecuteCmdOnList()"
88        //input filenames must be full path:file;ext, so they can be found on disk
89       
90        String cmdTemplate = "ExecuteProtocol(\"" + gMredProtoStr + "\",\"%s\")"
91        String theItem
92        Variable index=0
93        String cmd
94        Variable num = ItemsInList(list,",")
95        do
96                theItem = StringFromList(index,list,",")        //COMMA separated list
97                if(strlen(theItem)!=0)
98                        sprintf cmd,cmdTemplate,theItem         //null string items will be skipped
99                        //Print "cmd = ",cmd
100                        Execute cmd
101                endif
102                index +=1
103        while(index<num)        //exit after all items have been processed
104       
105        //will continue until all files in list are reduced, according to gMredProtoStr protocol
106        return(0)
107End
108
109
110//panel to allow reduction of a series of files using a selected  protocol
111//
112//main entry procedure to open the panel, initializing if necessary
113Proc ReduceMultipleFiles()
114       
115        DoWindow/F Multiple_Reduce_Panel
116        If(V_flag == 0)
117                InitializeMultReducePanel()
118                //draw panel
119                Multiple_Reduce_Panel()
120                //pop the protocol list
121                MRProtoPopMenuProc("",1,"")
122        Endif
123End
124
125//create the global variables needed to run the MReduce Panel
126//all are kept in root:myGlobals:MRED
127//
128Proc InitializeMultReducePanel()
129
130        If(DataFolderExists("root:myGlobals:MRED"))
131                //ok, do nothing
132        else
133                //no, create the folder and the globals
134                NewDataFolder/O root:myGlobals:MRED
135//              String/G root:myGlobals:MRED:gMRedMatchStr = "*"
136                PathInfo catPathName
137                If(V_flag==1)
138                        String dum = S_path
139                        String/G root:myGlobals:MRED:gCatPathStr = dum
140                else
141                        String/G root:myGlobals:MRED:gCatPathStr = "no path selected"
142                endif
143                String/G root:myGlobals:MRED:gMRedList = "none"
144                String/G root:myGlobals:MRED:gMRProtoList = "none"
145                String/G root:myGlobals:MRED:gFileNumList=""
146//              String/G root:myGlobals:MRED:gMRS1 = "no file selected"
147//              String/G root:myGlobals:MRED:gMRS2 = "no file selected"
148//              String/G root:myGlobals:MRED:gMRS3 = "no box selected"
149//              Variable/G root:myGlobals:MRED:gMRV1 =0
150//              Variable/G root:myGlobals:MRED:gMRV2 = 999
151        Endif
152End
153
154//panel recreation macro for the MRED panel
155//
156Window Multiple_Reduce_Panel()
157        PauseUpdate; Silent 1           // building window...
158        NewPanel /W=(535,72,951,228) /K=1 as "Multiple File Reduction"
159        ModifyPanel cbRGB=(65535,49151,29490)
160        ModifyPanel fixedSize=1
161        SetDrawLayer UserBack
162        DrawLine 7,30,422,30
163        SetVariable PathDisplay,pos={77,7},size={300,13},title="Path"
164        SetVariable PathDisplay,help={"This is the path to the folder that will be used to find the SANS data while reducing. If no files appear in the popup, make sure that this folder is set correctly"}
165        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:myGlobals:MRED:gCatPathStr
166        Button PathButton,pos={3,3},size={70,20},proc=PickMRPathButton,title="Pick Path"
167        Button PathButton,help={"Select the folder containing the raw SANS data files"}
168        Button helpButton,pos={385,3},size={25,20},proc=ShowMRHelp,title="?"
169        Button helpButton,help={"Show the help file for reducing multiple files using the same protocol"}
170        PopupMenu MRFilesPopup,pos={3,72},size={167,19},proc=MRedPopMenuProc,title="File(s) to Reduce"
171        PopupMenu MRFilesPopup,help={"The displayed file is the one that will be reduced. The entire list will be reduced if \"Reduce All..\" is selected. \r If no items, or the wrong items appear, click on the popup to refresh."}
172        PopupMenu MRFilesPopup,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRedList"
173        SetVariable MRList,pos={3,48},size={350,13},proc=FileNumberListProc,title="File number list: "
174        SetVariable MRList,help={"Enter a comma delimited list of file numbers to reduce. Ranges can be entered using a dash."}
175        SetVariable MRList,limits={-Inf,Inf,1},value= root:myGlobals:MRED:gFileNumList
176//      SetVariable MRLow,pos={3,72},size={150,13},proc=SetLowFileNumProc,title="File range: "
177//      SetVariable MRLow,help={"Enter the first file number to reduce. Files must be consecutively numbered."}
178//      SetVariable MRLow,limits={-Inf,Inf,0},value= root:myGlobals:MRED:gMRV1
179        Button ReduceAllButton,pos={3,128},size={180,20},proc=ReduceAllPopupFiles,title="Reduce All Files in Popup"
180        Button ReduceAllButton,help={"This will reduce ALL of the files in the popup list, not just the top file."}
181        Button DoneButton,pos={292,128},size={110,20},proc=MRDoneButtonProc,title="Done Reducing"
182        Button DoneButton,help={"When done reducing files, this will close this control panel."}
183        Button cat_short,pos={310,72},size={90,20},proc=DoCatShort,title="File Catalog"
184        Button cat_short,help={"Use this button to generate a table with file header information. Very useful for identifying files."}
185        Button show_cat_short,pos={280,98},size={120,20},proc=ShowCatShort_MRED,title="Show File Catalog"
186        Button show_cat_short,help={"Use this button to bring the File Catalog window to the front."}
187//      SetVariable MRHigh,pos={160,73},size={90,13},proc=SetHighFileNumProc,title=" to: "
188//      SetVariable MRHigh,help={"Enter the last file number to reduce. Files must be consecutively numbered."}
189//      SetVariable MRHigh,limits={-Inf,Inf,0},value= root:myGlobals:MRED:gMRV2
190        PopupMenu MRProto_pop,pos={3,98},size={119,19},proc=MRProtoPopMenuProc,title="Protocol "
191        PopupMenu MRProto_pop,help={"All of the data files in the popup will be reduced using this protocol"}
192        PopupMenu MRProto_pop,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRProtoList"
193EndMacro
194
195//executed when a list of filenumbers is entered in the box
196//responds as if the file popup was hit, to update the popup list contents
197//
198Function FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl
199        String ctrlName
200        Variable varNum
201        String varStr
202        String varName
203               
204        MRedPopMenuProc("MRFilesPopup",0,"")
205End
206
207Proc ShowMRHelp(ctrlName) : ButtonControl
208        String ctrlName
209
210        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Reduce Multiple Files]"
211End
212
213//button procedure for bringing File Catalog window to front, if it exists
214//so that the user can see what's going on
215//
216Proc ShowCatShort_MRED(ctrlName) : ButtonControl
217        String ctrlName
218
219        ShowCATWindow()
220End
221
222//obsolete procedure - unused
223//
224//procedure for setVar box to set the low file number (forced to be >=0)
225//sets the global variable, then forces an update of the popup
226//
227//Function SetLowFileNumProc(ctrlName,varNum,varStr,varName) : SetVariableControl
228//      String ctrlName
229//      Variable varNum
230//      String varStr
231//      String varName
232//     
233//      ControlInfo MRLow
234//      //low value must be >=0
235//      Variable test = v_value
236//      if (test < 0 )
237//              test = 0
238//      Endif
239//      Variable/G root:myGlobals:MRED:gMRV1 = test
240//      //then update the popup list
241//      MRedPopMenuProc("MRFilesPopup",1,"")
242//
243//End
244
245//obsolete procedure - unused
246//
247//procedure for setVar box to set the high file number (forced to be <=999)
248//sets the global variable, then forces an update of the popup
249//
250//Function SetHighFileNumProc(ctrlName,varNum,varStr,varName) : SetVariableControl
251//      String ctrlName
252//      Variable varNum
253//      String varStr
254//      String varName
255//
256//      ControlInfo MRHigh
257//      //high value must be <=999
258//      Variable test = V_value
259//      if(test > 999)
260//              test = 999
261//      Endif
262//      Variable/G root:myGlobals:MRED:gMRV2 = test
263//      //then update the popup list
264//      MRedPopMenuProc("MRFilesPopup",1,"")
265//End
266
267//allows the user to set the path to the local folder that contains the SANS data
268//2 global strings are reset after the path "catPathName" is reset in the function PickPath()
269// this path is the only one, the globals are simply for convenience
270//
271Function PickMRPathButton(PathButton) : ButtonControl
272        String PathButton
273       
274        PickPath()              //sets the main global path string for catPathName
275       
276        //then update the "local" copy in the MRED subfolder
277        PathInfo/S catPathName
278        String dum = S_path
279        if (V_flag == 0)
280                //path does not exist - no folder selected
281                String/G root:myGlobals:MRED:gCatPathStr = "no folder selected"
282        else
283                String/G root:myGlobals:MRED:gCatPathStr = dum
284        endif
285       
286        //Update the pathStr variable box
287        ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay"
288       
289        //then update the popup list
290        MRedPopMenuProc("MRFilesPopup",1,"")
291End
292
293// changes the contents of the popup list of files to be reduced based on the
294// range of file numbers entered in the text box
295//
296Function MRedPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl
297        String MRFilesPopup
298        Variable popNum
299        String popStr
300
301        String list = GetValidMRedPopupList()
302//      Wave/T redList = redList
303//      String list = Wave2SemiList(redWave)
304//     
305        String/G root:myGlobals:MRED:gMredList = list
306        ControlUpdate MRFilesPopup
307
308End
309
310//parses the file number list to get valid raw data filenames for reduction
311// -if the numbers and full ranges can be translated to correspond to actual files
312// on disk, the popup list is updated - otherwise the offending number is reported
313// and the user must fix the problem before any reduction can be done
314//
315//ParseRunNumberList() does the work, as it does for the protocol panel
316//
317Function/S GetValidMRedPopupList()
318
319        String commaList="",semiList=""
320        SVAR numList=root:myGLobals:MRED:gFileNumList
321       
322        commaList = ParseRunNumberList(numList)
323        //convert commaList to a semicolon delimited list
324        Variable num=ItemsinList(commaList,","),ii
325        for(ii=0;ii<num;ii+=1)
326                semiList += StringFromList(ii, commaList  ,",") + ";"
327        endfor
328//      print semiList
329//sort the list
330        semiList = SortList(semiList,";",0)
331        return(semiList)
332       
333//      //make sure that path exists
334//      PathInfo catPathName
335//      String path = S_path
336//      if (V_flag == 0)
337//              Abort "folder path does not exist - use Pick Path button"
338//      Endif
339//      String list=""
340//     
341//      list = IndexedFile(catPathName,-1,"????")       //get all files in folder
342//     
343//      NVAR  lownum = root:myGlobals:MRED:gMRV1
344//      NVAR  highnum = root:myGlobals:MRED:gMRV2
345//     
346//      //trim list to include only selected files that are RAW SANS files
347//      //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be reduced)
348//      Variable ii,isRAW,num,runNum=-1
349//      String item="",newList = "",fullName = "",partialName=""
350//     
351//      //get rid of version numbers first (up to 11)
352//      list =  RemoveVersNumsFromList(list)
353//     
354//      //then filter out only the raw data files within the range lownum to highnum
355//      num = ItemsInList(list,";")             //get the new number of items in the list
356//      ii=0
357//      do
358//              //parse through the list in this order:
359//              // 1 - get the run number from the file (AAAAANNN.SAn_asdfasdfasdf) by finding the "dot"
360//              // 2 - exclude by lownum/highnum
361//              // 3 - exclude by isRaw? (to minimize disk access)
362//              item = StringFromList(ii, list  ,";" )
363//              if(strlen(item) != 0)
364//                      //find the run number, if it exists
365//                      runNum = GetRunNumFromFile(item)
366//                      //is the runNum in the selected range?
367//                      if( (runNum >= lowNum) && (runNum <= highnum) )
368//                              //valid number, continue
369//                              //build valid filename
370//                              partialName = FindValidFileName(item)
371//                              if(strlen(partialName) != 0)            //non-null return from FindValidFileName()
372//                                      fullName = path + partialName
373//                                      //check if RAW, if so, add original item to newList
374//                                      isRAW = CheckIfRawData(fullName)
375//                                      if(isRaw)
376//                                              newList += item + ";"
377//                                      Endif
378//                              Endif
379//                      Endif
380//              Endif
381//              ii+=1
382//      while(ii<num)           //process all items in list
383//
384//      Return(newList)
385End
386
387//returns a list of the available protocol waves in the protocols folder
388//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
389//since these waves do not contain valid protocol instructions
390//
391Function MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
392        String MRProto_pop
393        Variable popNum
394        String popStr
395
396        //get list of currently valid protocols, and put it in the popup (the global list)
397        //excluding "tempProtocol" and "CreateNew" if they exist
398        SetDataFolder root:myGlobals:Protocols
399        String list = WaveList("*",";","")
400        SetDataFolder root:
401       
402        //remove items from the list (list is unchanged if the items are not present)
403        list = RemoveFromList("CreateNew", list, ";")
404        list = RemoveFromList("tempProtocol", list, ";")
405        list = RemoveFromList("fakeProtocol", list, ";")
406       
407        String/G root:myGlobals:MRED:gMRProtoList = list
408        ControlUpdate MRProto_pop
409
410End
411
412//button procedure to close the panel
413//
414Function MRDoneButtonProc(ctrlName) : ButtonControl
415        String ctrlName
416
417        // this button will make sure all files are closed
418        //and close the panel
419
420        Close/A
421        DoWindow/K Multiple_Reduce_Panel
422        KillDataFolder root:myGlobals:MRED
423End
424
425//button action function caled to reduce all of the files in the "file" popup
426//using the protocol specified in the "protocol" popup
427//converts list of files into comma delimited list of full path:filename;vers
428//that can be reduced as a list
429// also sets the current protocol to a global accessible to the list processing routine
430//
431Function ReduceAllPopupFiles(ctrlName) : ButtonControl
432        String ctrlName
433       
434        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
435        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
436       
437        SVAR semiList = root:myGlobals:MRED:gMredList
438       
439        //process each item in the list, and generate commaList
440        Variable num = ItemsInList(semiList,";" )
441        Variable ii=0
442        String commaList = "",item = ""
443        do
444                item = StringFromList(ii, semiList  ,";" )
445                commaList += item + ","
446                ii+=1
447        while(ii<num)
448        //080601 - send only the comma list of filenames, not full path:name   
449        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
450
451        //get the selected protocol, and pass as a global
452        ControlInfo MRProto_pop
453        String protocolNameStr = S_Value
454        String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolNameStr
455       
456        //also set this as the current protocol, for the function that writes the averaged waves
457        String/G root:myGlobals:Protocols:gProtoStr = protocolNameStr
458       
459        //reduce all the files in the list here, using the global protocol(the full reference)
460        //DoReduceList is found in MultipleReduce.ipf
461        DoReduceList(commaList)
462       
463        Return 0
464End
465
466
467//*************************************
468//under construction MRED function
469
470//testing - unused
471//Macro Init_NEW_MRED()
472//      Make/O/T/N=1 fileWave,redWave
473//      Make/O/N=1 selWave
474//End
475
476//testing - unused
477//
478//returns a list of raw data files from catPathName
479//Function/S RawDataList()
480//      //make sure that path exists
481//      PathInfo catPathName
482//      String path = S_path
483//      if (V_flag == 0)
484//              Abort "folder path does not exist - use Pick Path button"
485//      Endif
486//      String list=IndexedFile(catPathName,-1,"????")  //get all files in folder
487//     
488//      //trim list to include only selected files that are RAW SANS files
489//      //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be reduced)
490//      Variable ii,isRAW,num,runNum=-1
491//      String item="",newList = "",fullName = "",partialName=""
492//     
493//      //get rid of version numbers first (up to 11)
494//      list =  RemoveVersNumsFromList(list)
495//     
496//      //then filter out only the raw data files within the range lownum to highnum
497//      num = ItemsInList(list,";")             //get the new number of items in the list
498//      ii=0
499//      do
500//              //  exclude by isRaw? (to minimize disk access)
501//              item = StringFromList(ii, list  ,";" )
502//              if(strlen(item) != 0)
503//                              partialName = FindValidFileName(item)
504//                              if(strlen(partialName) != 0)            //non-null return from FindValidFileName()
505//                                      fullName = path + partialName
506//                                      //check if RAW, if so, add original item to newList
507//                                      isRAW = CheckIfRawData(fullName)
508//                                      if(isRaw)
509//                                              newList += item + ";"
510//                                      Endif
511//                              Endif
512//              Endif
513//              ii+=1
514//      while(ii<num)           //process all items in list
515//
516//      Return(newList)
517//End
518
519//testing - unused
520//
521//Function/S RunNumList2FileNameList(NumList)
522//      String numList          //text list of run numbers
523//
524//      //find a valid file name if possible, return null otherwise
525//      String retList = "",str=""
526//      Variable numRuns,ii,r_index
527//      numRuns = ItemsInList(numList,";")
528//      for(ii=0;ii<numRuns;ii+=1)
529//              r_index = str2num(StringFromList(ii,numList,";"))
530//              str= FindFileFromRunNumber(r_index)
531//              if(cmpstr(str,"")!=0)
532//                      retList += str + ";"
533//              Endif
534//      EndFor
535//      return(retList)
536//End
537
538//testing - unused
539//
540//Window panel0() : Panel
541//      PauseUpdate; Silent 1           // building window...
542//      NewPanel /W=(501,97,929,307) /K=1
543//      ListBox fileList,pos={0,0},size={179,146},listWave=root:fileWave
544//      ListBox fileList,selWave=root:selWave,mode= 4
545//      ListBox redList,pos={219,0},size={179,146},listWave=root:redWave,mode= 1
546//      ListBox redList,selRow= -1
547//      Button button0,pos={114,148},size={50,20},proc=AddButtonProc,title="Add"
548//      Button button1,pos={219,148},size={50,20},proc=ClearButtonProc,title="Clear"
549//      Button button2,pos={337,148},size={50,20},proc=PopButtonProc,title="Pop"
550//      Button button3,pos={4,148},size={50,20},proc=NewListButtonProc
551//      Button button4,pos={279,148},size={50,20},proc=DelButtonProc,title="Del"
552//EndMacro
553
554//testing - unused
555//
556//Function DelButtonProc(ctrlName) : ButtonControl
557//      String ctrlName
558//     
559//      ControlInfo redList
560//      Variable selRow=V_Value
561//      Wave lw=$S_Value
562//      DeletePoints selRow,1,lw
563//     
564//End
565
566//testing - unused
567//
568//Function NewListButtonProc(ctrlName) : ButtonControl
569//      String ctrlName
570//     
571//      String list=IndexedFile(catPathName,-1,"????")
572//      String newList="",item=""
573//      Variable num=ItemsInList(list,";"),ii
574//      for(ii=0;ii<num;ii+=1)
575//              item = StringFromList(ii, list  ,";")
576//              if( stringmatch(item,"*.sa1*") )
577//                      newlist += item + ";"
578//              endif
579//              if( stringmatch(item,"*.sa2*") )
580//                      newlist += item + ";"
581//              endif
582//              if( stringmatch(item,"*.sa3*") )
583//                      newlist += item + ";"
584//              endif
585//              //print "ii=",ii
586//      endfor
587//      newList = SortList(newList,";",0)
588//      num=ItemsInList(newlist,";")
589//      Make/O/T/N=(num) fileWave
590//      Make/O/N=(num) selWave
591//      fileWave = StringFromList(p,newlist,";")
592//      Sort filewave,filewave
593//End
594
595//testing - unused
596//
597//Function AddButtonProc(ctrlName) : ButtonControl
598//      String ctrlName
599//
600//      Wave/T fileWave=fileWave
601//      Wave/T redWave=redWave
602//      Wave sel=selWave
603//     
604//      Variable num=numpnts(sel),ii=0
605//      variable lastPt=numpnts(redwave)
606//      do
607//              if(sel[ii] == 1)
608//                      InsertPoints lastPt,1, redWave
609//                      redWave[lastPt]=filewave[ii]
610//                      lastPt +=1
611//              endif
612//              ii+=1
613//      while(ii<num)
614//      return(0)
615//End
616
617//testing - unused
618//
619//Function ClearButtonProc(ctrlName) : ButtonControl
620//      String ctrlName
621//      Make/O/T/N=1 redWave
622//End
623
624//testing - unused
625//
626//Function PopButtonProc(ctrlName) : ButtonControl
627//      String ctrlName         
628//      MRedPopMenuProc("MRFilesPopup",0,"")
629//End
630
631
632//****************************
633// below are very old procedures, not used (maybe of no value)
634
635
636//little used procedure - works only with menu selections of list processing
637//
638Proc ClearFileList()
639        String/G root:myGlobals:Protocols:gReduceList=""
640        DoAlert 0,"The file reduction list has been initialized"
641        ShowList()
642End
643
644//old procedure, (not used) - data is saved to the catPathName folder, the same folder
645//where the data came from in the first place, avoiding extra paths
646Proc PickSaveFolder()
647        NewPath/O/M="pick folder for averaged data" Save_path
648        PathInfo/S Save_path
649        if (V_flag == 0)
650                //path does not exist - no folder selected
651                Print "No destination path selected - save dialog will be presented"
652        endif
653End
654
655//little used reduction procedure, asks for protocol, then uses this protocol
656//to reduce the files in a list built by selecting files from the CAT window
657//did not get favorable reviews from users and may not be kept
658//
659Proc ReduceFilesInList()
660
661        String protocolName=""
662
663        //generate a list of valid path:file;ext items, comma separated as the input filenames for
664        //ExecuteProtocol(), their final destination
665       
666        String list = root:myGlobals:Protocols:gReduceList
667        Variable num = ItemsInList(list,"," )
668       
669        list = FullNameListFromFileList(list)
670       
671        //Print list
672       
673        //get protocolName in the same manner as "recallprotocol" button
674        //but remember to set a global for  Execute to use
675        SetDataFolder root:myGlobals:Protocols          //must be in protocols folder before executing this Proc       
676        Execute "PickAProtocol()"
677        //get the selected protocol wave choice through a global string variable
678        protocolName = root:myGlobals:Protocols:gProtoStr
679        //If "CreateNew" was selected, ask user to try again
680        if(cmpstr("CreateNew",protocolName) == 0)
681                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
682        Endif
683        SetDataFolder root:
684//      String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolName
685       
686        //pass the full path to the protocol for ExecuteProtocol() later
687        //Print gMredProtoStr," protocol name"
688       
689        DoReduceList(list)
690       
691//      KillStrings/Z gMredProtoStr
692       
693//      SetDataFolder root:
694       
695End
696
697//displays the current contents of the FileList window, for multiple file reduction
698//little used function and may not be kept
699//
700Proc ShowList()
701       
702        DoWindow/F ListWin
703        If(V_Flag ==0)
704                NewNotebook/F=1/N=ListWin as "File List"
705        Endif
706        //clear old window contents, reset the path
707        Notebook ListWin,selection={startOfFile,EndOfFile}
708        Notebook ListWin,text="\r"
709       
710        //Write out each item of the comma-delimited list to the notebook
711        String list = root:myGlobals:Protocols:gReduceList
712        Variable index = 0
713        String theItem=""
714        Variable num = ItemsInList(list,"," )
715        do
716                theItem = StringFromList(index,list,",")        //COMMA separated list
717                if(strlen(theItem)!=0)
718                        Notebook ListWin,text=(theItem+"\r")            //null string items will be skipped
719                endif
720                index +=1
721        while(index<num)        //exit after all items are printed
722End
723
724
725//little used function to add the selected file from the CAT/SHORT window to the fileList
726//so that the list of files can be processed batchwise
727//
728Proc AddSelectionToList()
729
730        if(WinType("CatWin")==0)
731                Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
732        Endif
733        GetSelection notebook,CatWin,3
734        //build a comma separated list of names
735        //does the global variable exist?
736        if(exists("root:myGlobals:Protocols:gReduceList")==2)           //a string exists
737                //do nothing extra
738        else
739                //create (initialize) the global string
740                String/G root:myGlobals:Protocols:gReduceList = ""
741        endif
742        String list = root:myGlobals:Protocols:gReduceList
743        list += S_Selection + ","
744        String/G root:myGlobals:Protocols:gReduceList = list            //reassign the global
745       
746       
747End
748
749//little used function to remove the selected file in the CAT/SHORT window from the fileList
750Proc RemoveFileFromList()
751        //if(WinType("CatWin")==0)
752                //Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
753        //Endif
754        GetSelection notebook,ListWin,3
755        //remove the selected item from the list
756        String list = root:myGlobals:Protocols:gReduceList
757        list = RemoveFromList(S_selection,list,",")
758        String/G root:myGlobals:Protocols:gReduceList = list
759       
760        ShowList()
761End
762
763// based on WM PossiblyQuoteList(list, separator)
764//      Input is a list of names that may contain liberal names.
765//      Returns the list with liberal names quoted.
766//      Example:
767//              Input:          "wave0;wave 1;"
768//              Output:         "wave0;'wave 1';"
769//      The list is expected to be a standard separated list, like "wave0;wave1;wave2;".
770//*****unused*******
771Function/S PossiblyQuoteFileList(list, separator)
772        String list
773        String separator
774       
775        String item, outputList = ""
776        Variable ii= 0
777        Variable items= ItemsInList(list, separator)
778        do
779                if (ii >= items)                        // no more items?
780                        break
781                endif
782                item= StringFromList(ii, list, separator)
783                outputList += PossiblyQuoteName(item) + separator
784                ii += 1
785        while(1)
786        return outputList
787End
788
Note: See TracBrowser for help on using the repository browser.