How to use Matlab to create dfs2 file from Ascii (text) file?

7 views (last 30 days)
Hello!
Is if possible to use any code for changing Ascii (text) file to create dfs2-file (described here) for DHI's Mike Modeling tools?
I have attached 2 examples of those Ascii files.
Currenlty it is possible to change Ascii files (single file) to dfs2 file format in Mike Zero toolbox by DHI! I dont see it efficient at all and it will be great if Matlab can handle this task instead!
Best regards!
/Harr

Accepted Answer

Walter Roberson
Walter Roberson on 28 Dec 2022
Edited: Walter Roberson on 28 Dec 2022
https://docs.mikepoweredbydhi.com/core_libraries/dfs/dfs-file-formats/ does not describe the details of the file format. It does tell you the name of functions to invoke through the C api or the .NET api. The C api would require a compiler but could be used with any of the supported operating systems. The .NET api would require MS Windows
As Mike's code is likely already using the same functions, I would not expect having matlab invoke the routines would be any faster.
  2 Comments
Harr
Harr on 28 Dec 2022
Dear Walter,
Thank you very much for your clarification! Unfortunately i couldn't find any better description for the DFS files. One of main problem with Mike's code is that it dosent have any loop in order to convert multiple (I have over 100) Ascii files. I am new to Matlab and i like how efficient Matlab is in performing similar tasks so i was hoping i get some help about handling DFS files as well ^_^
Happy new year soon!
Best regards
/Harr
Walter Roberson
Walter Roberson on 28 Dec 2022
When developers write code to convert files between formats, then developers almost always use their existing routines to read and write the relevant file formats. When they do not do that, when they write specific conversion code, the reasons almost always have to do with shortcuts that can be taken, such as mechanical reformatting that can be done without having to "understand" the data. So the developer-provided conversion routines are almost always as good as or faster than using the developer-provided reading and writing routines.
The exception to this situation is that sometimes when a developer writes a conversion routine, the developer puts in a bunch of sanity checks and cross-checks, or facilities intended to help examine and understand the details of what is happening. Like asking "Does it make sense that there is a non-zero force in the matrix between node 3 and node 7? No! Node 18 is physically between the two and would block the force!" Routines that validate and repair input files while converting to output files can be very useful... but take longer. So occasionally you can get better performance by using the developer provided reading and writing (without validation) routines... but not typically.
What MATLAB might provide is convenience -- an interface that makes it easier to invoke the developer-provided functions on a series of files. Not "efficiency", not unless you are talking about user-time instead of processing time, but convenience .

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!