1 |
************************************************************************* |
2 |
* |
3 |
* Subroutine read_B_inner.f |
4 |
* |
5 |
* it reads from rz files the two magnetic field maps taken inside the |
6 |
* spectrometer cavity and fills the variables in common_B_inner.f |
7 |
* |
8 |
* needs: |
9 |
* - ../common/common_B_inner.f common file for the inner magnetic field map |
10 |
* - .rz map files in ./ containing coordinates of measured points, Bx, By |
11 |
* and Bz components + errors |
12 |
* |
13 |
* output variables: (see common_B_inner.f) |
14 |
* - px#(nx,3) with #=1,2 for the 2 maps |
15 |
* - py#(ny,3) |
16 |
* - pz#(nz,3) |
17 |
* - b#(nx,ny,nz,3) |
18 |
* |
19 |
************************************************************************* |
20 |
|
21 |
subroutine read_B_inner(idata_dir) |
22 |
include './common_B_inner.for' |
23 |
c implicit double precision (a-h,o-z) |
24 |
CHARACTER*250 idata_dir |
25 |
parameter(NWPAWC=200000) |
26 |
common/pawc/hmem(NWPAWC) |
27 |
c save/pawc/ |
28 |
common/quest/iquest(100) |
29 |
c save/quest/ |
30 |
|
31 |
|
32 |
c------------------------------------------------------------------------ |
33 |
c |
34 |
c local variables |
35 |
c |
36 |
c------------------------------------------------------------------------ |
37 |
integer lastnb |
38 |
c integer lung |
39 |
|
40 |
character*264 Bmap_file !magnetic field file name |
41 |
c character*120 cmd1 |
42 |
c character*120 cmd2 |
43 |
parameter (lun_Bmap_file=66) !magnetic field map file id number |
44 |
|
45 |
parameter (ntpl_Bmap=20) !ntuple identifier |
46 |
|
47 |
REAL*4 PFX(3),FX,DFX, !Bx field component coordinates in m, value and error in T |
48 |
$ PFY(3),FY,DFY |
49 |
$ ,PFZ(3),FZ,DFZ |
50 |
INTEGER INDEX(3) !point index |
51 |
integer ic,iev,iemax,istat |
52 |
|
53 |
COMMON /ntplvars/ INDEX,PFX,FX,DFX,PFY,FY,DFY,PFZ,FZ,DFZ |
54 |
c save/pawcr4/ |
55 |
|
56 |
c------------------------------------------------------------------------ |
57 |
c |
58 |
c *** FIRST MAP *** |
59 |
c |
60 |
c------------------------------------------------------------------------ |
61 |
|
62 |
c------------------------------------------------------------------------ |
63 |
c |
64 |
c initialization and map file opening |
65 |
c |
66 |
c------------------------------------------------------------------------ |
67 |
|
68 |
c print*,' ' |
69 |
c print*,' ' |
70 |
c lastnb = length(idata_dir) |
71 |
c idata_dir(lastnb:lastnb+20)='/measure_n3_290302.rz' |
72 |
c lung = lastnb+20 |
73 |
lastnb = length(idata_dir)-1 |
74 |
Bmap_file = idata_dir(1:lastnb)//'/measure_n3_290302.rz' |
75 |
|
76 |
c Bmap_file='measure_n3_290302.rz' |
77 |
|
78 |
c$$$ cmd1='cp $TRK_GRND/source/magnet/' |
79 |
c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))//' .' |
80 |
c$$$ call system(cmd1) |
81 |
|
82 |
c opens magnetic field map first file |
83 |
c print *,'Opening file: -',idata_dir(1:lung),'- ' |
84 |
print *,'Opening file: ',Bmap_file(1:lastnb+21) |
85 |
c call HROPEN(lun_Bmap_file,'Bmap',idata_dir(1:lung), |
86 |
call HROPEN(lun_Bmap_file,'Bmap',Bmap_file, |
87 |
& 'P',1024,istat) |
88 |
c $ (lun_Bmap_file,'Bmap',idata_dir(1:lung),'P',1024,istat) |
89 |
c $ (lun_Bmap_file,'Bmap', |
90 |
c & '/wizard3/pamela/sw/calib/measure_n3_290302.rz', |
91 |
c & 'P',1024,istat) |
92 |
c $ (lun_Bmap_file,'Bmap','./bin-aux/'//Bmap_file,'P',1024,istat) |
93 |
if(istat.ne.0) goto 21 |
94 |
|
95 |
c goto 9000 |
96 |
c call HCDIR('//Bmap',' ') |
97 |
|
98 |
c goto 666 |
99 |
|
100 |
|
101 |
call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory |
102 |
|
103 |
c call HPRNTU(ntpl_Bmap) |
104 |
call HBNAME(ntpl_Bmap,' ',0,'$CLEAR') |
105 |
call HBNAME(ntpl_Bmap,'INDEX',index,'$SET') |
106 |
call HBNAME(ntpl_Bmap,'BX',pfx,'$SET') |
107 |
call HBNAME(ntpl_Bmap,'BY',pfy,'$SET') |
108 |
call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET') |
109 |
|
110 |
|
111 |
c------------------------------------------------------------------------ |
112 |
c |
113 |
c reads events and fills variables |
114 |
c |
115 |
c------------------------------------------------------------------------ |
116 |
|
117 |
call HNOENT(ntpl_Bmap,iemax) !number of events |
118 |
|
119 |
c initializes measurement grid edges |
120 |
do ic=1,3 |
121 |
px1max(ic)=0. |
122 |
px1min(ic)=0. |
123 |
py1max(ic)=0. |
124 |
py1min(ic)=0. |
125 |
pz1max(ic)=0. |
126 |
pz1min(ic)=0. |
127 |
enddo |
128 |
|
129 |
|
130 |
do iev=1,iemax !event loop |
131 |
|
132 |
call HGNT(ntpl_Bmap,iev,ierr) !reads event |
133 |
if(ierr.ne.0) goto 22 |
134 |
|
135 |
c the output consists of matrices for coordinates, B components values |
136 |
c and errors: |
137 |
c e.g. px1(4,2) = X coordinate of the point with index = 4 along X, |
138 |
c in which By (=2) component has been measured |
139 |
c e.g. b1(3,23,4,1) = Bx (=1) component value, measured in the point with |
140 |
c indexes = 3,23,4 along X, Y and Z |
141 |
|
142 |
c Bx component |
143 |
px1(index(1),1) = pfx(1) |
144 |
if(px1(index(1),1).lt.px1min(1)) px1min(1)=px1(index(1),1) |
145 |
if(px1(index(1),1).gt.px1max(1)) px1max(1)=px1(index(1),1) |
146 |
py1(index(2),1) = pfx(2) |
147 |
if(py1(index(2),1).lt.py1min(1)) py1min(1)=py1(index(2),1) |
148 |
if(py1(index(2),1).gt.py1max(1)) py1max(1)=py1(index(2),1) |
149 |
pz1(index(3),1) = pfx(3) |
150 |
if(pz1(index(3),1).lt.pz1min(1)) pz1min(1)=pz1(index(3),1) |
151 |
if(pz1(index(3),1).gt.pz1max(1)) pz1max(1)=pz1(index(3),1) |
152 |
|
153 |
b1(index(1),index(2),index(3),1) = fx |
154 |
|
155 |
|
156 |
c By component |
157 |
px1(index(1),2) = pfy(1) |
158 |
if(px1(index(1),2).lt.px1min(2)) px1min(2)=px1(index(1),2) |
159 |
if(px1(index(1),2).gt.px1max(2)) px1max(2)=px1(index(1),2) |
160 |
py1(index(2),2) = pfy(2) |
161 |
if(py1(index(2),2).lt.py1min(2)) py1min(2)=py1(index(2),2) |
162 |
if(py1(index(2),2).gt.py1max(2)) py1max(2)=py1(index(2),2) |
163 |
pz1(index(3),2) = pfy(3) |
164 |
if(pz1(index(3),2).lt.pz1min(2)) pz1min(2)=pz1(index(3),2) |
165 |
if(pz1(index(3),2).gt.pz1max(2)) pz1max(2)=pz1(index(3),2) |
166 |
|
167 |
b1(index(1),index(2),index(3),2) = fy |
168 |
|
169 |
|
170 |
c Bz component |
171 |
px1(index(1),3) = pfz(1) |
172 |
if(px1(index(1),3).lt.px1min(3)) px1min(3)=px1(index(1),3) |
173 |
if(px1(index(1),3).gt.px1max(3)) px1max(3)=px1(index(1),3) |
174 |
py1(index(2),3) = pfz(2) |
175 |
if(py1(index(2),3).lt.py1min(3)) py1min(3)=py1(index(2),3) |
176 |
if(py1(index(2),3).gt.py1max(3)) py1max(3)=py1(index(2),3) |
177 |
pz1(index(3),3) = pfz(3) |
178 |
if(pz1(index(3),3).lt.pz1min(3)) pz1min(3)=pz1(index(3),3) |
179 |
if(pz1(index(3),3).gt.pz1max(3)) pz1max(3)=pz1(index(3),3) |
180 |
|
181 |
b1(index(1),index(2),index(3),3) = fz |
182 |
|
183 |
enddo |
184 |
|
185 |
|
186 |
c------------------------------------------------------------------------ |
187 |
c |
188 |
c closes files |
189 |
c |
190 |
c------------------------------------------------------------------------ |
191 |
|
192 |
c 666 continue |
193 |
call HCDIR('//Bmap',' ') |
194 |
call HREND('Bmap') |
195 |
close(lun_Bmap_file) |
196 |
c$$$ cmd2='rm -f ' |
197 |
c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file)) |
198 |
c$$$ call system(cmd2) |
199 |
c$$$ |
200 |
|
201 |
c goto 9000 |
202 |
c------------------------------------------------------------------------ |
203 |
c |
204 |
c *** SECOND MAP *** |
205 |
c |
206 |
c------------------------------------------------------------------------ |
207 |
|
208 |
c------------------------------------------------------------------------ |
209 |
c |
210 |
c initialization and map file opening |
211 |
c |
212 |
c------------------------------------------------------------------------ |
213 |
|
214 |
c print*,' ' |
215 |
c print*,' ' |
216 |
lastnb = length(idata_dir)-1 |
217 |
Bmap_file = idata_dir(1:lastnb)//'/measure_n4_110402_corrected.rz' |
218 |
c lung = lastnb+30 |
219 |
|
220 |
c Bmap_file='measure_n4_110402_corrected.rz' |
221 |
c$$$ cmd1='cp $TRK_GRND/source/magnet/' |
222 |
c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))//' .' |
223 |
c$$$ call system(cmd1) |
224 |
|
225 |
c opens magnetic field map first file |
226 |
print *,'Opening file: ',Bmap_file(1:lastnb+31) |
227 |
c print *,'Opening file: -',idata_dir(1:lung),'- ' |
228 |
call HROPEN |
229 |
$ (lun_Bmap_file,'Bmap',Bmap_file,'P',1024,istat) |
230 |
c $ (lun_Bmap_file,'Bmap',idata_dir(1:lung),'P',1024,istat) |
231 |
c $ (lun_Bmap_file,'Bmap','./bin-aux/'//Bmap_file,'P',1024,istat) |
232 |
|
233 |
c idata_dir(lastnb:lastnb+1)='./' |
234 |
|
235 |
if(istat.ne.0) goto 21 |
236 |
|
237 |
|
238 |
call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory |
239 |
|
240 |
c call HPRNTU(ntpl_Bmap) |
241 |
call HBNAME(ntpl_Bmap,' ',0,'$CLEAR') |
242 |
call HBNAME(ntpl_Bmap,'INDEX',index,'$SET') |
243 |
call HBNAME(ntpl_Bmap,'BX',pfx,'$SET') |
244 |
call HBNAME(ntpl_Bmap,'BY',pfy,'$SET') |
245 |
call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET') |
246 |
|
247 |
|
248 |
c------------------------------------------------------------------------ |
249 |
c |
250 |
c reads events and fills variables |
251 |
c |
252 |
c------------------------------------------------------------------------ |
253 |
|
254 |
call HNOENT(ntpl_Bmap,iemax) !number of events |
255 |
|
256 |
do ic=1,3 !grid edges |
257 |
px2max(ic)=0. |
258 |
px2min(ic)=0. |
259 |
py2max(ic)=0. |
260 |
py2min(ic)=0. |
261 |
pz2max(ic)=0. |
262 |
pz2min(ic)=0. |
263 |
enddo |
264 |
|
265 |
|
266 |
do iev=1,iemax !event loop |
267 |
|
268 |
call HGNT(ntpl_Bmap,iev,ierr) !reads event |
269 |
if(ierr.ne.0) goto 22 |
270 |
|
271 |
c the output consists of matrices for coordinates, B components values |
272 |
c and errors: |
273 |
c e.g. px(4,2) = X coordinate of the point with index = 4 along X, |
274 |
c in which By (=2) component has been measured |
275 |
c e.g. b(3,23,4,1) = Bx (=1) component value, measured in the point with |
276 |
c indexes = 3,23,4 along X, Y and Z |
277 |
|
278 |
c Bx component |
279 |
px2(index(1),1) = pfx(1) |
280 |
if(px2(index(1),1).lt.px2min(1)) px2min(1)=px2(index(1),1) |
281 |
if(px2(index(1),1).gt.px2max(1)) px2max(1)=px2(index(1),1) |
282 |
py2(index(2),1) = pfx(2) |
283 |
if(py2(index(2),1).lt.py2min(1)) py2min(1)=py2(index(2),1) |
284 |
if(py2(index(2),1).gt.py2max(1)) py2max(1)=py2(index(2),1) |
285 |
pz2(index(3),1) = pfx(3) |
286 |
if(pz2(index(3),1).lt.pz2min(1)) pz2min(1)=pz2(index(3),1) |
287 |
if(pz2(index(3),1).gt.pz2max(1)) pz2max(1)=pz2(index(3),1) |
288 |
|
289 |
b2(index(1),index(2),index(3),1) = fx |
290 |
|
291 |
|
292 |
c By component |
293 |
px2(index(1),2) = pfy(1) |
294 |
if(px2(index(1),2).lt.px2min(2)) px2min(2)=px2(index(1),2) |
295 |
if(px2(index(1),2).gt.px2max(2)) px2max(2)=px2(index(1),2) |
296 |
py2(index(2),2) = pfy(2) |
297 |
if(py2(index(2),2).lt.py2min(2)) py2min(2)=py2(index(2),2) |
298 |
if(py2(index(2),2).gt.py2max(2)) py2max(2)=py2(index(2),2) |
299 |
pz2(index(3),2) = pfy(3) |
300 |
if(pz2(index(3),2).lt.pz2min(2)) pz2min(2)=pz2(index(3),2) |
301 |
if(pz2(index(3),2).gt.pz2max(2)) pz2max(2)=pz2(index(3),2) |
302 |
|
303 |
b2(index(1),index(2),index(3),2) = fy |
304 |
|
305 |
|
306 |
c Bz component |
307 |
px2(index(1),3) = pfz(1) |
308 |
if(px2(index(1),3).lt.px2min(3)) px2min(3)=px2(index(1),3) |
309 |
if(px2(index(1),3).gt.px2max(3)) px2max(3)=px2(index(1),3) |
310 |
py2(index(2),3) = pfz(2) |
311 |
if(py2(index(2),3).lt.py2min(3)) py2min(3)=py2(index(2),3) |
312 |
if(py2(index(2),3).gt.py2max(3)) py2max(3)=py2(index(2),3) |
313 |
pz2(index(3),3) = pfz(3) |
314 |
if(pz2(index(3),3).lt.pz2min(3)) pz2min(3)=pz2(index(3),3) |
315 |
if(pz2(index(3),3).gt.pz2max(3)) pz2max(3)=pz2(index(3),3) |
316 |
|
317 |
b2(index(1),index(2),index(3),3) = fz |
318 |
|
319 |
enddo |
320 |
|
321 |
|
322 |
c------------------------------------------------------------------------ |
323 |
c |
324 |
c closes files |
325 |
c |
326 |
c------------------------------------------------------------------------ |
327 |
call HCDIR('//Bmap',' ') |
328 |
call HREND('Bmap') |
329 |
close(lun_Bmap_file) |
330 |
c$$$ cmd2='rm -f ' |
331 |
c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file)) |
332 |
c$$$ call system(cmd2) |
333 |
|
334 |
|
335 |
c------------------------------------------------------------------------ |
336 |
c |
337 |
c no error exit |
338 |
c |
339 |
c------------------------------------------------------------------------ |
340 |
|
341 |
c$$$ print*,' ' |
342 |
c$$$ print*,'MAGNETIC FIELD SUCCESSFULLY READ' |
343 |
c$$$ print*,' ' |
344 |
c$$$ print*,' ' |
345 |
|
346 |
goto 9000 !happy ending |
347 |
|
348 |
c------------------------------------------------------------------------ |
349 |
c |
350 |
c magnetic field map file opening error |
351 |
c |
352 |
c------------------------------------------------------------------------ |
353 |
|
354 |
21 continue |
355 |
|
356 |
print*,' ' |
357 |
print*,'read_B_inner: ERROR OPENING MAGNETIC FIELD MAP FILE: ' |
358 |
$ ,Bmap_file |
359 |
print*,' ' |
360 |
print*,' ' |
361 |
|
362 |
goto 9000 !the end |
363 |
|
364 |
|
365 |
c------------------------------------------------------------------------ |
366 |
c |
367 |
c ntuple event reading error |
368 |
c |
369 |
c------------------------------------------------------------------------ |
370 |
|
371 |
22 continue |
372 |
|
373 |
print*,' ' |
374 |
print*,'read_B_inner: ERROR WHILE READING NTUPLE, AT EVENT |
375 |
$ : ',iev |
376 |
print*,' ' |
377 |
print*,' ' |
378 |
|
379 |
goto 9000 !the end |
380 |
|
381 |
|
382 |
c------------------------------------------------------------------------ |
383 |
c |
384 |
c exit |
385 |
c |
386 |
c------------------------------------------------------------------------ |
387 |
|
388 |
9000 continue |
389 |
|
390 |
return |
391 |
end |