Search code examples
datedatetimecalendarfortrannetcdf

Reading dates from a NetCDF file using Fortran


I have to use Fortran for some calculations using data from NetCDF files. And, depending on user selections, I need to select only one or some months from each year.

The dates in the NetCDF file are coded sometimes as "months since XXXX-XX-XX", other times as "days since XXXX-XX-XX", others as "hours since XXXX-XX-XX XX:XX", etc.

In addition, these have to be interpreted as belonging to a certain type of calendar, which can be Gregorian, Julian, proleptic Gregorian, 360-day, etc.

After many searches I have a plan to attack this problem, but want to ask the experts before.

My plan is as follows:

  1. Use the UDUNITS package to convert the date information contained in the NetCDF file, to a Julian/Gregorian date. For this, I have to:

    • Bind the C code of UDUNITS to Fortran.
  2. Convert the date obtained, to the desired calendar. For this, I think that I have to use a calendar package. Which would be a good choice?.

Do you agree with this?


Solution

  • I think I have found a good solution: the cdi libraries, developed by the Max-Plank Institute and distributed under the GNU GENERAL PUBLIC LICENSE Version 2.

    It defines the following types of calendars: CALENDAR STANDARD, CALENDAR PROLEPTIC, CALENDAR 360DAYS, CALENDAR 365DAYS and CALENDAR 366DAYS.

    This seems to be a very proven code, since it is used by cdo, a widely used tool that manages netcdf files.