Home > fvcom_prepro > read_sms_map.m

read_sms_map

PURPOSE ^

Reads a .map file from SMS

SYNOPSIS ^

function data = read_sms_map(file)

DESCRIPTION ^

 Reads a .map file from SMS

  data = read_sms_map(filename)

 DESCRIPTION:
   Reads a map file from SMS consisting of node coordinates for boundary
   lines. Each different arc is read into a different cell array (e.g. if
   you have multiple islands). Ensure that the polygons are built in SMS 
   to make handling islands easier.

 INPUT:
   file - file name to read from.

 OUTPUT:
   data.arc - cell array of coordinate pairs for the boundaries and
       elevation
   data.arcID - cell array of SMS ARC IDs
   data.arcN - cell array of number of nodes in each arc cell array

 EXAMPLE USAGE:
  arc = read_sms_map('/home/user/data/sms_project_v1.map')

 Author(s):
   Ricardo Torres (Plymouth Marine Laboratory)
   Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history:
   2013-05-03 First version.
   2013-11-28 Minor cosmetic changes.

==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data = read_sms_map(file)
0002 % Reads a .map file from SMS
0003 %
0004 %  data = read_sms_map(filename)
0005 %
0006 % DESCRIPTION:
0007 %   Reads a map file from SMS consisting of node coordinates for boundary
0008 %   lines. Each different arc is read into a different cell array (e.g. if
0009 %   you have multiple islands). Ensure that the polygons are built in SMS
0010 %   to make handling islands easier.
0011 %
0012 % INPUT:
0013 %   file - file name to read from.
0014 %
0015 % OUTPUT:
0016 %   data.arc - cell array of coordinate pairs for the boundaries and
0017 %       elevation
0018 %   data.arcID - cell array of SMS ARC IDs
0019 %   data.arcN - cell array of number of nodes in each arc cell array
0020 %
0021 % EXAMPLE USAGE:
0022 %  arc = read_sms_map('/home/user/data/sms_project_v1.map')
0023 %
0024 % Author(s):
0025 %   Ricardo Torres (Plymouth Marine Laboratory)
0026 %   Pierre Cazenave (Plymouth Marine Laboratory)
0027 %
0028 % Revision history:
0029 %   2013-05-03 First version.
0030 %   2013-11-28 Minor cosmetic changes.
0031 %
0032 %==========================================================================
0033 
0034 subname = 'read_sms_map';
0035 
0036 global ftbverbose
0037 if ftbverbose
0038     fprintf('\nbegin : %s \n', subname);
0039 end
0040 f = fopen(file, 'rt');
0041 if f < 0
0042     error('Unable to open output file (check permissions?)')
0043 end
0044 frewind(f)
0045 loopnode = 0;
0046 looparc = 0;
0047 data = [];
0048 while ~feof(f)
0049     % Read NODES found
0050     line = fgetl(f);
0051     while ~(strcmpi(line,'ARC') || strcmpi(line,'NODE') || strcmpi(line,'POLYGON'))
0052 
0053         line = fgetl(f);
0054         if feof(f); fclose (f); return; end
0055     end
0056     switch line
0057         case 'NODE'
0058             
0059             loopnode = loopnode + 1;
0060             line = fgetl(f);
0061             data.node(loopnode) = textscan(line, '%*s %f %f %*f', 'CollectOutput', 1);
0062             line = fgetl(f);
0063             data.nodeID(loopnode) = textscan(line, '%*s %u');
0064             line = fgetl(f);
0065             
0066         case 'ARC'
0067 
0068             looparc = looparc + 1;
0069 
0070             if ftbverbose
0071                 fprintf('Found arc number %i\n', looparc)
0072             end
0073 
0074             line = fgetl(f);
0075             data.arcID{looparc} = textscan(line, '%*s %u');
0076             % skip two lines
0077             dump = fgetl(f); line = fgetl(f);
0078             data.arcnode(looparc) = textscan(line, '%*s %u %u', 'CollectOutput', 1);
0079             line = fgetl(f);
0080             if strcmpi(line, 'END'); break; end
0081             % read number of vertices in ARC
0082             data.arcN(looparc) = textscan(line, '%*s %u');
0083             data.arc(looparc) = textscan(f, '%f %f %*f', data.arcN{looparc}, 'CollectOutput', 1, 'Delimiter', '\n');
0084         otherwise
0085             continue
0086     end
0087 end
0088 fclose(f);
0089 
0090 if ftbverbose
0091     fprintf('end   : %s \n', subname)
0092 end
0093 
0094 return

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005