Commit fd334d7f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added CALENDAR_GREGORIAN.

parent e32d5b87
......@@ -58,7 +58,7 @@ int days_per_year(int calendar, int year)
if ( daysperyear == 0 )
{
if ( year == 1582 && calendar == CALENDAR_STANDARD )
if ( year == 1582 && (calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN) )
daysperyear = 355;
else if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
daysperyear = 366;
......
......@@ -316,9 +316,10 @@ void set_zaxistype(const char *attstring, int *zaxistype)
void set_calendar(const char *attstring, int *calendar)
{
if ( str_is_equal(attstring, "standard") ||
str_is_equal(attstring, "gregorian") )
if ( str_is_equal(attstring, "standard") )
*calendar = CALENDAR_STANDARD;
else if ( str_is_equal(attstring, "gregorian") )
*calendar = CALENDAR_GREGORIAN;
else if ( str_is_equal(attstring, "none") )
*calendar = CALENDAR_NONE;
else if ( str_is_equal(attstring, "proleptic") )
......
......@@ -267,11 +267,12 @@ typedef struct {
/* CALENDAR types */
#define CALENDAR_STANDARD 0 /* don't change this value (used also in cgribexlib)! */
#define CALENDAR_PROLEPTIC 1
#define CALENDAR_360DAYS 2
#define CALENDAR_365DAYS 3
#define CALENDAR_366DAYS 4
#define CALENDAR_NONE 5
#define CALENDAR_GREGORIAN 1
#define CALENDAR_PROLEPTIC 2
#define CALENDAR_360DAYS 3
#define CALENDAR_365DAYS 4
#define CALENDAR_366DAYS 5
#define CALENDAR_NONE 6
/* number of unsigned char needed to store UUID */
#define CDI_UUID_SIZE 16
......
......@@ -425,6 +425,8 @@ void cdiInitialize(void)
{
if ( strncmp(envstr, "standard", 8) == 0 )
cdiDefaultCalendar = CALENDAR_STANDARD;
else if ( strncmp(envstr, "gregorian", 9) == 0 )
cdiDefaultCalendar = CALENDAR_GREGORIAN;
else if ( strncmp(envstr, "proleptic", 9) == 0 )
cdiDefaultCalendar = CALENDAR_PROLEPTIC;
else if ( strncmp(envstr, "360days", 7) == 0 )
......
......@@ -4,15 +4,15 @@
#ifdef HAVE_LIBNETCDF
# include <stdio.h>
# include <string.h>
#include <stdio.h>
#include <string.h>
# include <netcdf.h>
#include <netcdf.h>
# include "cdi.h"
# include "cdi_int.h"
# include "stream_cdf.h"
# include "cdf_int.h"
#include "cdi.h"
#include "cdi_int.h"
#include "stream_cdf.h"
#include "cdf_int.h"
static
int cdfDefTimeBounds(int fileID, int nctimevarid, int nctimedimid, const char *taxis_name, taxis_t* taxis)
......@@ -119,6 +119,7 @@ void cdfDefCalendar(int fileID, int ncvarid, int calendar)
{
static const struct { int calCode; const char *calStr; } calTab[] = {
{ CALENDAR_STANDARD, "standard" },
{ CALENDAR_GREGORIAN, "gregorian" },
{ CALENDAR_PROLEPTIC, "proleptic_gregorian" },
{ CALENDAR_NONE, "none" },
{ CALENDAR_360DAYS, "360_day" },
......
......@@ -17,7 +17,7 @@ void decode_julday(int calendar,
double b = floor((a - 1867216.25)/36524.25);
double c = a + b - floor(b/4) + 1525;
if ( calendar == CALENDAR_STANDARD )
if ( calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN )
if ( a < 2299161 ) c = a + 1524;
double d = floor((c - 122.1)/365.25);
......@@ -54,7 +54,7 @@ int encode_julday(int calendar, int year, int month, int day)
else
ib = (int)(iy/400) - (int)(iy/100);
if ( calendar == CALENDAR_STANDARD )
if ( calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN )
{
if ( year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15))) )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment