|
Here is explained how to do this in a batch program and interactively in PAW. The following batch program creates two simple ntuples (CWN) containing 3 real variables each and save them in two separated HBOOK files. Then it closes the ntuples files, reopen them and scan the two ntuples simultaneously in a single loop.
Program Read_Two_Ntuples
*
Parameter (Nhmax = 100000)
Common /Pawc/ Hmemor(Nhmax)
Common /P1/ A,B,C
Common /P2/ D,E,F
*
Call Hlimit(Nhmax)
*--------------------------------------------------
* Create and fill the Ntuple 1
*
Call Hropen(10,'P1','p1.hbook','N',1024,Ista)
If (Ista.Ne.0) Stop
Call Hbnt(1,'Test','D')
Call Hbname(1,'P1',A,'A,B,C')
*
Do I=1,10
A = Float(I)
B = Float(10*I)
C = Float(100*I)
Call Hfnt(1)
EndDo
*
Call Hrout(0,IC,'')
Call Hrend('P1')
Close(10)
*--------------------------------------------------
* Create and fill the Ntuple 2
*
Call Hropen(10,'P2','p2.hbook','N',1024,Ista)
If (Ista.Ne.0) Stop
Call Hbnt(2,'Test','D')
Call Hbname(2,'P2',D,'D,E,F')
*
Do I=1,100
D = Float(1000*I)
E = Float(10000*I)
F = Float(100000*I)
Call Hfnt(2)
EndDo
*
Call Hrout(0,IC,'')
Call Hrend('P2')
Close(10)
*--------------------------------------------------
* Reset the common blocks
*
Do I=1,10
A = 0.
B = 0.
C = 0.
D = 0.
E = 0.
F = 0.
EndDo
*--------------------------------------------------
* Read the two Ntuples in two loops.
*
Call Hropen(10,'P1','p1.hbook','U',1024,Ista)
If (Ista.Ne.0) Stop
Call Hrin (1,9999,0)
Call Hbname (1,' ',0,'$CLEAR')
Call Hbname (1,'P1',A,'$SET')
Call Hnoent (1,Noent1)
*
Call Hropen(20,'P2','p2.hbook','U',1024,Ista)
If (Ista.Ne.0) Stop
Call Hrin (2,9999,0)
Call Hbname (2,' ',0,'$CLEAR')
Call Hbname (2,'P2',D,'$SET')
Call Hnoent (2,Noent2)
*
Do I=1,Noent1
Call Hcdir('//P1',' ')
Call Hgnt(1,I,Ierr)
print*, 'Ntuple 1: I = ',I,' A = ',A,' B = ',B,' C = ', C
JStart = (I-1)*10+1
JEnd = JStart+9
Do J=JStart,JEnd
Call Hcdir('//P2',' ')
Call Hgnt(2,I,Ierr)
print*, ' Ntuple 2: J = ',J,' D = ',D,' E = ',E,' F = ', F
EndDo
EndDo
*
Call Hrend('P1')
Call Hrend('P2')
Close(10)
Close(20)
*
End
It is also possible, and in fact even simpler, to perform the same thing on
ntuples sitting in the same HBOOK file. The program in that case looks
the following:
Program Read_Two_Ntuples
*
Parameter (Nhmax = 100000)
Common /Pawc/ Hmemor(Nhmax)
Common /P1/ A,B,C
Common /P2/ D,E,F
*
Call Hlimit(Nhmax)
*--------------------------------------------------
* Create and fill the Ntuple 1
*
Call Hropen(10,'NTUPLES','ntuples.hbook','N',1024,Ista)
If (Ista.Ne.0) Stop
Call Hbnt(1,'Test','D')
Call Hbname(1,'P1',A,'A,B,C')
*
Do I=1,10
A = Float(I)
B = Float(10*I)
C = Float(100*I)
Call Hfnt(1)
EndDo
*--------------------------------------------------
* Create and fill the Ntuple 2
*
Call Hbnt(2,'Test','D')
Call Hbname(2,'P2',D,'D,E,F')
*
Do I=1,100
D = Float(1000*I)
E = Float(10000*I)
F = Float(100000*I)
Call Hfnt(2)
EndDo
*
Call Hrout(0,IC,'')
Call Hrend('NTUPLES')
Close(10)
*--------------------------------------------------
* Reset the common blocks
*
Do I=1,10
A = 0.
B = 0.
C = 0.
D = 0.
E = 0.
F = 0.
EndDo
*--------------------------------------------------
* Read the two Ntuples in two loops.
*
Call Hropen(10,'NTUPLES','ntuples.hbook','U',1024,Ista)
If (Ista.Ne.0) Stop
Call Hrin (1,9999,0)
Call Hbname (1,' ',0,'$CLEAR')
Call Hbname (1,'P1',A,'$SET')
Call Hnoent (1,Noent1)
*
Call Hrin (2,9999,0)
Call Hbname (2,' ',0,'$CLEAR')
Call Hbname (2,'P2',D,'$SET')
Call Hnoent (2,Noent2)
*
Do I=1,Noent1
Call Hgnt(1,I,Ierr)
print*, 'Ntuple 1: I = ',I,' A = ',A,' B = ',B,' C = ', C
JStart = (I-1)*10+1
JEnd = JStart+9
Do J=JStart,JEnd
Call Hgnt(2,I,Ierr)
print*, ' Ntuple 2: J = ',J,' D = ',D,' E = ',E,' F = ', F
EndDo
EndDo
*
Call Hrend('NTUPLES')
Close(10)
*
End
To read two CW-Ntuples simultaneously in PAW the simplest is to use the
NT/LOOP
command on the first ntuple and to load, as in the batch program, the
other ntuple within the
UWFUNC
generated function. After having done:
PAW > hi/file 1 p1.hbook
PAW > uwfunc 1 r1.f
PAW > hi/file 2 p2.hbook
PAW > uwfunc 2 r2.f
You should modify the function r1.f taking the common block
declaration of the ntuple 2 in r2.f.
The modified r1.f is (added code in red):
REAL FUNCTION r1()
*********************************************************
* *
* This file was generated by HUWFUN. *
* *
*********************************************************
*
* Ntuple Id: 1
* Ntuple Title: Test
* Creation: 26/07/1999 11.23.40
*
*********************************************************
*
LOGICAL CHAIN
CHARACTER*128 CFILE
INTEGER IDNEVT,NCHEVT,ICHEVT
REAL OBS(13)
*
COMMON /PAWIDN/ IDNEVT,OBS
COMMON /PAWCHN/ CHAIN, NCHEVT, ICHEVT
COMMON /PAWCHC/ CFILE
*
*-- Ntuple Variable Declarations
*
REAL A,B,C
*
COMMON /PAWCR4/ A,B,C
*
REAL D,E,F
*
COMMON /NT2/ D,E,F
*
if (idnevt.eq.1) then
Call Hbname (2,' ',0,'$CLEAR')
Call Hbname (2,'P2',D,'$SET')
Call Hnoent (2,Noent2)
Endif
*
print*, 'Ntuple 1: A = ',A,' B = ',B,' C = ', C
Call Hcdir('//LUN2',' ')
Call Hgnt(2,idnevt,Ierr)
print*, 'Ntuple 2: D = ',D,' E = ',E,' F = ', F
*
END
Having this function it is enough to do:
PAW > hrin 2
PAW > cd //lun1
PAW > nt/loop 1 r1.f
which produces:
Ntuple 1: A = 1.000000 B = 10.00000 C = 100.0000
Ntuple 2: D = 1000.000 E = 10000.00 F = 100000.0
Ntuple 1: A = 2.000000 B = 20.00000 C = 200.0000
Ntuple 2: D = 2000.000 E = 20000.00 F = 200000.0
Ntuple 1: A = 3.000000 B = 30.00000 C = 300.0000
Ntuple 2: D = 3000.000 E = 30000.00 F = 300000.0
Ntuple 1: A = 4.000000 B = 40.00000 C = 400.0000
Ntuple 2: D = 4000.000 E = 40000.00 F = 400000.0
Ntuple 1: A = 5.000000 B = 50.00000 C = 500.0000
Ntuple 2: D = 5000.000 E = 50000.00 F = 500000.0
Ntuple 1: A = 6.000000 B = 60.00000 C = 600.0000
Ntuple 2: D = 6000.000 E = 60000.00 F = 600000.0
Ntuple 1: A = 7.000000 B = 70.00000 C = 700.0000
Ntuple 2: D = 7000.000 E = 70000.00 F = 700000.0
Ntuple 1: A = 8.000000 B = 80.00000 C = 800.0000
Ntuple 2: D = 8000.000 E = 80000.00 F = 800000.0
Ntuple 1: A = 9.000000 B = 90.00000 C = 900.0000
Ntuple 2: D = 9000.000 E = 90000.00 F = 900000.0
Ntuple 1: A = 10.00000 B = 100.0000 C = 1000.000
Ntuple 2: D = 10000.00 E = 100000.0 F = 1000000.
![]() | Release Notes | Known bugs | FAQs | Contributions | Tutorial | Reference manual | Down load | Miscellaneous |