/[PAMELA software]/tracker/ground/source/magnet/magnetic-field.tar
ViewVC logotype

Annotation of /tracker/ground/source/magnet/magnetic-field.tar

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Wed Mar 8 15:00:38 2006 UTC (18 years, 9 months ago) by pam-fi
Branch point for: MAIN, trk-ground
File MIME type: application/x-tar
Initial revision

1 pam-fi 1.1 common_B_inner.f0100640000076700007640000000271110252260040014041 0ustar vannucciwizard*************************************************************************
2     *
3     * Common common_B_inner.f
4     *
5     * to be included in:
6     * - ../magnet/read_B_inner.f
7     * - ../magnet/inter_B.f
8     * - ../magnet/inter_B_inner.f
9     *
10     *************************************************************************
11    
12     c implicit double precision (a-h,o-z)
13    
14    
15     parameter (nx=29, ny=23, nz=101) !number of measures along X, Y and Z axes
16    
17     c coordinates in m of the edges of the volume in which the field
18     c is interpolated according to the inner maps
19     parameter (edgexmin=-0.085,edgexmax=0.085
20     $ ,edgeymin=-0.07,edgeymax=0.07
21     $ ,edgezmin=-0.26,edgezmax=0.26)
22    
23     ************
24     c first map
25     real*8 px1(nx,3),py1(ny,3),pz1(nz,3) !coordinates of measure points:
26     c e.g. py1(ny,1) = Y coordinates of Bx (=1) component of magnetic field
27    
28     real*8 b1(nx,ny,nz,3) !magnetic field values:
29     c e.g. b1(nx,ny,nz,2) = By (=2) component of magnetic field measured in (nx, ny, nz)
30    
31     real*8 px1max(3),px1min(3),py1max(3),py1min(3),pz1max(3),pz1min(3) !grid edges
32    
33     common/interpolation1/px1,py1,pz1,b1
34     $ ,px1max,px1min,py1max,py1min,pz1max,pz1min
35    
36     ************
37     c second map
38     real*8 px2(nx,3),py2(ny,3),pz2(nz,3)
39     real*8 b2(nx,ny,nz,3)
40     real*8 px2max(3),px2min(3),py2max(3),py2min(3),pz2max(3),pz2min(3)
41    
42     common/interpolation2/px2,py2,pz2,b2
43     $ ,px2max,px2min,py2max,py2min,pz2max,pz2min
44     common_B_outer.f0100640000076700007640000000303410252260012014062 0ustar vannucciwizard*************************************************************************
45     *
46     * Common common_B_outer.f
47     *
48     * to be included in:
49     * - ../magnet/read_B_outer.f
50     * - ../magnet/inter_B.f
51     * - ../magnet/inter_B_outer.f
52     *
53     *************************************************************************
54    
55     c implicit double precision (a-h,o-z)
56    
57    
58     c number of measures along X, Y and Z axes
59     parameter (nox=13, noy=13, noz=4)
60    
61     c coordinates in m of the edges of the volume in which the field
62     c is interpolated according to the inner maps
63     c UPPER VOLUME
64     parameter (edgeuxmin=-0.18)
65     parameter (edgeuxmax=0.18)
66     parameter (edgeuymin=-0.18)
67     parameter (edgeuymax=0.18)
68     parameter (edgeuzmin=0.28)
69     parameter (edgeuzmax=0.37)
70     c LOWER VOLUME
71     parameter (edgelxmin=edgeuxmin)
72     parameter (edgelxmax=edgeuxmax)
73     parameter (edgelymin=edgeuymin)
74     parameter (edgelymax=edgeuymax)
75     parameter (edgelzmin=-0.37)
76     parameter (edgelzmax=-0.28)
77    
78     ************
79     c MAGNETIC-FIELD MAP
80     real*8 pox(nox,3),poy(noy,3),poz(noz,3) !coordinates of measure points:
81     c e.g. py1(ny,1) = Y coordinates of Bx (=1) component of magnetic field
82    
83     real*8 bo(nox,noy,noz,3) !magnetic field values:
84     c e.g. b1(nx,ny,nz,2) = By (=2) component of magnetic field measured in (nx, ny, nz)
85    
86     real*8 poxmax(3),poxmin(3),poymax(3),poymin(3),pozmax(3),pozmin(3)
87     c grid edges
88    
89     common/interpolationo/pox,poy,poz,bo
90     $ ,poxmax,poxmin,poymax,poymin,pozmax,pozmin
91    
92     inter_B.f0100640000076700007640000001021710252303110012473 0ustar vannucciwizard*************************************************************************
93     *
94     * Subroutine inter_B.f
95     *
96     * it computes the magnetic field in a chosen point x,y,z inside or
97     * outside the magnetic cavity, using a trilinear interpolation of
98     * B field measurements (read before by means of ./read_B.f)
99     * if the point falls outside the interpolation volume, set the field to 0
100     *
101     * needs:
102     * - ../common/common_B_inner.f common file for the inner magnetic field map
103     * - ./inter_B_inner.f common file for the inner magnetic field map
104     * - ../common/common_B_outer.f common file for the outer magnetic field map
105     * - ./inter_B_outer.f common file for the outer magnetic field map
106     *
107     * to be called after ./read_B.f (magnetic field map reading subroutine)
108     *
109     * input: coordinates in m
110     * output: magnetic field in T
111     *
112     *************************************************************************
113    
114     subroutine inter_B(x,y,z,res) !coordinates in m, magnetic field in T
115    
116     implicit double precision (a-h,o-z)
117     include '../common/common_B_inner.f'
118     include '../common/common_B_outer.f'
119    
120    
121     c------------------------------------------------------------------------
122     c
123     c local variables
124     c
125     c------------------------------------------------------------------------
126    
127     real*8 x,y,z !point of interest
128     real*8 res(3) !interpolated B components: res = (Bx, By, Bz)
129    
130     real*8 zl,zu
131     real*8 resu(3),resl(3)
132    
133     c------------------------------------------------------------------------
134     c
135     c set the field outside the interpolation volume to be 0
136     c
137     c------------------------------------------------------------------------
138    
139     do ip=1,3
140     res(ip)=0.
141     enddo
142    
143    
144     c------------------------------------------------------------------------
145     c
146     c check if the point falls inside the interpolation volumes
147     c
148     c------------------------------------------------------------------------
149    
150     * -----------------------
151     * INNER MAP
152     * -----------------------
153     if(
154     $ (x.ge.edgexmin).and.(x.le.edgexmax)
155     $ .and.(y.ge.edgeymin).and.(y.le.edgeymax)
156     $ .and.(z.ge.edgezmin).and.(z.le.edgezmax)
157     $ ) then
158    
159     call inter_B_inner(x,y,z,res)
160     c print*,'INNER - ',z,res
161    
162     endif
163    
164     * -----------------------
165     * OUTER MAP
166     * -----------------------
167     if(
168     $ ((x.ge.edgeuxmin).and.(x.le.edgeuxmax)
169     $ .and.(y.ge.edgeuymin).and.(y.le.edgeuymax)
170     $ .and.(z.ge.edgeuzmin).and.(z.le.edgeuzmax))
171     $ .or.
172     $ ((x.ge.edgelxmin).and.(x.le.edgelxmax)
173     $ .and.(y.ge.edgelymin).and.(y.le.edgelymax)
174     $ .and.(z.ge.edgelzmin).and.(z.le.edgelzmax))
175     $ ) then
176    
177     call inter_B_outer(x,y,z,res)
178     c res(2)=res(2)*10
179     c print*,'OUTER - ',z,res
180    
181     endif
182    
183     * --------------------------------
184     * GAP between INNER and OUTER MAPS
185     * --------------------------------
186     if(
187     $ (x.gt.edgexmin).and.(x.lt.edgexmax)
188     $ .and.(y.gt.edgeymin).and.(y.lt.edgeymax)
189     $ .and.(z.gt.edgezmax).and.(z.lt.edgeuzmin)
190     $ )then
191    
192     zu = edgeuzmin
193     zl = edgezmax
194     call inter_B_inner(x,y,zl,resu)
195     call inter_B_outer(x,y,zu,resl)
196    
197     do i=1,3
198     res(i) = z * ((resu(i)-resl(i))/(zu-zl))
199     $ + resu(i)
200     $ - zu * ((resu(i)-resl(i))/(zu-zl))
201     enddo
202     c print*,'GAP U - ',z,res
203    
204     elseif(
205     $ (x.gt.edgexmin).and.(x.lt.edgexmax)
206     $ .and.(y.gt.edgeymin).and.(y.lt.edgeymax)
207     $ .and.(z.gt.edgelzmax).and.(z.lt.edgezmin)
208     $ ) then
209    
210    
211     zu = edgezmin
212     zl = edgelzmax
213     call inter_B_inner(x,y,zu,resu)
214     call inter_B_outer(x,y,zl,resl)
215    
216     do i=1,3
217     res(i) = z * ((resu(i)-resl(i))/(zu-zl))
218     $ + resu(i)
219     $ - zu * ((resu(i)-resl(i))/(zu-zl))
220     enddo
221     c print*,'GAP D - ',z,res
222    
223     endif
224    
225     return
226     end
227    
228    
229     include './inter_B_inner.f'
230     include './inter_B_outer.f'
231     inter_B_inner.f0100640000076700007640000001662510252260077013715 0ustar vannucciwizard*************************************************************************
232     *
233     * Subroutine inter_B_inner.f
234     *
235     * it computes the magnetic field in a chosen point x,y,z inside the
236     * magnetic cavity, using a trilinear interpolation of
237     * B field measurements (read before by means of ./read_B.f)
238     * the value is computed for two different inner maps and then averaged
239     *
240     * needs:
241     * - ../common/common_B_inner.f
242     *
243     * input: coordinates in m
244     * output: magnetic field in T
245     *
246     *************************************************************************
247    
248     subroutine inter_B_inner(x,y,z,res) !coordinates in m, magnetic field in T
249    
250     implicit double precision (a-h,o-z)
251     include '../common/common_B_inner.f'
252    
253    
254     c------------------------------------------------------------------------
255     c
256     c local variables
257     c
258     c------------------------------------------------------------------------
259    
260     real*8 x,y,z !point of interpolation
261     real*8 res(3) !interpolated B components: res = (Bx, By, Bz)
262     real*8 res1(3),res2(3) !interpolated B components for the two maps
263    
264     integer ic !index for B components:
265     ! ic=1 ---> Bx
266     ! ic=2 ---> By
267     ! ic=3 ---> Bz
268    
269     integer cube(3) !vector of indexes identifying the cube
270     ! containing the point of interpolation
271     ! (see later...)
272    
273     real*8 xl,xh,yl,yh,zl,zh !cube vertexes coordinates
274    
275     real*8 xr,yr,zr !reduced variables (coordinates of the
276     ! point of interpolation inside the cube)
277    
278     real*8 Bp(8) !vector of values of B component
279     ! being computed, on the eight cube vertexes
280    
281    
282     c------------------------------------------------------------------------
283     c
284     c *** FIRST MAP ***
285     c
286     c------------------------------------------------------------------------
287    
288     do ic=1,3 !loops on the three B components
289    
290     c------------------------------------------------------------------------
291     c
292     c chooses the coordinates interval containing the input point
293     c
294     c------------------------------------------------------------------------
295     c e.g.:
296     c
297     c x1 x2 x3 x4 x5...
298     c |-----|-+---|-----|-----|----
299     c ~~~~~~~~x
300     c
301     c in this case the right interval is identified by indexes 2-3, so the
302     c value assigned to cube variable is 2
303    
304     cube(1)=INT((nx-1)*(x-px1min(ic))/(px1max(ic)-px1min(ic))) +1
305     cube(2)=INT((ny-1)*(y-py1min(ic))/(py1max(ic)-py1min(ic))) +1
306     cube(3)=INT((nz-1)*(z-pz1min(ic))/(pz1max(ic)-pz1min(ic))) +1
307    
308     c------------------------------------------------------------------------
309     c
310     c if the point falls beyond the extremes of the grid...
311     c
312     c------------------------------------------------------------------------
313     c
314     c ~~~~~~~~~~x1 x2 x3...
315     c - - + - - |-----|-----|----
316     c ~~~~x
317     c
318     c in the case cube = 1
319     c
320     c
321     c ...nx-2 nx-1 nx
322     c ----|-----|-----| - - - + - -
323     c ~~~~~~~~~~~~~~~~~~~~~~~~x
324     c
325     c in this case cube = nx-1
326    
327     if (cube(1).le.0) cube(1) = 1
328     if (cube(2).le.0) cube(2) = 1
329     if (cube(3).le.0) cube(3) = 1
330     if (cube(1).ge.nx) cube(1) = nx-1
331     if (cube(2).ge.ny) cube(2) = ny-1
332     if (cube(3).ge.nz) cube(3) = nz-1
333    
334    
335     c------------------------------------------------------------------------
336     c
337     c temporary variables definition for field computation
338     c
339     c------------------------------------------------------------------------
340    
341     xl = px1(cube(1),ic) !X coordinates of cube vertexes
342     xh = px1(cube(1)+1,ic)
343    
344     yl = py1(cube(2),ic) !Y coordinates of cube vertexes
345     yh = py1(cube(2)+1,ic)
346    
347     zl = pz1(cube(3),ic) !Z coordinates of cube vertexes
348     zh = pz1(cube(3)+1,ic)
349    
350     xr = (x-xl) / (xh-xl) !reduced variables
351     yr = (y-yl) / (yh-yl)
352     zr = (z-zl) / (zh-zl)
353    
354     Bp(1) = b1(cube(1) ,cube(2) ,cube(3) ,ic) !ic-th component of B
355     Bp(2) = b1(cube(1)+1,cube(2) ,cube(3) ,ic) ! on the eight cube
356     Bp(3) = b1(cube(1) ,cube(2)+1,cube(3) ,ic) ! vertexes
357     Bp(4) = b1(cube(1)+1,cube(2)+1,cube(3) ,ic)
358     Bp(5) = b1(cube(1) ,cube(2) ,cube(3)+1,ic)
359     Bp(6) = b1(cube(1)+1,cube(2) ,cube(3)+1,ic)
360     Bp(7) = b1(cube(1) ,cube(2)+1,cube(3)+1,ic)
361     Bp(8) = b1(cube(1)+1,cube(2)+1,cube(3)+1,ic)
362    
363     c------------------------------------------------------------------------
364     c
365     c computes interpolated ic-th component of B in (x,y,z)
366     c
367     c------------------------------------------------------------------------
368    
369     res1(ic) =
370     + Bp(1)*(1-xr)*(1-yr)*(1-zr) +
371     + Bp(2)*xr*(1-yr)*(1-zr) +
372     + Bp(3)*(1-xr)*yr*(1-zr) +
373     + Bp(4)*xr*yr*(1-zr) +
374     + Bp(5)*(1-xr)*(1-yr)*zr +
375     + Bp(6)*xr*(1-yr)*zr +
376     + Bp(7)*(1-xr)*yr*zr +
377     + Bp(8)*xr*yr*zr
378    
379    
380     enddo
381    
382     c------------------------------------------------------------------------
383     c
384     c *** SECOND MAP ***
385     c
386     c------------------------------------------------------------------------
387    
388     c second map is rotated by 180 degree along the Z axis. so change sign
389     c of x and y coordinates and then change sign to Bx and By components
390     c to obtain the correct result
391    
392     x=-x
393     y=-y
394    
395     do ic=1,3
396    
397     cube(1)=INT((nx-1)*(x-px2min(ic))/(px2max(ic)-px2min(ic))) +1
398     cube(2)=INT((ny-1)*(y-py2min(ic))/(py2max(ic)-py2min(ic))) +1
399     cube(3)=INT((nz-1)*(z-pz2min(ic))/(pz2max(ic)-pz2min(ic))) +1
400    
401     if (cube(1).le.0) cube(1) = 1
402     if (cube(2).le.0) cube(2) = 1
403     if (cube(3).le.0) cube(3) = 1
404     if (cube(1).ge.nx) cube(1) = nx-1
405     if (cube(2).ge.ny) cube(2) = ny-1
406     if (cube(3).ge.nz) cube(3) = nz-1
407    
408     xl = px2(cube(1),ic)
409     xh = px2(cube(1)+1,ic)
410    
411     yl = py2(cube(2),ic)
412     yh = py2(cube(2)+1,ic)
413    
414     zl = pz2(cube(3),ic)
415     zh = pz2(cube(3)+1,ic)
416    
417     xr = (x-xl) / (xh-xl)
418     yr = (y-yl) / (yh-yl)
419     zr = (z-zl) / (zh-zl)
420    
421     Bp(1) = b2(cube(1) ,cube(2) ,cube(3) ,ic)
422     Bp(2) = b2(cube(1)+1,cube(2) ,cube(3) ,ic)
423     Bp(3) = b2(cube(1) ,cube(2)+1,cube(3) ,ic)
424     Bp(4) = b2(cube(1)+1,cube(2)+1,cube(3) ,ic)
425     Bp(5) = b2(cube(1) ,cube(2) ,cube(3)+1,ic)
426     Bp(6) = b2(cube(1)+1,cube(2) ,cube(3)+1,ic)
427     Bp(7) = b2(cube(1) ,cube(2)+1,cube(3)+1,ic)
428     Bp(8) = b2(cube(1)+1,cube(2)+1,cube(3)+1,ic)
429    
430     res2(ic) =
431     + Bp(1)*(1-xr)*(1-yr)*(1-zr) +
432     + Bp(2)*xr*(1-yr)*(1-zr) +
433     + Bp(3)*(1-xr)*yr*(1-zr) +
434     + Bp(4)*xr*yr*(1-zr) +
435     + Bp(5)*(1-xr)*(1-yr)*zr +
436     + Bp(6)*xr*(1-yr)*zr +
437     + Bp(7)*(1-xr)*yr*zr +
438     + Bp(8)*xr*yr*zr
439    
440     enddo
441    
442     c change Bx and By components sign
443     res2(1)=-res2(1)
444     res2(2)=-res2(2)
445    
446     c change back the x and y coordinate signs
447     x=-x
448     y=-y
449    
450    
451     c------------------------------------------------------------------------
452     c
453     c average the two maps results
454     c
455     c------------------------------------------------------------------------
456    
457     do ic=1,3
458     res(ic)=(res1(ic)+res2(ic))/2
459     enddo
460    
461    
462     return
463     end
464     inter_B_outer.f0100640000076700007640000001234110252267445013735 0ustar vannucciwizard*************************************************************************
465     *
466     * Subroutine inter_B_outer.f
467     *
468     * it computes the magnetic field in a chosen point x,y,z OUTSIDE the
469     * magnetic cavity, using a trilinear interpolation of
470     * B field measurements (read before by means of ./read_B.f)
471     * the value is computed for the outer map
472     *
473     * needs:
474     * - ../common/common_B_outer.f
475     *
476     * input: coordinates in m
477     * output: magnetic field in T
478     *
479     *************************************************************************
480    
481     subroutine inter_B_outer(x,y,z,res) !coordinates in m, magnetic field in T
482    
483     implicit double precision (a-h,o-z)
484     include '../common/common_B_outer.f'
485    
486    
487     c------------------------------------------------------------------------
488     c
489     c local variables
490     c
491     c------------------------------------------------------------------------
492    
493     real*8 x,y,z !point of interpolation
494     real*8 res(3) !interpolated B components: res = (Bx, By, Bz)
495     real*8 zin
496    
497     integer ic
498     c !index for B components:
499     c ! ic=1 ---> Bx
500     c ! ic=2 ---> By
501     c ! ic=3 ---> Bz
502    
503     integer cube(3)
504     c !vector of indexes identifying the cube
505     c ! containing the point of interpolation
506     c ! (see later...)
507    
508     real*8 xl,xh,yl,yh,zl,zh !cube vertexes coordinates
509    
510     real*8 xr,yr,zr
511     c !reduced variables (coordinates of the
512     c ! point of interpolation inside the cube)
513    
514     real*8 Bp(8)
515     c !vector of values of B component
516     c ! being computed, on the eight cube vertexes
517    
518    
519     c LOWER MAP
520     c ---> up/down simmetry
521     zin=z
522     if(zin.le.edgelzmax)z=-z
523    
524     c------------------------------------------------------------------------
525     c
526     c *** MAP ***
527     c
528     c------------------------------------------------------------------------
529    
530     do ic=1,3 !loops on the three B components
531    
532     c------------------------------------------------------------------------
533     c
534     c chooses the coordinates interval containing the input point
535     c
536     c------------------------------------------------------------------------
537     c e.g.:
538     c
539     c x1 x2 x3 x4 x5... xN
540     c |-----|-+---|-----|-----|---- ... ----|-----|
541     c ~~~~~~~~x
542     c
543     c in this case the right interval is identified by indexes 2-3, so the
544     c value assigned to cube variable is 2
545    
546     cube(1)=INT((nox-1)*(x-poxmin(ic))/(poxmax(ic)-poxmin(ic))) +1
547     cube(2)=INT((noy-1)*(y-poymin(ic))/(poymax(ic)-poymin(ic))) +1
548     cube(3)=INT((noz-1)*(z-pozmin(ic))/(pozmax(ic)-pozmin(ic))) +1
549    
550     c------------------------------------------------------------------------
551     c
552     c if the point falls beyond the extremes of the grid...
553     c
554     c------------------------------------------------------------------------
555     c
556     c ~~~~~~~~~~x1 x2 x3...
557     c - - + - - |-----|-----|----
558     c ~~~~x
559     c
560     c in the case cube = 1
561     c
562     c
563     c ...nx-2 nx-1 nx
564     c ----|-----|-----| - - - + - -
565     c ~~~~~~~~~~~~~~~~~~~~~~~~x
566     c
567     c in this case cube = nx-1
568    
569     if (cube(1).le.0) cube(1) = 1
570     if (cube(2).le.0) cube(2) = 1
571     if (cube(3).le.0) cube(3) = 1
572     if (cube(1).ge.nox) cube(1) = nox-1
573     if (cube(2).ge.noy) cube(2) = noy-1
574     if (cube(3).ge.noz) cube(3) = noz-1
575    
576    
577     c------------------------------------------------------------------------
578     c
579     c temporary variables definition for field computation
580     c
581     c------------------------------------------------------------------------
582    
583     xl = pox(cube(1),ic) !X coordinates of cube vertexes
584     xh = pox(cube(1)+1,ic)
585    
586     yl = poy(cube(2),ic) !Y coordinates of cube vertexes
587     yh = poy(cube(2)+1,ic)
588    
589     zl = poz(cube(3),ic) !Z coordinates of cube vertexes
590     zh = poz(cube(3)+1,ic)
591    
592     xr = (x-xl) / (xh-xl) !reduced variables
593     yr = (y-yl) / (yh-yl)
594     zr = (z-zl) / (zh-zl)
595    
596     Bp(1) = bo(cube(1) ,cube(2) ,cube(3) ,ic) !ic-th component of B
597     Bp(2) = bo(cube(1)+1,cube(2) ,cube(3) ,ic) ! on the eight cube
598     Bp(3) = bo(cube(1) ,cube(2)+1,cube(3) ,ic) ! vertexes
599     Bp(4) = bo(cube(1)+1,cube(2)+1,cube(3) ,ic)
600     Bp(5) = bo(cube(1) ,cube(2) ,cube(3)+1,ic)
601     Bp(6) = bo(cube(1)+1,cube(2) ,cube(3)+1,ic)
602     Bp(7) = bo(cube(1) ,cube(2)+1,cube(3)+1,ic)
603     Bp(8) = bo(cube(1)+1,cube(2)+1,cube(3)+1,ic)
604    
605     c------------------------------------------------------------------------
606     c
607     c computes interpolated ic-th component of B in (x,y,z)
608     c
609     c------------------------------------------------------------------------
610    
611     res(ic) =
612     + Bp(1)*(1-xr)*(1-yr)*(1-zr) +
613     + Bp(2)*xr*(1-yr)*(1-zr) +
614     + Bp(3)*(1-xr)*yr*(1-zr) +
615     + Bp(4)*xr*yr*(1-zr) +
616     + Bp(5)*(1-xr)*(1-yr)*zr +
617     + Bp(6)*xr*(1-yr)*zr +
618     + Bp(7)*(1-xr)*yr*zr +
619     + Bp(8)*xr*yr*zr
620    
621    
622     enddo
623    
624     c LOWER MAP
625     c ---> up/down simmetry
626     if(zin.le.edgelzmax)then
627     z=-z !back to initial ccoordinate
628     res(3)=-res(3) !invert BZ component
629     endif
630    
631     return
632     end
633     read_B.f0100640000076700007640000000156310252256652012313 0ustar vannucciwizard*************************************************************************
634     *
635     * Subroutine read_B.f
636     *
637     * it calls the subroutines which read the magnetic field maps for
638     * the PAMELA spectrometer
639     *
640     * needs:
641     * - ./read_B_inner.f inner map reading subroutine
642     * - ./read_B_outer.f outer map reading subroutine
643     *
644     * to be called before ./inter_B.f (interpolation subroutine)
645     *
646     *************************************************************************
647    
648     subroutine read_B
649    
650     c call the subroutine which reads the maps of the measurements taken
651     c inside the magnetic cavity
652     call read_B_inner
653    
654     c call the subroutine which reads the maps of the measurements taken
655     c outside the magnetic cavity
656     call read_B_outer
657    
658     return
659     end
660    
661     include './read_B_inner.f'
662     include './read_B_outer.f'
663     read_B_inner.f0100640000076700007640000002564510252261245013507 0ustar vannucciwizard*************************************************************************
664     *
665     * Subroutine read_B_inner.f
666     *
667     * it reads from rz files the two magnetic field maps taken inside the
668     * spectrometer cavity and fills the variables in common_B_inner.f
669     *
670     * needs:
671     * - ../common/common_B_inner.f common file for the inner magnetic field map
672     * - .rz map files in ./ containing coordinates of measured points, Bx, By
673     * and Bz components + errors
674     *
675     * output variables: (see common_B_inner.f)
676     * - px#(nx,3) with #=1,2 for the 2 maps
677     * - py#(ny,3)
678     * - pz#(nz,3)
679     * - b#(nx,ny,nz,3)
680     *
681     *************************************************************************
682    
683     subroutine read_B_inner
684    
685     implicit double precision (a-h,o-z)
686     include '../common/common_B_inner.f'
687    
688    
689     c------------------------------------------------------------------------
690     c
691     c local variables
692     c
693     c------------------------------------------------------------------------
694    
695     character*64 Bmap_file !magnetic field file name
696     c character*120 cmd1
697     c character*120 cmd2
698     parameter (lun_Bmap_file=66) !magnetic field map file id number
699    
700     parameter (ntpl_Bmap=20) !ntuple identifier
701    
702     REAL PFX(3),FX,DFX, !Bx field component coordinates in m, value and error in T
703     $ PFY(3),FY,DFY
704     $ ,PFZ(3),FZ,DFZ
705     INTEGER INDEX(3) !point index
706    
707     COMMON /PAWCR4/ INDEX,PFX,FX,DFX,PFY,FY,DFY,PFZ,FZ,DFZ
708    
709    
710     c------------------------------------------------------------------------
711     c
712     c *** FIRST MAP ***
713     c
714     c------------------------------------------------------------------------
715    
716     c------------------------------------------------------------------------
717     c
718     c initialization and map file opening
719     c
720     c------------------------------------------------------------------------
721    
722     c print*,' '
723     c print*,' '
724    
725     Bmap_file='measure_n3_290302.rz'
726    
727     c$$$ cmd1='cp $TRK_GRND/source/magnet/'
728     c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))//' .'
729     c$$$ call system(cmd1)
730    
731     c opens magnetic field map first file
732     print *,'Opening file: ',Bmap_file
733     call HROPEN
734     $ (lun_Bmap_file,'Bmap','./bin-aux/'//Bmap_file,'P',1024,istat)
735     if(istat.ne.0) goto 21
736    
737    
738     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
739    
740     c call HPRNTU(ntpl_Bmap)
741     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
742     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
743     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
744     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
745     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
746    
747    
748     c------------------------------------------------------------------------
749     c
750     c reads events and fills variables
751     c
752     c------------------------------------------------------------------------
753    
754     call HNOENT(ntpl_Bmap,iemax) !number of events
755    
756     c initializes measurement grid edges
757     do ic=1,3
758     px1max(ic)=0.
759     px1min(ic)=0.
760     py1max(ic)=0.
761     py1min(ic)=0.
762     pz1max(ic)=0.
763     pz1min(ic)=0.
764     enddo
765    
766    
767     do iev=1,iemax !event loop
768    
769     call HGNT(ntpl_Bmap,iev,ierr) !reads event
770     if(ierr.ne.0) goto 22
771    
772     c the output consists of matrices for coordinates, B components values
773     c and errors:
774     c e.g. px1(4,2) = X coordinate of the point with index = 4 along X,
775     c in which By (=2) component has been measured
776     c e.g. b1(3,23,4,1) = Bx (=1) component value, measured in the point with
777     c indexes = 3,23,4 along X, Y and Z
778    
779     c Bx component
780     px1(index(1),1) = pfx(1)
781     if(px1(index(1),1).lt.px1min(1)) px1min(1)=px1(index(1),1)
782     if(px1(index(1),1).gt.px1max(1)) px1max(1)=px1(index(1),1)
783     py1(index(2),1) = pfx(2)
784     if(py1(index(2),1).lt.py1min(1)) py1min(1)=py1(index(2),1)
785     if(py1(index(2),1).gt.py1max(1)) py1max(1)=py1(index(2),1)
786     pz1(index(3),1) = pfx(3)
787     if(pz1(index(3),1).lt.pz1min(1)) pz1min(1)=pz1(index(3),1)
788     if(pz1(index(3),1).gt.pz1max(1)) pz1max(1)=pz1(index(3),1)
789    
790     b1(index(1),index(2),index(3),1) = fx
791    
792    
793     c By component
794     px1(index(1),2) = pfy(1)
795     if(px1(index(1),2).lt.px1min(2)) px1min(2)=px1(index(1),2)
796     if(px1(index(1),2).gt.px1max(2)) px1max(2)=px1(index(1),2)
797     py1(index(2),2) = pfy(2)
798     if(py1(index(2),2).lt.py1min(2)) py1min(2)=py1(index(2),2)
799     if(py1(index(2),2).gt.py1max(2)) py1max(2)=py1(index(2),2)
800     pz1(index(3),2) = pfy(3)
801     if(pz1(index(3),2).lt.pz1min(2)) pz1min(2)=pz1(index(3),2)
802     if(pz1(index(3),2).gt.pz1max(2)) pz1max(2)=pz1(index(3),2)
803    
804     b1(index(1),index(2),index(3),2) = fy
805    
806    
807     c Bz component
808     px1(index(1),3) = pfz(1)
809     if(px1(index(1),3).lt.px1min(3)) px1min(3)=px1(index(1),3)
810     if(px1(index(1),3).gt.px1max(3)) px1max(3)=px1(index(1),3)
811     py1(index(2),3) = pfz(2)
812     if(py1(index(2),3).lt.py1min(3)) py1min(3)=py1(index(2),3)
813     if(py1(index(2),3).gt.py1max(3)) py1max(3)=py1(index(2),3)
814     pz1(index(3),3) = pfz(3)
815     if(pz1(index(3),3).lt.pz1min(3)) pz1min(3)=pz1(index(3),3)
816     if(pz1(index(3),3).gt.pz1max(3)) pz1max(3)=pz1(index(3),3)
817    
818     b1(index(1),index(2),index(3),3) = fz
819    
820     enddo
821    
822    
823     c------------------------------------------------------------------------
824     c
825     c closes files
826     c
827     c------------------------------------------------------------------------
828    
829     call HREND('Bmap')
830     close(lun_Bmap_file)
831     c$$$ cmd2='rm -f '
832     c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))
833     c$$$ call system(cmd2)
834     c$$$
835    
836    
837     c------------------------------------------------------------------------
838     c
839     c *** SECOND MAP ***
840     c
841     c------------------------------------------------------------------------
842    
843     c------------------------------------------------------------------------
844     c
845     c initialization and map file opening
846     c
847     c------------------------------------------------------------------------
848    
849     c print*,' '
850     c print*,' '
851    
852     Bmap_file='measure_n4_110402_corrected.rz'
853     c$$$ cmd1='cp $TRK_GRND/source/magnet/'
854     c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))//' .'
855     c$$$ call system(cmd1)
856    
857     c opens magnetic field map first file
858     print *,'Opening file: ',Bmap_file
859     call HROPEN
860     $ (lun_Bmap_file,'Bmap','./bin-aux/'//Bmap_file,'P',1024,istat)
861     if(istat.ne.0) goto 21
862    
863    
864     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
865    
866     c call HPRNTU(ntpl_Bmap)
867     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
868     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
869     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
870     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
871     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
872    
873    
874     c------------------------------------------------------------------------
875     c
876     c reads events and fills variables
877     c
878     c------------------------------------------------------------------------
879    
880     call HNOENT(ntpl_Bmap,iemax) !number of events
881    
882     do ic=1,3 !grid edges
883     px2max(ic)=0.
884     px2min(ic)=0.
885     py2max(ic)=0.
886     py2min(ic)=0.
887     pz2max(ic)=0.
888     pz2min(ic)=0.
889     enddo
890    
891    
892     do iev=1,iemax !event loop
893    
894     call HGNT(ntpl_Bmap,iev,ierr) !reads event
895     if(ierr.ne.0) goto 22
896    
897     c the output consists of matrices for coordinates, B components values
898     c and errors:
899     c e.g. px(4,2) = X coordinate of the point with index = 4 along X,
900     c in which By (=2) component has been measured
901     c e.g. b(3,23,4,1) = Bx (=1) component value, measured in the point with
902     c indexes = 3,23,4 along X, Y and Z
903    
904     c Bx component
905     px2(index(1),1) = pfx(1)
906     if(px2(index(1),1).lt.px2min(1)) px2min(1)=px2(index(1),1)
907     if(px2(index(1),1).gt.px2max(1)) px2max(1)=px2(index(1),1)
908     py2(index(2),1) = pfx(2)
909     if(py2(index(2),1).lt.py2min(1)) py2min(1)=py2(index(2),1)
910     if(py2(index(2),1).gt.py2max(1)) py2max(1)=py2(index(2),1)
911     pz2(index(3),1) = pfx(3)
912     if(pz2(index(3),1).lt.pz2min(1)) pz2min(1)=pz2(index(3),1)
913     if(pz2(index(3),1).gt.pz2max(1)) pz2max(1)=pz2(index(3),1)
914    
915     b2(index(1),index(2),index(3),1) = fx
916    
917    
918     c By component
919     px2(index(1),2) = pfy(1)
920     if(px2(index(1),2).lt.px2min(2)) px2min(2)=px2(index(1),2)
921     if(px2(index(1),2).gt.px2max(2)) px2max(2)=px2(index(1),2)
922     py2(index(2),2) = pfy(2)
923     if(py2(index(2),2).lt.py2min(2)) py2min(2)=py2(index(2),2)
924     if(py2(index(2),2).gt.py2max(2)) py2max(2)=py2(index(2),2)
925     pz2(index(3),2) = pfy(3)
926     if(pz2(index(3),2).lt.pz2min(2)) pz2min(2)=pz2(index(3),2)
927     if(pz2(index(3),2).gt.pz2max(2)) pz2max(2)=pz2(index(3),2)
928    
929     b2(index(1),index(2),index(3),2) = fy
930    
931    
932     c Bz component
933     px2(index(1),3) = pfz(1)
934     if(px2(index(1),3).lt.px2min(3)) px2min(3)=px2(index(1),3)
935     if(px2(index(1),3).gt.px2max(3)) px2max(3)=px2(index(1),3)
936     py2(index(2),3) = pfz(2)
937     if(py2(index(2),3).lt.py2min(3)) py2min(3)=py2(index(2),3)
938     if(py2(index(2),3).gt.py2max(3)) py2max(3)=py2(index(2),3)
939     pz2(index(3),3) = pfz(3)
940     if(pz2(index(3),3).lt.pz2min(3)) pz2min(3)=pz2(index(3),3)
941     if(pz2(index(3),3).gt.pz2max(3)) pz2max(3)=pz2(index(3),3)
942    
943     b2(index(1),index(2),index(3),3) = fz
944    
945     enddo
946    
947    
948     c------------------------------------------------------------------------
949     c
950     c closes files
951     c
952     c------------------------------------------------------------------------
953    
954     call HREND('Bmap')
955     close(lun_Bmap_file)
956     c$$$ cmd2='rm -f '
957     c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))
958     c$$$ call system(cmd2)
959    
960    
961     c------------------------------------------------------------------------
962     c
963     c no error exit
964     c
965     c------------------------------------------------------------------------
966    
967     c$$$ print*,' '
968     c$$$ print*,'MAGNETIC FIELD SUCCESSFULLY READ'
969     c$$$ print*,' '
970     c$$$ print*,' '
971    
972     goto 9000 !happy ending
973    
974     c------------------------------------------------------------------------
975     c
976     c magnetic field map file opening error
977     c
978     c------------------------------------------------------------------------
979    
980     21 continue
981    
982     print*,' '
983     print*,'read_B_inner: ERROR OPENING MAGNETIC FIELD MAP FILE: '
984     $ ,Bmap_file
985     print*,' '
986     print*,' '
987    
988     goto 9000 !the end
989    
990    
991     c------------------------------------------------------------------------
992     c
993     c ntuple event reading error
994     c
995     c------------------------------------------------------------------------
996    
997     22 continue
998    
999     print*,' '
1000     print*,'read_B_inner: ERROR WHILE READING NTUPLE, AT EVENT
1001     $ : ',iev
1002     print*,' '
1003     print*,' '
1004    
1005     goto 9000 !the end
1006    
1007    
1008     c------------------------------------------------------------------------
1009     c
1010     c exit
1011     c
1012     c------------------------------------------------------------------------
1013    
1014     9000 continue
1015    
1016     return
1017     end
1018     read_B_outer.f0100640000076700007640000001510610252261222013514 0ustar vannucciwizard*************************************************************************
1019     *
1020     * Subroutine read_B_outer.f
1021     *
1022     * it reads from rz files the two magnetic field maps taken inside the
1023     * spectrometer cavity and fills the variables in common_B_inner.f
1024     *
1025     * needs:
1026     * - ../common/common_B_outer.f common file for the outer magnetic field map
1027     * - .rz map files in ./ containing coordinates of measured points, Bx, By
1028     * and Bz components + errors
1029     *
1030     * output variables: (see common_B_outer.f)
1031     * - pxo(nx,3)
1032     * - pyo(ny,3)
1033     * - pzo(nz,3)
1034     * - bo(nx,ny,nz,3)
1035     *
1036     *************************************************************************
1037    
1038     subroutine read_B_outer
1039    
1040     implicit double precision (a-h,o-z)
1041     include '../common/common_B_outer.f'
1042    
1043    
1044     c------------------------------------------------------------------------
1045     c
1046     c local variables
1047     c
1048     c------------------------------------------------------------------------
1049    
1050     character*64 Bmap_file !magnetic field file name
1051     parameter (lun_Bmap_file=66) !magnetic field map file id number
1052    
1053     parameter (ntpl_Bmap=20) !ntuple identifier
1054    
1055     REAL PFX(3),FX,DFX, !Bx field component coordinates in m, value and error in T
1056     $ PFY(3),FY,DFY
1057     $ ,PFZ(3),FZ,DFZ
1058     INTEGER INDEX(3) !point index
1059    
1060     COMMON /PAWCR4/ INDEX,PFX,FX,DFX,PFY,FY,DFY,PFZ,FZ,DFZ
1061    
1062    
1063     c------------------------------------------------------------------------
1064     c
1065     c *** FIRST MAP ***
1066     c
1067     c------------------------------------------------------------------------
1068    
1069     c------------------------------------------------------------------------
1070     c
1071     c initialization and map file opening
1072     c
1073     c------------------------------------------------------------------------
1074    
1075     c print*,' '
1076     c print*,' '
1077    
1078     Bmap_file='External_top_map_n4_150402.rz'
1079    
1080     c opens magnetic field map first file
1081     print *,'Opening file: ',Bmap_file
1082     call HROPEN
1083     $ (lun_Bmap_file,'Bmap','./bin-aux/'//Bmap_file,'P',1024,istat)
1084     if(istat.ne.0) goto 21
1085    
1086    
1087     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
1088    
1089     c call HPRNTU(ntpl_Bmap)
1090     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
1091     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
1092     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
1093     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
1094     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
1095    
1096    
1097     c------------------------------------------------------------------------
1098     c
1099     c reads events and fills variables
1100     c
1101     c------------------------------------------------------------------------
1102    
1103     call HNOENT(ntpl_Bmap,iemax) !number of events
1104    
1105     c initializes measurement grid edges
1106     do ic=1,3
1107     poxmax(ic)=0.
1108     poxmin(ic)=0.
1109     poymax(ic)=0.
1110     poymin(ic)=0.
1111     pozmax(ic)=0.
1112     pozmin(ic)=0.
1113     enddo
1114    
1115    
1116     do iev=1,iemax !event loop
1117    
1118     call HGNT(ntpl_Bmap,iev,ierr) !reads event
1119     if(ierr.ne.0) goto 22
1120    
1121     c the output consists of matrices for coordinates, B components values
1122     c and errors:
1123     c e.g. px1(4,2) = X coordinate of the point with index = 4 along X,
1124     c in which By (=2) component has been measured
1125     c e.g. b1(3,23,4,1) = Bx (=1) component value, measured in the point with
1126     c indexes = 3,23,4 along X, Y and Z
1127    
1128     c Bx component
1129     pox(index(1),1) = pfx(1)
1130     if(pox(index(1),1).lt.poxmin(1)) poxmin(1)=pox(index(1),1)
1131     if(pox(index(1),1).gt.poxmax(1)) poxmax(1)=pox(index(1),1)
1132     poy(index(2),1) = pfx(2)
1133     if(poy(index(2),1).lt.poymin(1)) poymin(1)=poy(index(2),1)
1134     if(poy(index(2),1).gt.poymax(1)) poymax(1)=poy(index(2),1)
1135     poz(index(3),1) = pfx(3)
1136     if(poz(index(3),1).lt.pozmin(1)) pozmin(1)=poz(index(3),1)
1137     if(poz(index(3),1).gt.pozmax(1)) pozmax(1)=poz(index(3),1)
1138    
1139     bo(index(1),index(2),index(3),1) = fx
1140    
1141    
1142     c By component
1143     pox(index(1),2) = pfy(1)
1144     if(pox(index(1),2).lt.poxmin(2)) poxmin(2)=pox(index(1),2)
1145     if(pox(index(1),2).gt.poxmax(2)) poxmax(2)=pox(index(1),2)
1146     poy(index(2),2) = pfy(2)
1147     if(poy(index(2),2).lt.poymin(2)) poymin(2)=poy(index(2),2)
1148     if(poy(index(2),2).gt.poymax(2)) poymax(2)=poy(index(2),2)
1149     poz(index(3),2) = pfy(3)
1150     if(poz(index(3),2).lt.pozmin(2)) pozmin(2)=poz(index(3),2)
1151     if(poz(index(3),2).gt.pozmax(2)) pozmax(2)=poz(index(3),2)
1152    
1153     bo(index(1),index(2),index(3),2) = fy
1154    
1155    
1156     c Bz component
1157     pox(index(1),3) = pfz(1)
1158     if(pox(index(1),3).lt.poxmin(3)) poxmin(3)=pox(index(1),3)
1159     if(pox(index(1),3).gt.poxmax(3)) poxmax(3)=pox(index(1),3)
1160     poy(index(2),3) = pfz(2)
1161     if(poy(index(2),3).lt.poymin(3)) poymin(3)=poy(index(2),3)
1162     if(poy(index(2),3).gt.poymax(3)) poymax(3)=poy(index(2),3)
1163     poz(index(3),3) = pfz(3)
1164     if(poz(index(3),3).lt.pozmin(3)) pozmin(3)=poz(index(3),3)
1165     if(poz(index(3),3).gt.pozmax(3)) pozmax(3)=poz(index(3),3)
1166    
1167     bo(index(1),index(2),index(3),3) = fz
1168    
1169     enddo
1170    
1171    
1172     c------------------------------------------------------------------------
1173     c
1174     c closes files
1175     c
1176     c------------------------------------------------------------------------
1177    
1178     call HREND('Bmap')
1179     close(lun_Bmap_file)
1180    
1181    
1182     c------------------------------------------------------------------------
1183     c
1184     c no error exit
1185     c
1186     c------------------------------------------------------------------------
1187    
1188     c$$$ print*,' '
1189     c$$$ print*,'MAGNETIC FIELD SUCCESSFULLY READ'
1190     c$$$ print*,' '
1191     c$$$ print*,' '
1192    
1193     goto 9000 !happy ending
1194    
1195     c------------------------------------------------------------------------
1196     c
1197     c magnetic field map file opening error
1198     c
1199     c------------------------------------------------------------------------
1200    
1201     21 continue
1202    
1203     print*,' '
1204     print*,'read_B_inner: ERROR OPENING MAGNETIC FIELD MAP FILE: '
1205     $ ,Bmap_file
1206     print*,' '
1207     print*,' '
1208    
1209     goto 9000 !the end
1210    
1211    
1212     c------------------------------------------------------------------------
1213     c
1214     c ntuple event reading error
1215     c
1216     c------------------------------------------------------------------------
1217    
1218     22 continue
1219    
1220     print*,' '
1221     print*,'read_B_inner: ERROR WHILE READING NTUPLE, AT EVENT
1222     $ : ',iev
1223     print*,' '
1224     print*,' '
1225    
1226     goto 9000 !the end
1227    
1228    
1229     c------------------------------------------------------------------------
1230     c
1231     c exit
1232     c
1233     c------------------------------------------------------------------------
1234    
1235     9000 continue
1236    
1237     return
1238     end
1239    

  ViewVC Help
Powered by ViewVC 1.1.23