-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwgrib.c
executable file
·13674 lines (13212 loc) · 603 KB
/
wgrib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file
* version 1.2.1 of grib headers w. ebisuzaki
* 1.2.2 added access to spectral reference value l. kornblueh
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <math.h>
#include <float.h>
#ifndef INT2
#define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 0x7f) << 8) + b))
#endif
#define BDS_LEN(bds) (ec_large_grib ? len_ec_bds : ((int) ((bds[0]<<16)+(bds[1]<<8)+bds[2])) )
#define BDS_Flag(bds) (bds[3])
#define BDS_Grid(bds) ((bds[3] & 128) == 0)
#define BDS_Harmonic(bds) (bds[3] & 128)
#define BDS_Packing(bds) ((bds[3] & 64) != 0)
#define BDS_SimplePacking(bds) ((bds[3] & 64) == 0)
#define BDS_ComplexPacking(bds) ((bds[3] & 64) != 0)
#define BDS_OriginalType(bds) ((bds[3] & 32) != 0)
#define BDS_OriginalFloat(bds) ((bds[3] & 32) == 0)
#define BDS_OriginalInt(bds) ((bds[3] & 32) != 0)
#define BDS_MoreFlags(bds) ((bds[3] & 16) != 0)
#define BDS_UnusedBits(bds) ((int) (bds[3] & 15))
#define BDS_BinScale(bds) INT2(bds[4],bds[5])
#define BDS_RefValue(bds) (ibm2flt(bds+6))
#define BDS_NumBits(bds) ((int) bds[10])
#define BDS_Harmonic_RefValue(bds) (ibm2flt(bds+11))
#define BDS_DataStart(bds) ((int) (11 + BDS_MoreFlags(bds)*3))
#define BDS_P1(bds) (bds[16] * 256 + bds[17])
#define BDS_P2(bds) (bds[18] * 256 + bds[19])
/* undefined value -- if bitmap */
#define UNDEFINED 9.999e20
/* version 1.2 of grib headers w. ebisuzaki */
#define BMS_LEN(bms) ((bms) == NULL ? 0 : (bms[0]<<16)+(bms[1]<<8)+bms[2])
#define BMS_UnusedBits(bms) ((bms) == NULL ? 0 : bms[3])
#define BMS_StdMap(bms) ((bms) == NULL ? 0 : ((bms[4]<<8) + bms[5]))
#define BMS_bitmap(bms) ((bms) == NULL ? NULL : (bms)+6)
#define BMS_nxny(bms) ((((bms) == NULL) || BMS_StdMap(bms)) \
? 0 : (BMS_LEN(bms)*8 - 48 - BMS_UnusedBits(bms)))
/* cnames_file.c */
/* search order for parameter names
*
* #define P_TABLE_FIRST
* look at external parameter table first
*
* otherwise use builtin NCEP-2 or ECMWF-160 first
*/
/* #define P_TABLE_FIRST */
/* search order for external parameter table
* 1) environment variable GRIBTAB
* 2) environment variable gribtab
* 3) the file 'gribtab' in current directory
*/
/* cnames.c */
/* then default values */
char *k5toa(unsigned char *pds);
char *k5_comments(unsigned char *pds);
int setup_user_table(int center, int subcenter, int ptable);
struct ParmTable {
/* char *name, *comment; */
char *name, *comment;
};
/* version 1.4.5 of grib headers w. ebisuzaki */
/* this version is incomplete */
/* 5/00 - dx/dy or di/dj controlled by bit 1 of resolution byte */
/* 8/00 - dx/dy or di/dj for polar and lambert not controlled by res. byte */
/* Added headers for the triangular grid of the gme model of DWD
Helmut P. Frank, 13.09.2001 */
/* Clean up of triangular grid properties access and added spectral information
Luis Kornblueh, 27.03.2002 */
/* 8/08 - dx/dy (polar,lambert) controlled by bit 1 of resolution byte */
/* 5/11 Paul Schou: fixed GDS_Lambert_LonSP(gds) */
/* 6/11 Jeffery S. Smith Albers equal area projection */
#ifndef INT3
#define INT3(a,b,c) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 127) << 16)+(b<<8)+c))
#endif
#ifndef INT2
#define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 127) << 8) + b))
#endif
#ifndef UINT4
#define UINT4(a,b,c,d) ((int) ((a << 24) + (b << 16) + (c << 8) + (d)))
#endif
#ifndef UINT3
#define UINT3(a,b,c) ((int) ((a << 16) + (b << 8) + (c)))
#endif
#ifndef UINT2
#define UINT2(a,b) ((int) ((a << 8) + (b)))
#endif
#define GDS_Len1(gds) (gds[0])
#define GDS_Len2(gds) (gds[1])
#define GDS_Len3(gds) (gds[2])
#define GDS_LEN(gds) ((int) ((gds[0]<<16)+(gds[1]<<8)+gds[2]))
#define GDS_NV(gds) (gds[3])
#define GDS_DataType(gds) (gds[5])
#define GDS_LatLon(gds) (gds[5] == 0)
#define GDS_Mercator(gds) (gds[5] == 1)
#define GDS_Gnomonic(gds) (gds[5] == 2)
#define GDS_Lambert(gds) (gds[5] == 3)
#define GDS_Gaussian(gds) (gds[5] == 4)
#define GDS_Polar(gds) (gds[5] == 5)
#define GDS_Albers(gds) (gds[5] == 8)
#define GDS_RotLL(gds) (gds[5] == 10)
#define GDS_Harmonic(gds) (gds[5] == 50)
#define GDS_Triangular(gds) (gds[5] == 192)
#define GDS_ssEgrid(gds) (gds[5] == 201) /* semi-staggered E grid */
#define GDS_fEgrid(gds) (gds[5] == 202) /* filled E grid */
#define GDS_ss2dEgrid(gds) (gds[5] == 203) /* semi-staggered E grid 2 d*/
#define GDS_ss2dBgrid(gds) (gds[5] == 205) /* semi-staggered B grid 2 d*/
#define GDS_has_dy(mode) ((mode) & 128)
#define GDS_LatLon_nx(gds) ((int) ((gds[6] << 8) + gds[7]))
#define GDS_LatLon_ny(gds) ((int) ((gds[8] << 8) + gds[9]))
#define GDS_LatLon_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_LatLon_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_LatLon_mode(gds) (gds[16])
#define GDS_LatLon_La2(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_LatLon_Lo2(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_LatLon_dx(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_LatLon_dy(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_Gaussian_nlat(gds) ((gds[25]<<8)+gds[26])
#define GDS_LatLon_scan(gds) (gds[27])
#define GDS_Polar_nx(gds) (gds[16] & 128 ? ((gds[6] << 8) + gds[7]) : 0)
#define GDS_Polar_ny(gds) (gds[16] & 128 ? ((gds[8] << 8) + gds[9]) : 0)
#define GDS_Polar_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_Polar_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_Polar_mode(gds) (gds[16])
#define GDS_Polar_Lov(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_Polar_scan(gds) (gds[27])
#define GDS_Polar_Dx(gds) INT3(gds[20], gds[21], gds[22])
#define GDS_Polar_Dy(gds) INT3(gds[23], gds[24], gds[25])
#define GDS_Polar_pole(gds) ((gds[26] & 128) == 128)
#define GDS_Lambert_nx(gds) ((gds[6] << 8) + gds[7])
#define GDS_Lambert_ny(gds) ((gds[8] << 8) + gds[9])
#define GDS_Lambert_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_Lambert_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_Lambert_mode(gds) (gds[16])
#define GDS_Lambert_Lov(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_Lambert_dx(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_Lambert_dy(gds) INT3(gds[23],gds[24],gds[25])
#define GDS_Lambert_NP(gds) ((gds[26] & 128) == 0)
#define GDS_Lambert_scan(gds) (gds[27])
#define GDS_Lambert_Latin1(gds) INT3(gds[28],gds[29],gds[30])
#define GDS_Lambert_Latin2(gds) INT3(gds[31],gds[32],gds[33])
#define GDS_Lambert_LatSP(gds) INT3(gds[34],gds[35],gds[36])
/* bug found by Paul Schou 5/3/2011
#define GDS_Lambert_LonSP(gds) INT3(gds[37],gds[37],gds[37])
*/
#define GDS_Lambert_LonSP(gds) INT3(gds[37],gds[38],gds[39])
#define GDS_ssEgrid_n(gds) UINT2(gds[6],gds[7])
#define GDS_ssEgrid_n_dum(gds) UINT2(gds[8],gds[9])
#define GDS_ssEgrid_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_ssEgrid_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_ssEgrid_mode(gds) (gds[16])
#define GDS_ssEgrid_La2(gds) UINT3(gds[17],gds[18],gds[19])
#define GDS_ssEgrid_Lo2(gds) UINT3(gds[20],gds[21],gds[22])
#define GDS_ssEgrid_di(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_ssEgrid_dj(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_ssEgrid_scan(gds) (gds[27])
#define GDS_fEgrid_n(gds) UINT2(gds[6],gds[7])
#define GDS_fEgrid_n_dum(gds) UINT2(gds[8],gds[9])
#define GDS_fEgrid_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_fEgrid_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_fEgrid_mode(gds) (gds[16])
#define GDS_fEgrid_La2(gds) UINT3(gds[17],gds[18],gds[19])
#define GDS_fEgrid_Lo2(gds) UINT3(gds[20],gds[21],gds[22])
#define GDS_fEgrid_di(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_fEgrid_dj(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_fEgrid_scan(gds) (gds[27])
#define GDS_ss2dEgrid_nx(gds) UINT2(gds[6],gds[7])
#define GDS_ss2dEgrid_ny(gds) UINT2(gds[8],gds[9])
#define GDS_ss2dEgrid_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_ss2dEgrid_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_ss2dEgrid_mode(gds) (gds[16])
#define GDS_ss2dEgrid_La2(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_ss2dEgrid_Lo2(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_ss2dEgrid_di(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_ss2dEgrid_dj(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_ss2dEgrid_scan(gds) (gds[27])
#define GDS_ss2dBgrid_nx(gds) UINT2(gds[6],gds[7])
#define GDS_ss2dBgrid_ny(gds) UINT2(gds[8],gds[9])
#define GDS_ss2dBgrid_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_ss2dBgrid_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_ss2dBgrid_mode(gds) (gds[16])
#define GDS_ss2dBgrid_La2(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_ss2dBgrid_Lo2(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_ss2dBgrid_di(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_ss2dBgrid_dj(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_ss2dBgrid_scan(gds) (gds[27])
#define GDS_Merc_nx(gds) UINT2(gds[6],gds[7])
#define GDS_Merc_ny(gds) UINT2(gds[8],gds[9])
#define GDS_Merc_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_Merc_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_Merc_mode(gds) (gds[16])
#define GDS_Merc_La2(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_Merc_Lo2(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_Merc_Latin(gds) INT3(gds[23],gds[24],gds[25])
#define GDS_Merc_scan(gds) (gds[27])
#define GDS_Merc_dx(gds) (gds[16] & 128 ? INT3(gds[28],gds[29],gds[30]) : 0)
#define GDS_Merc_dy(gds) (gds[16] & 128 ? INT3(gds[31],gds[32],gds[33]) : 0)
/* rotated Lat-lon grid */
#define GDS_RotLL_nx(gds) UINT2(gds[6],gds[7])
#define GDS_RotLL_ny(gds) UINT2(gds[8],gds[9])
#define GDS_RotLL_La1(gds) INT3(gds[10],gds[11],gds[12])
#define GDS_RotLL_Lo1(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_RotLL_mode(gds) (gds[16])
#define GDS_RotLL_La2(gds) INT3(gds[17],gds[18],gds[19])
#define GDS_RotLL_Lo2(gds) INT3(gds[20],gds[21],gds[22])
#define GDS_RotLL_dx(gds) (gds[16] & 128 ? INT2(gds[23],gds[24]) : 0)
#define GDS_RotLL_dy(gds) (gds[16] & 128 ? INT2(gds[25],gds[26]) : 0)
#define GDS_RotLL_scan(gds) (gds[27])
#define GDS_RotLL_LaSP(gds) INT3(gds[32],gds[33],gds[34])
#define GDS_RotLL_LoSP(gds) INT3(gds[35],gds[36],gds[37])
#define GDS_RotLL_RotAng(gds) ibm2flt(&(gds[38]))
/* Triangular grid of DWD */
#define GDS_Triangular_ni2(gds) INT2(gds[6],gds[7])
#define GDS_Triangular_ni3(gds) INT2(gds[8],gds[9])
#define GDS_Triangular_ni(gds) INT3(gds[13],gds[14],gds[15])
#define GDS_Triangular_nd(gds) INT3(gds[10],gds[11],gds[12])
/* Harmonics data */
#define GDS_Harmonic_nj(gds) ((int) ((gds[6] << 8) + gds[7]))
#define GDS_Harmonic_nk(gds) ((int) ((gds[8] << 8) + gds[9]))
#define GDS_Harmonic_nm(gds) ((int) ((gds[10] << 8) + gds[11]))
#define GDS_Harmonic_type(gds) (gds[12])
#define GDS_Harmonic_mode(gds) (gds[13])
/* index of NV and PV */
#define GDS_PV(gds) ((gds[3] == 0) ? -1 : (int) gds[4] - 1)
#define GDS_PL(gds) ((gds[4] == 255) ? -1 : (int) gds[3] * 4 + (int) gds[4] - 1)
enum Def_NCEP_Table {rean, opn, rean_nowarn, opn_nowarn};
unsigned char *seek_grib(FILE *file, unsigned long *pos, long *len_grib,
unsigned char *buffer, unsigned int buf_len);
int read_grib(FILE *file, long pos, long len_grib, unsigned char *buffer);
long echack(FILE *file, long pos, long len_grib);
double ibm2flt(unsigned char *ibm);
void BDS_unpack(float *flt, unsigned char *bds, unsigned char *bitmap,
int n_bits, int n, double ref, double scale);
int BDS_NValues(unsigned char *bds);
double int_power(double x, int y);
int flt2ieee(float x, unsigned char *ieee);
int wrtieee(float *array, int n, int header, FILE *output);
int wrtieee_header(unsigned int n, FILE *output);
void levels(int, int, int, int verbose);
void PDStimes(int time_range, int p1, int p2, int time_unit);
int missing_points(unsigned char *bitmap, int n);
void EC_ext(unsigned char *pds, char *prefix, char *suffix, int verbose);
int GDS_grid(unsigned char *gds, unsigned char *bds, int *nx, int *ny,
long int *nxny);
void GDS_prt_thin_lon(unsigned char *gds);
void GDS_winds(unsigned char *gds, int verbose);
int PDS_date(unsigned char *pds, int option, int verf_time);
int add_time(int *year, int *month, int *day, int *hour, int dtime, int unit);
int verf_time(unsigned char *pds, int *year, int *month, int *day, int *hour);
void print_pds(unsigned char *pds, int print_PDS, int print_PDS10, int verbose);
void print_gds(unsigned char *gds, int print_GDS, int print_GDS10, int verbose);
void ensemble(unsigned char *pds, int mode);
/* version 3.4 of grib headers w. ebisuzaki */
/* this version is incomplete */
/* add center DWD Helmut P. Frank */
/* 10/02 add center CPTEC */
/* 29/04/2005 add center CHM Luiz Claudio M. Fonseca*/
/* 11/2008 add center LAMI Davide Sacchetti */
#ifndef INT2
#define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 0x7f) << 8) + b))
#endif
#ifndef UINT4
#define UINT4(a,b,c,d) ((int) ((a << 24) + (b << 16) + (c << 8) + (d)))
#endif
#ifndef UINT2
#define UINT2(a,b) ((int) ((a << 8) + (b)))
#endif
#define __LEN24(pds) ((pds) == NULL ? 0 : (int) ((pds[0]<<16)+(pds[1]<<8)+pds[2]))
#define PDS_Len1(pds) (pds[0])
#define PDS_Len2(pds) (pds[1])
#define PDS_Len3(pds) (pds[2])
#define PDS_LEN(pds) ((int) ((pds[0]<<16)+(pds[1]<<8)+pds[2]))
#define PDS_Vsn(pds) (pds[3])
#define PDS_Center(pds) (pds[4])
#define PDS_Model(pds) (pds[5])
#define PDS_Grid(pds) (pds[6])
#define PDS_HAS_GDS(pds) ((pds[7] & 128) != 0)
#define PDS_HAS_BMS(pds) ((pds[7] & 64) != 0)
#define PDS_PARAM(pds) (pds[8])
#define PDS_L_TYPE(pds) (pds[9])
#define PDS_LEVEL1(pds) (pds[10])
#define PDS_LEVEL2(pds) (pds[11])
#define PDS_KPDS5(pds) (pds[8])
#define PDS_KPDS6(pds) (pds[9])
#define PDS_KPDS7(pds) ((int) ((pds[10]<<8) + pds[11]))
/* this requires a 32-bit default integer machine */
#define PDS_Field(pds) ((pds[8]<<24)+(pds[9]<<16)+(pds[10]<<8)+pds[11])
#define PDS_Year(pds) (pds[12])
#define PDS_Month(pds) (pds[13])
#define PDS_Day(pds) (pds[14])
#define PDS_Hour(pds) (pds[15])
#define PDS_Minute(pds) (pds[16])
#define PDS_ForecastTimeUnit(pds) (pds[17])
#define PDS_P1(pds) (pds[18])
#define PDS_P2(pds) (pds[19])
#define PDS_TimeRange(pds) (pds[20])
#define PDS_NumAve(pds) ((int) ((pds[21]<<8)+pds[22]))
#define PDS_NumMissing(pds) (pds[23])
#define PDS_Century(pds) (pds[24])
#define PDS_Subcenter(pds) (pds[25])
#define PDS_DecimalScale(pds) INT2(pds[26],pds[27])
/* old #define PDS_Year4(pds) (pds[12] + 100*(pds[24] - (pds[12] != 0))) */
#define PDS_Year4(pds) (pds[12] + 100*(pds[24] - 1))
/* various centers */
#define NMC 7
#define JMA 34
#define ECMWF 98
#define DWD 78
#define CMC 54
#define CPTEC 46
#define CHM 146
#define LAMI 200
/* ECMWF Extensions */
#define PDS_EcLocalId(pds) (PDS_LEN(pds) >= 41 ? (pds[40]) : 0)
#define PDS_EcClass(pds) (PDS_LEN(pds) >= 42 ? (pds[41]) : 0)
#define PDS_EcType(pds) (PDS_LEN(pds) >= 43 ? (pds[42]) : 0)
#define PDS_EcStream(pds) (PDS_LEN(pds) >= 45 ? (INT2(pds[43], pds[44])) : 0)
#define PDS_EcENS(pds) (PDS_LEN(pds) >= 52 && pds[40] == 1 && \
pds[43] * 256 + pds[44] == 1035 && pds[50] != 0)
#define PDS_EcFcstNo(pds) (pds[49])
#define PDS_Ec16Version(pds) (pds + 45)
#define PDS_Ec16Number(pds) (PDS_EcLocalId(pds) == 16 ? UINT2(pds[49],pds[50]) : 0)
#define PDS_Ec16SysNum(pds) (PDS_EcLocalId(pds) == 16 ? UINT2(pds[51],pds[52]) : 0)
#define PDS_Ec16MethodNum(pds) (PDS_EcLocalId(pds) == 16 ? UINT2(pds[53],pds[54]) : 0)
#define PDS_Ec16VerfMon(pds) (PDS_EcLocalId(pds) == 16 ? UINT4(pds[55],pds[56],pds[57],pds[58]) : 0)
#define PDS_Ec16AvePeriod(pds) (PDS_EcLocalId(pds) == 16 ? pds[59] : 0)
#define PDS_Ec16FcstMon(pds) (PDS_EcLocalId(pds) == 16 ? UINT2(pds[60],pds[61]) : 0)
/* NCEP Extensions */
#define PDS_NcepENS(pds) (PDS_LEN(pds) >= 44 && pds[25] == 2 && pds[40] == 1)
#define PDS_NcepFcstType(pds) (pds[41])
#define PDS_NcepFcstNo(pds) (pds[42])
#define PDS_NcepFcstProd(pds) (pds[43])
/* time units */
#define MINUTE 0
#define HOUR 1
#define DAY 2
#define MONTH 3
#define YEAR 4
#define DECADE 5
#define NORMAL 6
#define CENTURY 7
#define HOURS3 10
#define HOURS6 11
#define HOURS12 12
#define MINUTES15 13
#define MINUTES30 14
#define SECOND 254
#define VERSION "v1.8.2 (3-17) Wesley Ebisuzaki\n\t\tDWD-tables 2,201-205 (11-28-2005) Helmut P. Frank\n\t\tspectral: Luis Kornblueh (MPI)"
#define CHECK_GRIB
/* #define DEBUG */
/*
* wgrib.c is placed into the public domain. While you could
* legally do anything you want with the code, telling the world
* that you wrote it would be uncool. Selling it would be really
* uncool. The code was originally written for NMC/NCAR Reanalysis
* and handles most GRIB files except for the ECMWF spectral files.
* (ECMWF's spectral->grid code are copyrighted and in FORTRAN.)
* The code, as usual, is not waranteed to be fit for any purpose
* what so ever. However, wgrib is operational NCEP code, so it
* better work for our files.
*/
/*
* wgrib.c extract/inventory grib records
*
* Wesley Ebisuzaki
*
* See Changes for update information
*
*/
/*
* MSEEK = I/O buffer size for seek_grib
*/
#define MSEEK 1024
#define BUFF_ALLOC0 40000
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) < (b) ? (b) : (a))
#endif
#ifndef DEF_T62_NCEP_TABLE
#define DEF_T62_NCEP_TABLE rean
#endif
enum Def_NCEP_Table def_ncep_table = DEF_T62_NCEP_TABLE;
int minute = 0;
int ncep_ens = 0;
int cmc_eq_ncep = 0;
extern int ec_large_grib, len_ec_bds;
int main(int argc, char **argv) {
unsigned char *buffer;
float *array;
double temp, rmin, rmax;
int i, nx, ny, file_arg;
long int len_grib, nxny, buffer_size, n_dump, count = 1;
long unsigned pos = 0;
unsigned char *msg, *pds, *gds, *bms, *bds, *pointer, *end_msg;
FILE *input, *dump_file = NULL;
char line[2000];
enum {BINARY, TEXT, IEEE, GRIB, NONE} output_type = NONE;
enum {DUMP_ALL, DUMP_RECORD, DUMP_POSITION, DUMP_LIST, INVENTORY}
mode = INVENTORY;
enum {none, dwd, simple} header = simple;
long int dump = -1;
int verbose = 0, append = 0, v_time = 0, year_4 = 0, output_PDS_GDS = 0;
int print_GDS = 0, print_GDS10 = 0, print_PDS = 0, print_PDS10 = 0;
char *dump_file_name = "dump", open_parm[3];
int return_code = 0;
if (argc == 1) {
fprintf(stderr, "\nPortable Grib decoder for %s etc.\n",
(def_ncep_table == opn_nowarn || def_ncep_table == opn) ?
"NCEP Operations" : "NCEP/NCAR Reanalysis");
fprintf(stderr, " it slices, dices %s\n", VERSION);
fprintf(stderr, " usage: %s [grib file] [options]\n\n", argv[0]);
fprintf(stderr, "Inventory/diagnostic-output selections\n");
fprintf(stderr, " -s/-v short/verbose inventory\n");
fprintf(stderr, " -V diagnostic output (not inventory)\n");
fprintf(stderr, " (none) regular inventory\n");
fprintf(stderr, " Options\n");
fprintf(stderr, " -PDS/-PDS10 print PDS in hex/decimal\n");
fprintf(stderr, " -GDS/-GDS10 print GDS in hex/decimal\n");
fprintf(stderr, " -verf print forecast verification time\n");
fprintf(stderr, " -ncep_opn/-ncep_rean default T62 NCEP grib table\n");
fprintf(stderr, " -4yr print year using 4 digits\n");
fprintf(stderr, " -min print minutes\n");
fprintf(stderr, " -ncep_ens ensemble info encoded in ncep format\n");
fprintf(stderr, "Decoding GRIB selection\n");
fprintf(stderr, " -d [record number|all] decode record number\n");
fprintf(stderr, " -p [byte position] decode record at byte position\n");
fprintf(stderr, " -i decode controlled by stdin (inventory list)\n");
fprintf(stderr, " (none) no decoding\n");
fprintf(stderr, " Options\n");
fprintf(stderr, " -text/-ieee/-grib/-bin convert to text/ieee/grib/bin (default)\n");
fprintf(stderr, " -nh/-h output will have no headers/headers (default)\n");
fprintf(stderr, " -dwdgrib output dwd headers, grib (do not append)\n");
fprintf(stderr, " -H output will include PDS and GDS (-bin/-ieee only)\n");
fprintf(stderr, " -append append to output file\n");
fprintf(stderr, " -o [file] output file name, 'dump' is default\n");
fprintf(stderr, " Misc\n");
fprintf(stderr, " -cmc [file] use NCEP tables for CMC (dangerous)\n");
exit(8);
}
file_arg = 0;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i],"-PDS") == 0) {
print_PDS = 1;
continue;
}
if (strcmp(argv[i],"-PDS10") == 0) {
print_PDS10 = 1;
continue;
}
if (strcmp(argv[i],"-GDS") == 0) {
print_GDS = 1;
continue;
}
if (strcmp(argv[i],"-GDS10") == 0) {
print_GDS10 = 1;
continue;
}
if (strcmp(argv[i],"-v") == 0) {
verbose = 1;
continue;
}
if (strcmp(argv[i],"-V") == 0) {
verbose = 2;
continue;
}
if (strcmp(argv[i],"-s") == 0) {
verbose = -1;
continue;
}
if (strcmp(argv[i],"-text") == 0) {
output_type = TEXT;
continue;
}
if (strcmp(argv[i],"-bin") == 0) {
output_type = BINARY;
continue;
}
if (strcmp(argv[i],"-ieee") == 0) {
output_type = IEEE;
continue;
}
if (strcmp(argv[i],"-grib") == 0) {
output_type = GRIB;
continue;
}
if (strcmp(argv[i],"-nh") == 0) {
header = none;
continue;
}
if (strcmp(argv[i],"-h") == 0) {
header = simple;
continue;
}
if (strcmp(argv[i],"-dwdgrib") == 0) {
header = dwd;
output_type = GRIB;
continue;
}
if (strcmp(argv[i],"-append") == 0) {
append = 1;
continue;
}
if (strcmp(argv[i],"-verf") == 0) {
v_time = 1;
continue;
}
if (strcmp(argv[i],"-cmc") == 0) {
cmc_eq_ncep = 1;
continue;
}
if (strcmp(argv[i],"-d") == 0) {
if (strcmp(argv[i+1],"all") == 0) {
mode = DUMP_ALL;
}
else {
dump = atol(argv[i+1]);
mode = DUMP_RECORD;
}
i++;
if (output_type == NONE) output_type = BINARY;
continue;
}
if (strcmp(argv[i],"-p") == 0) {
pos = atol(argv[i+1]);
i++;
dump = 1;
if (output_type == NONE) output_type = BINARY;
mode = DUMP_POSITION;
continue;
}
if (strcmp(argv[i],"-i") == 0) {
if (output_type == NONE) output_type = BINARY;
mode = DUMP_LIST;
continue;
}
if (strcmp(argv[i],"-H") == 0) {
output_PDS_GDS = 1;
continue;
}
if (strcmp(argv[i],"-NH") == 0) {
output_PDS_GDS = 0;
continue;
}
if (strcmp(argv[i],"-4yr") == 0) {
year_4 = 1;
continue;
}
if (strcmp(argv[i],"-ncep_opn") == 0) {
def_ncep_table = opn_nowarn;
continue;
}
if (strcmp(argv[i],"-ncep_rean") == 0) {
def_ncep_table = rean_nowarn;
continue;
}
if (strcmp(argv[i],"-o") == 0) {
dump_file_name = argv[i+1];
i++;
continue;
}
if (strcmp(argv[i],"--v") == 0) {
printf("wgrib: %s\n", VERSION);
exit(0);
}
if (strcmp(argv[i],"-min") == 0) {
minute = 1;
continue;
}
if (strcmp(argv[i],"-ncep_ens") == 0) {
ncep_ens = 1;
continue;
}
if (file_arg == 0) {
file_arg = i;
}
else {
fprintf(stderr,"argument: %s ????\n", argv[i]);
}
}
if (file_arg == 0) {
fprintf(stderr,"no GRIB file to process\n");
exit(8);
}
if ((input = fopen(argv[file_arg],"rb")) == NULL) {
fprintf(stderr,"could not open file: %s\n", argv[file_arg]);
exit(7);
}
if ((buffer = (unsigned char *) malloc(BUFF_ALLOC0)) == NULL) {
fprintf(stderr,"not enough memory\n");
}
buffer_size = BUFF_ALLOC0;
/* open output file */
if (mode != INVENTORY) {
open_parm[0] = append ? 'a' : 'w'; open_parm[1] = 'b'; open_parm[2] = '\0';
if (output_type == TEXT) open_parm[1] = '\0';
if ((dump_file = fopen(dump_file_name,open_parm)) == NULL) {
fprintf(stderr,"could not open dump file\n");
exit(8);
}
if (header == dwd && output_type == GRIB) wrtieee_header(0, dump_file);
}
/* skip dump - 1 records */
for (i = 1; i < dump; i++) {
msg = seek_grib(input, &pos, &len_grib, buffer, MSEEK);
if (msg == NULL) {
fprintf(stderr, "ran out of data or bad file\n");
exit(8);
}
pos += len_grib;
}
if (dump > 0) count += dump - 1;
n_dump = 0;
for (;;) {
if (n_dump == 1 && (mode == DUMP_RECORD || mode == DUMP_POSITION)) break;
if (mode == DUMP_LIST) {
if (fgets(line,sizeof(line), stdin) == NULL) break;
line[sizeof(line) - 1] = 0;
if (sscanf(line,"%ld:%lu:", &count, &pos) != 2) {
fprintf(stderr,"bad input from stdin\n");
fprintf(stderr," %s\n", line);
exit(8);
}
}
fail:
msg = seek_grib(input, &pos, &len_grib, buffer, MSEEK);
if (msg == NULL) {
if (mode == INVENTORY || mode == DUMP_ALL) break;
fprintf(stderr,"missing GRIB record(s)\n");
exit(8);
}
/* read all whole grib record */
if (len_grib + msg - buffer > buffer_size) {
buffer_size = len_grib + msg - buffer + 1000;
buffer = (unsigned char *) realloc((void *) buffer, buffer_size);
if (buffer == NULL) {
fprintf(stderr,"ran out of memory\n");
exit(8);
}
}
if (read_grib(input, pos, len_grib, buffer) == 0) {
fprintf(stderr,"error, could not read to end of record %ld\n",count);
exit(8);
}
/* parse grib message */
msg = buffer;
end_msg = msg + len_grib - 1;
/* check if last 4 bytes are '7777' */
// simple check is for last 4 bytes == '7777'
// better check to see if pointers don't go past end_msg
// if (end_msg[0] != 0x37 || end_msg[-1] != 0x37 || end_msg[-2] != 0x37 || end_msg[-3] != 0x37) {
// fprintf(stderr,"Skipping illegal grib1 message: error expected ending 7777\n");
// pos++;
// goto fail;
// }
if (msg + 8 + 27 > end_msg) {
pos++;
goto fail;
}
pds = (msg + 8);
pointer = pds + PDS_LEN(pds);
if (pointer > end_msg) {
pos++;
goto fail;
}
if (PDS_HAS_GDS(pds)) {
gds = pointer;
pointer += GDS_LEN(gds);
if (pointer > end_msg) {
pos++;
goto fail;
}
}
else {
gds = NULL;
}
if (PDS_HAS_BMS(pds)) {
bms = pointer;
pointer += BMS_LEN(bms);
}
else {
bms = NULL;
}
if (pointer+10 > end_msg) {
pos++;
goto fail;
}
bds = pointer;
pointer += BDS_LEN(bds);
if (pointer-msg+4 != len_grib) {
fprintf(stderr,"Len of grib message is inconsistent.\n");
}
/* end section - "7777" in ascii */
if (pointer[0] != 0x37 || pointer[1] != 0x37 ||
pointer[2] != 0x37 || pointer[3] != 0x37) {
fprintf(stderr,"\n\n missing end section\n");
fprintf(stderr, "%2x %2x %2x %2x\n", pointer[0], pointer[1],
pointer[2], pointer[3]);
#ifdef DEBUG
printf("ignoring missing end section\n");
#else
exit(8);
#endif
}
/* figure out size of array */
if (gds != NULL) {
GDS_grid(gds, bds, &nx, &ny, &nxny);
}
else if (bms != NULL) {
nxny = nx = BMS_nxny(bms);
ny = 1;
}
else {
if (BDS_NumBits(bds) == 0) {
nxny = nx = 1;
fprintf(stderr,"Missing GDS, constant record .. cannot "
"determine number of data points\n");
}
else {
nxny = nx = BDS_NValues(bds);
}
ny = 1;
}
#ifdef CHECK_GRIB
if (gds && ! GDS_Harmonic(gds)) {
/* this grib check only works for simple packing */
/* turn off if harmonic */
if (BDS_NumBits(bds) != 0) {
i = BDS_NValues(bds);
if (bms != NULL) {
i += missing_points(BMS_bitmap(bms),nxny);
}
if (i != nxny) {
fprintf(stderr,"grib header at record %ld: two values of nxny %ld %d\n",
count,nxny,i);
fprintf(stderr," LEN %d DataStart %d UnusedBits %d #Bits %d nxny %ld\n",
BDS_LEN(bds), BDS_DataStart(bds),BDS_UnusedBits(bds),
BDS_NumBits(bds), nxny);
return_code = 15;
nxny = nx = i;
ny = 1;
}
}
}
#endif
if (verbose <= 0) {
printf("%ld:%lu:d=", count, pos);
PDS_date(pds,year_4,v_time);
printf(":%s:", k5toa(pds));
if (verbose == 0) printf("kpds5=%d:kpds6=%d:kpds7=%d:TR=%d:P1=%d:P2=%d:TimeU=%d:",
PDS_PARAM(pds),PDS_KPDS6(pds),PDS_KPDS7(pds),
PDS_TimeRange(pds),PDS_P1(pds),PDS_P2(pds),
PDS_ForecastTimeUnit(pds));
levels(PDS_KPDS6(pds), PDS_KPDS7(pds),PDS_Center(pds),verbose); printf(":");
PDStimes(PDS_TimeRange(pds),PDS_P1(pds),PDS_P2(pds),
PDS_ForecastTimeUnit(pds));
if (PDS_Center(pds) == ECMWF) EC_ext(pds,"",":",verbose);
ensemble(pds, verbose);
printf("NAve=%d",PDS_NumAve(pds));
if (print_PDS || print_PDS10) print_pds(pds, print_PDS, print_PDS10, verbose);
if (gds && (print_GDS || print_GDS10)) print_gds(gds, print_GDS, print_GDS10, verbose);
printf("\n");
}
else if (verbose == 1) {
printf("%ld:%lu:D=", count, pos);
PDS_date(pds, 1, v_time);
printf(":%s:", k5toa(pds));
levels(PDS_KPDS6(pds), PDS_KPDS7(pds), PDS_Center(pds),verbose); printf(":");
printf("kpds=%d,%d,%d:",
PDS_PARAM(pds),PDS_KPDS6(pds),PDS_KPDS7(pds));
PDStimes(PDS_TimeRange(pds),PDS_P1(pds),PDS_P2(pds),
PDS_ForecastTimeUnit(pds));
if (PDS_Center(pds) == ECMWF) EC_ext(pds,"",":",verbose);
ensemble(pds, verbose);
GDS_winds(gds, verbose);
printf("\"%s", k5_comments(pds));
if (print_PDS || print_PDS10) print_pds(pds, print_PDS, print_PDS10, verbose);
if (gds && (print_GDS || print_GDS10)) print_gds(gds, print_GDS, print_GDS10, verbose);
printf("\n");
}
else if (verbose == 2) {
printf("rec %ld:%lu:date ", count, pos);
PDS_date(pds, 1, v_time);
printf(" %s kpds5=%d kpds6=%d kpds7=%d levels=(%d,%d) grid=%d ",
k5toa(pds), PDS_PARAM(pds), PDS_KPDS6(pds), PDS_KPDS7(pds),
PDS_LEVEL1(pds), PDS_LEVEL2(pds), PDS_Grid(pds));
levels(PDS_KPDS6(pds),PDS_KPDS7(pds),PDS_Center(pds),verbose);
printf(" ");
if (PDS_Center(pds) == ECMWF) EC_ext(pds,""," ",verbose);
ensemble(pds, verbose);
PDStimes(PDS_TimeRange(pds),PDS_P1(pds),PDS_P2(pds),
PDS_ForecastTimeUnit(pds));
if (bms != NULL)
printf(" bitmap: %d undef", missing_points(BMS_bitmap(bms),nxny));
printf("\n %s=%s\n", k5toa(pds), k5_comments(pds));
printf(" timerange %d P1 %d P2 %d TimeU %d nx %d ny %d GDS grid %d "
"num_in_ave %d missing %d\n",
PDS_TimeRange(pds),PDS_P1(pds),PDS_P2(pds),
PDS_ForecastTimeUnit(pds), nx, ny,
gds == NULL ? -1 : GDS_DataType(gds),
PDS_NumAve(pds), PDS_NumMissing(pds));
printf(" center %d subcenter %d process %d Table %d",
PDS_Center(pds),PDS_Subcenter(pds),PDS_Model(pds),
PDS_Vsn(pds));
GDS_winds(gds, verbose);
printf("\n");
if (gds && GDS_LatLon(gds) && nx != -1)
printf(" latlon: lat %f to %f by %f nxny %ld\n"
" long %f to %f by %f, (%d x %d) scan %d "
"mode %d bdsgrid %d\n",
0.001*GDS_LatLon_La1(gds), 0.001*GDS_LatLon_La2(gds),
0.001*GDS_LatLon_dy(gds), nxny, 0.001*GDS_LatLon_Lo1(gds),
0.001*GDS_LatLon_Lo2(gds), 0.001*GDS_LatLon_dx(gds),
nx, ny, GDS_LatLon_scan(gds), GDS_LatLon_mode(gds),
BDS_Grid(bds));
else if (gds && GDS_LatLon(gds) && nx == -1) {
printf(" thinned latlon: lat %f to %f by %f nxny %ld\n"
" long %f to %f, %ld grid pts (%d x %d) scan %d"
" mode %d bdsgrid %d\n",
0.001*GDS_LatLon_La1(gds), 0.001*GDS_LatLon_La2(gds),
0.001*GDS_LatLon_dy(gds), nxny, 0.001*GDS_LatLon_Lo1(gds),
0.001*GDS_LatLon_Lo2(gds),
nxny, nx, ny, GDS_LatLon_scan(gds), GDS_LatLon_mode(gds),
BDS_Grid(bds));
GDS_prt_thin_lon(gds);
}
else if (gds && GDS_Gaussian(gds) && nx != -1)
printf(" gaussian: lat %f to %f\n"
" long %f to %f by %f, (%d x %d) scan %d"
" mode %d bdsgrid %d\n",
0.001*GDS_LatLon_La1(gds), 0.001*GDS_LatLon_La2(gds),
0.001*GDS_LatLon_Lo1(gds), 0.001*GDS_LatLon_Lo2(gds),
0.001*GDS_LatLon_dx(gds),
nx, ny, GDS_LatLon_scan(gds), GDS_LatLon_mode(gds),
BDS_Grid(bds));
else if (gds && GDS_Gaussian(gds) && nx == -1) {
printf(" thinned gaussian: lat %f to %f\n"
" long %f to %f, %ld grid pts (%d x %d) scan %d"
" mode %d bdsgrid %d\n",
0.001*GDS_LatLon_La1(gds), 0.001*GDS_LatLon_La2(gds),
0.001*GDS_LatLon_Lo1(gds), 0.001*GDS_LatLon_Lo2(gds),
nxny, nx, ny, GDS_LatLon_scan(gds), GDS_LatLon_mode(gds),
BDS_Grid(bds));
GDS_prt_thin_lon(gds);
}
else if (gds && GDS_Polar(gds))
printf(" polar stereo: Lat1 %f Long1 %f Orient %f\n"
" %s pole (%d x %d) Dx %d Dy %d scan %d mode %d\n",
0.001*GDS_Polar_La1(gds),0.001*GDS_Polar_Lo1(gds),
0.001*GDS_Polar_Lov(gds),
GDS_Polar_pole(gds) == 0 ? "north" : "south", nx,ny,
GDS_Polar_Dx(gds),GDS_Polar_Dy(gds),
GDS_Polar_scan(gds), GDS_Polar_mode(gds));
else if (gds && GDS_Lambert(gds))
printf(" Lambert Conf: Lat1 %f Lon1 %f Lov %f\n"
" Latin1 %f Latin2 %f LatSP %f LonSP %f\n"
" %s (%d x %d) Dx %f Dy %f scan %d mode %d\n",
0.001*GDS_Lambert_La1(gds),0.001*GDS_Lambert_Lo1(gds),
0.001*GDS_Lambert_Lov(gds),
0.001*GDS_Lambert_Latin1(gds), 0.001*GDS_Lambert_Latin2(gds),
0.001*GDS_Lambert_LatSP(gds), 0.001*GDS_Lambert_LonSP(gds),
GDS_Lambert_NP(gds) ? "North Pole": "South Pole",
GDS_Lambert_nx(gds), GDS_Lambert_ny(gds),
0.001*GDS_Lambert_dx(gds), 0.001*GDS_Lambert_dy(gds),
GDS_Lambert_scan(gds), GDS_Lambert_mode(gds));
else if (gds && GDS_Albers(gds))
/* Albers equal area has same parameters as Lambert conformal */
printf(" Albers Equal-Area: Lat1 %f Lon1 %f Lov %f\n"
" Latin1 %f Latin2 %f LatSP %f LonSP %f\n"