Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / external / io_grib1 / WGRIB / PDStimes.c
blob2bcc9449906e4231ffb861e4e8389cc26c688ba8
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <string.h>
5 #include "pds4.h"
6 #include "grib.h"
8 /*
9 * PDStimes.c v1.2 wesley ebisuzaki
11 * prints something readable for time code in grib file
13 * not all cases decoded
14 * for NCEP/NCAR Reanalysis
16 * v1.2.1 1/99 fixed forecast time unit table
17 * v1.2.2 10/01 add time_range = 11 (at DWD) Helmut P. Frank
20 static char *units[] = {
21 "min", "hr", "d", "mon", "yr",
22 "decade", "normal", "century", "??", "??", " x3 hours", " x6 hours",
23 " x12 hours",
24 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
25 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
26 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
27 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
28 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
29 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
30 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
31 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
32 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
33 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
34 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
35 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
36 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
37 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
38 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
39 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
40 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
41 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
42 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
43 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
44 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
45 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
46 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
47 "??", "??", "??", "??", "??", "??", "??", "??", "??", "??",
48 "??", " sec"};
50 void PDStimes(int time_range, int p1, int p2, int time_unit) {
52 char *unit;
53 enum {anal, fcst, unknown} type;
54 int fcst_len = 0;
56 if (time_unit >= 0 && time_unit <= sizeof(units)/sizeof(char *))
57 unit = units[time_unit];
58 else unit = "";
61 /* change x3/x6/x12 to hours */
63 if (time_unit == HOURS3) {
64 p1 *= 3; p2 *= 3;
65 time_unit = HOUR;
67 else if (time_unit == HOURS6) {
68 p1 *= 6; p2 *= 6;
69 time_unit = HOUR;
71 else if (time_unit == HOURS12) {
72 p1 *= 12; p2 *= 12;
73 time_unit = HOUR;
76 if (time_unit >= 0 && time_unit <= sizeof(units)/sizeof(char *))
77 unit = units[time_unit];
78 else unit = "";
80 /* figure out if analysis or forecast */
81 /* in GRIB, there is a difference between init and uninit analyses */
82 /* not case at NMC .. no longer run initialization */
83 /* ignore diff between init an uninit analyses */
85 switch (time_range) {
87 case 0:
88 case 1:
89 case 113:
90 case 114:
91 case 118:
92 if (p1 == 0) type = anal;
93 else {
94 type = fcst;
95 fcst_len = p1;
97 break;
98 case 10: /* way NMC uses it, should be unknown? */
99 type = fcst;
100 fcst_len = p1*256 + p2;
101 if (fcst_len == 0) type = anal;
102 break;
104 case 51:
105 type = unknown;
106 break;
107 case 123:
108 case 124:
109 type = anal;
110 break;
112 case 135:
113 type = anal;
114 break;
116 default: type = unknown;
117 break;
120 /* ----------------------------------------------- */
122 if (type == anal) printf("anl:");
123 else if (type == fcst) printf("%d%s fcst:",fcst_len,unit);
126 if (time_range == 123 || time_range == 124) {
127 if (p1 != 0) printf("start@%d%s:",p1,unit);
131 /* print time range */
134 switch (time_range) {
136 case 0:
137 case 1:
138 case 10:
139 break;
140 case 2: printf("valid %d-%d%s:",p1,p2,unit);
141 break;
142 case 3: printf("%d-%d%s ave:",p1,p2,unit);
143 break;
144 case 4: printf("%d-%d%s acc:",p1,p2,unit);
145 break;
146 case 5: printf("%d-%d%s diff:",p1,p2,unit);
147 break;
148 case 11: if (p1 > 0) {
149 printf("init fcst %d%s:",p1,unit);
151 else {
152 printf("time?:");
154 break;
155 case 51: if (p1 == 0) {
156 /* printf("clim %d%s:",p2,unit); */
157 printf("0-%d%s product:ave@1yr:",p2,unit);
159 else if (p1 == 1) {
160 /* printf("clim (diurnal) %d%s:",p2,unit); */
161 printf("0-%d%s product:same-hour,ave@1yr:",p2,unit);
163 else {
164 printf("clim? p1=%d? %d%s?:",p1,p2,unit);
166 break;
167 case 113:
168 case 123:
169 printf("ave@%d%s:",p2,unit);
170 break;
171 case 114:
172 case 124:
173 printf("acc@%d%s:",p2,unit);
174 break;
175 case 115:
176 printf("ave of fcst:%d to %d%s:",p1,p2,unit);
177 break;
178 case 116:
179 printf("acc of fcst:%d to %d%s:",p1,p2,unit);
180 break;
181 case 118:
182 printf("var@%d%s:",p2,unit);
183 break;
184 case 128:
185 printf("%d-%d%s fcst acc:ave@24hr:", p1, p2, unit);
186 break;
187 case 129:
188 printf("%d-%d%s fcst acc:ave@%d%s:", p1, p2, unit, p2-p1,unit);
189 break;
190 case 130:
191 printf("%d-%d%s fcst ave:ave@24hr:", p1, p2, unit);
192 break;
193 case 131:
194 printf("%d-%d%s fcst ave:ave@%d%s:", p1, p2, unit,p2-p1,unit);
195 break;
196 /* for CFS */
197 case 132:
198 printf("%d-%d%s anl:ave@1yr:", p1, p2, unit);
199 break;
200 case 133:
201 printf("%d-%d%s fcst:ave@1yr:", p1, p2, unit);
202 break;
203 case 134:
204 printf("%d-%d%s fcst-anl:rms@1yr:", p1, p2, unit);
205 break;
206 case 135:
207 printf("%d-%d%s fcst-fcst_mean:rms@1yr:", p1, p2, unit);
208 break;
209 case 136:
210 printf("%d-%d%s anl-anl_mean:rms@1yr:", p1, p2, unit);
211 break;
214 default: printf("time?:");