Why a MATLAB Toolbox?
MATLAB provides a compact high-level technical programming/scripting language, which allows swift handling of time series data, analysis, visualisation and presentation. The MATLAB environment is very much hands-on and can be used without special programming skills for custom analysis of results from numerical models.
The DHI MATLAB toolbox provides a number of tools and examples for working with DHI related data files.
DFS support
From version 2011 of the MIKE by DHI software suite there is full support for reading and writing any DFS file from within MATLAB, without the need to install other components. The DHI MATLAB toolbox is strictly not required for working with DFS files, though it provides a number of convenience tools and also a number of examples of reading and writing different DFS files. Also, the toolbox contains a class for handling dfs0 files, the dfsTSO class, which should be used when working with dfs0 files.
DFS files are handled by the DHI.Generic.MikeZero.DFS component, which is a .NET component installed with any MIKE by DHI product. A user guide can be found from the Windows start menu:
- MIKE by DHI 2011 - Mike Zero - Documentation - MIKE Zero Documentation Index
Look for the "FileFormats" section. Together with the user guide are also detailed API documentation of all classes and methods, in the form of a compiled help file (.chm); look for the file DHI.Generic.MikeZero.DFS.chm in the folder (the installation folder can vary):
C:\Program Files\DHI\2012\MIKE Zero\Manuals\MIKE_ZERO\FileFormats
Examples are provided for download here, as part of the DHI MATLAB toolbox.
Other tools in the toolbox
- Reading and writing mesh files. Reordering and refining meshes.
- Analysing and modifying mesh files. The Mesh analyse tool, mzMeshAnalyse, analyses a mesh and highlights elements which gives the mesh a "bad" quality. The user can zoom in on the worse element or toggle between the 20 worse elements in the mesh. And the user can edit and modify the mesh in order to improve on the quality. See the User Guide for details
- Reading and writing xyz files
- Various operations on meshes, as, e.g., plotting, interpolation to nodes and calculation of gradients.
Requirements
MATLAB must be installed. Both the 32 bit and the 64 bit version of MATLAB will work. To read and write DFS files other than dfs0, MATLAB must be able to interact with .NET objects, hence version R2009a or later is required (tested on R2010a).
A MIKE by DHI version 2011 product must be installed in order to work with DFS files.
Installation of the DHI MATLAB toolbox
After download of the DHI MATLAB toolbox software please follow the instructions in the User Guide. Note that a MIKE by DHI 2011 product must be installed on the computer in order for the DFS interface to work.
Trouble shooting
Error using a .NET class in a function or in a compiled script
The error is on the form (function name may vary):
??? Undefined function or variable 'DfsFactory'.
Error in ==> my_script at 30
factory = DfsFactory();
By default you must refer to .NET classes by their fully qualified name, for example:
NET.addAssembly('DHI.Generic.MikeZero.DFS');
factory = DHI.Generic.MikeZero.DFS.DfsFactory();
builder = DHI.Generic.MikeZero.DFS.DfsBuilder.Create('Matlab dfs0 file','Matlab DFS',0);
The import statement makes it possible to skip the package/namespace part of the name and refer to the class names directly:
NET.addAssembly('DHI.Generic.MikeZero.DFS' );
import DHI.Generic.MikeZero.DFS.*;
factory = DfsFactory();
builder = DfsBuilder.Create('Matlab dfs0 file','Matlab DFS',0);
However, in certain cases the import statement seems not to work. The issue has been reported when using .NET DFS classes in functions and compiled scripts (the Matlab Compiler/deploytool). The solution is to use fully qualified names for all .NET DFS classes.
Error reading dfs0 files using the dfsTSO class
If you get en error alike:
??? Error using ==> @dfsTSO\private\parseDatetimeString
Error while reading time information from file:
DATEVEC failed, calling DTSTR2DTVECMX.
Failed on converting date string to date number.
then please check: http://faq.dhigroup.com/default.asp?module=Other+tools&ID=160#answer
Disclaimer
The DHI MATLAB toolbox is not a part of DHI Software Products and is delivered "as is".