MPTRAC
day2doy.c
Go to the documentation of this file.
1/*
2 This file is part of MPTRAC.
3
4 MPTRAC 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 MPTRAC 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 MPTRAC. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright (C) 2013-2026 Forschungszentrum Juelich GmbH
18*/
19
25#include "mptrac.h"
26
27/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32void usage(
33 void);
34
35/* ------------------------------------------------------------
36 Main...
37 ------------------------------------------------------------ */
38
39int main(
40 int argc,
41 char *argv[]) {
42
43 /* Print usage information... */
44 USAGE;
45
46 /* Check arguments... */
47 if (argc < 4)
48 ERRMSG("Missing or invalid command-line arguments.\n\n"
49 "Usage: day2doy <year> <mon> <day>\n\n" "Use -h for full help.");
50
51 /* Read arguments... */
52 const int year = atoi(argv[1]);
53 const int mon = atoi(argv[2]);
54 const int day = atoi(argv[3]);
55
56 /* Convert... */
57 int doy;
58 day2doy(year, mon, day, &doy);
59 printf("%d %d\n", year, doy);
60
61 return EXIT_SUCCESS;
62}
63
64/*****************************************************************************/
65
67void usage(
68 void) {
69
70 printf("\nMPTRAC day2doy tool.\n\n");
71 printf("Convert a calendar date to day of year.\n");
72 printf("\n");
73 printf("Usage:\n");
74 printf(" day2doy <year> <mon> <day>\n");
75 printf("\n");
76 printf("Arguments:\n");
77 printf(" <year> Year.\n");
78 printf(" <mon> Month.\n");
79 printf(" <day> Day of month.\n");
80 printf("\nFurther information:\n");
81 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
82}
int main(int argc, char *argv[])
Definition: day2doy.c:39
void usage(void)
Print command-line help.
Definition: day2doy.c:67
void day2doy(const int year, const int mon, const int day, int *doy)
Get day of year from date.
Definition: mptrac.c:1052
MPTRAC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2102
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:1909