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