
	Program simple_read
	integer*2 iht(1200),output(60,60)
	character*8 fname
	integer maxval,minval
	
	read(5,*) fname
C	fname='U10N040E'

	write(6,*) 'opening file ',fname

	open(unit=1,file=fname,status='old'
     .  ,form='unformatted',access='direct',recl=2400 ! reclen in bytes /4
     .  ,err=900)

	nrrd=1

	minval=5000
	maxval=-5000

	do 75 J=1,1200
	read(1,rec=nrrd) (iht(I),I=1,1200)
	call swap16(iht,1200)
	do I=1,1200
	if (iht(I) .gt. maxval) maxval=iht(I)
	if (iht(I) .lt. minval) minval=iht(I)
	enddo
	if (mod(J,20) .eq. 0) then
	do 76 I=20,1200,20
	ival=I/20
	jval=60-(J/20-1)

	output(ival,jval)=iht(I)
   76	continue

	write(6,23) (iht(I),I=1,1121,60)

	endif
	nrrd=nrrd+1
   75	continue

	write(6,*) ' '
	write(6,*) 'smallest and largest vals in file ', fname
	write(6,*) minval, maxval

   23	format(20(I4,x))

	open (unit=17,file='ascii_topo.dat',status='unknown',form='formatted',
     +  access='sequential')
	do J=60,1,-1
	write(17,24) (output(I,J),I=1,59,2)
	enddo
   24	format(30(I4,x))
	stop
  900	write(6,*) 'trouble opening file'
	END

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

       SUBROUTINE SWAP16(A,N)
C
C      REVERSE ORDER OF BYTES IN INTEGER*2 WORD, or REAL*2
C
       INTEGER*2   A(N)
C
       CHARACTER*1 JTEMP(2)
       CHARACTER*1 KTEMP
C
       EQUIVALENCE (JTEMP(1),ITEMP)
C
       DO 10 I = 1,N
C	if (mod(I,100) .eq. 0) write(6,*) 'start ', A(I)
         ITEMP    = A(I)
         KTEMP    = JTEMP(2)
         JTEMP(2) = JTEMP(1)
         JTEMP(1) = KTEMP
         A(I)     = ITEMP
C	if (mod(I,100) .eq. 0) write(6,*) 'endvl ', A(I)
 10    CONTINUE
       RETURN
       END

