JURASSIC
day2doy.c
Go to the documentation of this file.
1/*
2 This file is part of JURASSIC.
3
4 JURASSIC is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 JURASSIC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with JURASSIC. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright (C) 2003-2026 Forschungszentrum Juelich GmbH
18*/
19
25#include "jurassic.h"
26
27/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32static void usage(
33 void);
34
35/* ------------------------------------------------------------
36 Main...
37 ------------------------------------------------------------ */
38
39int main(
40 int argc,
41 char *argv[]) {
42
43 int doy;
44
45 /* Print usage information... */
46 USAGE;
47
48 /* Check arguments... */
49 if (argc < 4)
50 ERRMSG("Missing or invalid command-line arguments.\n\n"
51 "Usage: day2doy <year> <mon> <day>\n\n" "Use -h for full help.");
52
53 /* Read arguments... */
54 const int year = atoi(argv[1]);
55 const int mon = atoi(argv[2]);
56 const int day = atoi(argv[3]);
57
58 /* Convert... */
59 day2doy(year, mon, day, &doy);
60 printf("%d %d\n", year, doy);
61
62 return EXIT_SUCCESS;
63}
64
65/*****************************************************************************/
66
67static void usage(
68 void) {
69 printf("\nJURASSIC calendar converter.\n\n");
70 printf("Convert a calendar date to year and day-of-year.\n\n");
71 printf("Usage:\n");
72 printf(" day2doy <year> <mon> <day>\n\n");
73 printf("Arguments:\n");
74 printf(" <year> Calendar year.\n");
75 printf(" <mon> Calendar month.\n");
76 printf(" <day> Day of month.\n\n");
77 printf("Output:\n");
78 printf(" Writes results to standard output.\n\n");
79 printf("Further information:\n");
80 printf(" Manual: https://slcs-jsc.github.io/jurassic/\n");
81}
int main(int argc, char *argv[])
Definition: day2doy.c:39
void day2doy(int year, int mon, int day, int *doy)
Convert a calendar date to day-of-year.
Definition: jurassic.c:3358
JURASSIC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1325
#define USAGE
Print usage information on -h or --help.
Definition: jurassic.h:1206