source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/DisplayUtils.ipf @ 779

Last change on this file since 779 was 777, checked in by srkline, 12 years ago

Un-doing the "fix" of DisplayUtils? since this caused more problems than I expected.

Fixed the ILL_DataReadWrite ReadHeaderAndWork?() to properly keep the data on linear scale upon loading, which is the default.

File size: 9.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//*********************
6// Vers 1.2 090501
7//
8//*********************
9//
10// Utility procedures for displaying workfiles from data folders and
11// conversion utilities for log/linear scaling of data
12// NIH color index is also defined here
13//
14
15
16// plots the data in the "type" folder as a wireframe 3D surface.
17// uses (dynamically) the log/lin scaling of data in the folder
18//
19Proc Plot3DSurface(type)
20        String type
21        Prompt type,"Display 2-D data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;MSK;STO;SUB;DRK;RealTime"
22       
23        //macro will take whatever is in "type" folder
24        //check the contents of "type" to make sure that data exists
25        String wavePath = "root:Packages:NIST:"+type+":data"
26        if(WaveExists($wavePath) == 0)
27                String errString="There is no data in "+type
28                Abort errString
29        Endif
30       
31        PauseUpdate; Silent 1   // Building window...
32
33        // Do nothing if the Surface Plotter XOP is not available.
34        if (exists("CreateSurfer") !=4)
35                DoAlert 0, "Surface Plotter XOP must be installed"
36                return
37        endif
38
39        //creates a default-styled surface plot of the specified data
40        DoWindow/F Surface_3D
41        if(V_flag==0)
42                CreateSurfer
43        Endif
44        MoveWindow 4,44,517,382
45        ModifySurfer  FactoryDefaults, Update=0
46        ModifySurfer/K=1
47        ModifySurfer/N=Surface_3D
48        ModifySurfer/T=wavePath
49        ModifySurfer srcWave=$wavePath 
50        ModifySurfer  srcType=1,plotType=3
51        ModifySurfer  setControlView=3
52        ModifySurfer  theta=37.5,  phi=308.9,  zScale=1,  xStep=4,  yStep=2
53        ModifySurfer  frame=895,  drawFrame=1
54        ModifySurfer  drawBox=1
55        ModifySurfer  drawTicks=5
56        ModifySurfer topRGB={0,0,0},  bottomRGB={30583,30583,30583},  backRGB={65535,65535,65535}
57        ModifySurfer palette=YellowHot
58        ModifySurfer fillFrameRGB={21845,21845,21845}
59        ModifySurfer topContourRGB={0,26214,26214}
60        ModifySurfer gridRGB={0,0,0}
61        ModifySurfer  grids=1
62        ModifySurfer  numContourLevels=15
63        ModifySurfer  marker=19,  markerSize=1,  markerColorType=2
64        ModifySurfer  scatterDepthCue=1
65        ModifySurfer  rotationType=0
66        ModifySurfer  Update=1
67End
68
69//***************
70//a 'fake' version of the NIH "Fire 2" color table, preferable to IGOR's built-in
71//color tables - used by an image plot as a colorIndex wave
72//
73Function NIHColorIndex()
74       
75        Variable numberofColors=8,hi=65535,mid=35000,lo=0,step=16,ii=0,incr=0
76        Make/O/N=((numberOfColors-1)*step,3) $"root:myGlobals:NIHColors"
77        WAVE NIHColors = $"root:myGlobals:NIHColors"
78       
79        ii=0
80        incr = 0
81        do
82                NIHColors[ii+incr][0] = lo              //black to blue
83                NIHColors[ii+incr][1] = lo
84                NIHColors[ii+incr][2] = lo + (hi-lo)/step*ii
85                ii+=1
86        while(ii<step)
87       
88        ii=0
89        incr = step
90        do
91                NIHColors[ii+incr][0] = lo      + (mid-lo)/step*ii      //blue to purple
92                NIHColors[ii+incr][1] = lo
93                NIHColors[ii+incr][2] = hi
94                ii+=1
95        while(ii<step) 
96       
97        ii=0
98        incr = 2*step
99        do
100                NIHColors[ii+incr][0] = mid             //purple to magenta
101                NIHColors[ii+incr][1] = lo
102                NIHColors[ii+incr][2] = hi - (hi-mid)/step*ii
103                ii+=1
104        while(ii<step)
105               
106        ii=0
107        incr = 3*step
108        do
109                NIHColors[ii+incr][0] = mid + (hi-mid)/step*ii          //magenta to red
110                NIHColors[ii+incr][1] = lo
111                NIHColors[ii+incr][2] = mid - (mid-lo)/step*ii
112                ii+=1
113        while(ii<step)
114               
115        ii=0
116        incr = 4*step
117        do
118                NIHColors[ii+incr][0] = hi              //red to orange
119                NIHColors[ii+incr][1] = lo + (mid-lo)/step*ii
120                NIHColors[ii+incr][2] = lo
121                ii+=1
122        while(ii<step)
123               
124        ii=0
125        incr = 5*step
126        do
127                NIHColors[ii+incr][0] = hi              //orange to yellow
128                NIHColors[ii+incr][1] = mid + (hi-mid)/step*ii
129                NIHColors[ii+incr][2] = lo
130                ii+=1
131        while(ii<step)
132               
133        ii=0
134        incr = 6*step
135        do
136                NIHColors[ii+incr][0] = hi              //yellow to white
137                NIHColors[ii+incr][1] = hi
138                NIHColors[ii+incr][2] = lo + (hi-lo)/step*ii
139                ii+=1
140        while(ii<step)
141               
142        return(0)
143End
144
145// given a max and min Z-value (intensity), rescales the color wave to match the scale
146// - used every time a new image is plotted or for every scale change (sliders, log/lin...)
147Function ScaleColorsToData(zmin,zmax,colorWave)
148        Variable zmin,zmax
149        Wave colorWave
150       
151        SetScale/I x,zmin,zmax,colorWave
152       
153        return(0)
154End
155
156//*****************
157//unused procedure
158//
159Proc QuickViewFile(type)
160        String type
161        Prompt type,"Display 2-D data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;MSK;"
162       
163        //macro will take whatever is in "type" folder
164        //check for data existence
165        //and set it to the current display, in a separate image window
166       
167        if(cmpstr(type,"file") == 0)
168                //ask for a file
169                //?how do I know what type of data it is? - there are 3 choices - RAW,DIV,MASK
170                //that all must be read in differently
171               
172                //String fname = PromptForPath("Select file")
173                Print "file option currently not operational"
174        else
175                //check the contents of "type" to make sure that data exists
176                String wavePath = "root:Packages:NIST:"+type+":data"
177                if(WaveExists($wavePath) == 0)
178                        String errString="There is no data in "+type
179                        Abort errString
180                Endif
181               
182                NewImage/F/S=2/K=1 $wavePath
183                ModifyImage '' ctab= {*,*,YellowHot,0}          // '' will modify the first (only) image instance
184        Endif
185       
186        //back to root folder (redundant)
187        SetDataFolder root:
188       
189End
190//above is unused
191//*****************
192
193
194// changes the SANS_Data graph window to the selected work (folder), if the data exists
195//
196Proc ChangeDisplay(type)
197        String type
198        Prompt type,"Display WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;SAS;"
199       
200        //macro will take whatever is in "type" folder
201        //check for data existence
202        //and set it to the current display
203       
204        //check the contents of "type" to make sure that data exists
205        String wavePath = "root:Packages:NIST:"+type+":data"
206        if(WaveExists($wavePath) == 0)
207                Abort "There is no data in "+type
208        Endif
209       
210        //reset the current displaytype to "type"
211        String/G root:myGlobals:gDataDisplayType=type
212        ConvertFolderToLinearScale(type)
213        //need to update the display with "data" from the correct dataFolder
214        fRawWindowHook()
215End
216
217//****************
218//this utility function will check the data in a specified folder
219//and convert all of the necessary data, vlegend, and global variables
220//to linear scale
221//*** the global :gIsLogScale is checked first
222//if already linear, nothing is done
223Function ConvertFolderToLinearScale(folder)
224        String folder   
225       
226        String dest = "root:Packages:NIST:"+folder
227        NVAR isLogscale = $(dest + ":gIsLogScale")
228        If(!isLogScale)
229                Return(0)
230        Endif
231        //....the data is logscale, convert it
232        //check the waves for existence before operating on them
233        String msg = ""
234        If(WaveExists($dest+":data") == 0)
235                msg = "data not found in "+folder+" folder. Action aborted."
236                DoAlert 0, msg
237                Return (1)      //error
238        Endif
239
240        Duplicate/O $(dest + ":linear_data") $(dest + ":data")//back to linear scale
241       
242//Call the procedure that would normally be called if the threshold functions were activated
243//      DoWindow/F SANS_Data
244//      If(V_Flag)
245                MapSliderProc("reset", 0, 1)    //MapSlider function now checks for the existence of the SANS_Data graph
246//      Endif
247       
248        Variable/G $(dest + ":gIsLogScale") = 0
249       
250        Return(0)       //all is ok
251End
252
253//this utility function will check the data in a specified folder
254//and convert all of the necessary data, vlegend, and global variables
255//to LOG scale (base 10)
256//*** the global :gIsLogScale is checked first
257//if already log-scale, nothing is done
258//
259// works on a copy of the linear_data, so that the original data is always preserved
260//
261Function ConvertFolderToLogScale(folder)
262        String folder   
263       
264        String dest = "root:Packages:NIST:"+folder
265        NVAR isLogscale = $(dest + ":gIsLogScale")
266//      Print "ConvertFolderToLogScale() -- ",dest," has gIsLogscale = ",isLogScale
267        If(isLogScale)
268                Return(0)
269        Endif
270        //....the data is linear, convert it
271        //check the waves for existence before operating on them
272        String msg = ""
273        If(WaveExists($dest+":data") == 0)
274                msg = "data not found in "+folder+" folder. Action aborted."
275                DoAlert 0, msg
276                Return (1)      //error
277        Endif
278
279        WAVE data=$(dest + ":data")
280       
281        // works on a copy of the linear_data, so that the original data is always preserved
282       
283        Duplicate/O $(dest + ":data") $(dest + ":linear_data")          //wrong way, linear_data not protected
284//              but if the folder is being coverted to log, then "data" is linear
285
286//      Duplicate/O $(dest + ":linear_data") $(dest + ":data")          // right way, but linear_data not always copied to the next step
287
288// if the folder is being coverted to log, then "data" is linear
289        data = log(data)
290       
291        //Call the procedure that would normally be called if the threshold functions were activated
292//      DoWindow/F SANS_Data
293//      If(V_Flag)
294        MapSliderProc("reset", 0, 1)            //MapSlider function now checks for the existence of the SANS_Data graph
295//      Endif
296
297        //set the global
298        Variable/G $(dest + ":gIsLogScale") = 1
299
300        Return(0)       //all is ok
301End
302
303//make sure that the displayed state matches the button
304//text. This should be called separate from ConvertDataFolder...
305Function Fix_LogLinButtonState(state)
306        Variable state
307        //check for existence of SANS_Data window
308        //but don't bring to front
309        if(cmpstr(WinList("SANS_Data",";","WIN:1"),"")==0)
310                return(0)               //SANS_Data display not open, do nothing
311        endif
312        // fix the button if needed
313        //
314        ControlInfo/W=SANS_Data bisLin
315        if(V_flag==0)
316                //button must read "log"
317                if(state==0)
318                        //date is really linear scale
319                        Button $"bisLog",title="isLin",rename=bisLin,win=SANS_Data
320                endif
321        else
322                //button must read "lin"
323                if(state==1)
324                        //data is really log scale
325                        Button $"bisLin",title="isLog",rename=bisLog,win=SANS_Data
326                endif
327        endif
328        return(0)
329End
Note: See TracBrowser for help on using the repository browser.