Skip to content

FAQ/ I want to import topography, roughness, and embankment data in NetCDF format

Technical Reference Input/Output function/ Terrain, roughness, and embankment import function/ NetCDF format What are the tools and methods for creating netCDF files?

response

There are several ways to create a netCDF.

  • How to convert a text file to netCDF format using a tool called ncgen.exe
  • How to export mesh data in ASC format using GIS software such as QGIS and netCDF format using programming languages such as PowerShell

Here we will talk about the first method. The second method can be found here.

  1. Install the netCDF library.
    Get the netCDF4 64-bit version from the Installing and Using netCDF-C Libraries in Windows website of the official NetCDF website.
    The latest version as of October 2021 is netCDF4.8.0-NC4-64.exe.
    The following instructions assume that this version 4.8.0 is installed.
    By defaultC:\Program Files\netCDF 4.8.0\, the netCDF library is installed.

  2. Create the data.
    Here is some sample data: This is a format known as the CDL format. The CDL syntax is defined in NetCDF User's Guide - CDL Syntax.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    netcdf test {
    dimensions:
        lon = 9;
        lat = 15;
    variables:
        short lon(lon);
            lon:add_offset = 140.00015625;
            lon:scale_factor = 0.0003125;
            lon:units = "degrees_east";
        short lat(lat);
            lat:add_offset = 36.000104166666666666666666666667;
            lat:scale_factor = 0.000208333333333333333333333333;
            lat:units = "degrees_north";
        int glev(lat, lon);
            glev:valid_min = -100000;
            glev:valid_max = 1000000;
            glev:scale_factor = 0.01;
            glev:units = "m";
        short roughness(lat, lon);
            roughness:scale_factor = 0.001;
            roughness:units = "m\^(-1/3).s";
        int leveeHeight(lat, lon);
            leveeHeight:valid_min = -100000;
            leveeHeight:valid_max = 1000000;
            leveeHeight:scale_factor = 0.01;
            leveeHeight:units = "m";
        byte leveeFlag(lat, lon);
            leveeFlag:flag_meanings = "east north";
            leveeFlag:flag_masks = 1b, 2b;
    data:
        lon = 0, 1, 2, 3, 4, 5, 6, 7, 8;
        lat = 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
        glev = 100, 100, 100, 100, 100, 100, 100, 100, 100,
            100, 109, 116, 121, 122, 121, 116, 109, 100,
            100, 117, 131, 140, 143, 140, 131, 117, 100,
            100, 124, 144, 158, 162, 158, 144, 124, 100,
            100, 130, 155, 172, 178, 172, 155, 130, 100,
            100, 135, 164, 183, 190, 183, 164, 135, 100,
            100, 137, 169, 190, 198, 190, 169, 137, 100,
            100, 138, 171, 192, 200, 192, 171, 138, 100,
            100, 137, 169, 190, 198, 190, 169, 137, 100,
            100, 135, 164, 183, 190, 183, 164, 135, 100,
            100, 130, 155, 172, 178, 172, 155, 130, 100,
            100, 124, 144, 158, 162, 158, 144, 124, 100,
            100, 117, 131, 140, 143, 140, 131, 117, 100,
            100, 109, 116, 121, 122, 121, 116, 109, 100,
            100, 100, 100, 100, 100, 100, 100, 100, 100;
       roughness = 30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30, 30, 30, 30, 30, 30;
        leveeHeight = 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            300, 300, 300, 300, 300, 0, 0, 0, 0,
            0, 0, 0, 0, 300, 0, 0, 0, 0,
            0, 0, 0, 0, 300, 0, 0, 0, 0,
            0, 0, 0, 0, 300, 0, 0, 0, 0,
            0, 0, 0, 0, 300, 0, 0, 0, 0;
        leveeFlag = 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0,
            2, 2, 2, 2, 3, 0, 0, 0, 0,
            0, 0, 0, 0, 1, 0, 0, 0, 0,
            0, 0, 0, 0, 1, 0, 0, 0, 0,
            0, 0, 0, 0, 1, 0, 0, 0, 0,
            0, 0, 0, 0, 1, 0, 0, 0, 0;
    }
    
    • Here's an example of creating data with latitude and longitude in the lower left corner (36.0 deg, 140.0 deg), 9 cells wide, 15 cells high, and a mesh size of 25 m in latitude and longitude coordinates.
    • The data is 9 cells wide and 15 cells high. Give these values lon to and lat (lines 3~4).
    • A mesh size of 25 m for latitude-longitude coordinates corresponds to a resolution of 1/3200 = 0.0003125 deg for longitude and 1/4800 = 0.000208333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 Give these values lon:scale_factor to and respectively lat:scale_factor (lines 8 and 12). (Reference: Relationship between mesh size and latitude-longitude resolution)
    • Lower left longitude 140.0 plus longitude resolution multiplied by 1/2 and lon:add_offset given to (line 7). It also adds the lower-left latitude of 36.0 multiplied by 1/2 of the latitude resolutionlat:add_offset and gives to (line 11). Note that the reason why only 1/2 cells are shifted to the upper right in this way is that netCDF gives the value of the center of the cell.
    • Line 31 gives a sequence of numbers that increases by 1, starting from 0 and ending with the number of horizontal cells - 1.
    • The 32nd row gives a sequence of vertical cells - a number that decreases by 1, starting with 1 and ending with 0.
    • Line 33 ~ stores the elevation data (m) multiplied by 100 glev in . Top left, upper right, bottom left, bottom right, separated by commas (,). There are 9 cells wide and 15 vertical cells, so the values for 45 cells are lined up here. There is no need for a line break after the comma. Write a semicolon () after the last value;. Note that the reason for multiplying the elevation data by 100 is that the value stored here glev:scale_factor must be a reciprocal multiple of .
    • Line 48~, stores the roughness data multiplied by 1000 roughness in .
    • Line 63 ~ stores the embankment top (m) multiplied by 100 leveeHeight in .
    • Line 78~, stores the levee flag leveeFlag in . If you do not make an embankment, if you make an 0embankment on the east side of the cell1, if you make it on the north side2, if you make it on the east and north3 side, give it. Note that has a at leveeFlag:flag_masks the end of the number b . This byte means (signed 8-bit integer).

      Figure: leveeFlag Positional relationship between the embankment and
    • Save the created data to your desktop with the file name sample.cdl.txt.
  3. Convert using the tool ncgen.exe included with the netCDF library.
    By default,C:\Program Files\netCDF 4.8.0\bin\ncgen.exe it is stored in .
    From the command prompt cmd.exe , call the following command:

    1
    2
    cd %USERPROFILE%\Desktop
    "C:\Program Files\netCDF 4.8.0\bin\ncgen.exe" -b -k 4 sample.cdl.txt
    

is created on your desktop sample.cdl.nc .

  1. Bring the created netCDF into DioVISTA.

    1. Launch DioVISTA.
    2. Select Menu [file] > > [Create new from template] [Latitude and longitude coordinates] >.

    3. Select Project > [Calculation area] > [Import from NetCDF] .

    4. Specify for the file name of the dialog that appears sample.cdl.nc .
      Specify a mesh size of 25 m.

    5. Data has been ingested into DioVISTA.

Last update: 2023-03-20