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, 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.
I have been searching the internet for a straight forward way to make this, but found only fragmented information.
After many searches I have a plan to attack this problem, but want to ask the experts before.
My plan is as follows:
Use the UDUNITS pakcage (http://www.unidata.ucar.edu/software/udunits/udunits-2.2.16/doc/udunits/udunits2lib.html#Time) 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.
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?
Thanks a lot in advance.
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.