#!/bin/bash
#First set 2 variable that extract from kml and save as csv


kml_input=$1


csv_output=$2

echo "Timestamp,Latitude,Longitude,MinSeaLevelPressure,MaxIntensity" > $2
	 
echo "Converting report.kml -> storm_info.csv..."

#Second have 5 kml data and get the information we care about with unit


count=$(grep -E -c "<lat>" $1)
grep "<lat>" $1 | cut -d ">" -f 2 | cut -d "<" -f 1 |  sed "s/$/& N/g" >lat.txt
grep "<lon>" $1 | cut -d ">" -f 2 | cut -d "<" -f 1 | sed "s/$/& W/g" > lon.txt
grep "<dtg>" $1 | cut -d ">" -f 2 | cut -d "<" -f 1 > ts.txt
grep "<intensity>" $1 | cut -d ">" -f 2 | cut -d "<" -f 1 | sed "s/$/& knots/g" > inten.txt
grep "<minSea.*>" $1 | cut -d ">" -f 2 | cut -d "<" -f 1 | sed "s/$/& mb/g" > press.txt


#Third sort data, outupt it as a csv file


paste -d ',' ts.txt lat.txt lon.txt press.txt inten.txt >>$2

echo "Done!"

