#%% Create a Delft3D WAQ segment input file # Alexander Rey, 2023-06-27 # These files can be used to define a value for every cell at every time step # The files are binary and have a specific format # The format is described in the Delft3D WAQ manual # Each lauer is a different segmnent # Typically, segments increase sequentially from 1 to N, then the second layer will be N+1 to 2N, etc. # The number of layers is defined in the GUI # Use QUICKPLOT to extract segment numbers in layer 1, then adjust from there # Note: it will go to zero at the end of the time series, so ensure that the last time step is covered #%% Import libraries import struct NOSEG = 5 # Number of segments NOTIME = 10 # Number of time steps VALUE = [[0.0] * NOSEG for _ in range(NOTIME)] # Initialize VALUE as a 2D matrix for i in range(NOTIME): for j in range(NOSEG): # Fill the matrix with the desired values. VALUE[i][j] = i + j with open('output_seg10.bin', 'wb') as file: for i in range(NOTIME): # TIMER is the number of seconds from the reference date (set in the GUI) TIMER = (i - 1) * 31536000 file.write(struct.pack('i', TIMER)) # Write TIMER as a 4-byte integer for j in range(NOSEG): file.write(struct.pack('f', VALUE[i][j])) # Write VALUE[i][j] as a 4-byte float