nctime.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*********************************************************************
  2. * Copyright 2008, University Corporation for Atmospheric Research
  3. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  4. * $Id: nctime.h,v 1.6 2010/03/18 19:24:26 russ Exp $
  5. *********************************************************************/
  6. struct bounds_node{
  7. int ncid; /* group (or file) in which variable with associated
  8. * bounds variable resides */
  9. int varid; /* has "bounds" attribute naming its bounds variable */
  10. char *bounds_name; /* the named variable, which stores bounds for varid */
  11. struct bounds_node *next; /* next node on list or NULL ifn last list node */
  12. };
  13. typedef struct bounds_node bounds_node_t;
  14. /*
  15. * This code was extracted with permission from the CDMS time
  16. * conversion and arithmetic routines developed by Bob Drach, Lawrence
  17. * Livermore National Laboratory as part of the cdtime library.
  18. * Changes and additions were made to support the "-t" option of the
  19. * netCDF ncdump utility.
  20. *
  21. * For the complete time conversion and climate calendar facilities of
  22. * the CDMS library, get the original sources from LLNL.
  23. */
  24. #define CD_MAX_RELUNITS 64 /* Max characters in relative units */
  25. #define CD_MAX_CHARTIME 48 /* Max characters in character time */
  26. #define CD_NULL_DAY 1 /* Null day value */
  27. #define CD_NULL_HOUR 0.0 /* Null hour value */
  28. #define CD_NULL_ID 0 /* Reserved ID */
  29. #define CD_NULL_MONTH 1 /* Null month value */
  30. #define CD_NULL_YEAR 0 /* Null year value, component time */
  31. typedef enum CdTimeUnit {
  32. CdBadTimeUnit = 0,
  33. CdMinute = 1,
  34. CdHour = 2,
  35. CdDay = 3,
  36. CdWeek = 4, /* Always = 7 days */
  37. CdMonth = 5,
  38. CdSeason = 6, /* Always = 3 months */
  39. CdYear = 7,
  40. CdSecond = 8
  41. } CdTimeUnit;
  42. typedef enum cdUnit {
  43. cdBadUnit = CdBadTimeUnit,
  44. cdMinute = CdMinute,
  45. cdHour = CdHour,
  46. cdDay = CdDay,
  47. cdWeek = CdWeek, /* Always = 7 days */
  48. cdMonth = CdMonth,
  49. cdSeason = CdSeason, /* Always = 3 months */
  50. cdYear = CdYear,
  51. cdSecond = CdSecond,
  52. cdFraction /* Fractional part of absolute time */
  53. } cdUnitTime;
  54. #define CdChronCal 0x1
  55. #define CdClimCal 0x0
  56. #define CdBaseRel 0x00
  57. #define CdBase1970 0x10
  58. #define CdHasLeap 0x100
  59. #define CdNoLeap 0x000
  60. #define Cd366 0x2000
  61. #define Cd365 0x1000
  62. #define Cd360 0x0000
  63. #define CdJulianType 0x10000
  64. typedef enum CdTimeType {
  65. CdChron = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365), /* 4369 */
  66. CdJulianCal = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365 | CdJulianType),
  67. CdChronNoLeap = ( CdChronCal | CdBase1970 | CdNoLeap | Cd365), /* 4113 */
  68. CdChron360 = ( CdChronCal | CdBase1970 | CdNoLeap | Cd360), /* 17 */
  69. CdRel = ( CdChronCal | CdBaseRel | CdHasLeap | Cd365), /* 4353 */
  70. CdRelNoLeap = ( CdChronCal | CdBaseRel | CdNoLeap | Cd365), /* 4097 */
  71. CdClim = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365), /* 4096 */
  72. CdClimLeap = ( CdClimCal | CdBaseRel | CdHasLeap | Cd365),
  73. CdClim360 = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365),
  74. CdChron366 = ( CdChronCal | CdBase1970 | CdNoLeap | Cd366)
  75. } CdTimeType;
  76. typedef struct {
  77. long year; /* e.g., 1979 */
  78. short month; /* e.g., CdDec */
  79. short day; /* e.g., 30 */
  80. double hour; /* hour and fractional hour */
  81. long baseYear; /* base year for relative, 1970 for CdChron */
  82. CdTimeType timeType; /* e.g., CdChron */
  83. } CdTime;
  84. #define cdStandardCal 0x11
  85. #define cdClimCal 0x0
  86. #define cdHasLeap 0x100
  87. #define cdHasNoLeap 0x000
  88. #define cd366Days 0x2000
  89. #define cd365Days 0x1000
  90. #define cd360Days 0x0000
  91. #define cdJulianCal 0x10000
  92. #define cdMixedCal 0x20000
  93. typedef enum cdCalenType {
  94. cdStandard = ( cdStandardCal | cdHasLeap | cd365Days),
  95. cdJulian = ( cdStandardCal | cdHasLeap | cd365Days | cdJulianCal),
  96. cdNoLeap = ( cdStandardCal | cdHasNoLeap | cd365Days),
  97. cd360 = ( cdStandardCal | cdHasNoLeap | cd360Days),
  98. cd366 = ( cdStandardCal | cdHasNoLeap | cd366Days),
  99. cdClim = ( cdClimCal | cdHasNoLeap | cd365Days),
  100. cdClimLeap = ( cdClimCal | cdHasLeap | cd365Days),
  101. cdClim360 = ( cdClimCal | cdHasNoLeap | cd360Days),
  102. cdMixed = ( cdStandardCal | cdHasLeap | cd365Days | cdMixedCal)
  103. } cdCalenType;
  104. /* Component time */
  105. typedef struct {
  106. long year; /* Year */
  107. short month; /* Numerical month (1..12) */
  108. short day; /* Day of month (1..31) */
  109. double hour; /* Hour and fractional hours */
  110. } cdCompTime;
  111. typedef struct {
  112. long count; /* units count */
  113. CdTimeUnit units; /* time interval units */
  114. } CdDeltaTime;
  115. typedef struct timeinfo_t {
  116. cdCalenType calendar;
  117. cdUnitTime unit;
  118. char *units;
  119. cdCompTime origin;
  120. } timeinfo_t;
  121. #if defined(DLL_NETCDF) /* Defined when library is a DLL */
  122. # if defined(DLL_EXPORT) /* define when building the library. */
  123. # define MSC_NCTIME_EXTRA __declspec(dllexport)
  124. # else
  125. # define MSC_NCTIME_EXTRA __declspec(dllimport)
  126. # endif
  127. MSC_NCTIME_EXTRA extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime);
  128. MSC_NCTIME_EXTRA extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
  129. MSC_NCTIME_EXTRA extern void Cdh2e(CdTime *htime, double *etime);
  130. MSC_NCTIME_EXTRA extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
  131. MSC_NCTIME_EXTRA extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
  132. #else
  133. extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime);
  134. extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
  135. extern void Cdh2e(CdTime *htime, double *etime);
  136. extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
  137. extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
  138. #endif /* DLL Considerations. */