C
C  Program to convert .MOD files created using MOD.CMD into FORTRAN
c  comment lines to be included with the code.
C
C  AUTHOR:  H. BARTA
c	    E. Lakia
C  DATE OF LAST UPDATE:  6/10/85
c
	CHARACTER	INFIL*40, OUTFIL*40, EXT(4)*4, ISEL*1, COM(4)*2,
	1		SCOM(4)*2,	ECOM(4)*2
C
	LOGICAL*1	DIR
C
	BYTE INLIN(132)
	DATA 	EXT / '.FOR', '.MAR', '.PAS', '.C  ' /,
	1	COM / 'C ', '; ', '  ', '  ' /,
	2	SCOM/ 'C.', ';.', '{.', '/*' /,
	3	ECOM/ '  ', '  ', '.}', '*/' /
C
	INTEGER*2	TTLUN,	LANG
	DATA TTLUN / 5 /
	DIR=.FALSE.
C
20	WRITE( TTLUN, 125 )
 125	FORMAT( '$Enter source file (or ^Z) :' )
	READ( TTLUN, 130, END=999, ERR=20 ) INFIL
 130	FORMAT( A40 )
C
C
C  now open the .MOD file and .CMT files to convert the document to comments
C  first create the output file name
c
	OUTFIL=INFIL
C
C  add file extension
 4	WRITE( TTLUN, 210 ) INFIL
 210	FORMAT( 1H ' Choose language for ', A40 //
	1	1H ' 	1	FORTRAN'	/
	2	1H '	2	MACRO'		/
	3	1H '	3	PASCAL'		/
	4	1H '	4	C'		//
	5	'$enter selection (1,2,3,4, or <CR>=FORTRAN):'		)
c
	READ(TTLUN, 220, END=999, ERR=4 )LANG
 220	FORMAT( I1 )
C
	IF (LANG.EQ.0 ) THEN
		LANG=1
	ELSEIF( LANG.LT.1 .OR. LANG.GT.4 ) THEN
		GOTO 4
	ENDIF
C
	IPER=INDEX( INFIL, '.' )
	IF (IPER.EQ.0.OR.IPER.GT.35) THEN
	  WRITE(5, 200 )INFIL
 200	  FORMAT( ' ', A40, ' is no good' )
	  GOTO 20
	ELSE
	  OUTFIL(IPER:)=EXT(LANG)
	ENDIF
C
C
	OPEN (UNIT=2, TYPE='OLD', NAME=INFIL)
C
	OPEN (	UNIT=3, 
	1	TYPE='NEW', 
	2	NAME=OUTFIL, 
	3	CARRIAGECONTROL='LIST'	)
C
C  write first line
c
	WRITE(3, 310)SCOM(LANG)
 310	FORMAT( A2,'begin.doc ************************** begin.doc')
C
 3	READ(2, 330, END=5, ERR=5) LEN,(INLIN(N), N=1, LEN)
 330	format( Q, 132A1 )
C
	WRITE(3, 300)COM(LANG), (INLIN(N), N=1, LEN)
 300	FORMAT( A2,132A1 )
C
	GOTO 3
c
C  Arrive here when .MOD file=EOF
C
 5	WRITE(3, 320) COM(LANG), ECOM(LANG)
 320	FORMAT( A2,'end.doc ****************************** end.doc',A2)
C
	CLOSE (UNIT=2, DISPOSE='SAVE')
	CLOSE (UNIT=3, DISPOSE='SAVE')
C
C  fetch next file
	GOTO 20
C
C  Arrive here with no more files to convert
 99	CLOSE (UNIT=1, DISPOSE='SAVE')
 999	CALL EXIT
	END
