program URS_IkeLA

  implicit none

      character(120)                :: ike08
      character(120), allocatable   :: HWMid(:), parish(:), floodtype(:)
      integer                       :: Nsta, i, j
      integer                       :: yy, mo, dd, hh, mi
      double precision, allocatable :: lat(:), lon(:), HWM(:)
      parameter ( yy = 2008, mo = 9, dd = 13, 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 ike.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,*)      

!!Allocate the variables in each column into there own arrays.      
      allocate(HWMid(1:Nsta), parish(1:Nsta), floodtype(1:Nsta), HWM(1:Nsta), lat(1:Nsta))
      allocate(lon(1:Nsta))

!! Collect data from URS output file
      do i = 1,Nsta
         write(6,*) "Collecting data for each station", i, "."
         read(61,*) HWMid(i), parish(i), HWM(i), lat(i), lon(i), floodtype(i)
      enddo
      close(61)
     
!! Reformat data as IMEDS generic output for each floodtype
open(unit=21,file="hwm_URS_IkeLA_riverine.txt",status='replace',action='write')
      write(21,*) "% IMEDS generic format - High Water Mark, Riverine-Hurricane floodtype"
      write(21,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(21,*) "URS " , "UTC", " NAVD88"
open(unit=22,file="hwm_URS_IkeLA_coastalstill.txt",status='replace',action='write')
      write(22,*) "% IMEDS generic format - High Water Mark, &
                   Coastal-Still water only floodtype"
      write(22,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(22,*) "URS " , "UTC", " NAVD88"
 open(unit=23,file="hwm_URS_IkeLA_coastalheight.txt",status='replace',action='write')
      write(23,*) "% IMEDS generic format - High Water Mark, Coastal-Wave height floodtype"
      write(23,*) "% ", "year ","month ","day ","hour ","min ", "hwm (m)"
      write(23,*) "URS " , "UTC", " NAVD88"
     
                  
do j = 1,Nsta
select case (floodtype(j))
case("Riverine-Hurricane")
      write(21,*) "URS_"//TRIM(HWMid(j)), lat(j), lon(j) 
      write(21,*) yy, mo, dd, hh, mi, HWM(j)*.3048
case("Coastal-StillwaterOnly")
      write(22,*) "URS_"//TRIM(HWMid(j)), lat(j), lon(j)
      write(22,*) yy, mo, dd, hh, mi, HWM(j)*.3048
case("Coastal-WaveHeight")
      write(23,*) "URS_"//TRIM(HWMid(j)), lat(j), lon(j)
      write(23,*) yy, mo, dd, hh, mi, HWM(j)*.3048
      end select
enddo
close(21)
close(22)
close(23)

end program
