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

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

Realtime Updating

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