# VMT_LoadMap

## PURPOSE

This routine loads a map file from either a text file or a .mat file.

## SYNOPSIS

function Map = VMT_LoadMap(filetype,coord,varargin);

## DESCRIPTION

     This routine loads a map file from either a text file or a .mat file.

     Input:  filetype = 'txt' for a text file (2 col (x,y), no headers); 'mat' for a matlab data file
            coord    = 'UTM' for UTM coordinates or 'LL' for latitude, longitude (in dec deg)
            zone     = zone for UTM coordinates (Removed from Input--will be
            determined from the data automatically)

     P.R. Jackson, 12-9-08
     Last Modified: Frank L. Engel, 7/25/2013

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function Map = VMT_LoadMap(filetype,coord,varargin);
    0002 % This routine loads a map file from either a text file or a .mat file.
    0003 %
    0004 % Input:  filetype = 'txt' for a text file (2 col (x,y), no headers); 'mat' for a matlab data file
    0005 %        coord    = 'UTM' for UTM coordinates or 'LL' for latitude, longitude (in dec deg)
    0006 %        zone     = zone for UTM coordinates (Removed from Input--will be
    0007 %        determined from the data automatically)
    0008 %
    0009 %
    0010 % P.R. Jackson, 12-9-08
    0011 % Last Modified: Frank L. Engel, 7/25/2013
    0012
    0013 if ~isempty(varargin)
    0014     guiprefs = varargin{1};
    0015 else
    0016     guiprefs = [];
    0017 end
    0018
    0019 switch filetype
    0020     case{'txt'}
    0021         [file,shorepath] = uigetfile(...
    0022             {'*.txt;*.csv','All Text Files'; '*.*','All Files'},...
    0023             'Select Map Text File',...
    0024             fullfile(guiprefs.shoreline_path,guiprefs.shoreline_file));
    0025
    0026 %         defaultpath = 'C:\';
    0027 %         shorepath = [];
    0028 %         if 0 %exist('VMT\LastDir.mat') == 2
    0029 %             load('VMT\LastDir.mat');
    0030 %             if exist(shorepath) == 7
    0031 %                 [file,shorepath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Map Text File',shorepath);
    0032 %             else
    0033 %                 [file,shorepath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Map Text File',defaultpath);
    0034 %             end
    0035 %         else
    0036 %             [file,shorepath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Map Text File',defaultpath);
    0037 %         end
    0038
    0039         if ischar(file) % User did not hit cancel
    0040             infile = [shorepath file];
    0041             %disp('Loading Map File...' );
    0042             %disp(infile);
    0043             data = dlmread(infile);
    0044             switch coord
    0045                 case{'LL'}
    0046                     % convert lat long into UTMe and UTMn
    0047                     [Map.UTMe,Map.UTMn,Map.UTMzone] = deg2utm(data(:,1),data(:,2));
    0048                 case{'UTM'}
    0049                     Map.UTMe = data(:,1);
    0050                     Map.UTMn = data(:,2);
    0051                     %Map.UTMzone = zone;
    0052             end
    0053         else
    0054             Map = [];
    0055             return
    0056         end
    0057
    0058     case{'mat'} %assumes Map data structure (above) is present
    0059         [file,shorepath] = uigetfile(...
    0060             '*.mat',...
    0061             'Select Map File',...
    0062             fullfile(guiprefs.shoreline_path,guiprefs.shoreline_file));
    0063
    0064         if ischar(file) % User did not hit cancel
    0065             infile = [shorepath file];
    0066             %disp('Loading Map File...' );
    0067             %disp(infile);
    0068             load(infile);
    0069         else
    0070             Map = [];
    0071             return
    0072         end
    0073 end
    0074
    0075 Map.infile = infile;
    0076
    0077 %Save the shorepath
    0078 % if exist('LastDir.mat') == 2
    0079     % save('LastDir.mat','shorepath','-append')
    0080 % else
    0081     % save('LastDir.mat','shorepath')
    0082 % end