Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
calday.c
Go to the documentation of this file.
1 static int days[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
2 
3 int daysInYear(int year) {
4  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
5  return 366;
6  else return 365;
7 }
8 
9 int daysInMonth(int year, int month) {
10  if ((month == 2) && (daysInYear(year) == 366)) return 29;
11  else return days[month];
12 }
13 
14 int getCalDay(int year, int jday, int *month, int *day) {
15  int i, sub_days, mdays;
16  sub_days = jday;
17  for (i = 1; i < 13; i++) {
18  mdays = daysInMonth(year, i);
19  sub_days -= mdays;
20  if (sub_days <= 0)
21  break;
22  }
23  if (sub_days == 0) {
24  *month = i;
25  *day = daysInMonth(year, i);
26  } else {
27  *month = i;
28  *day = daysInMonth(year, i) + sub_days;
29  }
30  return 0;
31 }
32 
33 int getJulianDay(int year, int month, int day) {
34  int i;
35  int julday = 0;
36 
37  if (month < 1 || month > 12)
38  return -1;
39  if (day < 1 || day > daysInMonth(year, month))
40  return -1;
41  for (i = 1; i < month; i++)
42  julday += daysInMonth(year, i);
43  julday += day;
44  return julday;
45 }
int32_t day
int getCalDay(int year, int jday, int *month, int *day)
Definition: calday.c:14
int daysInYear(int year)
Definition: calday.c:3
int32_t jday(int16_t i, int16_t j, int16_t k)
Converts a calendar date to the corresponding Julian day starting at noon on the calendar date....
Definition: jday.c:14
subroutine julday(YYMMDD, JDAY)
Definition: julday.f:2
int daysInMonth(int year, int month)
Definition: calday.c:9
int getJulianDay(int year, int month, int day)
Definition: calday.c:33
int i
Definition: decode_rs.h:71