% hurricane.m   P. Conrad for CISC106, Fall 2006   10/05/2006
% Plot lat. vs. long for multiple hurricanes, until user types quit


% Ask user for filename containing hurricane data, then load that file
% Print a graph of latitude vs. longitude to the web, then ask for another file
% Keep asking for another file until the user types "quit"


% Ask user for first filename

filename = ...
    input('Enter filename you want to load or "quit" to exit: ','s');  

% As long as it is NOT true that filename is quit, keep going

while( strcmp(filename,'quit') ~= 1 )

  % try to load this file.  If you can't print an error message
  % set a true/false value (boolean) called "loaded" to indicate
  % whether it worked
  
  try
    thisHurricane = load(filename);
    fprintf('Loaded: %s\n', filename);
    loaded = true;
  catch
    fprintf('Sorry, could not load: %s\n', filename);
    loaded = false;
  end
  
  % only do the plotting steps if the file loaded successfully
  
  if (loaded)
    
    longitude = thisHurricane(:,6);
    latitude = thisHurricane(:,5);
    
    plot(-longitude,latitude);
    xlabel('longitude, degrees west of Greenwich');
    ylabel('latitude, degrees north of Equator');
    legend(filename);
    title(['Path of hurricane from ' filename]);
    
    % prepare a web directory, and write the plot to that directory
    % then make the file readable on the web.  These steps will
    % only work on strauss---not on the PC version of MATLAB 
    
    !mkdir -p -m 755 ~/public_html/cisc106/lab06
    jpegFilename = ['~/public_html/cisc106/lab06/' filename '.jpg'];
    print('-djpeg',jpegFilename);
    !chmod -R 755 ~/public_html/cisc106/lab06
    
    % the following command will ONLY work on strauss
    % This sets the variable
    % myUsername to my own username on strauss.  I need that to
    % form a message with the URL of the web page   
    
    [status, myUsername] = system('whoami'); 
    
    % remove any extra space at start and end of myUsername
    
    myUsername = strtrim(myUsername);
  
    % set up a string with the URL on the web, and print a message
    
    theURL = ['http://copland.udel.edu/~' myUsername '/cisc106/lab06/' ...
	      filename '.jpg'];
    fprintf('Plot written to %s\n',theURL);

  end; % if loaded
  
  filename = ...
	input(['Enter filename you want to load or "quit" to exit:' ...
	       ' '],'s');  

  

  
end; % while 
