source: sans/USANSReduction/trunk/Put in User Procedures Folder/USANS Procedures v2.20/BT5_Loader.ipf @ 35

Last change on this file since 35 was 35, checked in by ajj, 16 years ago

Set pragma = 2.20 and required version >= 2.20 for includes in USANS_Includes.ipf

  • Property eol-style set to native
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3
4/////////////////////////
5// 101001 Vers. 1
6//
7// functions to load and parse the ASCII ICP files generated at BT5 USANS
8// Nearly all of the important information about the data is dragged around
9// with the DetCts wave as a wave note
10//
11// - thes wave note is a string of KEY:value items
12//
13//      str = "FILE:"+filen+";"
14//      str += "TIMEPT:"+num2str(counttime)+";"
15//      str += "PEAKANG:;"              //no value yet
16//      str += "STATUS:;"               //no value yet
17//      str += "LABEL:"+fileLabel+";"
18//      str += "PEAKVAL:;"              //no value yet
19//      str += "TWIDE:0;"               //no value yet
20//
21/////////////////////////
22
23
24//given the filename, loads a single data file into a "TYPE" folder, into a
25//series of 1D waves. counting time is associated with the DetCts wave as a note
26//"blank" note entries are set up here as well, so later they can be polled/updated
27Function LoadBT5File(fname,type)
28        String fname,type
29       
30        Variable num=200,err=0,refnum
31        Make/O/D/N=(num) $("root:"+type+":Angle")
32        Make/O/D/N=(num) $("root:"+type+":DetCts")
33        Make/O/D/N=(num) $("root:"+type+":ErrDetCts")
34        Make/O/D/N=(num) $("root:"+type+":MonCts")
35        Make/O/D/N=(num) $("root:"+type+":TransCts")
36        Wave Angle = $("root:"+type+":Angle")
37        Wave DetCts = $("root:"+type+":DetCts")
38        Wave ErrDetCts = $("root:"+type+":ErrDetCts")
39        Wave MonCts = $("root:"+type+":MonCts")
40        Wave TransCts = $("root:"+type+":TransCts")
41       
42        Open/R refNum as fname          //if fname is "", a dialog will be presented
43        if(refnum==0)
44                return(1)               //user cancelled
45        endif
46        //read in the ASCII data line-by-line
47        Variable numLinesLoaded = 0,firstchar,countTime
48        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead
49        String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10
50        String filen="",fileLabel=""
51       
52        //parse the first line
53        FReadLine refnum,buffer
54        sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8
55        ii=strlen(s1)
56        filen=s1[1,(ii-2)]                      //remove the ' from beginning and end
57        //Print "filen = ",filen,strlen(filen)
58        countTime=v1
59        //Print "time (sec) = ",countTime
60       
61        //skip line 2
62        FReadLine refnum,buffer
63        //the next line is the sample label, use it all, minus the terminator
64        FReadLine refnum,filelabel
65       
66        //skip the next 10 lines
67        For(ii=0;ii<10;ii+=1)
68                FReadLine refnum,buffer
69        EndFor
70       
71        //read the data until EOF - assuming always a pair or lines
72        do
73                FReadLine refNum, buffer
74                if (strlen(buffer) == 0)
75                        break                                                   // End of file
76                endif
77                firstChar = char2num(buffer[0])
78                if ( (firstChar==10) || (firstChar==13) )
79                        break                                                   // Hit blank line. End of data in the file.
80                endif
81                sscanf buffer,"%g%g%g",v1,v2,v3         //v2,v3 not used
82                angle[numlinesloaded] = v1              //[0] is the ANGLE
83               
84                FReadLine refNum,buffer //assume a 2nd line is there, w/16 values
85                sscanf buffer,"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g",v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16
86                //valuesRead = V_flag
87                //print valuesRead
88                MonCts[numlinesloaded] = v1             //monitor
89                DetCts[numlinesloaded] = v2 + v3 + v5 + v6 + v7         //5 detectors
90                TransCts[numlinesloaded] = v4           //trans detector
91                ErrDetCts[numlinesloaded] = sqrt(detCts[numlinesloaded])
92                //values 8-16 are always zero
93                numlinesloaded += 1             //2 lines in file read, one "real" line of data
94        while(1)
95               
96        Close refNum            // Close the file.
97        //Print "numlines = ",numlinesloaded
98        //trim the waves to the correct number of points
99        Redimension/N=(numlinesloaded) Angle,MonCts,DetCts,TransCts,ErrDetCts
100       
101        //remove LF from end of filelabel
102        filelabel=fileLabel[0,(strlen(fileLabel)-2)]
103       
104        //set the wave note for the DetCts
105        String str=""
106        str = "FILE:"+filen+";"
107        str += "TIMEPT:"+num2str(counttime)+";"
108        str += "PEAKANG:;"              //no value yet
109        str += "STATUS:;"               //no value yet
110        str += "LABEL:"+fileLabel+";"
111        str += "PEAKVAL:;"              //no value yet
112        str += "TWIDE:0;"               //no value yet
113        Note DetCts,str
114       
115        String/G fileLbl = filelabel
116        return err                      // Zero signifies no error.     
117End
118
119
120//will search for peak in root:type:DetCts,  find and returns the angle
121// of the peak poistion (= q=0)
122//returns -9999 if error, appends value to wavenote
123// !can't return -1,0,1, since these may be the peak angle!
124//
125Function FindZeroAngle(type)
126        String type
127       
128        Variable pkNotFound,pkPt,pkAngle,pkVal,temp
129        Wave angle = $("root:"+type+":Angle")
130        Wave detCts = $("root:"+type+":DetCts")
131
132        WaveStats/Q detcts
133        temp=V_Maxloc           //in points
134        FindPeak/P/Q/M=10/R=[(temp-10),(temp+10)] DetCts                //+/- 10 pts from maximum
135       
136        //FindPeak/P/Q/M=(1000) detCts          // /M=min ht -- peak must be at least 100x higher than 1st pt
137        pkNotFound=V_Flag               //V_Flag==1 if no pk found
138        pkPt = V_PeakLoc
139        pkVal = V_PeakVal               //for calc of T_rock
140        if(pkNotFound)
141                //DoAlert 0, "Peak not found"
142                Return (-9999)          //fatal error
143        Endif
144        pkAngle = Angle[pkPt]
145        //Print "Peak Angle = ",pkAngle
146        //update the note
147        String str=""
148        str=note(DetCts)
149        str = ReplaceNumberByKey("PEAKANG",str,pkangle,":",";")
150        str = ReplaceNumberByKey("PEAKVAL",str,pkVal,":",";")
151        Note/K DetCts
152        Note detCts,str
153       
154        return(pkAngle)
155End
156
157// given the peakAngle (q=0) and the "type" folder of scattering angle,
158// convert the angle to Q-values [degrees to (1/A)]
159// makes a new Qvals wave, duplicating the Angle wave, which is assumed to exist
160// Uses a conversion constant supplied by John Barker, and is hard-wired in
161//
162Function ConvertAngle2Qvals(type,pkAngle)
163        String type
164        Variable pkAngle
165       
166        Wave angle = $("root:"+type+":Angle")
167        Variable num=numpnts(angle)
168        Variable deg2QConv=5.55e-5              //JGB -- 2/24/01
169       
170        Make/O/N=(num) $("root:"+type+":Qvals")
171        Wave qvals = $("root:"+type+":Qvals")   
172        Qvals = deg2QConv*(angle[p] - pkAngle)
173       
174        return(0)       //no error
175End
176
177//updates the wavenote with the average Trans det cts for calculation of T_Wide
178//  finds the average number of counts on the transmission detector at angles
179// greater than 2 deg. (per John, practical experience where the trans data levels off)
180//
181// error value of 1 is returned and wavenote not updated if level is not found
182//
183//
184Function FindTWideCts(type)
185        String type
186       
187        Variable levNotFound,levPt,Cts,num,ii
188        Wave angle = $("root:"+type+":Angle")
189        Wave detCts = $("root:"+type+":DetCts")
190        Wave TransCts = $("root:"+type+":TransCts")
191        FindLevel/Q/P angle,2           //use angles greater than 2 deg
192        levNotFound=V_Flag              //V_Flag==1 if no pk found
193        if(levNotFound)
194                return(1)
195        endif
196        levPt = trunc(V_LevelX)         // in points, force to integer
197       
198        //average the trans cts from levPt to the end of the dataset
199        num=numpnts(TransCts)
200        Cts=0
201        for(ii=levPt;ii<num;ii+=1)
202                Cts += transCts[ii]
203        endfor
204        Cts /= (num-levPt-1)
205       
206        //update the note
207        Wave DetCts = $("root:"+type+":DetCts")
208        String str,strVal
209        str=note(DetCts)
210        str = ReplaceNumberByKey("TWIDE",str,Cts,":",";")
211        Note/K DetCts
212        Note detCts,str
213       
214        return(0)
215End
Note: See TracBrowser for help on using the repository browser.