JURASSIC
planck.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 /* Print usage information... */
44 USAGE;
45
46 /* Check arguments... */
47 if (argc != 3 && argc != 7)
48 ERRMSG("Missing or invalid command-line arguments.\n\n"
49 "Usage: planck <t> <nu>\n"
50 " or: planck <t0> <t1> <dt> <nu0> <nu1> <dnu>\n\n"
51 "Use -h for full help.");
52
53 /* Calculate single value... */
54 if (argc == 3) {
55
56 /* Read arguments... */
57 const double t = atof(argv[1]);
58 const double nu = atof(argv[2]);
59
60 /* Compute Planck function... */
61 printf("%.10g\n", PLANCK(t, nu));
62 }
63
64 /* Calculate table... */
65 else if (argc == 7) {
66
67 /* Read arguments... */
68 const double t0 = atof(argv[1]);
69 const double t1 = atof(argv[2]);
70 const double dt = atof(argv[3]);
71 const double nu0 = atof(argv[4]);
72 const double nu1 = atof(argv[5]);
73 const double dnu = atof(argv[6]);
74
75 /* Write header... */
76 printf("# $1 = brightness temperature [K]\n"
77 "# $2 = wavenumber [cm^-1]\n"
78 "# $3 = radiance [W/(m^2 sr cm^-1)]\n");
79
80 /* Compute Planck function... */
81 for (double t = t0; t <= t1; t += dt) {
82 printf("\n");
83 for (double nu = nu0; nu <= nu1; nu += dnu)
84 printf("%.10g %.4f %.10g\n", t, nu, PLANCK(t, nu));
85 }
86 }
87
88 return EXIT_SUCCESS;
89}
90
91/*****************************************************************************/
92
93static void usage(
94 void) {
95 printf("\nJURASSIC Planck-function converter.\n\n");
96 printf("Convert brightness temperature to radiance for a single value\n");
97 printf("or a tabulated temperature and wavenumber range.\n\n");
98 printf("Usage:\n");
99 printf(" planck <t> <nu>\n");
100 printf(" planck <t0> <t1> <dt> <nu0> <nu1> <dnu>\n\n");
101 printf("Arguments:\n");
102 printf(" <t> Brightness temperature [K].\n");
103 printf(" <nu> Wavenumber [cm^-1].\n");
104 printf(" <t0> First temperature value for table output.\n");
105 printf(" <t1> Last temperature value for table output.\n");
106 printf(" <dt> Temperature increment for table output.\n");
107 printf(" <nu0> First wavenumber for table output.\n");
108 printf(" <nu1> Last wavenumber for table output.\n");
109 printf(" <dnu> Wavenumber increment for table output.\n\n");
110 printf("Output:\n");
111 printf(" Writes results to standard output.\n\n");
112 printf("Further information:\n");
113 printf(" Manual: https://slcs-jsc.github.io/jurassic/\n");
114}
void usage(void)
Print command-line help.
Definition: formod.c:163
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
#define PLANCK(T, nu)
Compute spectral radiance using Planck’s law.
Definition: jurassic.h:1004
int main(int argc, char *argv[])
Definition: planck.c:39