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" |
---|
8 | |
---|
9 | /* |
---|
10 | * ensemble.c v0.1 wesley ebisuzaki |
---|
11 | * |
---|
12 | * prints ensemble meta-data |
---|
13 | * |
---|
14 | * only for NCEP and ECMWF |
---|
15 | * |
---|
16 | * output format: |
---|
17 | * |
---|
18 | * ECMWF |
---|
19 | * ens=n/N: n: 0=ctl, +/-ve |
---|
20 | * N: total number of members |
---|
21 | * |
---|
22 | * NCEP |
---|
23 | * ens=n/type: n: 0=ctl, +/-ve, CLUST, PROD/ |
---|
24 | * type: Mn, WtdMn, SDev, NSDev |
---|
25 | */ |
---|
26 | |
---|
27 | extern int ncep_ens; |
---|
28 | |
---|
29 | void ensemble(unsigned char *pds, int mode) { |
---|
30 | |
---|
31 | int pdslen; |
---|
32 | unsigned char ctmp; |
---|
33 | char char_end; |
---|
34 | |
---|
35 | pdslen = PDS_LEN(pds); |
---|
36 | char_end = mode == 2 ? ' ' : ':'; |
---|
37 | |
---|
38 | if ((PDS_Center(pds) == NMC || ncep_ens) && pdslen >= 45 && pds[40] == 1) { |
---|
39 | |
---|
40 | /* control run */ |
---|
41 | |
---|
42 | if (pds[41] == 1) { |
---|
43 | if (mode != 2) { |
---|
44 | printf("ens%c0:", pds[42] == 1 ? '+' : '-'); |
---|
45 | } |
---|
46 | else { |
---|
47 | printf("%s-res_ens_control ", pds[42] == 1 ? "hi" : "low"); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | /* perturbation run */ |
---|
52 | |
---|
53 | else if (pds[41] == 2 || pds[41] == 3) { |
---|
54 | if (mode != 2) { |
---|
55 | printf("ens%c%d:", pds[41] == 3 ? '+' : '-', pds[42]); |
---|
56 | } |
---|
57 | else { |
---|
58 | printf("ens_perturbation=%c%d ",pds[41] == 3 ? '+' : '-', |
---|
59 | pds[42]); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | /* ensemble mean */ |
---|
64 | |
---|
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); |
---|
70 | } |
---|
71 | else { |
---|
72 | printf("ensemble-mean(%d members) ",pds[60]); |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | /* other case .. debug code */ |
---|
78 | |
---|
79 | else { |
---|
80 | printf("ens %d/%d/%d/%d:", pds[41],pds[42],pds[43],pds[44]); |
---|
81 | } |
---|
82 | |
---|
83 | /* NCEP probability limits */ |
---|
84 | |
---|
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); |
---|
90 | } |
---|
91 | else if (pds[46] == 2 && pdslen >= 54) { |
---|
92 | printf("prob(%s>%f)%c", k5toa(pds), ibm2flt(pds+51), char_end); |
---|
93 | } |
---|
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); |
---|
97 | } |
---|
98 | PDS_PARAM(pds) = ctmp; |
---|
99 | } |
---|
100 | |
---|
101 | } |
---|
102 | /* ECMWF test should go here */ |
---|
103 | } |
---|