      INCLUDE 'VICMAIN_FOR'
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C  REVISION HISTORY
C   4-97  SP  Made portable for UNIX.
c   4-01  lwk removed RECLEN from OPEN, since it gives errors on linux
c	      and is not needed on VMS

	SUBROUTINE MAIN44
C
C	VICAR PROGRAM EZLIST
C
        PARAMETER (MAXNS = 1024)
	INTEGER	WIDTH,SLEN
	REAL	DATA(MAXNS)
        LOGICAL XVPTST, REMOVEDOTS
	CHARACTER*80 FORMAT, FORM
        character*255 OUTNAME
	CHARACTER*20000 STRING

	REMOVEDOTS = XVPTST ('INTEGER')
	IF (XVPTST('W132')) THEN
	    WIDTH = 132
	ELSE
	    WIDTH = 80
	ENDIF

	CALL XVP ('OUT', OUTNAME, ICNTO)
	IF (ICNTO .GT. 0) THEN
           OPEN (UNIT=1,FILE=OUTNAME,STATUS='UNKNOWN',
     1            ERR=999, IOSTAT=J)
	ENDIF

	CALL XVUNIT(inunit,'INP',1,IST,' ')
	CALL XVOPEN(inunit,IST,'U_FORMAT','REAL','OPEN_ACT', 'SA',
     .             'IO_ACT', 'SA' ,' ')

	IF (IST .NE. 1) GO TO 998
	CALL XVGET(inunit,IST,'NL',NL,'NS',NS,' ')
        IF (NS .GT. MAXNS)
     .     CALL MABEND('ERR: Input NS too large. Try COPY of subimage')

	CALL XVPARM ('FORMAT',FORMAT,ICNT,IDEF,1)
	IF (ICNT .EQ. 0) THEN
	   FORMAT = '(F9.2,2X)'
	END IF
        CALL UPRCASE(FORMAT)    ! INSURE IT IS UPPER CASE.

	IF (INDEX(FORMAT(1:),'F') .EQ. 0) GO TO 996

	LENF = INDEX(FORMAT(1:),' ')-1

C-------if format is missing parens, add them
	IF (FORMAT(1:1) .NE. '(' ) THEN
		FORMAT(1:LENF+2) = '('// FORMAT(1:LENF) //')'
		LENF=LENF+2
	END IF
c-------add Repeat factor of NS to 'run-time' format

	FORM = '(xxxx' // FORMAT(1:LENF) // ')'
	WRITE (FORM(2:5), '(I4)') NS
c
	DO K = 1, NL
            CALL XVREAD(INUNIT,DATA,IST,' ')
	    WRITE (STRING, FORM) (DATA(I), I = 1, NS)
	    IF (REMOVEDOTS)  CALL REMOVEPOINTS (STRING)
            LENS = SLEN(STRING)
	    IF (ICNTO .GT. 0)  THEN
		WRITE (1, '(1X, A)', IOSTAT=J,ERR=999)  STRING(1:LENS)
	    ELSE
		CALL XVMESSAGE ( STRING(1: MIN(LENS,WIDTH)) ,' ')
	    ENDIF
	ENDDO
	CALL XVCLOSE (INUNIT,IST,' ')

	IF (ICNTO .GT. 0) THEN
	    CLOSE (UNIT=1)
	ENDIF

	RETURN
996	CALL XVMESSAGE('NO F IN FORMAT PARAMETER',' ')
	CALL ABEND
998	CALL XVMESSAGE('ERROR OPENING INPUT FILE',' ')
	CALL ABEND
999	CALL XVMESSAGE('ERROR WRITING OUTPUT FILE',' ')
	CALL PRNT(4,1,J,'IOSTAT=.')
	CALL ABEND
	END
	SUBROUTINE REMOVEPOINTS (STRING)
	IMPLICIT NONE
	CHARACTER*(*) STRING
	INTEGER	I

	DO I = 1, LEN(STRING)
	    IF (STRING(I:I+1) .EQ. '. ')  STRING(I:I) = ' '
	ENDDO

	RETURN
	END
	INTEGER FUNCTION SLEN (STRING)
	IMPLICIT NONE
	CHARACTER*(*) STRING
	INTEGER	N

	N = LEN(STRING)
	DO WHILE (N .GT. 1 .AND. STRING(N:N) .EQ. ' ')
	    N = N - 1
	ENDDO
	SLEN = N
	RETURN
	END
