DART icon indicating copy to clipboard operation
DART copied to clipboard

Feature request: Add additional helper functions to utilities_mod

Open johnsonbk opened this issue 1 year ago • 0 comments

Use case

While writing the model_to_dart code for the aether cube_sphere interface I found that it would be useful if there were a few additional functions DART's utilities_mod to make the model_to_dart code simpler.

Is your feature request related to a problem?

Yes. DART typically uses one-based indexing for ensemble members, whereas some models (such as aether) and languages (such as python) use zero-based indexing.

If so, give a clear and concise description of what the problem is.

For the model_to_dart code for aether, for example, the code takes blocks from the zeroth ensemble member to create the analogous DART filter input file (the DART filter input file could be denoted by '0000' but that isn't the typical DART convention):

  1. A string '0000' in a block input file
  2. Converts to an integer 0
  3. The integer is incremented to 1
  4. Which converts and is padded to a string '0001' in a filter input file
  5. filter is run
  6. The string '0001' in a filter output file
  7. Converts to an integer 1
  8. Decrements to an integer 0
  9. Which converts and is padded to a string '0000' in a block output file

Describe your preferred solution

Add three additional functions to the utilities_mod:

  • integer_to_string This function compliments the already existing string_to_integer function. It takes an integer and converts it to a string analog of the integer.
  • pad_left: this function takes a string and pads it to the left with a specified character
  • zero_fill: this function takes a string and pads it to the left with zeros

zero_fill will be implemented as a specific use case of pad_left but it is included because python users are typically familiar the use of the zfill function included in the standard libraries of that language.

Describe any alternatives you have considered

These functions could just be included in a specific model directory, but that encourages code redundancy. For example, the RTTOV forward operators: ./observations/forward_operators/obs_def_rttov_mod.f90 ./observations/forward_operators/obs_def_rttov13_mod.f90 contain their own stray version of a str2int function, which replicates the functionality of the string_to_integer function in utilities_mod.

johnsonbk avatar Feb 28 '24 20:02 johnsonbk