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

Last change on this file since 80 was 76, checked in by srkline, 16 years ago

2nd pass of pulling out NCNR calls. Also cleared a lot of deadwood from the code, removing depricated functions that were mostly already commented out.

File size: 18.5 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 100901
7//
8//***************************
9
10//Procedures to create a layout of 2D raw data files selected from a list.
11//2D data files are log or linear scale, selected on the panel. The min/max range of the Z-scale (counts)
12// can be fixed so that all images are on a directly comparable scale.
13//New or existing layouts can be used.
14//Graphics are repeatedly read in to the "RAW" folder, then saved to the Clipboard
15//as PNG files (note that the Demo version of IGOR can't do this operation) to be
16//appended to the seelcted layout. Graphics are sequentially named with the suffix "L_PNG"
17//created layouts are killed along with the graphics files in memory when the panel is killed
18//********************
19// Also contains procedures for a simple panel for 2d export of data files (especially raw data)
20//
21//
22
23// initializes data folder and waves needed for the panel (contains a listbox)
24Proc Init_Tile()
25        //create the data folder
26        NewDataFolder/O/S root:myGlobals:Tile_2D
27        //create the waves
28        Make/O/T/N=1 fileWave=""
29        Make/O/N=1 selWave=0
30        Variable/G ind=0
31        Variable/G minScale=0
32        Variable/G maxScale=100
33        SetDataFolder root:
34End
35
36// main procedure to call to bring up the panel
37// re-initializes necessary folders and waves
38Proc Show_Tile_2D_Panel()
39        DoWindow/F Tile_2D
40        if(V_Flag==0)
41                Init_Tile()
42                Tile_2D()
43        endif
44End
45
46//procedure to draw the "tile" panel
47Proc Tile_2D()
48        PauseUpdate; Silent 1           // building window...
49        NewPanel /K=2 /W=(550,342,934,527)
50        DoWindow/C Tile_2D
51       
52        ListBox fileList,pos={4,3},size={206,179}
53        ListBox fileList,listWave=root:myGlobals:Tile_2D:fileWave
54        ListBox fileList,selWave=root:myGlobals:Tile_2D:selWave,mode= 4
55        Button button0,pos={233,131},size={110,20},proc=AddToLayoutButtonProc,title="Add To Layout"
56        Button button0,help={"Adds images of the selected files to the layout selected in the popup menu"}
57        Button button1,pos={266,157},size={50,20},proc=TileDoneButtonProc,title="Done"
58        Button button1,help={"Closes the panel, kills the layouts, and kills images from your memory"}
59        Button button3,pos={227,6},size={60,20},proc=GetListButtonProc,title="Get List"
60        Button button3,help={"Refreshes the list of data files"}
61        Button button4,pos={340,6},size={25,20},proc=ShowTileHelp,title="?"
62        Button button4,help={"Show help file for tiling raw data files in a layout"}
63        CheckBox check0,pos={216,64},size={71,14},title="Log scaling"
64        CheckBox check0,help={"If checked, the image color will be log scale"},value= 1
65        PopupMenu popup0,pos={226,38},size={141,20},title="Layout ?"
66        PopupMenu popup0,help={"Sets a new or existing layout as the destination when adding images"}
67        PopupMenu popup0,mode=1,popvalue="New Layout",value= #"\"New Layout;\"+WinList(\"*\", \";\",\"WIN:4\")"
68        CheckBox check1,pos={216,86},size={72,14},proc=FixScale_CheckProc,title="Fixed Scale"
69        CheckBox check1,value= 0,help={"Sets a fixed z-scale (counts) for all images in the layout. Enter the min and max values"}
70        SetVariable scale_0,pos={216,105},size={80,15},title="min"
71        SetVariable scale_0,limits={-Inf,Inf,0},value= root:myGlobals:Tile_2D:minScale
72        SetVariable scale_0,help={"Minimum mapped count value"},disable=1               //initially not visible
73        SetVariable scale_1,pos={300,105},size={80,15},title="max"
74        SetVariable scale_1,limits={-Inf,Inf,0},value=root:myGlobals:Tile_2D:maxScale
75        SetVariable scale_1,help={"Maximum mapped count value"},disable=1               //initially not visible
76EndMacro
77
78Function ShowTileHelp(ctrlName) : ButtonControl
79        String ctrlName
80        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Tile 2-D Images]"
81end
82
83Function FixScale_CheckProc(ctrlName,checked) : CheckBoxControl
84        String ctrlName
85        Variable checked
86
87//      Print "fix scale =",checked
88        //Tile_2D panel must be on top, since it's being checked
89        SetVariable scale_0,disable=(!checked)
90        SetVariable scale_1,disable=(!checked)
91End
92
93
94// upon hitting the "add to layout" button...
95// polls the selected file(s) in the listbox and sequentially loads each
96// file into RAW folder, and makes a PNG of the file, and appends each to the selected layout
97// ...see SetGraphic() in Schematic.ipf
98Function AddToLayoutButtonProc(ctrlName) : ButtonControl
99        String ctrlName
100
101        ControlInfo popup0
102        String layoutStr=S_Value        //create new layout or append to old one
103       
104        ControlInfo check0
105        Variable makeLog=V_Value        //make the images logscale?
106       
107        ControlInfo check1
108        Variable fixScale=V_Value       //use fixed, user-defined scale
109       
110        Variable minScale,maxScale
111        NVAR mns=root:myGlobals:Tile_2D:minScale
112        NVAR mxs=root:myGlobals:Tile_2D:maxScale
113        if(fixScale==1)
114                if(makeLog==1)
115                //check for zero
116                        if((mns<=0) || (mxs<=0) )
117                                Abort "min and max scale must be greater than zero for log-scaling"
118                        endif
119                        minScale=log(mns)
120                        maxScale=log(mxs)
121                else
122                        minScale=mns
123                        maxScale=mxs
124                endif
125        else
126                minScale = -1
127                maxScale = -1           //if both are equal, autoscale data
128        endif
129       
130        //loop through the selected files in the list...
131        Wave/T fileWave=$"root:myGlobals:Tile_2D:fileWave"
132        Wave sel=$"root:myGlobals:Tile_2D:selWave"
133        NVAR ind=root:myGlobals:Tile_2D:ind
134        Variable num=numpnts(sel),ii=0,err=0,startInd=ind,shift
135        Variable ht=1.5,wd=1.5          //height and width of the graphic (in inches)
136        String fname="",pathStr=""
137       
138        PathInfo catPathName                    //this is where the files are
139        pathStr=S_path
140       
141        // get the current state
142        NVAR defaultScaling = root:myGlobals:gLogScalingAsDefault
143        Variable oldState = defaultScaling
144        defaultScaling = 0              //set the scaling to linear
145       
146        do
147                if(sel[ii] == 1)
148                        fname=pathStr + FindValidFilename(fileWave[ii]) //in case of VAX version numbers
149                        ReadHeaderAndData(fname)                //fname is the full path
150                        String/G root:myGlobals:gDataDisplayType="RAW" 
151                        fRawWindowHook()
152                        if(makeLog)
153                                err = ConvertFolderToLogScale("RAW")
154                        endif
155                        MakePNGforLayout(minScale,maxScale,"RAW",ind)
156                        ind+=1                  //a running count of all of the PNG's
157                endif
158                ii+=1
159        while(ii<num)
160        //close the SANS_Data window
161        DoWindow/K SANS_Data
162       
163        //now add to the appropriate layout
164        if(cmpstr(layoutStr,"New Layout")==0)
165                NewLayout
166                DoWindow/C $("PNGLayout"+num2str(ind))
167        else   
168                DoWindow/F $layoutStr
169        endif
170        for(ii=startInd;ii<ind;ii+=1)
171                AppendLayoutObject/F=1/R=(72,40,144,112) picture $("RAW"+num2str(ii)+"L_PNG")
172                ModifyLayout top($("RAW"+num2str(ii)+"L_PNG"))=(40+mod(30*ii,560))      //separate the graphics (in points)
173                ModifyLayout/I width($("RAW"+num2str(ii)+"L_PNG"))=(wd),height($("RAW"+num2str(ii)+"L_PNG"))=(wd) //(in inches)
174        endfor
175        //maybe don't tile or stack the objects in the layout - it alters the aspect ratio
176        Variable totalNumPNGs = itemsinlist(PICTList("*L_PNG", ";", "WIN:"))
177        String rcStr="/A=(4,3)"
178//      Print totalNumPNGs
179        if(totalNumPNGs>12)
180                rcStr="/A=(5,4)"
181        endif
182        if(totalNumPNGs>20)
183                rcStr="/A=(7,5)"
184        endif
185        if(totalNumPNGs>35)
186                rcStr="/A=(8,5)"
187        endif
188        if(totalNumPNGs>40)
189                rcStr=""
190        endif
191        Execute "Tile"+rcStr+"/O=8"
192       
193        defaultScaling = oldState               //set the scaling back to the previous state
194        return(0)
195End
196
197// upon hitting the "add to layout" button...
198// loads all of the data files in the list
199// file into RAW folder, and makes a PNG of the file, and appends each to the selected layout
200// ...see SetGraphic() in Schematic.ipf
201// This test version will add 40 images to each layout, and tile them
202//
203// curently a Beta-only function
204//
205Function AddALLToLayout()// : ButtonControl
206        String ctrlName
207
208        DoWindow/F Tile_2D
209        if(V_flag==0)
210                DoAlert 0,"You must have the Tile_2D panel open to use this operation"
211                Return(0)
212        endif
213       
214        //pop the file list to get a current list
215        GetListButtonProc("")
216       
217        //tile_2d will now be the top window, but check anyways, since this is not called from a button control
218        ControlInfo/W=Tile_2D popup0
219        String layoutStr=S_Value        //create new layout or append to old one
220       
221        ControlInfo/W=Tile_2D check0
222        Variable makeLog=V_Value        //make the images logscale?
223       
224        ControlInfo/W=Tile_2D check1
225        Variable fixScale=V_Value       //use fixed, user-defined scale
226       
227        Variable minScale,maxScale
228        NVAR mns=root:myGlobals:Tile_2D:minScale
229        NVAR mxs=root:myGlobals:Tile_2D:maxScale
230        if(fixScale==1)
231                if(makeLog==1)
232                //check for zero
233                        if((mns<=0) || (mxs<=0) )
234                                Abort "min and max scale must be greater than zero for log-scaling"
235                        endif
236                        minScale=log(mns)
237                        maxScale=log(mxs)
238                else
239                        minScale=mns
240                        maxScale=mxs
241                endif
242        else
243                minScale = -1
244                maxScale = -1           //if both are equal, autoscale data
245        endif
246       
247        //loop through the selected files in the list...
248        Wave/T fileWave=$"root:myGlobals:Tile_2D:fileWave"
249        Wave sel=$"root:myGlobals:Tile_2D:selWave"
250        NVAR ind=root:myGlobals:Tile_2D:ind             //largest index of the PNG files currently in memory
251        Variable num,ii=0,err=0,startInd,shift
252        Variable ht=1.5,wd=1.5          //height and width of the graphic (in inches)
253        String fname="",pathStr=""
254        Variable numPerLayout=40                        //number of images per layout
255       
256        num=numpnts(fileWave)           //total number of files
257        startind = ind                                  //this layout(s) PNG files start with this index
258       
259        PathInfo catPathName                    //this is where the files are
260        pathStr=S_path
261       
262        // get the current state
263        NVAR defaultScaling = root:myGlobals:gLogScalingAsDefault
264        Variable oldState = defaultScaling
265        defaultScaling = 0              //set the scaling to linear
266       
267        //make all of the PNG files
268        do
269                fname=pathStr + FindValidFilename(fileWave[ii]) //in case of VAX version numbers
270                ReadHeaderAndData(fname)                //fname is the full path
271                String/G root:myGlobals:gDataDisplayType="RAW" 
272                fRawWindowHook()
273                if(makeLog)
274                        err = ConvertFolderToLogScale("RAW")
275                endif
276                MakePNGforLayout(minScale,maxScale,"RAW",ind)
277                ind+=1                  //a running count of all of the PNG's
278
279                ii+=1
280        while(ii<num)
281        //close the SANS_Data window
282        DoWindow/K SANS_Data
283       
284        //now add to the appropriate layout(s)
285       
286//      if(cmpstr(layoutStr,"New Layout")==0)
287//              NewLayout
288//              DoWindow/C $("PNGLayout"+num2str(ind))
289//      else   
290//              DoWindow/F $layoutStr
291//      endif
292        Variable jj
293       
294        NewLayout
295        DoWindow/C $("PNGLayout"+num2str(startInd))
296        for(ii=startInd;ii<ind;ii+=numPerLayout)
297                jj=ii
298                do
299                        AppendLayoutObject/F=1/R=(72,40,144,112) picture $("RAW"+num2str(jj)+"L_PNG")
300                        ModifyLayout/I width($("RAW"+num2str(jj)+"L_PNG"))=(wd),height($("RAW"+num2str(ii)+"L_PNG"))=(wd) //(in inches)
301                        jj+=1
302                while( (jj<ii+numPerLayout) && (jj<ind) )       //index in batch, keep from running over total number of PNGs
303                Execute "Tile/O=8"              //done with this layout
304                if(jj<ind)              //need another layout
305                        NewLayout
306                        DoWindow/C $("PNGLayout"+num2str(jj))
307                endif
308        endfor
309        Execute "Tile/O=8"              //tile the last layout
310       
311        defaultScaling = oldState               //set the scaling back to the previous state
312        return(0)
313End
314
315
316//filters to keep onle the files that are named like a raw data file, i.e. "*.SAn"
317//does not check to see if they really are RAW files though...(too slow)
318// ... if the filename does NOt have "SA1","SA2", or "SA3" in the name (anywhere)
319// the files will NOT show up in the list box
320//
321Function GetListButtonProc(ctrlName) : ButtonControl
322        String ctrlName
323       
324        //make sure that path exists
325        PathInfo catPathName
326        if (V_flag == 0)
327                Abort "Folder path does not exist - use Pick Path button on Main Panel"
328        Endif
329       
330        String newList=""
331        Variable num
332
333        newList = GetRawDataFileList()
334       
335        num=ItemsInList(newlist,";")
336        WAVE/T fileWave=$"root:myGlobals:Tile_2D:fileWave"
337        WAVE selWave=$"root:myGlobals:Tile_2D:selWave"
338        Redimension/N=(num) fileWave
339        Redimension/N=(num) selWave
340        fileWave = StringFromList(p,newlist,";")
341        Sort filewave,filewave
342End
343
344// procedure called when user is done
345// deletes all of the graphs, layouts, etc associated with the files that were read in...
346//to free up memory and cluttered space
347//
348//since panel and graphics are killed, gives the user a chance to reconsider
349Function TileDoneButtonProc(ctrlName) : ButtonControl
350        String ctrlName
351
352        DoAlert 1,"Closing the panel will kill the created Layouts. Do you want to continue?"
353        if(V_Flag==2)
354                return(0)
355        endif
356       
357        String pngList=PICTList("*L_PNG",";",""),item=""
358        String ltList=WinList("PNGLayout*", ";","WIN:4")                //default named layout windows
359        Variable ii,num
360       
361        //close the layouts, then kill the PNG's
362        num=ItemsinList(ltList,";")
363        for(ii=0;ii<num;ii+=1)
364                item=StringFromList(ii,ltList,";")
365                DoWindow/K $item
366        endfor
367       
368        num=ItemsinList(pngList,";")
369        for(ii=0;ii<num;ii+=1)
370                item=StringFromList(ii,pngList,";")
371                KillPICTs/Z $item
372        endfor
373        //kill the panel, and reset the globals
374        DoWindow/K Tile_2D
375        Execute "Init_Tile()"
376        return(0)
377End
378
379// data has laready been loaded into RAW folder
380// make a PNG file by first creating a small graph, then save the graph to the  clipboard,
381// and then load it back in from the clipboard in to memory
382// (from memory it can be easily appended to a layout)
383//
384// if minScale and maxScale are equal, data will be (individually) autoscaled
385// if minScale and maxScale are unequal, all sets will be scaled to those values
386//
387Function MakePNGforLayout(minScale,maxScale,type,ii)
388        Variable minScale,maxScale
389        String type
390        Variable ii
391       
392        if(!WaveExists($"root:myGlobals:NIHColors"))
393                NIHColorIndex()
394        Endif
395       
396        WAVE NIHColors = $"root:myGlobals:NIHColors"
397        WAVE data = $("root:"+type+":data")
398        String nameStr = type +num2str(ii)+ "L_PNG"
399
400        PauseUpdate; Silent 1           // building window...
401        Display /W=(40,40,196,196)
402        //plot and name the picture, then kill it
403        AppendImage data
404        DoWindow/C temp_png
405        if(minScale==maxScale)
406                WaveStats/Q data
407                minScale=V_min
408                maxScale=V_max
409        Endif
410        ScaleColorsToData(minScale, maxScale, NIHColors)
411        ModifyImage data cindex=NIHColors
412        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
413        ModifyGraph nticks=4
414        ModifyGraph minor=1
415        ModifyGraph fSize=9
416        ModifyGraph standoff=0
417        ModifyGraph tkLblRot(left)=90
418        ModifyGraph btLen=3
419        ModifyGraph tlOffset=-2
420        SVAR fileStr = $("root:"+type+":fileList")
421        Textbox/N=text0/F=0/A=MT/X=0.00/Y=0.00/E fileStr
422       
423// comment out the line below for DEMO_MODIFIED version
424        SavePICT/Z/E=-5 as "Clipboard"          //saves as PNG format
425       
426        LoadPICT/O/Q "Clipboard",$nameStr
427        DoWindow/K temp_png
428        return(0)
429End
430
431
432//******************
433//procedures to display a simple panel to export a list of files as ASCII
434//******************
435
436// initialization procedure to create the necessary data floder and the waves for
437// the list box in the panel
438Proc Init_RawExport()
439        //create the data folder
440        NewDataFolder/O/S root:myGlobals:RAW2ASCII
441        //create the waves
442        Make/O/T/N=1 fileWave=""
443        Make/O/N=1 selWave=0
444        Variable/G ind=0
445        SetDataFolder root:
446End
447
448// main procedure for invoking the raw to ascii panel
449// initializes each time to make sure
450Proc Export_RAW_Ascii_Panel()
451        Init_RawExport()
452        DoWindow/F RAW_to_ASCII
453        if(V_Flag==0)
454                RAW_to_ASCII()
455        endif
456End
457
458//procedure for drawing the simple panel to export raw->ascii
459//
460Proc RAW_to_ASCII()
461        PauseUpdate; Silent 1           // building window...
462        NewPanel /W=(501,97,885,282) /K=2
463        DoWindow/C RAW_to_ASCII
464        ListBox fileList,pos={4,3},size={206,179}
465        ListBox fileList,listWave=root:myGlobals:RAW2ASCII:fileWave
466        ListBox fileList,selWave=root:myGlobals:RAW2ASCII:selWave,mode= 4
467        Button button0,pos={239,112},size={110,20},proc=RA_ExportButtonProc,title="Export File(s)"
468        Button button0,help={"Exports (saves to disk) the selected files as ASCII format"}
469        Button button1,pos={270,156},size={50,20},proc=RawExportDoneButtonProc,title="Done"
470        Button button1,help={"Closes the panel"}
471        Button button3,pos={230,16},size={60,20},proc=RA_GetListButtonProc,title="Get List"
472        Button button3,help={"Refreshes the file listing"}
473        Button button4,pos={330,16},size={25,20},proc=ShowRawExportHelp,title="?"
474        Button button4,help={"Show the help file for 2-D export of raw data files"}
475        CheckBox check0,pos={242,66},size={115,14},title="detector coordinates",value= 1,mode=1
476        CheckBox check0,proc=RA_ExportCheckProc
477        CheckBox check1,pos={242,82},size={104,14},title="Qx,Qy coordinates",value= 0,mode=1
478        CheckBox check1,proc=RA_ExportCheckProc
479EndMacro
480
481Function RA_ExportCheckProc(ctrlName,checked) : CheckBoxControl
482        String ctrlName
483        Variable checked
484
485        strswitch (ctrlName)
486                case "check0":
487                        CheckBox check0,value=1
488                        CheckBox check1,value=0
489                        break
490                case "check1":
491                        CheckBox check0,value=0
492                        CheckBox check1,value=1
493        endswitch
494        return(0)
495End
496
497
498//closes the panel when done
499Function RawExportDoneButtonProc(ctrlName) : ButtonControl
500        String ctrlName
501
502        //kill the panel
503        DoWindow/K RAW_to_ASCII
504        return(0)
505End
506
507//filters to keep onle the files that are named like a raw data file, i.e. "*.SAn"
508//does not check to see if they really are RAW files though...(too slow)
509Function RA_GetListButtonProc(ctrlName) : ButtonControl
510        String ctrlName
511       
512        //make sure that path exists
513        PathInfo catPathName
514        if (V_flag == 0)
515                Abort "Folder path does not exist - use Pick Path button on Main Panel"
516        Endif
517       
518        Variable num
519        String newList = GetRawDataFileList()
520       
521        num=ItemsInList(newlist,";")
522        WAVE/T fileWave=$"root:myGlobals:RAW2ASCII:fileWave"
523        WAVE selWave=$"root:myGlobals:RAW2ASCII:selWave"
524        Redimension/N=(num) fileWave
525        Redimension/N=(num) selWave
526        fileWave = StringFromList(p,newlist,";")
527        Sort filewave,filewave
528End
529
530// does a Fast2DExport of the files selected from the listbox
531//polls the listbox for selected files and loops through each selection
532//exported file is filename + ".ASC" if an ascii detector image
533// or ".DAT" if it is in Qx, Qy, I(Qx,Qy) triple format
534//
535// temporarily change the default logScale display to linear during export
536//
537Function RA_ExportButtonProc(ctrlName) : ButtonControl
538        String ctrlName
539       
540        //loop through the selected files in the list...
541        Wave/T fileWave=$"root:myGlobals:RAW2ASCII:fileWave"
542        Wave sel=$"root:myGlobals:RAW2ASCII:selWave"
543        Variable num=numpnts(sel),ii=0,qxqy=0
544        String fname="",pathStr="",fullPath="",newFileName=""
545       
546        PathInfo catPathName                    //this is where the files are
547        pathStr=S_path
548       
549        //what type of export? check1 is qxqy
550        ControlInfo check1
551        qxqy=V_Value            //==1 if qxqy desired
552       
553        // get the current state
554        NVAR defaultScaling = root:myGlobals:gLogScalingAsDefault
555        Variable oldState = defaultScaling
556        defaultScaling = 0              //set the scaling to linear
557        do
558                if(sel[ii] == 1)
559                        fname=pathStr + FindValidFilename(fileWave[ii])         //in case of VAX version numbers
560                        ReadHeaderAndData(fname)                //fname is the full path
561                        String/G root:myGlobals:gDataDisplayType="RAW" 
562                        fRawWindowHook()
563                        WAVE/T/Z tw = $"root:RAW:textRead"      //to be sure that wave exists if no data was ever displayed
564                        newFileName= GetNameFromHeader(tw[0])
565                        if(qxqy==1)
566                                fullPath=pathStr+newFileName+".DAT"
567                                QxQy_Export("RAW",fullpath,0)
568                        else
569                                fullPath=pathStr+newFileName+".ASC"
570                                Fast2dExport("RAW",fullpath,0)
571                        endif
572                endif
573                ii+=1
574        while(ii<num)
575       
576        defaultScaling = oldState               //set the scaling back to what it was
577        return(0)
578End
579
580Function ShowRawExportHelp(ctrlName) : ButtonControl
581        String ctrlName
582        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[2-D ASCII Export]"
583end
Note: See TracBrowser for help on using the repository browser.