*=====================================================================
*      OPTARG for UNIX f77                        92/05/05 Numaguti.A.
*                                   for dcl-5.0 : 95/05/22 Takehiro.S. 
*                              for grph1 option : 95/10/27 Akahori.K. 
*                                               : 97/02/14 Takehiro S.
*=====================================================================
      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,LENNNM=20)
      CHARACTER  HOPARG  *(LENARG)
      CHARACTER  HFLNUM  *(LENNUM)
      CHARACTER  HNMNUM  *(LENNNM)
*
      OPEN  ( IOPUNT,STATUS='SCRATCH' ) 
      HNMNUM = ' &'//HNMLST
      WRITE ( IOPUNT,'(A)' ) HNMNUM(1:LENC(HNMNUM))
*
      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
*                                                  95/10/27 by Akahori.K
*                                     for grph1 option (ex.-sg:xxxx=xxxx)
*
         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
            HNMNUM = HFLOPT
            WRITE ( HFLNUM,'(I3)' ) NFILE
	    WRITE ( IOPUNT,'(A)' ) 
     &         '  '//HNMNUM(1:LENC(HNMNUM))//
     &          '('//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
