/[PAMELA software]/DarthVader/TrackerLevel2/src/F77/readB.f
ViewVC logotype

Annotation of /DarthVader/TrackerLevel2/src/F77/readB.f

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Fri May 19 13:15:56 2006 UTC (18 years, 6 months ago) by mocchiut
Branch: MAIN
Branch point for: DarthVader
Initial revision

1 mocchiut 1.1 *************************************************************************
2     *
3     * Subroutine read_B.f
4     *
5     * it calls the subroutines which read the magnetic field maps for
6     * the PAMELA spectrometer
7     *
8     * needs:
9     * - ./read_B_inner.f inner map reading subroutine
10     * - ./read_B_outer.f outer map reading subroutine
11     *
12     * to be called before ./inter_B.f (interpolation subroutine)
13     *
14     *************************************************************************
15    
16     subroutine readB(cpath)
17     include 'common_c2f.f'
18     character*80 cpath
19     character*80 ppath
20    
21    
22     b_error=0
23    
24     la=80
25     do i=1,80
26     if(cpath(i:i).eq.'/')la=i
27     enddo
28     ppath=cpath(1:la)
29    
30     b_path = ppath
31     b_pathlen = la
32    
33     c FUNZIONAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!
34    
35     if(b_debug.eq.1)print*,'Field loaded: ',b_loaded
36     if(b_loaded.eq.0)then
37    
38     c call the subroutine which reads the maps of the measurements taken
39     c inside the magnetic cavity
40     call readBinner(ppath)
41     if(b_error.eq.1)return
42    
43     c call the subroutine which reads the maps of the measurements taken
44     c outside the magnetic cavity
45     call readBouter(ppath)
46     if(b_error.eq.1)return
47    
48     b_loaded = 1
49     endif
50    
51     return
52     end
53    
54     ************************************************************
55    
56    
57     *************************************************************************
58     *
59     * Subroutine readBinner
60     *
61     * it reads from rz files the two magnetic field maps taken inside the
62     * spectrometer cavity and fills the variables in common_B_inner.f
63     *
64     * needs:
65     * - common_B.f common file for the inner magnetic field map
66     * - .rz map files in ./ containing coordinates of measured points, Bx, By
67     * and Bz components + errors
68     *
69     * output variables: (see common_B_inner.f)
70     * - px#(nx,3) with #=1,2 for the 2 maps
71     * - py#(ny,3)
72     * - pz#(nz,3)
73     * - b#(nx,ny,nz,3)
74     *
75     *************************************************************************
76    
77     subroutine readBinner(path)
78    
79     c implicit double precision (a-h,o-z)
80     include 'common_B.f'
81     include 'common_c2f.f'
82     character*80 path
83    
84     C
85     REAL hmemor(10000000)
86     integer Iquest(100)
87     COMMON /pawc/hmemor
88     save /pawc/
89     C
90     Common /QUEST/ Iquest
91     save /quest/
92    
93    
94     c------------------------------------------------------------------------
95     c
96     c local variables
97     c
98     c------------------------------------------------------------------------
99    
100     character*64 Bmap_file !magnetic field file name
101     parameter (lun_Bmap_file=66) !magnetic field map file id number
102    
103     parameter (ntpl_Bmap=20) !ntuple identifier
104    
105     REAL PFX(3),FX,DFX, !Bx field component coordinates in m, value and error in T
106     $ PFY(3),FY,DFY
107     $ ,PFZ(3),FZ,DFZ
108     INTEGER INDEX(3) !point index
109    
110     COMMON /PAWCR4/ INDEX,PFX,FX,DFX,PFY,FY,DFY,PFZ,FZ,DFZ
111    
112    
113     CALL HLIMIT(10000000)
114     C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115     C largest RZ file: IQUEST(10) records x LREC words x 4 byte
116     C with the following settings: 65000 x 4096 x 4 = 1G
117     C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118    
119     c permette di ottenere ntuple funzionanti nonostante
120     c il messaggio dei 64K di RZOUT
121     Iquest(10) = 512000
122     c------------------------------------------------------------------------
123     c
124     c *** FIRST MAP ***
125     c
126     c------------------------------------------------------------------------
127    
128     c------------------------------------------------------------------------
129     c
130     c initialization and map file opening
131     c
132     c------------------------------------------------------------------------
133    
134     c print*,' '
135     c print*,' '
136    
137     Bmap_file='measure_n3_290302.rz'
138    
139     c opens magnetic field map first file
140     if(b_debug.eq.1)print *
141     $ ,path(1:LNBLNK(path))//Bmap_file
142     call HROPEN
143     $ (lun_Bmap_file,'Bmap'
144     $ ,path(1:LNBLNK(path))//Bmap_file
145     $ ,'P',1024,istat)
146     if(istat.ne.0) goto 21
147    
148    
149     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
150    
151     c call HPRNTU(ntpl_Bmap)
152     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
153     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
154     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
155     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
156     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
157    
158    
159     c------------------------------------------------------------------------
160     c
161     c reads events and fills variables
162     c
163     c------------------------------------------------------------------------
164    
165     call HNOENT(ntpl_Bmap,iemax) !number of events
166    
167     c initializes measurement grid edges
168     do ic=1,3
169     px1max(ic)=0.
170     px1min(ic)=0.
171     py1max(ic)=0.
172     py1min(ic)=0.
173     pz1max(ic)=0.
174     pz1min(ic)=0.
175     enddo
176    
177    
178     do iev=1,iemax !event loop
179    
180     call HGNT(ntpl_Bmap,iev,ierr) !reads event
181     if(ierr.ne.0) goto 22
182    
183     c the output consists of matrices for coordinates, B components values
184     c and errors:
185     c e.g. px1(4,2) = X coordinate of the point with index = 4 along X,
186     c in which By (=2) component has been measured
187     c e.g. b1(3,23,4,1) = Bx (=1) component value, measured in the point with
188     c indexes = 3,23,4 along X, Y and Z
189    
190     c Bx component
191     px1(index(1),1) = pfx(1)
192     if(px1(index(1),1).lt.px1min(1)) px1min(1)=px1(index(1),1)
193     if(px1(index(1),1).gt.px1max(1)) px1max(1)=px1(index(1),1)
194     py1(index(2),1) = pfx(2)
195     if(py1(index(2),1).lt.py1min(1)) py1min(1)=py1(index(2),1)
196     if(py1(index(2),1).gt.py1max(1)) py1max(1)=py1(index(2),1)
197     pz1(index(3),1) = pfx(3)
198     if(pz1(index(3),1).lt.pz1min(1)) pz1min(1)=pz1(index(3),1)
199     if(pz1(index(3),1).gt.pz1max(1)) pz1max(1)=pz1(index(3),1)
200    
201     b1(index(1),index(2),index(3),1) = fx
202    
203    
204     c By component
205     px1(index(1),2) = pfy(1)
206     if(px1(index(1),2).lt.px1min(2)) px1min(2)=px1(index(1),2)
207     if(px1(index(1),2).gt.px1max(2)) px1max(2)=px1(index(1),2)
208     py1(index(2),2) = pfy(2)
209     if(py1(index(2),2).lt.py1min(2)) py1min(2)=py1(index(2),2)
210     if(py1(index(2),2).gt.py1max(2)) py1max(2)=py1(index(2),2)
211     pz1(index(3),2) = pfy(3)
212     if(pz1(index(3),2).lt.pz1min(2)) pz1min(2)=pz1(index(3),2)
213     if(pz1(index(3),2).gt.pz1max(2)) pz1max(2)=pz1(index(3),2)
214    
215     b1(index(1),index(2),index(3),2) = fy
216    
217    
218     c Bz component
219     px1(index(1),3) = pfz(1)
220     if(px1(index(1),3).lt.px1min(3)) px1min(3)=px1(index(1),3)
221     if(px1(index(1),3).gt.px1max(3)) px1max(3)=px1(index(1),3)
222     py1(index(2),3) = pfz(2)
223     if(py1(index(2),3).lt.py1min(3)) py1min(3)=py1(index(2),3)
224     if(py1(index(2),3).gt.py1max(3)) py1max(3)=py1(index(2),3)
225     pz1(index(3),3) = pfz(3)
226     if(pz1(index(3),3).lt.pz1min(3)) pz1min(3)=pz1(index(3),3)
227     if(pz1(index(3),3).gt.pz1max(3)) pz1max(3)=pz1(index(3),3)
228    
229     b1(index(1),index(2),index(3),3) = fz
230    
231     enddo
232    
233     c------------------------------------------------------------------------
234     c
235     c closes files
236     c
237     c------------------------------------------------------------------------
238    
239     call HREND('Bmap')
240     close(lun_Bmap_file)
241     c$$$ cmd2='rm -f '
242     c$$$ $ //Bmap_file(1:LNBLNK(Bmap_file))
243     c$$$ call system(cmd2)
244     c$$$
245    
246    
247     c------------------------------------------------------------------------
248     c
249     c *** SECOND MAP ***
250     c
251     c------------------------------------------------------------------------
252    
253     c------------------------------------------------------------------------
254     c
255     c initialization and map file opening
256     c
257     c------------------------------------------------------------------------
258    
259     c print*,' '
260     c print*,' '
261    
262     Bmap_file='measure_n4_110402_corrected.rz'
263     c opens magnetic field map first file
264     if(b_debug.eq.1)print * !,'Opening file: '
265     $ ,path(1:LNBLNK(path))//Bmap_file
266     call HROPEN
267     $ (lun_Bmap_file,'Bmap'
268     $ ,path(1:LNBLNK(path))//Bmap_file
269     $ ,'P',1024,istat)
270     if(istat.ne.0) goto 21
271    
272    
273     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
274    
275     c call HPRNTU(ntpl_Bmap)
276     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
277     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
278     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
279     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
280     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
281    
282    
283     c------------------------------------------------------------------------
284     c
285     c reads events and fills variables
286     c
287     c------------------------------------------------------------------------
288    
289     call HNOENT(ntpl_Bmap,iemax) !number of events
290    
291     c print*,'iemax ',iemax
292    
293     do ic=1,3 !grid edges
294     px2max(ic)=0.
295     px2min(ic)=0.
296     py2max(ic)=0.
297     py2min(ic)=0.
298     pz2max(ic)=0.
299     pz2min(ic)=0.
300     enddo
301    
302    
303     do iev=1,iemax !event loop
304    
305     call HGNT(ntpl_Bmap,iev,ierr) !reads event
306     if(ierr.ne.0) goto 22
307    
308     c the output consists of matrices for coordinates, B components values
309     c and errors:
310     c e.g. px(4,2) = X coordinate of the point with index = 4 along X,
311     c in which By (=2) component has been measured
312     c e.g. b(3,23,4,1) = Bx (=1) component value, measured in the point with
313     c indexes = 3,23,4 along X, Y and Z
314    
315     c Bx component
316     px2(index(1),1) = pfx(1)
317     if(px2(index(1),1).lt.px2min(1)) px2min(1)=px2(index(1),1)
318     if(px2(index(1),1).gt.px2max(1)) px2max(1)=px2(index(1),1)
319     py2(index(2),1) = pfx(2)
320     if(py2(index(2),1).lt.py2min(1)) py2min(1)=py2(index(2),1)
321     if(py2(index(2),1).gt.py2max(1)) py2max(1)=py2(index(2),1)
322     pz2(index(3),1) = pfx(3)
323     if(pz2(index(3),1).lt.pz2min(1)) pz2min(1)=pz2(index(3),1)
324     if(pz2(index(3),1).gt.pz2max(1)) pz2max(1)=pz2(index(3),1)
325    
326     b2(index(1),index(2),index(3),1) = fx
327    
328    
329     c By component
330     px2(index(1),2) = pfy(1)
331     if(px2(index(1),2).lt.px2min(2)) px2min(2)=px2(index(1),2)
332     if(px2(index(1),2).gt.px2max(2)) px2max(2)=px2(index(1),2)
333     py2(index(2),2) = pfy(2)
334     if(py2(index(2),2).lt.py2min(2)) py2min(2)=py2(index(2),2)
335     if(py2(index(2),2).gt.py2max(2)) py2max(2)=py2(index(2),2)
336     pz2(index(3),2) = pfy(3)
337     if(pz2(index(3),2).lt.pz2min(2)) pz2min(2)=pz2(index(3),2)
338     if(pz2(index(3),2).gt.pz2max(2)) pz2max(2)=pz2(index(3),2)
339    
340     b2(index(1),index(2),index(3),2) = fy
341    
342    
343     c Bz component
344     px2(index(1),3) = pfz(1)
345     if(px2(index(1),3).lt.px2min(3)) px2min(3)=px2(index(1),3)
346     if(px2(index(1),3).gt.px2max(3)) px2max(3)=px2(index(1),3)
347     py2(index(2),3) = pfz(2)
348     if(py2(index(2),3).lt.py2min(3)) py2min(3)=py2(index(2),3)
349     if(py2(index(2),3).gt.py2max(3)) py2max(3)=py2(index(2),3)
350     pz2(index(3),3) = pfz(3)
351     if(pz2(index(3),3).lt.pz2min(3)) pz2min(3)=pz2(index(3),3)
352     if(pz2(index(3),3).gt.pz2max(3)) pz2max(3)=pz2(index(3),3)
353    
354     b2(index(1),index(2),index(3),3) = fz
355    
356     enddo
357    
358     c------------------------------------------------------------------------
359     c
360     c closes files
361     c
362     c------------------------------------------------------------------------
363    
364     call HREND('Bmap')
365     close(lun_Bmap_file)
366    
367     c------------------------------------------------------------------------
368     c
369     c no error exit
370     c
371     c------------------------------------------------------------------------
372    
373     goto 9000 !happy ending
374    
375     c------------------------------------------------------------------------
376     c
377     c magnetic field map file opening error
378     c
379     c------------------------------------------------------------------------
380    
381     21 continue
382    
383     b_error = 1
384     if(b_debug.eq.1)
385     $ print*
386     $ ,'read_B_inner: ERROR OPENING MAGNETIC FIELD MAP FILE: '
387     $ ,Bmap_file
388    
389     goto 9000 !the end
390    
391    
392     c------------------------------------------------------------------------
393     c
394     c ntuple event reading error
395     c
396     c------------------------------------------------------------------------
397    
398     22 continue
399    
400     b_error = 1
401     if(b_debug.eq.1)
402     $ print*,'read_B_inner: ERROR WHILE READING NTUPLE, at entry
403     $ : ',iev
404    
405     goto 9000 !the end
406    
407    
408     c------------------------------------------------------------------------
409     c
410     c exit
411     c
412     c------------------------------------------------------------------------
413    
414     9000 continue
415    
416     return
417     end
418     *************************************************************************
419     *
420     * Subroutine readBouter
421     *
422     * it reads from rz files the two magnetic field maps taken inside the
423     * spectrometer cavity and fills the variables in common_B_inner.f
424     *
425     * needs:
426     * - common_B_outer.f common file for the outer magnetic field map
427     * - .rz map files in ./ containing coordinates of measured points, Bx, By
428     * and Bz components + errors
429     *
430     * output variables: (see common_B_outer.f)
431     * - pxo(nx,3)
432     * - pyo(ny,3)
433     * - pzo(nz,3)
434     * - bo(nx,ny,nz,3)
435     *
436     *************************************************************************
437    
438     subroutine readBouter(path)
439    
440     c implicit double precision (a-h,o-z)
441     include 'common_B.f'
442     include 'common_c2f.f'
443     C
444     character*80 path
445    
446     REAL hmemor(10000000)
447     integer Iquest(100)
448     COMMON /pawc/hmemor
449     save /pawc/
450     C
451     Common /QUEST/ Iquest
452     save /quest/
453    
454    
455    
456     c------------------------------------------------------------------------
457     c
458     c local variables
459     c
460     c------------------------------------------------------------------------
461    
462     character*64 Bmap_file !magnetic field file name
463     parameter (lun_Bmap_file=66) !magnetic field map file id number
464    
465     parameter (ntpl_Bmap=20) !ntuple identifier
466    
467     REAL PFX(3),FX,DFX, !Bx field component coordinates in m, value and error in T
468     $ PFY(3),FY,DFY
469     $ ,PFZ(3),FZ,DFZ
470     INTEGER INDEX(3) !point index
471    
472     COMMON /PAWCR4/ INDEX,PFX,FX,DFX,PFY,FY,DFY,PFZ,FZ,DFZ
473    
474    
475     c print*,'Calling HLIMIT'
476     CALL HLIMIT(10000000)
477     C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
478     C largest RZ file: IQUEST(10) records x LREC words x 4 byte
479     C with the following settings: 65000 x 4096 x 4 = 1G
480     C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
481    
482     c permette di ottenere ntuple funzionanti nonostante
483     c il messaggio dei 64K di RZOUT
484     Iquest(10) = 512000
485     c------------------------------------------------------------------------
486     c
487     c *** FIRST MAP ***
488     c
489     c------------------------------------------------------------------------
490    
491     c------------------------------------------------------------------------
492     c
493     c initialization and map file opening
494     c
495     c------------------------------------------------------------------------
496    
497     c print*,' '
498     c print*,' '
499    
500     Bmap_file='External_top_map_n4_150402.rz'
501    
502     c opens magnetic field map first file
503     if(b_debug.eq.1)print *
504     $ ,path(1:LNBLNK(path))//Bmap_file
505     call HROPEN
506     $ (lun_Bmap_file,'Bmap'
507     $ ,path(1:LNBLNK(path))//Bmap_file
508     $ ,'P',1024,istat)
509     if(istat.ne.0) goto 21
510    
511    
512     call HRIN(ntpl_Bmap,9999,0) !puts B map ntuple in memory
513    
514     c call HPRNTU(ntpl_Bmap)
515     call HBNAME(ntpl_Bmap,' ',0,'$CLEAR')
516     call HBNAME(ntpl_Bmap,'INDEX',index,'$SET')
517     call HBNAME(ntpl_Bmap,'BX',pfx,'$SET')
518     call HBNAME(ntpl_Bmap,'BY',pfy,'$SET')
519     call HBNAME(ntpl_Bmap,'BZ',pfz,'$SET')
520    
521    
522     c------------------------------------------------------------------------
523     c
524     c reads events and fills variables
525     c
526     c------------------------------------------------------------------------
527    
528     call HNOENT(ntpl_Bmap,iemax) !number of events
529    
530     c initializes measurement grid edges
531     do ic=1,3
532     poxmax(ic)=0.
533     poxmin(ic)=0.
534     poymax(ic)=0.
535     poymin(ic)=0.
536     pozmax(ic)=0.
537     pozmin(ic)=0.
538     enddo
539    
540    
541     do iev=1,iemax !event loop
542    
543     call HGNT(ntpl_Bmap,iev,ierr) !reads event
544     if(ierr.ne.0) goto 22
545    
546     c the output consists of matrices for coordinates, B components values
547     c and errors:
548     c e.g. px1(4,2) = X coordinate of the point with index = 4 along X,
549     c in which By (=2) component has been measured
550     c e.g. b1(3,23,4,1) = Bx (=1) component value, measured in the point with
551     c indexes = 3,23,4 along X, Y and Z
552    
553     c Bx component
554     pox(index(1),1) = pfx(1)
555     if(pox(index(1),1).lt.poxmin(1)) poxmin(1)=pox(index(1),1)
556     if(pox(index(1),1).gt.poxmax(1)) poxmax(1)=pox(index(1),1)
557     poy(index(2),1) = pfx(2)
558     if(poy(index(2),1).lt.poymin(1)) poymin(1)=poy(index(2),1)
559     if(poy(index(2),1).gt.poymax(1)) poymax(1)=poy(index(2),1)
560     poz(index(3),1) = pfx(3)
561     if(poz(index(3),1).lt.pozmin(1)) pozmin(1)=poz(index(3),1)
562     if(poz(index(3),1).gt.pozmax(1)) pozmax(1)=poz(index(3),1)
563    
564     bo(index(1),index(2),index(3),1) = fx
565    
566    
567     c By component
568     pox(index(1),2) = pfy(1)
569     if(pox(index(1),2).lt.poxmin(2)) poxmin(2)=pox(index(1),2)
570     if(pox(index(1),2).gt.poxmax(2)) poxmax(2)=pox(index(1),2)
571     poy(index(2),2) = pfy(2)
572     if(poy(index(2),2).lt.poymin(2)) poymin(2)=poy(index(2),2)
573     if(poy(index(2),2).gt.poymax(2)) poymax(2)=poy(index(2),2)
574     poz(index(3),2) = pfy(3)
575     if(poz(index(3),2).lt.pozmin(2)) pozmin(2)=poz(index(3),2)
576     if(poz(index(3),2).gt.pozmax(2)) pozmax(2)=poz(index(3),2)
577    
578     bo(index(1),index(2),index(3),2) = fy
579    
580    
581     c Bz component
582     pox(index(1),3) = pfz(1)
583     if(pox(index(1),3).lt.poxmin(3)) poxmin(3)=pox(index(1),3)
584     if(pox(index(1),3).gt.poxmax(3)) poxmax(3)=pox(index(1),3)
585     poy(index(2),3) = pfz(2)
586     if(poy(index(2),3).lt.poymin(3)) poymin(3)=poy(index(2),3)
587     if(poy(index(2),3).gt.poymax(3)) poymax(3)=poy(index(2),3)
588     poz(index(3),3) = pfz(3)
589     if(poz(index(3),3).lt.pozmin(3)) pozmin(3)=poz(index(3),3)
590     if(poz(index(3),3).gt.pozmax(3)) pozmax(3)=poz(index(3),3)
591    
592     bo(index(1),index(2),index(3),3) = fz
593    
594     enddo
595    
596    
597     c------------------------------------------------------------------------
598     c
599     c closes files
600     c
601     c------------------------------------------------------------------------
602    
603     call HREND('Bmap')
604     close(lun_Bmap_file)
605    
606    
607     c------------------------------------------------------------------------
608     c
609     c no error exit
610     c
611     c------------------------------------------------------------------------
612    
613     goto 9000 !happy ending
614    
615     c------------------------------------------------------------------------
616     c
617     c magnetic field map file opening error
618     c
619     c------------------------------------------------------------------------
620    
621     21 continue
622    
623     b_error = 1
624     if(b_debug.eq.1)
625     $ print*
626     $ ,'read_B_inner: ERROR OPENING MAGNETIC FIELD MAP FILE: '
627     $ ,Bmap_file
628    
629     goto 9000 !the end
630    
631    
632     c------------------------------------------------------------------------
633     c
634     c ntuple event reading error
635     c
636     c------------------------------------------------------------------------
637    
638     22 continue
639    
640     b_error = 1
641     if(b_debug.eq.1)
642     $ print*
643     $ ,'read_B_inner: ERROR WHILE READING NTUPLE, at event
644     $ : ',iev
645    
646     goto 9000 !the end
647    
648    
649     c------------------------------------------------------------------------
650     c
651     c exit
652     c
653     c------------------------------------------------------------------------
654    
655     9000 continue
656    
657     return
658     end
659    

  ViewVC Help
Powered by ViewVC 1.1.23