*=====================================================================
*      OPTARG for UNIX f77               92/05/05 Numaguti.A.
*                                        95/05/22 Takehiro by dcl-5.0
*                                        95/10/27 small changes
*=====================================================================
      SUBROUTINE OPTARG
     I         ( IOPUNT, HNMLST, HFLOPT,
     O           NOPT  , NFILE           )
*
      CHARACTER  HNMLST  *(*)
      CHARACTER  HFLOPT  *(*)
*     
*      get command line options
*
*      example:
*
*      CHARACTER GALA*16      / 'gala.gala.' /
*      CHARACTER HFILE(2)*128 / 'gala.out', ' '/
*      LOGICAL   HELP         / .FALSE. /
*      NAMELIST  /OPTION/ GALA, PEN, HFILE, HELP
*
*      CALL OPTARG ( 91, 'OPTION', 'HFILE', NOPT, NFILE )
*      READ  (91,OPTION,IOSTAT=IOS)
*      CLOSE (91)
*      IF ( IOS.NE.0 .OR. HELP ) THEN
*         WRITE (6,OPTION)
*         STOP
*      ENDIF
*
      PARAMETER (LENARG=256,LENNUM=3)
      CHARACTER  HOPARG  *(LENARG)
      CHARACTER  HFLNUM  *(LENNUM)
*
      OPEN  ( IOPUNT,STATUS='SCRATCH' ) 
      WRITE ( IOPUNT,'(A)' ) ' &'//HNMLST
*
      NFILE = 0
      NARG  = IARGC()
*
      DO 1100 I = 1, NARG
         CALL OSGARG( I,HOPARG )
         CALL CLADJ( HOPARG )
         LENHOP = LENC( HOPARG )
         IF ((HOPARG(1:1).EQ.'-').AND.(HOPARG(4:4) .EQ.':')) GOTO 1100
         IF      ( INDEX( HOPARG,':' ).GT.1 ) THEN
	    IC = INDEX( HOPARG,':' )
	    WRITE ( IOPUNT,'(A)' )
     &         '  '//HOPARG(1:IC-1)//'='''
     &             //HOPARG(IC+1:LENHOP)//''''//','
         ELSE IF ( INDEX( HOPARG,'-' ).EQ.1 ) THEN
            WRITE ( IOPUNT,'(A)' ) '  '//HOPARG(2:LENHOP)//'=T'//','
         ELSE IF ( INDEX( HOPARG,'#' ).EQ.1 ) THEN
            WRITE ( IOPUNT,'(A)' ) '  '//HOPARG(2:LENHOP)//'=F'//','
         ELSE IF ( INDEX( HOPARG,'=' ).LE.0 ) THEN
            NFILE = NFILE+1
            WRITE ( HFLNUM,'(I3)' ) NFILE
	    WRITE ( IOPUNT,'(A)' ) 
     &         '  '//HFLOPT//'('//HFLNUM(LENB(HFLNUM)+1:)//')='''
     &             //HOPARG(1:LENHOP)//''''//','
         ELSE
            WRITE ( IOPUNT,'(A)' ) '  '//HOPARG(1:LENHOP)//','
         ENDIF
 1100 CONTINUE
*
      WRITE ( IOPUNT, '(A)' ) '  &END'
      REWIND( IOPUNT )
*
      NOPT = NARG - NFILE
*
      RETURN
      END
