% Initial Location of the City of Interest is defined as the Origin (x1,y1) 
% where x1 = 0 and y2 = 0
x1 = 0;
y1 = 0;
speed = 0;
City = [x1,y1];
% Student uses the scale of the map to calculate the exact (x2, y2) location 
% of the hurricane. Note: This program does not use the latitude nor longitude 
% values.  Part of the lesson is to have students use the scale of the map
% instead to determine horizontal and vertical distances in miles.
% 
x2 = input ('Enter the X2 value in miles (X2) =  ');
y2 = input ('Enter the Y2 value in miles (Y2) =  ');
disp ('The initial linear distance in miles of the hurricane to our city is');
hurricanepoint = [x2,y2];
aPointMatrix = repmat(City,size(hurricanepoint,1),1);
LinearDistance = (sum(((aPointMatrix-hurricanepoint).^2),2)).^0.5
format short g
speed = input ('Enter the travelling speed of the hurricane in mph (SPEED) =   ');
time = input ('Enter the time interval in hours  (HOURS) =  ');  

j=LinearDistance-(speed*time);
accumtime=0;
nextlocation=LinearDistance;
timeland=LinearDistance/speed;

disp ('The data shows distances from our city and time to landfall of the hurricane every =  ');
disp (time);
disp ('HOURS');

fid = fopen('hurricane.dat','w'); 


for i=1:j;
    moretime = accumtime + time;
    newdistance = nextlocation - (speed*time);
    newtime = timeland-time;
    if newdistance > 0
        accumtime = accumtime + time;
        nextlocation = nextlocation - (speed*time);
        timeland = timeland -time;
        disp (accumtime)
        disp (nextlocation);
        disp (timeland);
    end
    
    fprintf(fid,'%4.8f  %4.8f   %4.8f\n',accumtime,nextlocation,timeland);

        
end
t=LinearDistance/(speed*time);
%
disp ('The initial linear distance in miles of the hurricane to our city is');
disp (LinearDistance);
inilandtime = LinearDistance/speed;
disp ('From this distance, the HURRICANE WILL HIT LAND in exactly');
disp(inilandtime);
disp ('HOURS');

disp ('TIME ELAPSED (HOURS) = ');
disp(accumtime);
disp ('  ');
disp ('Number of HOURS left before the hurricane hits land! BE PREPARED!');
disp (timeland);
disp (' ');
disp ('Enter the word "hurricane" at the prompt to start over');

fclose(fid);

hurricane_data = load('hurricane.dat'); 

plot(hurricane_data(:,1),hurricane_data(:,2),'b-*');
xlabel('ELAPSED TIME'); ylabel('DISTANCE BEFORE LANDFALL'); 
