Home > mrg > MRG_MIKE > mrg_ttide_to_mike.m

mrg_ttide_to_mike

PURPOSE ^

Outputs a .con file that is compatible with MIKE.

SYNOPSIS ^

function mrg_ttide_to_mike(tidestruc, tidedata, outfname)

DESCRIPTION ^

 Outputs a .con file that is compatible with MIKE.

 INPUT
   tidestruc   The struct returned by t_tide contining the harmonics,
               phase and amplitude
   tidedata    An optional matrix containing the original data used for
               the harmonic analysis.  Used to calculate Z0 (which is not
               provided by t_tide).  Assumed to be zero if not supplied.
   outfname    An optional string specifying the output filename. Prompted
               if not supplied.

 OUTPUT
   NO OUTPUT AT CONSOLE
   User input is required if output filename (outfname) not supplied.

 LICENCE
   Created by Daniel Pritchard (www.pritchard.co)
   Distributed under a creative commons CC BY-SA licence.  See here:
   http://creativecommons.org/licenses/by-sa/3.0/

 DEVELOPMENT
   v 1.0   2011-09
           Initial attempt.  DP
   v 1.1   2012-09-05
           Added output filename checking. DP
           Documentation.  DP

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mrg_ttide_to_mike(tidestruc, tidedata, outfname)
0002 % Outputs a .con file that is compatible with MIKE.
0003 %
0004 % INPUT
0005 %   tidestruc   The struct returned by t_tide contining the harmonics,
0006 %               phase and amplitude
0007 %   tidedata    An optional matrix containing the original data used for
0008 %               the harmonic analysis.  Used to calculate Z0 (which is not
0009 %               provided by t_tide).  Assumed to be zero if not supplied.
0010 %   outfname    An optional string specifying the output filename. Prompted
0011 %               if not supplied.
0012 %
0013 % OUTPUT
0014 %   NO OUTPUT AT CONSOLE
0015 %   User input is required if output filename (outfname) not supplied.
0016 %
0017 % LICENCE
0018 %   Created by Daniel Pritchard (www.pritchard.co)
0019 %   Distributed under a creative commons CC BY-SA licence.  See here:
0020 %   http://creativecommons.org/licenses/by-sa/3.0/
0021 %
0022 % DEVELOPMENT
0023 %   v 1.0   2011-09
0024 %           Initial attempt.  DP
0025 %   v 1.1   2012-09-05
0026 %           Added output filename checking. DP
0027 %           Documentation.  DP
0028 
0029 %% Check input
0030 if ~exist('tidedata', 'var')
0031     warning('ttide2mikecon:assumingZ0', 'You did not supply the orignal tide data.  Assuming a Z0 of zero');
0032     Z0 = 0;
0033 else
0034     Z0 = nanmean(tidedata);
0035 end
0036 
0037 if ~exist('tidestruc', 'var')
0038     error('You did not supply the data returned by t_tide.');
0039 end
0040 
0041 if ~isstruct(tidestruc)
0042     error('The "tidestruc" variable supplied is not a structure.  You must supply the object returned by t_tide.');
0043 end
0044 
0045 %% Get harmonic names and add 'Z0'
0046 names = cellstr(tidestruc.name);
0047 names = vertcat({'Z0'}, names);
0048 
0049 %% Get phase and Amp
0050 phase = [Z0;tidestruc.tidecon(:,1)];
0051 amp = [0;tidestruc.tidecon(:,3)];
0052 
0053 %% Contruct a numbered column
0054 no = 1:size(names,1);
0055 
0056 %% Write out file
0057 if ~exist('outfname', 'var')
0058     [fname,path] = uiputfile('*.con','Output filename');
0059     outfname = [path,fname];
0060 end
0061 
0062 fid = fopen(outfname,'w');
0063 fprintf(fid, 'Constituents from t_tide analysis in MATLAB\n');
0064 fprintf(fid, 'Name\tAmp.\tPhase\n');
0065 for i = 1:size(names,1)
0066     fprintf(fid,'%s \t %s \t %s \t %s\n',num2str(no(i)),names{i},num2str(phase(i)),num2str(amp(i)));
0067 end
0068 fclose(fid);
0069 end

Generated on Thu 29-May-2014 21:29:53 by m2html © 2005