program IkeHarris

  implicit none

      character(120)                :: ike08
      character(120), allocatable   :: HWMid(:), marktype(:)
      integer                       :: Nsta, i, j, hh, mi
      integer, allocatable          :: yy(:), mo(:), dd(:)
      double precision, allocatable :: lat(:), lon(:), HWM(:)
      parameter (hh = 0, mi = 0)

!!Program will ask for the name of the text file that contains the
!hurricane data and store it as ike08.
      write(6,*) "Enter the name of the harriscounty.txt file"
      read(5,*) ike08
      write(6,*)      

!!The program will now open the designated file and read how many stations there
!are within the text file. This number will be stored as Nsta.
      open(unit=61,file=ike08,status='old',action='read')
      read(61,*) Nsta
      read(61,*)      
      read(61,*)

!!Allocate the variables in each column into there own arrays.      
      allocate(HWMid(1:Nsta), marktype(1:Nsta), yy(1:Nsta), mo(1:Nsta))
      allocate(dd(1:Nsta), lat(1:Nsta), lon(1:Nsta), HWM(1:Nsta))

!! Collect data from ADCIRC output file
      do i = 1,Nsta
         write(6,*) "Collecting data for each station", i, "."
         read(61,*) mo(i), dd(i), yy(i), HWM(i), lon(i), lat(i),& 
                    HWMid(i), marktype(i)
      enddo
      close(61)
     
!! Reformat data as IMEDS generic output for each floodtype
open(unit=21,file="hwm_harriscounty_ike_waveheight.txt",status='replace',action='write')
      write(21,*) "% IMEDS generic format - High Water Mark, wave height mark type"
      write(21,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(21,*) "ADCIRC " , "UTC", " NAVD88"
open(unit=22,file="hwm_harriscounty_ike_stillwater.txt",status='replace',action='write')
      write(22,*) "% IMEDS generic format - High Water Mark, still water mark type"
      write(22,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(22,*) "ADCIRC " , "UTC", " NAVD88"
open(unit=23,file="hwm_harriscounty_ike_waverunup.txt",status='replace',action='write')
      write(23,*) "% IMEDS generic format - High Water Mark, wave run-up mark type"
      write(23,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(23,*) "ADCIRC " , "UTC", " NAVD88"
open(unit=24,file="hwm_harriscounty_ike_unknown.txt",status='replace',action='write')
      write(24,*) "% IMEDS generic format - High Water Mark, unknown mark type"
      write(24,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(24,*) "ADCIRC " , "UTC", " NAVD88"
                  
do j = 1,Nsta
select case (marktype(j))
case("waveheight")
      write(21,*) "HarrisCounty_"//TRIM(HWMid(j)), lat(j), lon(j) 
      write(21,*) yy(j), mo(j), dd(j), hh, mi, HWM(j)*.3048
case("stillwater")
      write(22,*) "HarrisCounty_"//TRIM(HWMid(j)), lat(j), lon(j)
      write(22,*) yy(j), mo(j), dd(j), hh, mi, HWM(j)*.3048
case("waverun-up")
      write(23,*) "HarrisCounty_"//TRIM(HWMid(j)), lat(j), lon(j)
      write(23,*) yy(j), mo(j), dd(j), hh, mi, HWM(j)*.3048
case("unknown")
      write(24,*) "HarrisCounty_"//TRIM(HWMid(j)), lat(j), lon(j)
      write(24,*) yy(j), mo(j), dd(j), hh, mi, HWM(j)*.3048
      end select
enddo
close(21)
close(22)
close(23)
close(24)

end program
