! gfortran -o rd_geos3 -fconvert=big-endian rd_geos3.f 
	program rd_geos3

	implicit none

	byte hdr(52),data(52)
	character*80 fn
	integer iargc,i,j
	logical head

	integer*2 mb(22)
	integer*4 nrec,hlnk,irec

	equivalence (hdr(1),mb),(hdr(45),nrec),(hdr(49),hlnk)

	integer*4 mjd,sec,usec,lat,lon,ht,orb
 	integer*2 otide,stide,swh,sig0,wind,swell
 	integer*2 att,slope,agc,ice,rev,stat

	equivalence (data(1),mjd),(data(5),sec),(data(9),usec)
	equivalence (data(13),lat),(data(17),lon)
	equivalence (data(21),ht),(data(25),orb)
	equivalence (data(29),otide),(data(31),stide)
	equivalence (data(33),swh),(data(35),sig0)
	equivalence (data(37),wind),(data(39),swell)
	equivalence (data(41),att),(data(43),slope)
	equivalence (data(45),agc),(data(47),ice)
	equivalence (data(49),rev),(data(51),stat)

	if(iargc().lt.1)then
	  write(7,*)'Usage: rd_geos3 [-h] geos3_file'
	  write(7,*)' the optional -h reads/prints headers vs. data'
	  stop
	endif

	head=.false.

	call getarg(1,fn)

	if(fn.eq.'-h')then
	  head=.true.
	  call getarg(2,fn)
	endif

	open(10,file=fn,access='direct',recl=52)	! for sun & hp
c	open(10,file=fn,access='direct',recl=52/4)	! for sgi

	irec=1

	do while (.true.)
	  read(10,rec=irec,err=99)hdr
          write(8,*) irec, INT(hdr) 
	  if(head)then
	    write(6,'("Header Record: ",i8," Data Records: ",i12)')
     &		  irec,nrec
 	    write(6,'("Morrison Blocks:",$)')
	    do j=1,22
	      if(mb(j).ne.0)write(6,'(i5,$)')mb(j)
	    enddo
	    write(6,*)
	  else
	    do i=1,nrec
	      read(10,rec=irec+i)data
	      write(6,'(i5,2i6,i7,4i12,o7)')rev,mjd,sec,usec,
     &					      lat,lon,ht,orb,stat
	      write(6,'(10i7)')otide,stide,swh,sig0,wind,swell,
     &	                       att,slope,agc,ice
	    enddo
	  endif
	  irec=hlnk
	enddo
99	end
