C
C SUBROUTINE 'FLMOPN'
C ===================
C
C OPEN FILM IMAGE FILE AND SET INITIAL RECORD NUMBER FOR READING
C
      SUBROUTINE FLMOPN(IUN,FILNAM,LREC,IREC,MSGERR,ERR)
C
C PARAMETERS
C
C         IUN (I)   FORTRAN UNIT NO. (CAN GIVE -IUN TO SUPPRESS OPEN MESSAGE)
C      FILNAM (I)   FILE NAME FOR FILM IMAGE FILE (CHARACTER STRING)
C        LREC (I)   RECORD LENGTH IN BYTES
C        IREC (I)   START RECORD NO. FOR READING
C      MSGERR (I)   UNIT NO. FOR PRINTING ERROR MESSAGES (0 IF NO
C                   MESSAGES REQUIRED)
C         ERR (O)   ERROR FLAG: .TRUE. ERROR, .FALSE. NO ERROR ON
C                   OPENING FILE (OTHER ERRORS ARE FATAL)
C
C ***GENERAL VERSION***
C
C PARAMETER STATEMENT
C -------------------
C
C MAXLRC = MAXIMUM RECORD LENGTH COPED WITH BY THE ROUTINES
C
      PARAMETER (MAXLRC=9600)
C
C SPECIFICATION STATEMENTS
C ------------------------
C
      LOGICAL ERR
      CHARACTER*(*) FILNAM
      INTEGER IBUF(MAXLRC/4)
      COMMON /FLMQQQ/KREC,IRECL,NBW,IBUF
      LOGICAL CCPBYT
C
C OPEN FILE
C ---------
C
      IF(LREC.GT.MAXLRC)GO TO 800
      IF(.NOT.CCPBYT(NBW))GO TO 810
      IF(MOD(LREC,NBW).NE.0)GO TO 820
      IRECL=LREC/NBW
      KREC=IREC-1
      ERR=.FALSE.
      IFAIL=1
      CALL CCPDPN(IUN,FILNAM,'READONLY','DU',IRECL,IFAIL)
      IF(IFAIL.EQ.-1)GO TO 830
      RETURN
C
C ERROR CONDITIONS
C ----------------
C
800   IF(MSGERR.GT.0)WRITE(MSGERR,2001)MAXLRC
      STOP '**FLMOPN ERROR**'
810   IF(MSGERR.GT.0)WRITE(MSGERR,2002)
      STOP '**FLMOPN ERROR**'
820   IF(MSGERR.GT.0)WRITE(MSGERR,2003)NBW
      STOP '**FLMOPN ERROR**'
830   IF(MSGERR.GT.0)WRITE(MSGERR,2004)FILNAM
      ERR=.TRUE.
      RETURN
C
C FORMAT STATEMENTS
C -----------------
C
2001  FORMAT(/,' **ROUTINE FLMOPN HAS MAXIMUM RECORD LENGTH OF ',I5,
     *' **')
2002  FORMAT(/,' **FILM ROUTINES CANNOT BE USED AS NO BYTE HANDLING',
     *' IS AVAILABLE**')
2003  FORMAT(/,' **RECORD LENGTH FOR FILM HANDLING ROUTINES MUST BE',
     *' A MULTIPLE OF',I2,' BYTES**')
2004  FORMAT(/,' **ERROR OPENING FILM IMAGE**',/,' FILE NAME: ',A)
      END
