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