source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/RealTimeUpdate_RT.ipf @ 486

Last change on this file since 486 was 486, checked in by ajj, 13 years ago

Changes to make RealTime? update work with new location for live data

File size: 25.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.0
4
5//*****************************
6// Vers. 1.0 100401
7//
8// hook function and associated procedures that interact with the user
9// and the RealTime_SANS window
10// -displays pixel counts
11// - displays Q, qx, qy values
12// - displays q axes and pixel axes
13//
14// - of course, displays the detector image, w/ nice colors, legend, sliders to adjust color mapping
15// and a control bar to let the user adjust scaling, do averaging...
16//
17// as of 110101, the help file has not been written
18//
19//*****************************
20
21// takes care of all of the necessary initialization for the RT control process
22// creates the folders, etc. that are needed for the SANS reduction package as well, but the end user
23// doesn't need to see this.
24//
25// only used for testing - as this will re-initialize everything, including globals used as preferences
26//
27Proc Init_for_RealTime()
28        // initialize the reduction folders as for normal SANS Reduction, but don't draw the main Reduction control panel
29        InitFolders()
30        InitFakeProtocols()
31        InitGlobals()
32        InitFacilityGlobals()
33
34        // specific for RealTime display
35        //set the current display type to RealTime
36        String/G root:myGlobals:gDataDisplayType = "RealTime"
37        // draw the RealTime control panel
38        Show_RealTime_Panel()
39End
40
41// Proc to bring the RT control panel to the front, always initializes the panel
42// - always initialize to make sure that the background task is properly set
43//
44Proc Show_RealTime_Panel()
45        Init_RT()               //always init, data folders and globals are created here
46        DoWindow/F RT_Panel
47        if(V_flag==0)
48                RT_Panel()
49        Endif
50End
51
52// folder and globals that are needed ONLY for the RT process
53//
54Function Init_RT()
55        //create folders
56        NewDataFolder/O root:Packages:NIST:RealTime
57        NewDataFolder/O/S root:myGlobals:RT
58        //create default globals only if they don't already exist, so you don't overwrite user-entered values.
59        NVAR xCtr=xCtr
60        if(NVAR_Exists(xctr)==0)
61                Variable/G xCtr=110                     //pixels
62        endif
63        NVAR yCtr=yCtr
64        if(NVAR_Exists(yCtr)==0)
65                Variable/G yCtr=64
66        endif
67        NVAR SDD=SDD
68        if(NVAR_Exists(SDD)==0)
69                Variable/G SDD=3.84                                     //in meters
70        endif
71        NVAR lambda=lambda
72        if(NVAR_Exists(lambda)==0)
73                Variable/G lambda=6                             //angstroms
74        endif
75        NVAR updateInt=updateInt
76        if(NVAR_Exists(updateInt)==0)
77                Variable/G updateInt=5                  //seconds
78        endif
79        NVAR timeout=timeout
80        if(NVAR_Exists(timeout)==0)
81                Variable/G timeout=300          //seconds
82        endif
83        NVAR elapsed=elapsed
84        if(NVAR_Exists(elapsed)==0)
85                Variable/G elapsed=0
86        endif
87        NVAR totalCounts=totalCounts            //total detector counts
88        if(NVAR_Exists(totalCounts)==0)
89                Variable/G totalCounts=0
90        endif
91       
92        // set the explicit path to the data file on "relay" computer (the user will be propmted for this)
93        SVAR RT_fileStr=RT_fileStr
94        if(SVAR_Exists(RT_fileStr)==0)
95                String/G RT_fileStr=""
96        endif
97
98        // set the background task
99        AssignBackgroundTask()
100       
101        SetDataFolder root:
102End
103
104//sets the background task and period (in ticks)
105//
106Function AssignBackgroundTask()
107
108        Variable updateInt=NumVarOrDefault("root:myGlobals:RT:updateInt",5)
109        // set the background task
110        SetBackground BkgUpdateHST()
111        CtrlBackground period=(updateInt*60),noBurst=1          //noBurst prevents rapid "catch-up calls
112        return(0)
113End
114
115//draws the RT panel and enforces bounds on the SetVariable controls for update period and timeout
116//
117Proc RT_Panel()
118        PauseUpdate; Silent 1           // building window...
119        NewPanel /W=(300,350,602,480) /K=2
120        DoWindow/C RT_Panel
121        DoWindow/T RT_Panel,"Real Time Display Controls"
122        ModifyPanel cbRGB=(65535,52428,6168)
123        SetDrawLayer UserBack
124        SetDrawEnv fstyle= 1
125        DrawText 26,21,"Enter values for real-time display"
126        Button bkgStart,pos={171,54},size={120,20},proc=UpdateHSTButton,title="Start Updating"
127        Button bkgStart,help={"Starts or stops the updating of the real-time SANS image"}
128//      SetVariable setvar_0,pos={15,29},size={100,15},proc=RT_Param_SetVarProc,title="X Center"
129//      SetVariable setvar_0,help={"Set this to the current beamcenter x-coordinate (in pixels)"}
130//      SetVariable setvar_0,limits={0,128,0},value= root:myGlobals:RT:xCtr
131//      SetVariable setvar_1,pos={14,46},size={100,15},proc=RT_Param_SetVarProc,title="Y Center"
132//      SetVariable setvar_1,help={"Set this to the current beamcenter y-coordinate (in pixels)"}
133//      SetVariable setvar_1,limits={0,128,0},value= root:myGlobals:RT:yCtr
134//      SetVariable setvar_2,pos={14,64},size={100,15},proc=RT_Param_SetVarProc,title="SDD (m)"
135//      SetVariable setvar_2,help={"Set this to the sample-to-detector distance of the current instrument configuration"}
136//      SetVariable setvar_2,limits={0,1600,0},value= root:myGlobals:RT:SDD
137//      SetVariable setvar_3,pos={15,82},size={100,15},proc=RT_Param_SetVarProc,title="Lambda (A)"
138//      SetVariable setvar_3,help={"Set this to the wavelength of the current instrument configuration"}
139//      SetVariable setvar_3,limits={0,30,0},value= root:myGlobals:RT:lambda
140        SetVariable setvar_4,pos={11,31},size={150,20},proc=UpdateInt_SetVarProc,title="Update Interval (s)"
141        SetVariable setvar_4,help={"This is the period of the update"}
142        SetVariable setvar_4,limits={1,3600,0},value= root:myGlobals:RT:updateInt
143        SetVariable setvar_5,pos={11,56},size={150,20},title="Timeout Interval (s)"
144        SetVariable setvar_5,help={"After the timeout interval has expired, the update process will automatically stop"}
145        SetVariable setvar_5,limits={1,3600,0},value= root:myGlobals:RT:timeout
146        Button button_1,pos={170,29},size={120,20},proc=LoadRTButtonProc,title="Load Live Data"
147        Button button_1,help={"Load the data file for real-time display"}
148        Button button_2,pos={250,2},size={30,20},proc=RT_HelpButtonProc,title="?"
149        Button button_2,help={"Display the help file for real-time controls"}
150        //Button button_3,pos={230,80},size={60,20},proc=RT_DoneButtonProc,title="Done"
151        //Button button_3,help={"Closes the panel and stops the updating process"}
152        SetVariable setvar_6,pos={11,82},size={200,20},title="Total Detector Counts"
153        SetVariable setvar_6,help={"Total counts on the detector, as displayed"}
154        SetVariable setvar_6,limits={0,Inf,0},value= root:myGlobals:RT:totalCounts
155EndMacro
156
157//
158Proc RT_HelpButtonProc(ctrlName) : ButtonControl
159        String ctrlName
160//      DoAlert 0,"the help file has not been written yet :-("
161        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Real Time Data Display]"
162End
163
164//close the panel gracefully, and stop the background task if necessary
165//
166Proc RT_DoneButtonProc(ctrlName) : ButtonControl
167        String ctrlName
168       
169        BackgroundInfo
170        if(V_Flag==2)           //task is currently running
171                CtrlBackground stop
172        endif
173        DoWindow/K RT_Panel
174End
175
176//prompts for the RT data file - only needs to be set once, then the user can start/stop
177//
178Function LoadRTButtonProc(ctrlName) : ButtonControl
179        String ctrlName
180
181        DoAlert 0,"The RealTime detector image is located on charlotte"
182        Read_RT_File("Select the Live Data file")
183        return(0)
184End
185
186// Sets "fake" header information to allow qx,qy scales on the graph, and to allow
187// averaging to be done on the real-time dataset
188//
189// keep in mind that only the select bits of header information that is USER-SUPPLIED
190// on the panel is available for calculations. The RT data arrives at the relay computer
191// with NO header, only the 128x128 data....
192//
193// see also FillFakeHeader() for a few constant header values ...
194//
195//
196// check on a case-by-case basis
197Function RT_Param_SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
198        String ctrlName
199        Variable varNum
200        String varStr
201        String varName
202
203        Wave rw=$"root:Packages:NIST:RealTime:RealsRead"
204        if(WaveExists(rw)==0)
205                return(1)
206        Endif
207        strswitch(ctrlName)     // string switch
208                case "setvar_0":                //xCtr
209                        rw[16]=varNum
210                        break   
211                case "setvar_1":                //yCtr
212                        rw[17]=varNum
213                        break   
214                case "setvar_2":                //SDD
215                        rw[18]=varNum
216                        break
217                case "setvar_3":                //lambda
218                        rw[26]=varNum
219                        break
220        endswitch
221        //only update the graph if it is open, and is a RealTime display...
222        if(WinType("SANS_Data")==0)
223                return(0) //SANS_Data window not open
224        Endif
225        SVAR type=root:myGlobals:gDataDisplayType
226        if(cmpstr("RealTime",type)!=0)
227                return(0)               //display not RealTime
228        Endif
229        fRawWindowHook()                //force a redraw of the graph
230        DoWindow/F RT_Panel             //return panel to the front
231        return(0)
232End
233
234// (re)-sets the period of the update background task
235//
236Function UpdateInt_SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
237        String ctrlName
238        Variable varNum
239        String varStr
240        String varName
241
242//      BackgroundInfo
243//      if(V_flag==2)
244//              CtrlBackground stop
245//      Endif
246
247        // quite surprised that you can change the period of repeat while the task is active
248        CtrlBackground period=(varNum*60),noBurst=1
249        return(0)
250End
251
252
253/////////////////////////////
254//simple, main entry procedure that will load a HST sans data file (not a work file)
255//into the RealTime dataFolder
256//(typically called from main panel button)
257//
258//(ununsed)
259Proc Load_RT_Data()
260        String msgStr = "Select a RT Ordela data file"
261        Read_RT_File(msgStr)
262End
263
264//function called by the main entry procedure (the load button)
265//sets global display variable, reads in the data, and displays it
266//aborts if no file was selected
267//
268//(re)-sets the GLOBAL path:filename of the RT file to update
269// also resets the path to the RT file, so that the dialog brings you back to the right spot
270//
271// reads the data in if all is OK
272//
273Function Read_RT_File(msgStr)
274        String msgStr
275
276        String filename="",pathStr=""
277        Variable refnum
278
279        //check for the path
280        PathInfo RT_Path
281        If(V_Flag==1)           //      /D does not open the file
282                Open/D/R/T="????"/M=(msgStr)/P=RT_Path refNum
283        else
284                Open/D/R/T="????"/M=(msgStr) refNum
285        endif
286        filename = S_FileName           //get the filename, or null if canceled from dialog
287        if(strlen(filename)==0)
288                //user cancelled, abort
289                SetDataFolder root:
290                Abort "No file selected, action aborted"
291        Endif
292        //set the globals and reset the RT_Path value
293        pathStr = GetPathStrFromfullName(filename)
294        NewPath/O RT_Path,pathStr
295        Variable/G root:Packages:NIST:RealTime:gIsLogScale = 0          //force data to linear scale (1st read)
296        String/G root:myGlobals:RT:RT_fileStr=filename  //full path:file of the Run.hst file to re-read
297        //read in the data
298        //ReadOrdelaHST(filename)
299       
300        //ReadHeaderAndData(filename)
301        //Raw_to_Work("RealTime")
302        ReadRTAndData(filename)
303
304        //the calling macro must change the display type
305        String/G root:myGlobals:gDataDisplayType="RealTime"             //displayed data type is RealTime
306       
307        //FillFakeHeader()              //uses info on the panel, if available
308
309        //data is displayed here, and needs header info
310       
311        fRawWindowHook()
312       
313        // set the SANS_Data graph to "live" mode to allow fast updating
314        //fRawWindowHook just drew the graph, so it should exist
315        ModifyGraph/W=SANS_Data live=1          //not much speed help...
316       
317        return(0)
318End
319
320//function that does the guts of reading the binary data file
321//fname is the full path:name;vers required to open the file
322//The final root:Packages:NIST:RealTime:data wave is the real
323//neutron counts and can be directly used
324//
325//returns 0 if read was ok
326//returns 1 if there was an error
327Function ReadOrdelaHST(fname)
328        String fname
329        //this function is for reading in RealTime data only, so it will always put data in RealTime folder
330        SetDataFolder "root:Packages:NIST:RealTime"     
331        //keep a string with the filename in the RealTime folder
332        String/G root:Packages:NIST:RealTime:fileList = "Real-Time Data Display"
333        //get log/linear state based on SANS_Data window
334        Variable isLogScale=NumVarOrDefault("root:Packages:NIST:RealTime:gIsLogScale", 0)
335        Variable/G root:Packages:NIST:RealTime:gIsLogScale = isLogScale         //creates if needed, "sets" to cur val if already exists
336       
337        Variable refNum=0,ii,p1,p2,tot,num=128
338        String str=""
339        Make/O/T/N=11 hdrLines
340        Make/O/I/N=(num*num) a1         // /I flag = 32 bit integer data
341       
342        //full filename and path is now passed in...
343        //actually open the file
344        Open/R/Z refNum as fname                // /Z flag means I must handle open errors
345        if(refnum==0)           //FNF error, get out
346                DoAlert 0,"Could not find file: "+fname
347                Close/A
348                return(1)
349        endif
350        if(V_flag!=0)
351                DoAlert 0,"File open error: V_flag="+num2Str(V_Flag)
352                Close/A
353                return(1)
354        Endif
355        // as of 12MAY03, the run.hst for real-time display has no header lines (M. Doucet)
356//      for(ii=0;ii<11;ii+=1)           //read (or skip) 11 header lines
357//              FReadLine refnum,str
358//              hdrLines[ii]=str
359//      endfor
360        // 4-byte integer binary data follows, num*num integer values
361        FBinRead/B=3/F=3 refnum,a1
362        //     
363        Close refnum
364       
365        //we want only the first [0,127][0,127] quadrant of the 256x256 image
366        // this is done most quickly by two successive redimension operations
367        // (the duplicate is for testing only)
368        //final redimension can make the data FP if desired..
369        //Redimension/N=(256,256) a1
370        Redimension/N=(128,128) a1
371
372        if(exists("root:Packages:NIST:RealTime:data")!=1)               //wave DN exist
373                Make/O/N=(128,128) $"root:Packages:NIST:RealTime:data"
374        endif
375        WAVE data=$"root:Packages:NIST:RealTime:data"
376        Duplicate/O data,$"root:Packages:NIST:RealTime:linear_data"
377        WAVE lin_data=$"root:Packages:NIST:RealTime:linear_data"
378        lin_data=a1
379        if(isLogScale)
380                data=log(a1)
381        else
382                data=a1
383        Endif
384       
385        KillWaves/Z a1 
386       
387        //return the data folder to root
388        SetDataFolder root:
389       
390        Return 0
391End
392
393// fills the "default" fake header so that the SANS Reduction machinery does not have to be altered
394// pay attention to what is/not to be trusted due to "fake" information
395//
396Function FillFakeHeader()
397
398        Make/O/N=23 $"root:Packages:NIST:RealTime:IntegersRead"
399        Make/O/N=52 $"root:Packages:NIST:RealTime:RealsRead"
400        Make/O/T/N=11 $"root:Packages:NIST:RealTime:TextRead"
401       
402        Wave intw=$"root:Packages:NIST:RealTime:IntegersRead"
403        Wave realw=$"root:Packages:NIST:RealTime:RealsRead"
404        Wave/T textw=$"root:Packages:NIST:RealTime:TextRead"
405       
406        //Put in appropriate "fake" values
407        // first 4 are user-defined on the Real Time control panel, so user has the opportunity to change these values.
408        //
409        realw[16]=NumVarOrDefault("root:myGlobals:RT:xCtr", 64.5)               //xCtr(pixels)
410        realw[17]=NumVarOrDefault("root:myGlobals:RT:yCtr", 64.5)               //yCtr (pixels)
411        realw[18]=NumVarOrDefault("root:myGlobals:RT:SDD", 5)           //SDD (m)
412        realw[26]=NumVarOrDefault("root:myGlobals:RT:lambda", 6)                //wavelength (A)
413        //
414        // necessary values
415        realw[10]=5                     //detector calibration constants, needed for averaging
416        realw[11]=10000
417        realw[13]=5
418        realw[14]=10000
419        //
420        // used in the resolution calculation, ONLY here to keep the routine from crashing
421        realw[20]=65            //det size
422        realw[27]=0.15  //delta lambda
423        realw[21]=50.8  //BS size
424        realw[23]=50            //A1
425        realw[24]=12.7  //A2
426        realw[25]=8.57  //A1A2 distance
427        realw[4]=1              //trans
428        realw[3]=0              //atten
429        realw[5]=0.1            //thick
430        //
431        //
432        realw[0]=1e8            //def mon cts
433
434        // fake values to get valid deadtime and detector constants
435        //
436        textw[9]="ORNL  "               //6 characters
437        textw[3]="[NGxSANS00]"  //11 chars, NGx will return default values for atten trans, deadtime...
438       
439        return(0)
440End
441
442// action procedure to start/stop the updating process.
443//checks for update display graph, current background task, etc..
444// then update the button and at last controls the background task
445//
446Function UpdateHSTButton(ctrlName) : ButtonControl
447        String ctrlName
448       
449        //check that the RT window is open, and that the display type is "RealTime"
450        if(WinType("SANS_Data")==0)
451                return(1) //SANS_Data window not open
452        Endif
453        SVAR type=root:myGlobals:gDataDisplayType
454        if(cmpstr("RealTime",type)!=0)
455                return(1)               //display not RealTime
456        Endif
457        //check the current state of the background task
458        BackgroundInfo          //returns 0 if no task defined, 1 if idle, 2 if running
459        if(V_flag==0)
460                AssignBackgroundTask()
461        Endif
462       
463        String Str=""
464        //control the task, and update the button text
465        if (cmpstr(ctrlName,"bkgStart") == 0)
466                Button $ctrlName,win=RT_Panel,title="Stop Updating",rename=bkgStop             
467        //      Start the updating - BkgUpdateHST() has been designated as the background task
468                CtrlBackground start
469        else
470                Button $ctrlName,win=RT_Panel,title="Start Updating",rename=bkgStart
471                NVAR elapsed=root:myGlobals:RT:elapsed
472                elapsed=0       //reset the timer
473        //      Stop the updating
474                CtrlBackground stop
475        endif
476        return(0)
477End
478
479
480// THIS IS THE BACKGROUND TASK
481//
482// simply re-reads the designated .hst file (which can be located anywhere, as long as it
483// appears as a local disk)
484// return value of 0 continues background execution
485// return value of 1 turns background task off
486//
487Function BkgUpdateHST()
488
489        WAVE data = $"root:Packages:NIST:RealTime:data"
490        NVAR elapsed=root:myGlobals:RT:elapsed
491        NVAR timeout=root:myGlobals:RT:timeout
492        NVAR updateInt=root:myGlobals:RT:updateInt
493        NVAR totCounts=root:myGlobals:RT:totalCounts
494       
495        Variable err=0
496//      Variable t1=ticks
497        SVAR RT_fileStr=root:myGlobals:RT:RT_fileStr
498       
499        elapsed += updateInt
500//      get the new data by re-reading the datafile from the relay computer
501        if(elapsed<timeout)
502       
503                if(WinType("SANS_Data")==0)
504                        Button $"bkgStop",win=RT_Panel,title="Start Updating",rename=bkgStart
505                        return(1) //SANS_Data window not open
506                Endif
507                SVAR type=root:myGlobals:gDataDisplayType
508                if(cmpstr("RealTime",type)!=0)
509                        Button $"bkgStop",win=RT_Panel,title="Start Updating",rename=bkgStart
510                        return(1)               //display not RealTime
511                Endif
512                SVAR title=root:myGlobals:gCurDispFile
513                title="Reading new data..."
514                ControlUpdate/W=SANS_Data/A
515               
516                //Copy file from ICE server
517                //ExecuteScriptText/B "\"C:\\Documents and Settings\\user\\Desktop\\ICE Test\\getdata.bat\""
518               
519                //err = ReadOrdelaHST(RT_fileStr)
520                //err = ReadHeaderAndData(RT_fileStr)
521                err = ReadRTAndData(RT_fileStr)
522                if(err==1)
523                        Button $"bkgStop",win=RT_Panel,title="Start Updating",rename=bkgStart
524                        return(err)     //file not found
525                Endif
526                //Raw_to_work("RealTime")
527                // for testing only...
528//              data += abs(enoise(data))
529                //
530                MapSliderProc("reset", 0, 1)
531               
532                title="Real-Time Data Display"
533                //sum the total counts, global variable will automatically update
534                WAVE/Z linear_data = $"root:Packages:NIST:RealTime:linear_data"
535                if(WaveExists(linear_data))
536                        totCounts = sum(linear_data, -Inf, Inf )
537                else
538                        WAVE/Z data = $"root:Packages:NIST:RealTime:data"
539                        totCounts = sum(data, -Inf, Inf )
540                endif
541               
542//              print "Bkg task time (s) =",(ticks-t1)/60.15
543                return 0                //keep the process going
544        else
545                //timeout, stop the process, reset the button label
546                elapsed=0
547                Button $"bkgStop",win=RT_Panel,title="Start Updating",rename=bkgStart
548                return(1)
549        endif
550       
551End
552
553Function ReadRTAndData(fname)
554        String fname
555        //this function is for reading in RAW data only, so it will always put data in RAW folder
556        String curPath = "root:Packages:NIST:RealTime:"
557        SetDataFolder curPath           //use the full path, so it will always work
558        //Variable/G root:Packages:NIST:RAW:gIsLogScale = 0             //initial state is linear, keep this in RAW folder
559        Variable isLogScale=NumVarOrDefault("root:Packages:NIST:RealTime:gIsLogScale", 0)
560        Variable/G root:Packages:NIST:RealTime:gIsLogScale = isLogScale
561       
562        Variable refNum,integer,realval
563        String sansfname,textstr
564       
565        Make/O/N=23 $"root:Packages:NIST:RealTime:IntegersRead"
566        Make/O/N=52 $"root:Packages:NIST:RealTime:RealsRead"
567        Make/O/T/N=11 $"root:Packages:NIST:RealTime:TextRead"
568       
569        Wave intw=$"root:Packages:NIST:RealTime:IntegersRead"
570        Wave realw=$"root:Packages:NIST:RealTime:RealsRead"
571        Wave/T textw=$"root:Packages:NIST:RealTime:TextRead"
572       
573        //***NOTE ****
574        // the "current path" gets mysteriously reset to "root:" after the SECOND pass through
575        // this read routine, after the open dialog is presented
576        // the "--read" waves end up in the correct folder, but the data does not! Why?
577        //must re-set data folder before writing data array (done below)
578       
579        //full filename and path is now passed in...
580        //actually open the file
581        Open/R refNum as fname
582        //skip first two bytes (VAX record length markers, not needed here)
583        FSetPos refNum, 2
584        //read the next 21 bytes as characters (fname)
585        FReadLine/N=21 refNum,textstr
586        textw[0]= textstr
587        //read four i*4 values  /F=3 flag, B=3 flag
588        FBinRead/F=3/B=3 refNum, integer
589        intw[0] = integer
590        //
591        FBinRead/F=3/B=3 refNum, integer
592        intw[1] = integer
593        //
594        FBinRead/F=3/B=3 refNum, integer
595        intw[2] = integer
596        //
597        FBinRead/F=3/B=3 refNum, integer
598        intw[3] = integer
599        // 6 text fields
600        FSetPos refNum,55               //will start reading at byte 56
601        FReadLine/N=20 refNum,textstr
602        textw[1]= textstr
603        FReadLine/N=3 refNum,textstr
604        textw[2]= textstr
605        FReadLine/N=11 refNum,textstr
606        textw[3]= textstr
607        FReadLine/N=1 refNum,textstr
608        textw[4]= textstr
609        FReadLine/N=8 refNum,textstr
610        textw[5]= textstr
611        FReadLine/N=60 refNum,textstr
612        textw[6]= textstr
613       
614        //3 integers
615        FSetPos refNum,174
616        FBinRead/F=3/B=3 refNum, integer
617        intw[4] = integer
618        FBinRead/F=3/B=3 refNum, integer
619        intw[5] = integer
620        FBinRead/F=3/B=3 refNum, integer
621        intw[6] = integer
622       
623        //2 integers, 3 text fields
624        FSetPos refNum,194
625        FBinRead/F=3/B=3 refNum, integer
626        intw[7] = integer
627        FBinRead/F=3/B=3 refNum, integer
628        intw[8] = integer
629        FReadLine/N=6 refNum,textstr
630        textw[7]= textstr
631        FReadLine/N=6 refNum,textstr
632        textw[8]= textstr
633        FReadLine/N=6 refNum,textstr
634        textw[9]= textstr
635       
636        //2 integers
637        FSetPos refNum,244
638        FBinRead/F=3/B=3 refNum, integer
639        intw[9] = integer
640        FBinRead/F=3/B=3 refNum, integer
641        intw[10] = integer
642       
643        //2 integers
644        FSetPos refNum,308
645        FBinRead/F=3/B=3 refNum, integer
646        intw[11] = integer
647        FBinRead/F=3/B=3 refNum, integer
648        intw[12] = integer
649       
650        //2 integers
651        FSetPos refNum,332
652        FBinRead/F=3/B=3 refNum, integer
653        intw[13] = integer
654        FBinRead/F=3/B=3 refNum, integer
655        intw[14] = integer
656       
657        //3 integers
658        FSetPos refNum,376
659        FBinRead/F=3/B=3 refNum, integer
660        intw[15] = integer
661        FBinRead/F=3/B=3 refNum, integer
662        intw[16] = integer
663        FBinRead/F=3/B=3 refNum, integer
664        intw[17] = integer
665       
666        //1 text field - the file association for transmission are the first 4 bytes
667        FSetPos refNum,404
668        FReadLine/N=42 refNum,textstr
669        textw[10]= textstr
670       
671        //1 integer
672        FSetPos refNum,458
673        FBinRead/F=3/B=3 refNum, integer
674        intw[18] = integer
675       
676        //4 integers
677        FSetPos refNum,478
678        FBinRead/F=3/B=3 refNum, integer
679        intw[19] = integer
680        FBinRead/F=3/B=3 refNum, integer
681        intw[20] = integer
682        FBinRead/F=3/B=3 refNum, integer
683        intw[21] = integer
684        FBinRead/F=3/B=3 refNum, integer
685        intw[22] = integer
686       
687        Close refNum
688       
689        //now get all of the reals
690        //
691        //Do all the GBLoadWaves at the end
692        //
693        //FBinRead Cannot handle 32 bit VAX floating point
694        //GBLoadWave, however, can properly read it
695        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
696        String strToExecute
697        //append "/S=offset/U=numofreals" to control the read
698        // then append fname to give the full file path
699        // then execute
700       
701        Variable a=0,b=0
702       
703        SetDataFolder curPath
704       
705        // 4 R*4 values
706        strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
707        Execute strToExecute
708        Wave w=$"root:Packages:NIST:RealTime:tempGBWave0"
709        b=4     //num of reals read
710        realw[a,a+b-1] = w[p-a]
711        a+=b
712       
713        // 4 R*4 values
714        SetDataFolder curPath
715        strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""
716        Execute strToExecute
717        b=4     
718        realw[a,a+b-1] = w[p-a]
719        a+=b
720
721///////////
722        // 2 R*4 values
723        SetDataFolder curPath
724        strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
725        Execute strToExecute
726        b=2     
727        realw[a,a+b-1] = w[p-a]
728        a+=b
729
730        // 6 R*4 values
731        SetDataFolder curPath
732        strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""
733        Execute strToExecute
734        b=6     
735        realw[a,a+b-1] = w[p-a]
736        a+=b
737       
738        // 13 R*4 values
739        SetDataFolder curPath
740        strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""
741        Execute strToExecute
742        b=13
743        realw[a,a+b-1] = w[p-a]
744        a+=b
745       
746        // 3 R*4 values
747        SetDataFolder curPath
748        strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""
749        Execute strToExecute
750        b=3     
751        realw[a,a+b-1] = w[p-a]
752        a+=b
753       
754        // 7 R*4 values
755        SetDataFolder curPath
756        strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""
757        Execute strToExecute
758        b=7
759        realw[a,a+b-1] = w[p-a]
760        a+=b
761       
762        // 4 R*4 values
763        SetDataFolder curPath
764        strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""
765        Execute strToExecute
766        b=4     
767        realw[a,a+b-1] = w[p-a]
768        a+=b
769       
770        // 2 R*4 values
771        SetDataFolder curPath
772        strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""
773        Execute strToExecute
774        b=2
775        realw[a,a+b-1] = w[p-a]
776        a+=b
777       
778        // 2 R*4 values
779        SetDataFolder curPath
780        strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""
781        Execute strToExecute
782        b=2
783        realw[a,a+b-1] = w[p-a]
784        a+=b
785       
786        // 5 R*4 values
787        SetDataFolder curPath
788        strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""
789        Execute strToExecute
790        b=5     
791        realw[a,a+b-1] = w[p-a]
792       
793        //if the binary VAX data ws transferred to a MAC, all is OK
794        //if the data was trasnferred to an Intel machine (IBM), all the real values must be
795        //divided by 4 to get the correct floating point values
796        // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly
797        // on an Intel machine.
798        //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read
799        //VAX reals correctly, and no checking is necessary 12 APR 99
800        //if(cmpstr("Macintosh",IgorInfo(2)) == 0)
801                //do nothing
802        //else
803                //either Windows or Windows NT
804                //realw /= 4
805        //endif
806       
807        SetDataFolder curPath
808        //read in the data
809        strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\""
810        Execute strToExecute
811
812        SetDataFolder curPath           //use the full path, so it will always work
813       
814        Make/O/N=16384 $"root:Packages:NIST:RealTime:data"
815        WAVE data=$"root:Packages:NIST:RealTime:data"
816        SkipAndDecompressVAX(w,data)
817        Redimension/N=(128,128) data                    //NIST raw data is 128x128 - do not generalize
818       
819        Duplicate/O data,$"root:Packages:NIST:RealTime:linear_data"
820        WAVE lin_data=$"root:Packages:NIST:RealTime:linear_data"
821        if(isLogScale)
822                data=log(lin_data)
823        else
824                data=lin_data
825        Endif
826       
827        //keep a string with the filename in the RAW folder
828        String/G root:Packages:NIST:RealTime:fileList = textw[0]
829       
830        //set the globals to the detector dimensions (pixels)
831        Variable/G root:myGlobals:gNPixelsX=128         //default for Ordela data (also set in Initialize/NCNR_Utils.ipf)
832        Variable/G root:myGlobals:gNPixelsY=128
833//      if(cmpstr(textW[9],"ILL   ")==0)                //override if OLD Cerca data
834//              Variable/G root:myGlobals:gNPixelsX=64
835//              Variable/G root:myGlobals:gNPixelsY=64
836//      endif
837       
838        //clean up - get rid of w = $"root:Packages:NIST:RAW:tempGBWave0"
839//      KillWaves/Z w
840       
841        //return the data folder to root
842        SetDataFolder root:
843       
844        Return 0
845
846End
Note: See TracBrowser for help on using the repository browser.