Posted Mon, 14 Oct 2013 05:12:53 GMT by Lee Cellyn
Hi all,

I am interested in using MATLAB to create the bathymetry for MIKE 21. Anybody can help on this?
Thanks.
Posted Mon, 25 Nov 2013 10:09:56 GMT by Jesper Grooss
Try take a look at the create_dfs2.m example within the DHI MATLAB Toolbox. This creates a dfs2 file with multiple items and time steps.

A bathymetry dfs2 file only needs one item and one time step. Below I have copied in some code that does this for a bathymetry matching the Oresund example from the MIKE 21 installed examples. This is C# code, so you will need to translate it to MATLAB, but matching it with the create_dfs2.m example should show you all the tricky bits.

What you need to modify in the code below is:
[list]
[li]Projection information[/li]
[li]Temporal information - temporal axis - start time[/li]
[li]Spatial information - spatial axis - dx, dy, size in x and y direction (n x m)[/li]
[li]M21_Misc custom block: first value (327f) is rotation, which must match the rotation from the projection information. The 10f is the land value.[/li]
[/list]
And then you need to create the array of bathymetry data to write to the file, the "[tt]float[] bathyData[/tt] = ..." below.

Best regards
Jesper

[hr]
[code]

      DfsFactory factory = new DfsFactory();
      Dfs2Builder builder = Dfs2Builder.Create(@"C:\0\Training\Bat1_0.dfs2", @"Grid editor", 1);

      // Set up the header
      builder.SetDataType(0);
      builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin("UTM-33", 12.438741600559911, 55.2257078424238, 327));
      builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(2003, 01, 01, 0, 0, 0), 0, 1));
      builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUmeter, 72, 0, 900, 94, 0, 900));
      builder.DeleteValueFloat = -1e-30f;

      builder.AddCustomBlock(factory.CreateCustomBlock("Display Settings", new int[] { 1, 0, 0 }));
      builder.AddCustomBlock(factory.CreateCustomBlock("M21_Misc", new float[] { 327f, 0f, -900f, 10f, 0f, 0f, 0f }));

      // Set up dynamic items
      builder.AddDynamicItem("Bathymetry", eumQuantity.Create(eumItem.eumIWaterLevel, eumUnit.eumUmeter),
                            DfsSimpleType.Float, DataValueType.Instantaneous);

      // Create and get file
      builder.CreateFile(filename);
      Dfs2File file = builder.GetFile();

      // Add bathymetry data
      float[] bathyData = ...
      file.WriteItemTimeStepNext(0, bathyData);

      file.Close();
[/code]

You must be signed in to post in this forum.