c--------------------------------------------------------------------------
c  read harward falut plane solutions, output in nordic format
c--------------------------------------------------------------------------c
c
c  input format read is as show on stanadrd screen
c
c  For detail on parameters and variables naames, see rea.inc
c
c  
c
c
      implicit none                       ! force delcaration of all variables
      include 'seidim.inc'                ! dimensions for rea block
      include 'rea.inc'                   ! parameter common bliock

      character*80 data(5000)             ! s-file with data in text array
      character*80 err_text               ! error text
      character*80 infile                 ! input file
      integer strike,dip,slip
      character*80 text

      logical all                         ! true: read all data, false: headers
      integer code                        ! error return code
      integer nevent                      ! number of events in file
      integer i                           ! counter
c
c   open output file

       open(2,file='harnor.out',status='unknown')
    
c
c   get input file name, check if exist
c

 9    continue
      write(6,*) 'Give input file'
      read(5,'(a)') infile
      open(1,file=infile,status='old',err=10)
      goto 11
 10    continue
      write(6,*)' No such input file'
      goto 9
 11   continue
c
      all=.true.                  ! read all parameters
      nevent=0                    ! initialize counter

c
c-----------------------------------------------------------------
c  Loop to read events start here
c-----------------------------------------------------------------
c

  50  continue
c
c   read all parameters for one event form file unit 1
c
      read(1,'(a)',end=1000) text      
      if(text(3:6).ne.'Date') goto 50
c
c   start of event found
c
          call rea_hyp_clear(1)
          rea_id_line=' '
          rea_nhyp=1
          rea_nfault=1
          rea_nstat=0
          rea_nhead=2
          rea_nrecord=3
          rea_nphase=0
          hyp_fix_org(1)=' '
          hyp_dist_id(1)='D'
          read(text(9:18),'(i4,1x,i2,1x,i2)') 
     *    hyp_year(1),hyp_month(1),hyp_day(1)    
          read(text(37:46),'(i2,1x,i2,1x,f4.1)') 
     *    hyp_hour(1),hyp_min(1),hyp_sec(1)
c          write(6,*) hyp_year(1)
          read(1,'(a)') text
          read(text,'(6x,f7.2,6x,f7.2)') 
     *    hyp_lat(1),hyp_lon(1)
c          write(6,*) hyp_lat(1)
c          read(5,*) i

          read(1,'(8x,f6.1)') hyp_depth(1)
c          write(6,*) hyp_depth(1)
c          read(5,*) i
          read(1,'(a)') text
          read(1,'(a)') text
          read(1,'(7x,f3.1,9x,f3.1,9x,f3.1))') 
     *    hyp_MAG(1,1),hyp_mag(2,1),hyp_mag(3,1)
c          write(6,*) hyp_mag(1,1)
c          read(5,*) i
          hyp_mag_type(1,1)='W'
          hyp_mag_type(2,1)='B'
          hyp_mag_type(3,1)='S'
          hyp_mag_agency(1,1)='HRW  '
          hyp_mag_agency(2,1)='HRW  '
          hyp_mag_agency(3,1)='HRW  '
          hyp_agency(1)='HRW  '
          read(1,'(23x,i3,8x,i2,8x,i4)') strike,dip,slip
          rea_fault(1)=' '
          write(rea_fault(1),'(3f10.0)') 
     *    float(strike),float(dip),float(slip)
          rea_fault(1)(71:76)='HARWAR'
          rea_fault(1)(80:80)='F'
          nevent=nevent+1               ! count events
c    
c   write on screen a bit info on event
c
          write(6,*)' Strike, dip, rake',strike,dip,slip
 
c
c   write out 
c
          call rea_event_out(2,all,data,code)
c
c   get next event
c
      goto 50
c
c     end of file
c
 1000 continue
c
      write(6,*)            ! blank line
      close(2)              ! close output file
      write(6,*) 'Number of events in input file', nevent
      write(6,*) 'Output file name is harnor.out'

      stop
      end
