CJAB(BGS)Mar 23/95 : Solaris version pulling across 2 arguments when actioned
CJAB(BGS)Mar 23/95 : from eev, the second argument is blank!!, since 1st
CJAB(BGS)Mar 23/95 : argument is the one required, remove test for more than
CJAB(BGS)Mar 23/95 : item.
C                                                                               
C                       
C  Program to make a HYPOINVERSE file form a Nordic file                                  
C                                                                               
C  J. Havskov           1993                                                        
c  Updates:
c
CJAB(BGS)Mar95    : Solaris version pulling 2 arguments when supplied by "eev",
CJAB(BGS)Mar95    : the second being blank.
c  jan 95         ************** version 5.0 **********************
c  feb 99         ---------------version 7.0 ----------------------
c                 increase dimention of data to 2500, read century in year
c                 remove reference to computer type, PROGRAM CAN ONLY WORK
c                 WITH 4 CHAR STATION CODES
c  oct 25         read secs as f6.1
c
c                                                                               
c
c
      implicit none
      CHARACTER*80 DATA(2500)                                                  
      CHARACTER*80 infile                                                     
      CHARACTER*1 TYPE,EXP                                                      
      integer nstat,nphase,nhead,nrecord
c---number of arguments 
      integer nars
c-- arguments
      character*80 args(10)
      integer n,id
c--compact or not
      logical compact


c
c print version
c
      include 'version.inc'
      out_version_date='July 23, 2001'
      if (version_new) out_version_date=version_date
      call print_ver

c 
c   check if input from file given in argument
        call get_arguments(nars,args)
        if(nars.eq.0) then
           write(6,*)' You must give input file as argument'
           stop
        endif
c
c   case with output on standard output
c
        if(nars.gt.2) then                   !JAB(BGS)Mar95. Definitely too many
          write(6,*)' Too many arguments'
          stop
        endif
c
c   output file
c
        open(2,file='norhin.out',status='unknown')
c
c   get input file name
c
        infile=args(1)
        open(1,file=infile,status='old')
c
c   check that not a compact file
c
        call nortype(1,compact)
        if(compact) then
           write(6,*)' Input file is compact, cannot be used'
           stop
        endif
c
c   read and write to end of file
c
        n=0
  10    continue
c
c   read one event in nordic format
c
           CALL INDATA(1,NSTAT,NPHASE,NHEAD,NRECORD,TYPE,EXP,DATA,ID)
           if(nrecord.eq.0) goto 99
c
c   convert to hypoinverse and write out 
c
           call norhin(2,nrecord,nhead,data)
           n=n+1
        goto 10
c
 99     continue
        write(6,*)
c        write(6,*)' The input file had ',n,' events'
c        stop
        end
                       

c
c
      subroutine norhin(unit,nrecord,nhead,data)
	  
c
c   gets one event in nordic format in array data and writes it to unit
c   in hypoinverse format
c
      implicit none
      character*80 data(*)
      integer nrecord,unit,nhead
      integer year,month,day,hour,min
      real sec
      double precision head_time,phase_time   ! abs times for header and phase
      integer k
c
c   write header
c
      write(unit,'(a2,a4,a4)') data(1)(4:5),data(1)(7:10),
     *data(1)(12:15)
c
c   read reference time, put sec to zero so all following times 
c   are referred to a whole minute
c
      sec=0.0
      read(data(1),'(1x,i4,1x,2i2,1x,2i2)') 
     *year,month,day,hour,min
c
c   get header abs time
c
      call timsec(year,month,day,hour,min,sec,head_time)
c
c   read phases to end of event
c
      do k=nhead+1,nrecord-1
         read(data(k)(19:28),'(i2,i2,f6.1)') hour,min,sec
         call timsec(year,month,day,hour,min,sec,phase_time)
         phase_time=phase_time-head_time      ! time relative to header
         write(unit,'(a4,a2,2a1,f5.1,a4)') data(k)(2:5),data(k)(10:11),
     *   data(k)(17:17),data(k)(15:15),phase_time,data(k)(30:33)
      enddo
c
c   write blank line
c
      write(unit,*)'       '
      return
      end
