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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Thu Nov 2 15:31:06 2006 UTC (18 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.4: +2 -2 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23