C                                                          <HTML><PRE>
C Program ASCBIN to convert gridded data (data cubes) from formatted
C ascii files to direct-access binary files
C
C Version: 7.40
C Date: 2017, May 18
C
C Coded by: Ludek Klimes
C     Department of Geophysics, Charles University Prague,
C     Ke Karlovu 3, 121 16 Praha 2, Czech Republic,
C     http://sw3d.cz/staff/klimes.htm
C
C.......................................................................
C
C Attention:  Functionality of program ASCBIN is strongly affected by
C the Fortran compiler and by the options of the compiler.
C Program ASCBIN can work only if the compiler supports unformatted
C direct-access files "without headers".
C Binary data on little-endian hardware (PC's) and big-endian hardware
C (VAX, Alpha, RISC workstations) should strictly be distinguished.
C
C.......................................................................
C                                                    <A NAME="data"></A>
C Description of data files:
C
C Input data read from the standard input device (*):
C     The data are read by the list directed input (free format) and
C     consist of a single string 'SEP':
C     'SEP'...String in apostrophes containing the name of the input
C             SEP parameter or history file with the input data.
C     No default, 'SEP' must be specified and cannot be blank.
C
C                                                     <A NAME="SEP"></A>
C Input data file 'SEP':
C     File 'SEP' has the form of the <A HREF="../forms/sep.htm">SEP</A>
C     parameter file.  The parameters, which do not differ from their
C     defaults, need not be specified in file 'SEP'.
C Data specifying dimensions of the input grid:
C     N1=positive integer... Number of gridpoints along the X1 axis.
C             Default: N1=1
C     N2=positive integer... Number of gridpoints along the X2 axis.
C             Default: N2=1
C     N3=positive integer... Number of gridpoints along the X3 axis.
C             Default: N3=1
C Names of the grid files:
C     GRD='string'... String with the name of the input formatted file
C             containing the gridded values.  The file contains N1*N2*N3
C             reals designed to be read by a single list directed (free
C             format) read statement.
C             No default, GRD must be specified and cannot be blank.
C     IN='string'... String with the name of the output unformatted file
C             to contain the gridded values.  The file will contain just
C             the 4 byte IEEE reals.  The length of the file will thus
C             be exactly 4*N1*N2*N3 bytes.
C             No default, IN must be specified and cannot be blank.
C Data specifying output format:
C     ESIZE=integer... Number of bytes per a real in the output binary
C             file.  Must be ESIZE=4.
C             Default: ESIZE=4
C     UNDEF=real... If the input ascii file contains undefined values,
C             the value of UNDEF will be written in place of the
C             undefined values into the output binary file.
C             Default: UNDEF=undefined value used in
C             <A HREF="forms.for#UARRAY" TYPE="text/html">forms.for</A>
C
C=======================================================================
C
C Common block /RAMC/:
      INCLUDE 'ram.inc'
C     <A HREF="ram.inc" TYPE="text/html">ram.inc</A>
C
C.......................................................................
C
C     External functions and subroutines:
      EXTERNAL UARRAY
      REAL     UARRAY
C
      CHARACTER*80 FILE1,FILE2
      INTEGER LU1,LU2
      PARAMETER (LU1=1,LU2=2)
C
      INTEGER N1,N2,N3,I
      REAL UNDEF
C
C.......................................................................
C
C     Reading main input data:
      WRITE(*,'(A)') '+ASCBIN: Enter input filename: '
      FILE1=' '
      READ(*,*) FILE1
      IF (FILE1.NE.' ') THEN
        CALL RSEP1(LU1,FILE1)
      ELSE
C       <A NAME="error01"></A><FONT COLOR="RED">ASCBIN-01</FONT>
        CALL ERROR('ASCBIN-01: SEP file not given')
C       Input file in the form of the SEP (Stanford Exploration Project)
C       parameter or history file must be specified.
C       There is no default filename.
      ENDIF
C
C     Input and output files with gridded data:
      CALL RSEP3T('GRD',FILE1,' ')
      IF (FILE1.EQ.' ') THEN
C       <A NAME="error02"></A><FONT COLOR="RED">ASCBIN-02</FONT>
        CALL ERROR('ASCBIN-02: Input file not specified')
      END IF
      CALL RSEP3T('IN',FILE2,' ')
      IF (FILE2.EQ.' ') THEN
C       <A NAME="error03"></A><FONT COLOR="RED">ASCBIN-03</FONT>
        CALL ERROR('ASCBIN-03: Output file not specified')
      END IF
      CALL RSEP3I('ESIZE',I,4)
      IF (I.NE.4) THEN
C       <A NAME="error04"></A><FONT COLOR="RED">ASCBIN-04</FONT>
        CALL ERROR('ASCBIN-04: Binary reals not 4-byte long')
      END IF
C     Reading the value of UNDEF:
      UNDEF=UARRAY()
C
C     Reading grid dimensions:
      CALL RSEP3I('N1',N1,1)
      CALL RSEP3I('N2',N2,1)
      CALL RSEP3I('N3',N3,1)
      IF (N1*N2*N3.GT.MRAM) THEN
C       <A NAME="error05"></A><FONT COLOR="RED">ASCBIN-05</FONT>
        CALL ERROR('ASCBIN-05: Small dimension MRAM of array RAM')
      END IF
C
C     Reading input grid values:
      WRITE(*,'(A)') '+ASCBIN: Reading...            '
      CALL RARRAY(LU1,FILE1,'FORMATTED',.TRUE.,UNDEF,N1*N2*N3,RAM)
C
C     Writing output grid values:
      WRITE(*,'(A)') '+ASCBIN: Writing...            '
      CALL WBIN(LU2,FILE2,RAM,N1*N2*N3)
C
      WRITE(*,'(A)') '+ASCBIN: Done.                 '
      STOP
      END
C
C=======================================================================
C
      SUBROUTINE WBIN(LU,FILE,GRID,N)
      INTEGER LU,N
      CHARACTER*(*) FILE
      REAL GRID(N)
C
C-----------------------------------------------------------------------
C
      INTEGER I
C
C     Any Fortran 77 compiler (option "direct files without headers"):
      OPEN(LU,FILE=FILE,FORM='UNFORMATTED',ACCESS='DIRECT',RECL=4)
      DO 10 I=1,N
        WRITE(LU,REC=I) GRID(I)
   10 CONTINUE
C
C     Lahey F77L3 (compiler-dependent Fortran extension):
*     OPEN(LU,FILE=FILE,FORM='UNFORMATTED',ACCESS='TRANSPARENT')
*     WRITE(LU) GRID
C
      CLOSE(LU)
      RETURN
      END
C
C=======================================================================
C
      INCLUDE 'error.for'
C     <A HREF="error.for" TYPE="text/html">error.for</A>
      INCLUDE 'sep.for'
C     <A HREF="sep.for" TYPE="text/html">sep.for</A>
      INCLUDE 'forms.for'
C     <A HREF="forms.for" TYPE="text/html">forms.for</A>
      INCLUDE 'length.for'
C     <A HREF="length.for" TYPE="text/html">length.for</A>
C
C=======================================================================
C                                                                 </PRE>
