How to Write to an Output ZBS File

The following example opens an output file and writes selected events to it.

Files for this example

Copy the following files from

$TUTEXAMPLES/tutorials

into your working directory:

  • example4.F: contains the source code for the program
  • example4.sh: a shell script for running the program
  • The GNUmakefile should already have instructions for compiling example4 in it.

Outputting events in ZBS format to a file

Take a look inside example4.F.

  • Before the file loop, both input and output files are opened using SKOPENF. SKOPENF is given the argument LUNI (set to the value 10) for the input file, and the argument LUNO (set to the value 20). These are the “logical unit numbers” (luns) associated with the files. These logical unit numbers are associated with the input and output files in set_rflist functions, which is where the file properties (RED/WRT, old/new) are set.
           CALL set_rflist(LUNO, 'example4.zbs', 'LOCAL',' ','WRT',' ',
         &   ' ', 'recl=5670 status=new', ' ', ' ')

    There is another similar call for the input files.  This method of setting the parameters for input and output zbs files replaces the older method of writing an “rflist” file from a shell script.  You may see this rflist method used in some Super-K programs.  It is functionally the same as using set_rflist, though it requires an extra shell script, in which the rflist information (essentially the same as in set_rflist) is written to a file.  You can see an example of this old method here (*put link!*).

  • For each event with greater than 50 hits in the ID, it writes the event to the output file, using the subroutine KZWRIT:
                   if (nqisk.gt.50) then
                      call kzwrit(luno)
                   endif

    This subroutine takes the lun of the file to write to as an argument.

  • At the end of the event and file loops, it closes both input and output files with SKCLOSEF.

Compile and run this program in the same way as for the first examples. You should get a file called example4.zbs created. This contains the selected events in ZBS format. You can look at them with superscan, or use this file as input to another SK program.

You can have access to more than one input or output file in the same program, by adding more lines to the script that runs the program, and associating a different lun to each file.

Notes for C++ code

As an “other how-to” tutorial, a C++ version is not currently provided.  Files can be opened as in other examples.  The difference between opening a file for reading and writing is in the read/write argument of the fort_fopen_ call.  It should be 1 for writing, and 0 for reading.  Other than that, files can be opened and closed as normal.