updated top-level README and version_decl for V4.4.2 (#1795)
[WRF.git] / external / io_grib1 / WGRIB / ensemble.c
blob5e2a5f47ddb7969ae02ed3de55a43a4577e6f4df
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <string.h>
5 #include "grib.h"
6 #include "pds4.h"
7 #include "cnames.h"
9 /*
10 * ensemble.c v0.1 wesley ebisuzaki
12 * prints ensemble meta-data
14 * only for NCEP and ECMWF
16 * output format:
18 * ECMWF
19 * ens=n/N: n: 0=ctl, +/-ve
20 * N: total number of members
22 * NCEP
23 * ens=n/type: n: 0=ctl, +/-ve, CLUST, PROD/
24 * type: Mn, WtdMn, SDev, NSDev
27 extern int ncep_ens;
29 void ensemble(unsigned char *pds, int mode) {
31 int pdslen;
32 unsigned char ctmp;
33 char char_end;
35 pdslen = PDS_LEN(pds);
36 char_end = mode == 2 ? ' ' : ':';
38 if ((PDS_Center(pds) == NMC || ncep_ens) && pdslen >= 45 && pds[40] == 1) {
40 /* control run */
42 if (pds[41] == 1) {
43 if (mode != 2) {
44 printf("ens%c0:", pds[42] == 1 ? '+' : '-');
46 else {
47 printf("%s-res_ens_control ", pds[42] == 1 ? "hi" : "low");
51 /* perturbation run */
53 else if (pds[41] == 2 || pds[41] == 3) {
54 if (mode != 2) {
55 printf("ens%c%d:", pds[41] == 3 ? '+' : '-', pds[42]);
57 else {
58 printf("ens_perturbation=%c%d ",pds[41] == 3 ? '+' : '-',
59 pds[42]);
63 /* ensemble mean */
65 else if (pds[41] == 5) {
66 /* makes no sense to say "ensemble mean" for prob forecasts */
67 if (PDS_PARAM(pds) != 191 && PDS_PARAM(pds) != 192) {
68 if (mode != 2 || pdslen < 61) {
69 printf("ens-mean%c", char_end);
71 else {
72 printf("ensemble-mean(%d members) ",pds[60]);
77 /* other case .. debug code */
79 else {
80 printf("ens %d/%d/%d/%d:", pds[41],pds[42],pds[43],pds[44]);
83 /* NCEP probability limits */
85 if ((PDS_PARAM(pds) == 191 || PDS_PARAM(pds) == 192) && pdslen >= 47) {
86 ctmp = PDS_PARAM(pds);
87 PDS_PARAM(pds) = pds[45];
88 if (pds[46] == 1 && pdslen >= 51) {
89 printf("prob(%s<%f)%c", k5toa(pds), ibm2flt(pds+47),char_end);
91 else if (pds[46] == 2 && pdslen >= 54) {
92 printf("prob(%s>%f)%c", k5toa(pds), ibm2flt(pds+51), char_end);
94 else if (pds[46] == 3 && pdslen >= 54) {
95 printf("prob(%f<%s<%f)%c", ibm2flt(pds+47), k5toa(pds),
96 ibm2flt(pds+51), char_end);
98 PDS_PARAM(pds) = ctmp;
102 /* ECMWF test should go here */