Another advantage of the use of ZEBRA in HBOOK is that ZEBRA's direct access RZ package is available. The RZ package allows data structures to be uniquely addressed via pathnames, which are based on Unix file names. Related data structures are addressed from a directory.
Routine HROPEN issues a the Fortran OPEN statement and declares the RZ top directory.
Example of using HROPEN
CALL HROPEN(LUN,'HISTO1','HISTOS.DAT',CHOPT,LRECL,ISTAT)
In this example, HROPEN issues a Fortran direct-access open statement for the file HISTOS.DAT. If, on input, LRECL contains the value 0, HROPEN will automatically determine the record length of the file, provided that the file already exists.
Each time a RZ file is opened via a call to HROPEN or HRFILE, a supplementary top directory is created with a name specified in the calling sequence. This means that the user can more easily keep track of his data and also the same histogram identifiers can be used in various files, what makes life easier if one wants to study various data samples with the same program, since they can be addressed by changing to the relevant file by a call to HCDIR first. For more information on the RZ package, see the ZEBRA RZ manual.
In the case of the second call to HROPEN, where update mode is requested, it is the users responsibility to ensure that write-acess is enabled, i.e. the file is not on a read-only mini-disk (VM/CMS systems), or is opened with the SHARED attribute (VAX/VMS systems) etc. indexVMS
A Fortran CLOSE statement is also required for each file after calling HREND. Further details of HBOOK's usage of ZEBRA RZ files are given below.
Defining HBOOK files
CALL HROPEN(1,'HISTO1','HISTO1.DAT',' ',1024,ISTAT) ! Open first HBOOK RZ file (read only) CALL HROPEN(2,'HISTO2','HISTO2.DAT','U',1024,ISTAT) ! Open second HBOOK RZ file (update) CALL HCDIR('//HISTO1',' ') ! Make HISTO1 current directory CALL HRIN(20,9999,0) ! Read ID 20 on file 1 .... CALL HCDIR('//HISTO2',' ') ! Make HISTO2 current directory CALL HRIN(10,9999,0) ! Read ID 10 on file 2 .... CALL HROUT(20,ICYCLE,' ') ! Write ID 20 to file 2 CALL HREND('HISTO1') ! Close file 1 CALL HREND('HISTO2') ! Close file 2
In the previous example (and also in figures [more info] and [more info]) it is shown how an external file is available via a directory name inside HBOOK (and PAW), and that one can change from one to the other file by merely changing directory, with HBOOK routine HCDIR
The use of subdirectories, both in memory and on disk, is shown in the following example.
Example of using subdirectories
PROGRAM TEST INTEGER NWPAWC PARAMETER (NWPAWC=15000) COMMON/PAWC/PAW(NWPAWC) CHARACTER*8 CHTAGS(5) DIMENSION EVENT(5) EQUIVALENCE (EVENT(1),X),(EVENT(2),Y),(EVENT(3),Z) EQUIVALENCE (EVENT(4),ENERGY),(EVENT(5),ELOSS) DATA CHTAGS/'X','Y','Z','Energy','Eloss'/ *-- Tell HBOOK how many words are in PAWC. CALL HLIMIT(NWPAWC) CALL HROPEN(1,'EXAMPLE','EXAMPLE.DAT','N',1024,ISTAT) IF(ISTAT.NE.0)GO TO 99 *-- Make sub-directory on disk (as HROUT does not do this for us). CALL HMDIR ('US','S') CALL HCDIR('//PAWC',' ') *-- Make sub-directory in memory. CALL HMDIR ('US','S') CALL HCDIR('//PAWC/US',' ') *-- Book Ntuple + 1d histogram CALL HBOOKN(10,'A simple Ntuple',5,'EXAMPLE',5000,CHTAGS) CALL HBOOK1(100,'Energy distribution',100,0.,100.,0.) *-- Fill the Ntuple and histogram DO 10 I=1,1000 CALL RANNOR(X,Y) Z=SQRT(X*X+Y*Y) ENERGY=50. + 10.*X ELOSS=10.*ABS(Y) CALL HFN(10,EVENT) CALL HFILL(100,ENERGY,0.,1.) 10 CONTINUE *-- Juggle top directories (order of these calls is important!!). CALL HCDIR('//PAWC',' ') CALL HCDIR('//EXAMPLE',' ') *-- Write out everything to disk CALL HROUT(0,ICYCLE,'T') *-- Flush remaining buffers to disk. CALL HREND('EXAMPLE') 99 CONTINUE END