Home > mrg > MRG_MIKE > mrg_dfs2_to_radians.m

mrg_dfs2_to_radians

PURPOSE ^

Convert directions in a dfs2 file to radians.

SYNOPSIS ^

function mrg_dfs2_to_radians(item_no, filename)

DESCRIPTION ^

 Convert directions in a dfs2 file to radians.

 INPUT
   item_no     An non-zero integer specifying the item in the DFS2 file
               containing the direction data.
   filename    An optional string specifying the name of the DFS2 to convert.

 OUTPUT
   NO OUTPUT AT CONSOLE
   This function copies the original file and converts item specified by
   'item_no' to radians.  It creates a DFS2 file with '_radians' 
   appended to the filename.

 NOTES
   Created to address a bug in the DHI software which has now been fixed.

 REQUIREMENTS
   The DHI/MIKE Matlab toolbox 2011 (developed with v. 20110304)

 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   2012
           DP. Initial attempt and distribution. 
   v 1.1   14/02/2013
           DP. Documentation. 
 TODO 
   Better parsing of input number.  Optional select of input item.
   Do something about delete value handeling.  At the moment they are not
       handeled at all, which is OK for ERA data only...

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mrg_dfs2_to_radians(item_no, filename)
0002 % Convert directions in a dfs2 file to radians.
0003 %
0004 % INPUT
0005 %   item_no     An non-zero integer specifying the item in the DFS2 file
0006 %               containing the direction data.
0007 %   filename    An optional string specifying the name of the DFS2 to convert.
0008 %
0009 % OUTPUT
0010 %   NO OUTPUT AT CONSOLE
0011 %   This function copies the original file and converts item specified by
0012 %   'item_no' to radians.  It creates a DFS2 file with '_radians'
0013 %   appended to the filename.
0014 %
0015 % NOTES
0016 %   Created to address a bug in the DHI software which has now been fixed.
0017 %
0018 % REQUIREMENTS
0019 %   The DHI/MIKE Matlab toolbox 2011 (developed with v. 20110304)
0020 %
0021 % LICENCE
0022 %   Created by Daniel Pritchard (www.pritchard.co)
0023 %   Distributed under a creative commons CC BY-SA licence. See here:
0024 %   http://creativecommons.org/licenses/by-sa/3.0/
0025 %
0026 % DEVELOPMENT
0027 %   v 1.0   2012
0028 %           DP. Initial attempt and distribution.
0029 %   v 1.1   14/02/2013
0030 %           DP. Documentation.
0031 % TODO
0032 %   Better parsing of input number.  Optional select of input item.
0033 %   Do something about delete value handeling.  At the moment they are not
0034 %       handeled at all, which is OK for ERA data only...
0035 
0036 %% Load libraries
0037 NET.addAssembly('DHI.Generic.MikeZero.DFS');
0038 import DHI.Generic.MikeZero.DFS.*;
0039 
0040 %% Sort out files
0041 if (~exist('filename', 'var'))
0042     [file, path] = uigetfile('*.dfs2', 'Select a DFS2 file to convert');
0043     filename = [path, file];
0044 end
0045 
0046 out_filename = [filename(1:end-5),'_radians', filename(end-4:end)];
0047 
0048 copyfile(filename, out_filename, 'f');
0049 
0050 dfs2_in = DfsFileFactory.Dfs2FileOpen(filename);
0051 dfs2_out = DfsFileFactory.Dfs2FileOpenEdit(out_filename);
0052 
0053 %% Get some basic info
0054 nsteps = dfs2_in.FileInfo.TimeAxis.NumberOfTimeSteps;
0055 
0056 %% Do the conversion and write out data
0057 for i=0:nsteps-1
0058     itemData = dfs2_in.ReadItemTimeStep(item_no,i);
0059     out_data = degtorad(double(itemData.Data));
0060     dfs2_out.WriteItemTimeStep(item_no,i,itemData.Time,NET.convertArray(single(out_data(:))));
0061 end
0062 
0063 %% Finish up
0064 dfs2_in.Close();
0065 dfs2_out.Close();
0066 
0067 end

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