Home > fvcom_prepro > read_fvcom_obc.m

read_fvcom_obc

PURPOSE ^

Read fvcom open boundary file

SYNOPSIS ^

function Mobj = read_fvcom_obc(Mobj, obcfile)

DESCRIPTION ^

 Read fvcom open boundary file 

 Mobj = function read_fvcom_obc(obcfile)

 DESCRIPTION:
    Read FVCOM open boundary node specification file.

 INPUT:
   Mobj : existing mesh object into which obc data is added
   obcfile : fvcom open boundary file

 OUTPUT:
    Mobj.read_obc_nodes : open boundary node cell array (length = number
    of open boundaries).

 EXAMPLE USAGE
    Mobj = read_fvcom_obc('tst_obc.dat')

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

 Revision history
    2015-01-12 Create function.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Mobj = read_fvcom_obc(Mobj, obcfile) 
0002 % Read fvcom open boundary file
0003 %
0004 % Mobj = function read_fvcom_obc(obcfile)
0005 %
0006 % DESCRIPTION:
0007 %    Read FVCOM open boundary node specification file.
0008 %
0009 % INPUT:
0010 %   Mobj : existing mesh object into which obc data is added
0011 %   obcfile : fvcom open boundary file
0012 %
0013 % OUTPUT:
0014 %    Mobj.read_obc_nodes : open boundary node cell array (length = number
0015 %    of open boundaries).
0016 %
0017 % EXAMPLE USAGE
0018 %    Mobj = read_fvcom_obc('tst_obc.dat')
0019 %
0020 % Author(s):
0021 %    Pierre Cazenave (Plymouth Marine Laboratory)
0022 %
0023 % Revision history
0024 %    2015-01-12 Create function.
0025 %
0026 %==========================================================================
0027 
0028 subname = 'read_fvcom_obc';
0029 global ftbverbose
0030 if ftbverbose
0031     fprintf('\nbegin : %s\n', subname)
0032 end
0033 
0034 have_strings = false;
0035 
0036 %--------------------------------------------------------------------------
0037 % read in the FVCOM open boundary nodes
0038 %--------------------------------------------------------------------------
0039 fid = fopen(obcfile,'r');
0040 assert(fid >= 0, 'file: %s does not exist.', obcfile)
0041 
0042 reading = true;
0043 while reading
0044     lin = fgetl(fid);
0045     if lin ~= -1 % EOF is -1
0046         lin = strtrim(lin);
0047         switch lin(1:2)
0048             case 'OB'
0049                 tmp = regexp(lin, ' = ', 'split');
0050                 nObcNodes = str2double(tmp(end));
0051                 clear tmp
0052                 read_obc_nodes = cell(1, 1);
0053         end
0054     else
0055         reading = false;
0056     end
0057 end
0058 fclose(fid);
0059 
0060 if nObcNodes > 0
0061     have_strings = true;
0062     fprintf('nObcNodes = %d\n', nObcNodes)
0063 end
0064 
0065 % We have to assume we have only a single open boundary as the _obc.dat
0066 % file has no way of indicating how many open boundaries there are.
0067 fid = fopen(obcfile,'r');
0068 S = textscan(fid, '%f%f%f%*s%*s%[^\n\r]', 'HeaderLines', 1, ...
0069     'Delimiter', {'\t',' '}, 'MultipleDelimsAsOne', true);
0070 fclose(fid);
0071 read_obc_nodes{1} = S{:, 2};
0072 
0073 if have_strings
0074     Mobj.have_strings = have_strings;
0075     Mobj.read_obc_nodes = read_obc_nodes;
0076 end
0077 
0078 if ftbverbose
0079     fprintf('\nend   : %s\n', subname)
0080 end

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