-
Notifications
You must be signed in to change notification settings - Fork 3
/
grib2class.js
2097 lines (1669 loc) · 104 KB
/
grib2class.js
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
// adapt GRIB2CLASS from grib2_solarchvision processing/java to JavaScript
"use strict";
var nf0 = require("./nf0");
var info = require("./info");
var logger = require("./logger");
var println = logger.println;
var printst = logger.printst;
var cout = logger.cout;
var rEarthKm = 6367.470;
function /* int */ uNumX2 (/* int */ m2, /* int */ m1) {
return ((m2 << 8) + m1);
}
function /* int */ sNumX2 (/* int */ m2, /* int */ m1) {
var /* long */ v = 0;
if (m2 < 128) {
v = (m2 << 8) + m1;
} else {
m2 -= 128;
v = (m2 << 8) + m1;
v *= -1;
}
return /* (int) */ v;
}
function /* int */ uNumX4 (/* int */ m4, /* int */ m3, /* int */ m2, /* int */ m1) {
return ((m4 << 24) + (m3 << 16) + (m2 << 8) + m1);
}
function /* int */ sNumX4 (/* int */ m4, /* int */ m3, /* int */m2, /* int */ m1) {
var /* long */ v = 0;
if (m4 < 128) {
v = ((m4 << 24) + (m3 << 16) + (m2 << 8) + m1);
} else {
m4 -= 128;
v = ((m4 << 24) + (m3 << 16) + (m2 << 8) + m1);
v *= -1;
}
return /* (int) */ v;
}
function /* long */ uNumX8 (/* int */ m8, /* int */ m7, /* int */ m6, /* int */ m5, /* int */ m4, /* int */ m3, /* int */ m2, /* int */ m1) {
return (m8 << 56) + (m7 << 48) + (m6 << 40) + (m5 << 32) + (m4 << 24) + (m3 << 16) + (m2 << 8) + m1;
}
function /* int */ uNumXI (/* int[] */ m) { // note: follows reverse rule as this: int m[0], int m[1], int m[2] ...
// println(m);
var /* long */ v = 0;
var len = m.length;
for (var i = 0; i < len; i++) {
v += m[i] << (len - 1 - i);
}
// println(v);
return /* (int) */ v;
}
function /* int */ sNumXI (/* int[] */ m) { // note: follows reverse rule as this: int m[0], int m[1], int m[2] ...
// println(m);
var /* long */ v = 0;
var vSign = 1;
if (m[0] < 1) {
v += m[0] << (m.length - 1);
} else {
v += (m[0] - 1) << (m.length - 1);
vSign = -1;
}
for (var i = 1; i < m.length; i++) {
v += m[i] << (m.length - 1 - i);
}
v *= vSign;
// println(v);
return /* (int) */ v;
}
function /* int */ getNthBit (/* Byte */ valByte, /* int */ posBit) {
var valInt = valByte >> (8 - (posBit + 1)) & 0x0001;
return /* (int) */ valInt;
}
function hex (byte) {
return Buffer.from([byte]).toString("hex").toUpperCase();
}
function binary (uint, n) {
var s = uint.toString(2);
var len = s.length;
var zeros = "";
for (var i = 0; i < n - len; i++) {
zeros += "0";
}
return (zeros + s).substring(0, n);
}
function /* String */ integerToBinaryString (/* int */ n) {
return n.toString(2);
}
function /* String */ IntToBinary32 (/* int */ n) {
var i;
var s1 = integerToBinaryString(n);
var len = s1.length;
var s2 = "";
for (i = 0; i < 32 - len; i++) {
s2 += "0";
}
for (i = 0; i < len; i++) {
s2 += s1.substring(i, i + 1);
}
return s2;
}
function /* float */ IEEE32 (/* String */ s) {
var /* float */ vSign = Math.pow(-1, parseInt(s.substring(0, 1), 2));
//println("v_sign", v_sign);
var /* float */ vExponent = parseInt(s.substring(1, 9), 2) - 127;
//println("v_exponent", v_exponent);
var /* float */ vFraction = 0;
for (var i = 0; i < 23; i++) {
var q = parseInt(s.substring(9 + i, 10 + i), 2);
vFraction += q * Math.pow(2, -(i + 1));
}
vFraction += 1;
//println("v_fraction", v_fraction);
return vSign * vFraction * Math.pow(2, vExponent);
}
module.exports = function /* class */ GRIB2CLASS (options) {
logger.disable(!options.log);
var numMembers = options.numMembers || 1;
var lThis = this;
this.meta = {};
this.ParameterNameAndUnit = null;
this.DataTitles = [];
this.DataValues = null;
this.DataAllocated = false;
this.DisciplineOfProcessedData = 0;
this.LengthOfMessage = 0;
this.IdentificationOfCentre = 0;
this.IdentificationOfSubCentre = 0;
this.MasterTablesVersionNumber = 0;
this.LocalTablesVersionNumber = 0;
this.SignificanceOfReferenceTime = 0;
this.Year = null;
this.Month = null;
this.Day = null;
this.Hour = null;
this.Minute = null;
this.Second = null;
this.ProductionStatusOfData = 0;
this.TypeOfData = 0;
this.TypeOfProjection = 0;
this.Np = 0;
this.Nx = 0;
this.Ny = 0;
this.ResolutionAndComponentFlags = 0;
this.La1 = -90;
this.Lo1 = -180;
this.La2 = 90;
this.Lo2 = 180;
this.LaD = 0;
this.LoV = 0;
this.Dx = 1;
this.Dy = 1;
this.FirstLatIn = 0;
this.SecondLatIn = 0;
this.SouthLat = 0;
this.SouthLon = 0;
this.Rotation = 0;
this.PCF = 0;
this.ScanX = 0;
this.ScanY = 0;
this.Flag_BitNumbers = "00000000";
this.ScanningMode = 0;
this.Mode_BitNumbers = "00000000";
this.NumberOfCoordinateValuesAfterTemplate = 0;
this.ProductDefinitionTemplateNumber = 0;
this.CategoryOfParametersByProductDiscipline = 0;
this.ParameterNumberByProductDisciplineAndParameterCategory = 0;
this.IndicatorOfUnitOfTimeRange = 0;
this.ForecastTimeInDefinedUnits = 0;
this.ForecastConvertedTime = null;
this.TypeOfFirstFixedSurface = 0;
this.NumberOfDataPoints = 0;
this.DataRepresentationTemplateNumber = 0;
this.ReferenceValue = null;
this.BinaryScaleFactor = null;
this.DecimalScaleFactor = null;
this.NumberOfBitsUsedForEachPackedValue = null;
this.NullBitmapFlags = null;
this.fileBytes = [];
var /* int */ nPointer;
this.printMore = function (/* int */ startN, /* int */ displayMORE) {
var i;
for (i = 0; i < displayMORE; i++) {
cout(this.fileBytes[startN + i]);
}
println();
for (i = 0; i < displayMORE; i++) {
printst("(" + hex(this.fileBytes[startN + i], 2) + ")");
}
println();
for (i = 0; i < displayMORE; i++) {
printst("[" + this.fileBytes[startN + i] + "]");
}
println();
};
this.getGrib2Section = function (/* int */ SectionNumber) {
println("-----------------------------");
printst("Section:\t");
println(SectionNumber);
var /* int */ nFirstBytes = 6;
if (SectionNumber === 8) nFirstBytes = 4;
var /* int[] */ SectionNumbers = new Int32Array(nFirstBytes);
SectionNumbers[0] = 0;
(function (lThis) {
for (var j = 1; j < nFirstBytes; j += 1) {
var c = lThis.fileBytes[nPointer + j];
if (c < 0) c += 256;
SectionNumbers[j] = c;
cout(c);
}
println();
})(this);
var /* int */ lengthOfSection = -1;
if (SectionNumber === 0) lengthOfSection = 16;
else if (SectionNumber === 8) lengthOfSection = 4;
else lengthOfSection = uNumX4(SectionNumbers[1], SectionNumbers[2], SectionNumbers[3], SectionNumbers[4]);
var /* int */ newSectionNumber = -1;
if (SectionNumber === 0) newSectionNumber = 0;
else if (SectionNumber === 8) newSectionNumber = 8;
else newSectionNumber = SectionNumbers[5];
if (newSectionNumber === SectionNumber) {
SectionNumbers = new Int32Array(1 + lengthOfSection);
SectionNumbers[0] = 0;
(function (lThis) {
for (var j = 1; j <= lengthOfSection; j += 1) {
var /* int */ c = lThis.fileBytes[nPointer + j];
if (c < 0) c += 256;
SectionNumbers[j] = c;
//cout(c);
}
//println();
})(this);
} else {
println();
println("Not available section", SectionNumber);
lengthOfSection = 0;
SectionNumbers = new Int32Array(1);
SectionNumbers[0] = 0;
}
for (var j = 1; j < SectionNumbers.length; j += 1) {
//printst("(" + SectionNumbers[j] + ")");
//printst("(" + hex(SectionNumbers[j], 2) + ")");
}
//println();
printst("Length of section:\t");
println(lengthOfSection);
nPointer += lengthOfSection;
return SectionNumbers;
};
this.readGrib2Members = function (/* int */ numberOfMembers) {
var /* const int */ gridDefNumberOfDataPoints = 7;
var /* const int */ gridDefNumberOfPointsAlongTheXaxis = 31;
var /* const int */ gridDefNumberOfPointsAlongTheYaxis = 35;
var /* const int */ gridDefLatLonLatitudeOfFirstGridPoint = 47;
var /* const int */ gridDefLatLonLongitudeOfFirstGridPoint = 51;
var /* const int */ gridDefLatLonResolutionAndComponentFlags = 55;
var /* const int */ gridDefLatLonLatitudeOfLastGridPoint = 56;
var /* const int */ gridDefLatLonLongitudeOfLastGridPoint = 60;
// for Rotated latitude/longitude :
var /* const int */ gridDefLatLonSouthPoleLatitude = 73;
var /* const int */ gridDefLatLonSouthPoleLongitude = 77;
var /* const int */ gridDefLatLonRotationOfProjection = 81;
var /* const int */ gridDefPolarLatitudeOfFirstGridPoint = 39;
var /* const int */ gridDefPolarLongitudeOfFirstGridPoint = 43;
var /* const int */ gridDefPolarResolutionAndComponentFlags = 47;
var /* const int */ gridDefPolarDeclinationOfTheGrid = 48;
var /* const int */ gridDefPolarOrientationOfTheGrid = 52;
var /* const int */ gridDefPolarXDirectionGridLength = 56;
var /* const int */ gridDefPolarYDirectionGridLength = 60;
var /* const int */ gridDefPolarProjectionCenterFlag = 64;
var /* const int */ gridDefLambertLatitudeOfFirstGridPoint = 39;
var /* const int */ gridDefLambertLongitudeOfFirstGridPoint = 43;
var /* const int */ gridDefLambertResolutionAndComponentFlags = 47;
var /* const int */ gridDefLambertDeclinationOfTheGrid = 48;
var /* const int */ gridDefLambertOrientationOfTheGrid = 52;
var /* const int */ gridDefLambertXDirectionGridLength = 56;
var /* const int */ gridDefLambertYDirectionGridLength = 60;
var /* const int */ gridDefLambertProjectionCenterFlag = 64;
var /* const int */ gridDefLambert1stLatitudeIn = 66;
var /* const int */ gridDefLambert2ndLatitudeIn = 70;
// var /* const int */ gridDefLambertSouthPoleLatitude = 74;
var /* const int */ gridDefLambertSouthPoleLongitude = 78;
var /* int */ gridDefScanningMode = 72;
var /* int */ ComplexPackingGroupSplittingMethodUsed = 0;
var /* int */ ComplexPackingMissingValueManagementUsed = 0;
var /* float */ ComplexPackingPrimaryMissingValueSubstitute = 0.0;
var /* float */ ComplexPackingSecondaryMissingValueSubstitute = 0.0;
var /* int */ ComplexPackingNumberOfGroupsOfDataValues = 0;
var /* int */ ComplexPackingReferenceForGroupWidths = 0;
var /* int */ ComplexPackingNumberOfBitsUsedForGroupWidths = 0;
var /* int */ ComplexPackingReferenceForGroupLengths = 0;
var /* int */ ComplexPackingLengthIncrementForTheGroupLengths = 0;
var /* int */ ComplexPackingTrueLengthOfLastGroup = 0;
var /* int */ ComplexPackingNumberOfBitsUsedForTheScaledGroupLengths = 0;
var /* int */ ComplexPackingOrderOfSpatialDifferencing = 0;
var /* int */ ComplexPackingNumberOfExtraOctetsRequiredInDataSection = 0;
this.Bitmap_Indicator = 0;
var /* int */ BitmapBeginPointer = 0;
var /* int */ BitmapEndPointer = 0;
var /* int */ jpeg2000TypeOfOriginalFieldValues = 0;
var /* int */ jpeg2000TypeOfCompression = 0;
var /* int */ jpeg2000TargetCompressionRatio = 0;
var /* int */ jpeg2000Lsiz = 0;
var /* int */ jpeg2000Rsiz = 0;
var /* int */ jpeg2000Xsiz = 0;
var /* int */ jpeg2000Ysiz = 0;
var /* int */ jpeg2000XOsiz = 0;
var /* int */ jpeg2000YOsiz = 0;
var /* int */ jpeg2000XTsiz = 0;
var /* int */ jpeg2000YTsiz = 0;
var /* int */ jpeg2000XTOsiz = 0;
var /* int */ jpeg2000YTOsiz = 0;
var /* int */ jpeg2000Csiz = 0;
var /* int */ jpeg2000Ssiz = 0;
var /* int */ jpeg2000XRsiz = 0;
var /* int */ jpeg2000YRsiz = 0;
var /* int */ jpeg2000Lcom = 0;
var /* int */ jpeg2000Rcom = 0;
var /* int */ jpeg2000Lcod = 0;
var /* int */ jpeg2000Scod = 0;
var /* int */ jpeg2000SGcodProgressionOrder = 0;
var /* int */ jpeg2000SGcodNumberOfLayers = 0;
var /* int */ jpeg2000SGcodMultipleComponentTransformation = 0;
var /* int */ jpeg2000SPcodNumberOfDecompositionLevels = 0;
var /* int */ jpeg2000SPcodCodeBlockWidth = 0;
var /* int */ jpeg2000SPcodCodeBlockHeight = 0;
var /* int */ jpeg2000SPcodCodeBlockStyle = 0;
var /* int */ jpeg2000SPcodTransformation = 0;
var /* int */ jpeg2000Lqcd = 0;
var /* int */ jpeg2000Sqcd = 0;
var /* int */ jpeg2000Lsot = 0;
var /* int */ jpeg2000Isot = 0;
var /* int */ jpeg2000Psot = 0;
var /* int */ jpeg2000TPsot = 0;
var /* int */ jpeg2000TNsot = 0;
nPointer = -1;
for (var memberID = 0; memberID < numberOfMembers; memberID += 1) {
var /* int[] */ SectionNumbers = this.getGrib2Section(0); // Section 0: Indicator Section
if (SectionNumbers.length > 1) {
printst("Discipline of processed data:\t");
this.DisciplineOfProcessedData = SectionNumbers[7];
info.DisciplineOfProcessedData(lThis);
printst("Length of message:\t");
this.LengthOfMessage = uNumX8(SectionNumbers[9], SectionNumbers[10], SectionNumbers[11], SectionNumbers[12], SectionNumbers[13], SectionNumbers[14], SectionNumbers[15], SectionNumbers[16]);
println(this.LengthOfMessage);
}
SectionNumbers = this.getGrib2Section(1); // Section 1: Identification Section
if (SectionNumbers.length > 1) {
printst("Identification of originating/generating centre: ");
this.IdentificationOfCentre = uNumX2(SectionNumbers[6], SectionNumbers[7]);
info.IdentificationOfCentre(lThis);
printst("Sub-centre:\t");
this.IdentificationOfSubCentre = uNumX2(SectionNumbers[8], SectionNumbers[9]);
info.IdentificationOfSubCentre(lThis);
printst("Master Tables Version Number:\t");
this.MasterTablesVersionNumber = SectionNumbers[10];
info.MasterTablesVersionNumber(lThis);
printst("Local Tables Version Number:\t");
this.LocalTablesVersionNumber = SectionNumbers[11];
info.LocalTablesVersionNumber(lThis);
printst("Significance of Reference Time:\t");
this.SignificanceOfReferenceTime = SectionNumbers[12];
info.SignificanceOfReferenceTime(lThis);
printst("Year:\t");
this.Year = uNumX2(SectionNumbers[13], SectionNumbers[14]);
println(this.Year);
printst("Month:\t");
this.Month = SectionNumbers[15];
println(this.Month);
printst("Day:\t");
this.Day = SectionNumbers[16];
println(this.Day);
printst("Hour:\t");
this.Hour = SectionNumbers[17];
println(this.Hour);
printst("Minute:\t");
this.Minute = SectionNumbers[18];
println(this.Minute);
printst("Second:\t");
this.Second = SectionNumbers[19];
println(this.Second);
printst("Production status of data:\t");
this.ProductionStatusOfData = SectionNumbers[20];
info.ProductionStatusOfData(lThis);
printst("Type of data:\t");
this.TypeOfData = SectionNumbers[20];
info.TypeOfData(lThis);
}
SectionNumbers = this.getGrib2Section(2); // Section 2: Local Use Section (optional)
if (SectionNumbers.length > 1) {
// don't do anything!
}
SectionNumbers = this.getGrib2Section(3); // Section 3: Grid Definition Section
if (SectionNumbers.length > 1) {
printst("Grid Definition Template Number:\t");
this.TypeOfProjection = uNumX2(SectionNumbers[13], SectionNumbers[14]);
switch (this.TypeOfProjection) {
case 0: gridDefScanningMode = 72; println("Latitude/longitude (equidistant cylindrical)"); break;
case 1: gridDefScanningMode = 72; println("Rotated latitude/longitude"); break;
case 2: gridDefScanningMode = 72; println("Stretched latitude/longitude"); break;
case 3: gridDefScanningMode = 72; println("Stretched and rotated latitude/longitude"); break;
case 4: gridDefScanningMode = 48; println("Variable resolution latitude/longitude"); break;
case 5: gridDefScanningMode = 48; println("Variable resolution rotated latitude/longitude"); break;
case 10: gridDefScanningMode = 60; println("Mercator"); break;
case 12: gridDefScanningMode = 60; println("Transverse Mercator"); break;
case 20: gridDefScanningMode = 65; println("Polar Stereographic Projection (can be north or south)"); gridDefScanningMode = 65; break;
case 30: gridDefScanningMode = 65; println("Lambert conformal (can be secant, tangent, conical, or bipolar)"); break;
case 31: gridDefScanningMode = 65; println("Albers equal area"); break;
case 40: gridDefScanningMode = 72; println("Gaussian latitude/longitude"); break;
case 41: gridDefScanningMode = 72; println("Rotated Gaussian latitude/longitude"); break;
case 42: gridDefScanningMode = 72; println("Stretched Gaussian latitude/longitude"); break;
case 43: gridDefScanningMode = 72; println("Stretched and rotated Gaussian latitude/longitude"); break;
case 50: println("Spherical harmonic coefficients"); break;
case 51: println("Rotated spherical harmonic coefficients"); break;
case 52: println("Stretched spherical harmonic coefficients"); break;
case 53: println("Stretched and rotated spherical harmonic coefficients"); break;
case 90: gridDefScanningMode = 64; println("Space view perspective orthographic"); break;
case 100: gridDefScanningMode = 34; println("Triangular grid based on an icosahedron"); break;
case 110: gridDefScanningMode = 57; println("Equatorial azimuthal equidistant projection"); break;
case 120: gridDefScanningMode = 39; println("Azimuth-range projection"); break;
case 140: gridDefScanningMode = 64; println("Lambert azimuthal equal area projection"); break;
case 204: gridDefScanningMode = 72; println("Curvilinear orthogonal grids"); break;
case 1000: println("Cross-section grid, with points equally spaced on the horizontal"); break;
case 1100: gridDefScanningMode = 51; println("Hovmöller diagram grid, with points equally spaced on the horizontal"); break;
case 1200: println("Time section grid"); break;
case 32768: gridDefScanningMode = 72; println("Rotated latitude/longitude (arakawa staggered E-grid)"); break;
case 32769: gridDefScanningMode = 72; println("Rotated latitude/longitude (arakawa non-E staggered grid)"); break;
case 65535: println("Missing"); break;
default: println(this.TypeOfProjection); break;
}
printst("Number of data points (Nx * Ny):\t");
this.Np = uNumX4(SectionNumbers[gridDefNumberOfDataPoints], SectionNumbers[gridDefNumberOfDataPoints + 1], SectionNumbers[gridDefNumberOfDataPoints + 2], SectionNumbers[gridDefNumberOfDataPoints + 3]);
println(this.Np);
printst("Number of points along the X-axis:\t");
this.Nx = uNumX4(SectionNumbers[gridDefNumberOfPointsAlongTheXaxis], SectionNumbers[gridDefNumberOfPointsAlongTheXaxis + 1], SectionNumbers[gridDefNumberOfPointsAlongTheXaxis + 2], SectionNumbers[gridDefNumberOfPointsAlongTheXaxis + 3]);
println(this.Nx);
printst("Number of points along the Y-axis:\t");
this.Ny = uNumX4(SectionNumbers[gridDefNumberOfPointsAlongTheYaxis], SectionNumbers[gridDefNumberOfPointsAlongTheYaxis + 1], SectionNumbers[gridDefNumberOfPointsAlongTheYaxis + 2], SectionNumbers[gridDefNumberOfPointsAlongTheYaxis + 3]);
println(this.Ny);
if (this.TypeOfProjection === 0) { // Latitude/longitude
this.ResolutionAndComponentFlags = SectionNumbers[gridDefLatLonResolutionAndComponentFlags];
println("Resolution and component flags:\t" + this.ResolutionAndComponentFlags);
this.La1 = 0.000001 * sNumX4(SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 3]);
println("Latitude of first grid point:\t" + this.La1);
this.Lo1 = 0.000001 * uNumX4(SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 3]);
if (this.Lo1 === 180) this.Lo1 = -180;
println("Longitude of first grid point:\t" + this.Lo1);
this.La2 = 0.000001 * sNumX4(SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 1], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 2], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 3]);
println("Latitude of last grid point:\t" + this.La2);
this.Lo2 = 0.000001 * uNumX4(SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 1], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 2], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 3]);
if (this.Lo2 < this.Lo1) this.Lo2 += 360;
println("Longitude of last grid point:\t" + this.Lo2);
} else if (this.TypeOfProjection === 1) { // Rotated latitude/longitude
this.ResolutionAndComponentFlags = SectionNumbers[gridDefLatLonResolutionAndComponentFlags];
println("Resolution and component flags:\t" + this.ResolutionAndComponentFlags);
this.La1 = 0.000001 * sNumX4(SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLatLonLatitudeOfFirstGridPoint + 3]);
println("Latitude of first grid point:\t" + this.La1);
this.Lo1 = 0.000001 * uNumX4(SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLatLonLongitudeOfFirstGridPoint + 3]);
if (this.Lo1 === 180) this.Lo1 = -180;
println("Longitude of first grid point:\t" + this.Lo1);
this.La2 = 0.000001 * sNumX4(SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 1], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 2], SectionNumbers[gridDefLatLonLatitudeOfLastGridPoint + 3]);
println("Latitude of last grid point:\t" + this.La2);
this.Lo2 = 0.000001 * uNumX4(SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 1], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 2], SectionNumbers[gridDefLatLonLongitudeOfLastGridPoint + 3]);
if (this.Lo2 < this.Lo1) this.Lo2 += 360;
println("Longitude of last grid point:\t" + this.Lo2);
this.SouthLat = 0.000001 * sNumX4(SectionNumbers[gridDefLatLonSouthPoleLatitude], SectionNumbers[gridDefLatLonSouthPoleLatitude + 1], SectionNumbers[gridDefLatLonSouthPoleLatitude + 2], SectionNumbers[gridDefLatLonSouthPoleLatitude + 3]);
println("Latitude of the southern pole of projection:\t" + this.SouthLat);
this.SouthLon = 0.000001 * uNumX4(SectionNumbers[gridDefLatLonSouthPoleLongitude], SectionNumbers[gridDefLatLonSouthPoleLongitude + 1], SectionNumbers[gridDefLatLonSouthPoleLongitude + 2], SectionNumbers[gridDefLatLonSouthPoleLongitude + 3]);
println("Longitude of the southern pole of projection:\t" + this.SouthLon);
this.Rotation = sNumX4(SectionNumbers[gridDefLatLonRotationOfProjection], SectionNumbers[gridDefLatLonRotationOfProjection + 1], SectionNumbers[gridDefLatLonRotationOfProjection + 2], SectionNumbers[gridDefLatLonRotationOfProjection + 3]);
println("Angle of rotation of projection:\t" + this.Rotation);
} else if (this.TypeOfProjection === 20) { // Polar Stereographic Projection
this.ResolutionAndComponentFlags = SectionNumbers[gridDefPolarResolutionAndComponentFlags];
println("Resolution and component flags:\t" + this.ResolutionAndComponentFlags);
this.La1 = 0.000001 * sNumX4(SectionNumbers[gridDefPolarLatitudeOfFirstGridPoint], SectionNumbers[gridDefPolarLatitudeOfFirstGridPoint + 1], SectionNumbers[gridDefPolarLatitudeOfFirstGridPoint + 2], SectionNumbers[gridDefPolarLatitudeOfFirstGridPoint + 3]);
println("Latitude of first grid point:\t" + this.La1);
this.Lo1 = 0.000001 * uNumX4(SectionNumbers[gridDefPolarLongitudeOfFirstGridPoint], SectionNumbers[gridDefPolarLongitudeOfFirstGridPoint + 1], SectionNumbers[gridDefPolarLongitudeOfFirstGridPoint + 2], SectionNumbers[gridDefPolarLongitudeOfFirstGridPoint + 3]);
println("Longitude of first grid point:\t" + this.Lo1);
this.LaD = 0.000001 * sNumX4(SectionNumbers[gridDefPolarDeclinationOfTheGrid], SectionNumbers[gridDefPolarDeclinationOfTheGrid + 1], SectionNumbers[gridDefPolarDeclinationOfTheGrid + 2], SectionNumbers[gridDefPolarDeclinationOfTheGrid + 3]);
println("Latitude where Dx and Dy are specified:\t" + this.LaD);
this.LoV = 0.000001 * uNumX4(SectionNumbers[gridDefPolarOrientationOfTheGrid], SectionNumbers[gridDefPolarOrientationOfTheGrid + 1], SectionNumbers[gridDefPolarOrientationOfTheGrid + 2], SectionNumbers[gridDefPolarOrientationOfTheGrid + 3]);
println("Orientation of the grid:\t" + this.LoV);
this.Dx = 0.000001 * uNumX4(SectionNumbers[gridDefPolarXDirectionGridLength], SectionNumbers[gridDefPolarXDirectionGridLength + 1], SectionNumbers[gridDefPolarXDirectionGridLength + 2], SectionNumbers[gridDefPolarXDirectionGridLength + 3]);
println("X-direction grid length (km):\t" + this.Dx);
this.Dy = 0.000001 * uNumX4(SectionNumbers[gridDefPolarYDirectionGridLength], SectionNumbers[gridDefPolarYDirectionGridLength + 1], SectionNumbers[gridDefPolarYDirectionGridLength + 2], SectionNumbers[gridDefPolarYDirectionGridLength + 3]);
println("Y-direction grid length (km):\t" + this.Dy);
this.PCF = SectionNumbers[gridDefPolarProjectionCenterFlag];
println("Projection center flag:\t" + this.PCF);
} else if (this.TypeOfProjection === 30) { // Lambert Conformal Projection
this.ResolutionAndComponentFlags = SectionNumbers[gridDefLambertResolutionAndComponentFlags];
println("Resolution and component flags:\t" + this.ResolutionAndComponentFlags);
this.La1 = 0.000001 * sNumX4(SectionNumbers[gridDefLambertLatitudeOfFirstGridPoint], SectionNumbers[gridDefLambertLatitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLambertLatitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLambertLatitudeOfFirstGridPoint + 3]);
println("Latitude of first grid point:\t" + this.La1);
this.Lo1 = 0.000001 * uNumX4(SectionNumbers[gridDefLambertLongitudeOfFirstGridPoint], SectionNumbers[gridDefLambertLongitudeOfFirstGridPoint + 1], SectionNumbers[gridDefLambertLongitudeOfFirstGridPoint + 2], SectionNumbers[gridDefLambertLongitudeOfFirstGridPoint + 3]);
println("Longitude of first grid point:\t" + this.Lo1);
this.LaD = 0.000001 * sNumX4(SectionNumbers[gridDefLambertDeclinationOfTheGrid], SectionNumbers[gridDefLambertDeclinationOfTheGrid + 1], SectionNumbers[gridDefLambertDeclinationOfTheGrid + 2], SectionNumbers[gridDefLambertDeclinationOfTheGrid + 3]);
println("Latitude where Dx and Dy are specified:\t" + this.LaD);
this.LoV = 0.000001 * uNumX4(SectionNumbers[gridDefLambertOrientationOfTheGrid], SectionNumbers[gridDefLambertOrientationOfTheGrid + 1], SectionNumbers[gridDefLambertOrientationOfTheGrid + 2], SectionNumbers[gridDefLambertOrientationOfTheGrid + 3]);
println("Orientation of the grid:\t" + this.LoV);
this.Dx = 0.000001 * uNumX4(SectionNumbers[gridDefLambertXDirectionGridLength], SectionNumbers[gridDefLambertXDirectionGridLength + 1], SectionNumbers[gridDefLambertXDirectionGridLength + 2], SectionNumbers[gridDefLambertXDirectionGridLength + 3]);
println("X-direction grid length (km):\t" + this.Dx);
this.Dy = 0.000001 * uNumX4(SectionNumbers[gridDefLambertYDirectionGridLength], SectionNumbers[gridDefLambertYDirectionGridLength + 1], SectionNumbers[gridDefLambertYDirectionGridLength + 2], SectionNumbers[gridDefLambertYDirectionGridLength + 3]);
println("Y-direction grid length (km):\t" + this.Dy);
this.PCF = SectionNumbers[gridDefLambertProjectionCenterFlag];
println("Projection center flag:\t" + this.PCF);
this.FirstLatIn = 0.000001 * sNumX4(SectionNumbers[gridDefLambert1stLatitudeIn], SectionNumbers[gridDefLambert1stLatitudeIn + 1], SectionNumbers[gridDefLambert1stLatitudeIn + 2], SectionNumbers[gridDefLambert1stLatitudeIn + 3]);
println("First latitude from the pole at which the secant cone cuts the sphere:\t" + this.FirstLatIn);
this.SecondLatIn = 0.000001 * sNumX4(SectionNumbers[gridDefLambert2ndLatitudeIn], SectionNumbers[gridDefLambert2ndLatitudeIn + 1], SectionNumbers[gridDefLambert2ndLatitudeIn + 2], SectionNumbers[gridDefLambert2ndLatitudeIn + 3]);
println("Second latitude from the pole at which the secant cone cuts the sphere:\t" + this.SecondLatIn);
this.SouthLat = 0.000001 * sNumX4(SectionNumbers[gridDefLambert2ndLatitudeIn], SectionNumbers[gridDefLambert2ndLatitudeIn + 1], SectionNumbers[gridDefLambert2ndLatitudeIn + 2], SectionNumbers[gridDefLambert2ndLatitudeIn + 3]);
println("Latitude of the southern pole of projection:\t" + this.SouthLat);
this.SouthLon = 0.000001 * uNumX4(SectionNumbers[gridDefLambertSouthPoleLongitude], SectionNumbers[gridDefLambertSouthPoleLongitude + 1], SectionNumbers[gridDefLambertSouthPoleLongitude + 2], SectionNumbers[gridDefLambertSouthPoleLongitude + 3]);
println("Longitude of the southern pole of projection:\t" + this.SouthLon);
}
printst("Flag bit numbers:\n");
this.Flag_BitNumbers = binary(this.ResolutionAndComponentFlags, 8);
{
if (this.Flag_BitNumbers.substring(2, 3) === "0") {
println("\ti direction increments not given");
} else {
println("\ti direction increments given");
}
if (this.Flag_BitNumbers.substring(3, 4) === "0") {
println("\tj direction increments not given");
} else {
println("\tj direction increments given");
}
if (this.Flag_BitNumbers.substring(4, 5) === "0") {
println("\tResolved u- and v- components of vector quantities relative to easterly and northerly directions");
} else {
println("\tResolved u- and v- components of vector quantities relative to the defined grid in the direction of increasing x and y (or i and j) coordinates respectively");
}
}
printst("Scanning mode:\t");
this.ScanningMode = SectionNumbers[gridDefScanningMode];
println(this.ScanningMode);
this.ScanX = 1;
this.ScanY = 1;
printst("Mode bit numbers:\n");
this.Mode_BitNumbers = binary(this.ScanningMode, 8);
{
if (this.Mode_BitNumbers.substring(0, 1) === "0") {
println("\tPoints of first row or column scan in the +i (+x) direction");
} else {
println("\tPoints of first row or column scan in the -i (-x) direction");
this.ScanX = 0;
}
if (this.Mode_BitNumbers.substring(1, 2) === "0") {
println("\tPoints of first row or column scan in the -j (-y) direction");
} else {
println("\tPoints of first row or column scan in the +j (+y) direction");
this.ScanY = 0;
}
if (this.Mode_BitNumbers.substring(2, 3) === "0") {
println("\tAdjacent points in i (x) direction are consecutive");
} else {
println("\tAdjacent points in j (y) direction is consecutive");
}
if (this.Mode_BitNumbers.substring(3, 4) === "0") {
println("\tAll rows scan in the same direction");
} else {
println("\tAdjacent rows scan in opposite directions");
}
}
}
SectionNumbers = this.getGrib2Section(4); // Section 4: Product Definition Section
if (SectionNumbers.length > 1) {
printst("Number of coordinate values after Template:\t");
this.NumberOfCoordinateValuesAfterTemplate = uNumX2(SectionNumbers[6], SectionNumbers[7]);
println(this.NumberOfCoordinateValuesAfterTemplate);
printst("Number of coordinate values after Template:\t");
this.ProductDefinitionTemplateNumber = uNumX2(SectionNumbers[8], SectionNumbers[9]);
info.ProductDefinitionTemplateNumber(lThis);
printst("Category of parameters by product discipline:\t");
this.CategoryOfParametersByProductDiscipline = SectionNumbers[10];
if (this.DisciplineOfProcessedData === 0) { // Meteorological
info.CategoryOfParametersByProductDiscipline(lThis);
} else {
println(this.CategoryOfParametersByProductDiscipline);
}
printst("Parameter number by product discipline and parameter category:\t");
this.ParameterNumberByProductDisciplineAndParameterCategory = SectionNumbers[11];
if (this.DisciplineOfProcessedData === 0) { // Meteorological
if (this.CategoryOfParametersByProductDiscipline === 0) { // Temperature
info.ParameterNumberByProductDisciplineAndParameterCategory_0_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Moisture
info.ParameterNumberByProductDisciplineAndParameterCategory_0_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 2) { // Momentum
info.ParameterNumberByProductDisciplineAndParameterCategory_0_2(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 3) { // Mass
info.ParameterNumberByProductDisciplineAndParameterCategory_0_3(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 4) { // Short wave radiation
info.ParameterNumberByProductDisciplineAndParameterCategory_0_4(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 5) { // Long wave radiation
info.ParameterNumberByProductDisciplineAndParameterCategory_0_5(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 6) { // Cloud
info.ParameterNumberByProductDisciplineAndParameterCategory_0_6(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 7) { // Thermodynamic stability indices
info.ParameterNumberByProductDisciplineAndParameterCategory_0_7(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 13) { // Aerosols
info.ParameterNumberByProductDisciplineAndParameterCategory_0_13(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 14) { // Trace gases
info.ParameterNumberByProductDisciplineAndParameterCategory_0_14(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 15) { // Radar
info.ParameterNumberByProductDisciplineAndParameterCategory_0_15(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 16) { // Forecast Radar Imagery
info.ParameterNumberByProductDisciplineAndParameterCategory_0_16(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 17) { // Electrodynamics
info.ParameterNumberByProductDisciplineAndParameterCategory_0_17(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 18) { // Nuclear/radiology
info.ParameterNumberByProductDisciplineAndParameterCategory_0_18(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 19) { // Physical atmospheric Properties
info.ParameterNumberByProductDisciplineAndParameterCategory_0_19(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 20) { // Atmospheric Chemical Constituents
info.ParameterNumberByProductDisciplineAndParameterCategory_0_20(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 190) { // CCITT IA5 string
info.ParameterNumberByProductDisciplineAndParameterCategory_0_190(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 191) { // Miscellaneous
info.ParameterNumberByProductDisciplineAndParameterCategory_0_191(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 192) { // Covariance
info.ParameterNumberByProductDisciplineAndParameterCategory_0_192(lThis);
}
} else if (this.DisciplineOfProcessedData === 1) { // Hydrological
if (this.CategoryOfParametersByProductDiscipline === 0) { // Hydrology Basic
info.ParameterNumberByProductDisciplineAndParameterCategory_1_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Hydrology Probabilities
info.ParameterNumberByProductDisciplineAndParameterCategory_1_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 2) { // Inland Water and Sediment Properties
info.ParameterNumberByProductDisciplineAndParameterCategory_1_2(lThis);
}
} else if (this.DisciplineOfProcessedData === 2) { // Land surface
if (this.CategoryOfParametersByProductDiscipline === 0) { // Vegetation/Biomass
info.ParameterNumberByProductDisciplineAndParameterCategory_2_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Agricultural/aquacultural special products
info.ParameterNumberByProductDisciplineAndParameterCategory_2_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 3) { // Soil
info.ParameterNumberByProductDisciplineAndParameterCategory_2_3(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 4) { // Fire Weather
info.ParameterNumberByProductDisciplineAndParameterCategory_2_4(lThis);
}
} else if (this.DisciplineOfProcessedData === 3) { // Space
if (this.CategoryOfParametersByProductDiscipline === 0) { // Image format
info.ParameterNumberByProductDisciplineAndParameterCategory_3_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Quantitative
info.ParameterNumberByProductDisciplineAndParameterCategory_3_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 192) { // Forecast Satellite Imagery
info.ParameterNumberByProductDisciplineAndParameterCategory_3_192(lThis);
}
} else if (this.DisciplineOfProcessedData === 4) { // Space Weather
if (this.CategoryOfParametersByProductDiscipline === 0) { // Temperature
info.ParameterNumberByProductDisciplineAndParameterCategory_4_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Momentum
info.ParameterNumberByProductDisciplineAndParameterCategory_4_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 2) { // Charged Particle Mass and Number
info.ParameterNumberByProductDisciplineAndParameterCategory_4_2(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 3) { // Electric and Magnetic Fields
info.ParameterNumberByProductDisciplineAndParameterCategory_4_3(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 4) { // Energetic Particles
info.ParameterNumberByProductDisciplineAndParameterCategory_4_4(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 5) { // Waves
info.ParameterNumberByProductDisciplineAndParameterCategory_4_5(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 6) { // Solar Electromagnetic Emissions
info.ParameterNumberByProductDisciplineAndParameterCategory_4_6(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 7) { // Terrestrial Electromagnetic Emissions
info.ParameterNumberByProductDisciplineAndParameterCategory_4_7(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 8) { // Imagery
info.ParameterNumberByProductDisciplineAndParameterCategory_4_8(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 9) { // Ion-Neutral Coupling
info.ParameterNumberByProductDisciplineAndParameterCategory_4_9(lThis);
}
} else if (this.DisciplineOfProcessedData === 10) { // Oceanographic
if (this.CategoryOfParametersByProductDiscipline === 0) { // Waves
info.ParameterNumberByProductDisciplineAndParameterCategory_10_0(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 1) { // Currents
info.ParameterNumberByProductDisciplineAndParameterCategory_10_1(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 2) { // Ice
info.ParameterNumberByProductDisciplineAndParameterCategory_10_2(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 3) { // Surface Properties
info.ParameterNumberByProductDisciplineAndParameterCategory_10_3(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 4) { // Sub-surface Properties
info.ParameterNumberByProductDisciplineAndParameterCategory_10_4(lThis);
} else if (this.CategoryOfParametersByProductDiscipline === 191) { // Miscellaneous
info.ParameterNumberByProductDisciplineAndParameterCategory_10_191(lThis);
}
} else {
this.ParameterNameAndUnit = nf0(this.ParameterNumberByProductDisciplineAndParameterCategory, 0);
}
println(this.ParameterNameAndUnit);
var /* float */ DayPortion = 0;
printst("Indicator of unit of time range:\t");
this.IndicatorOfUnitOfTimeRange = SectionNumbers[18];
switch (this.IndicatorOfUnitOfTimeRange) {
case 0: println("Minute"); DayPortion = 1.0 / 60.0; break;
case 1: println("Hour"); DayPortion = 1; break;
case 2: println("Day"); DayPortion = 24; break;
case 3: println("Month"); DayPortion = 30.5 * 24; break;
case 4: println("Year"); DayPortion = 365 * 24; break;
case 5: println("Decade (10 years)"); DayPortion = 10 * 365 * 24; break;
case 6: println("Normal (30 years)"); DayPortion = 30 * 365 * 24; break;
case 7: println("Century (100 years)"); DayPortion = 100 * 365 * 24; break;
case 10: println("3 hours"); DayPortion = 3; break;
case 11: println("6 hours"); DayPortion = 6; break;
case 12: println("12 hours"); DayPortion = 12; break;
case 13: println("Second"); DayPortion = 1.0 / 3600.0; break;
case 255: println("Missing"); DayPortion = 0; break;
default: println(this.IndicatorOfUnitOfTimeRange); break;
}
printst("Forecast time in defined units:\t");
this.ForecastTimeInDefinedUnits = uNumX4(SectionNumbers[19], SectionNumbers[20], SectionNumbers[21], SectionNumbers[22]);
if (this.ProductDefinitionTemplateNumber === 8) { // Average, accumulation, extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval. (see Template 4.8)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[50], SectionNumbers[51], SectionNumbers[52], SectionNumbers[53]);
} else if (this.ProductDefinitionTemplateNumber === 9) { // Probability forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval. (see Template 4.9)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[63], SectionNumbers[64], SectionNumbers[65], SectionNumbers[66]);
} else if (this.ProductDefinitionTemplateNumber === 10) { // Percentile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval. (see Template 4.10)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[51], SectionNumbers[52], SectionNumbers[53], SectionNumbers[54]);
} else if (this.ProductDefinitionTemplateNumber === 11) { // Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval. (see Template 4.11)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[53], SectionNumbers[54], SectionNumbers[55], SectionNumbers[56]);
} else if (this.ProductDefinitionTemplateNumber === 12) { // Derived forecasts based on all ensemble members at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval. (see Template 4.12)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[52], SectionNumbers[53], SectionNumbers[54], SectionNumbers[55]);
} else if (this.ProductDefinitionTemplateNumber === 13) { // Derived forecasts based on a cluster of ensemble members over a rectangular area at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval. (see Template 4.13)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[84], SectionNumbers[85], SectionNumbers[86], SectionNumbers[87]);
} else if (this.ProductDefinitionTemplateNumber === 14) { // Derived forecasts based on a cluster of ensemble members over a circular area at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval. (see Template 4.14)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[80], SectionNumbers[81], SectionNumbers[82], SectionNumbers[83]);
} else if (this.ProductDefinitionTemplateNumber === 42) { // Average, accumulation, and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents. (see Template 4.42)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[52], SectionNumbers[53], SectionNumbers[54], SectionNumbers[55]);
} else if (this.ProductDefinitionTemplateNumber === 43) { // Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval for atmospheric chemical constituents. (see Template 4.43)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[55], SectionNumbers[56], SectionNumbers[57], SectionNumbers[58]);
} else if (this.ProductDefinitionTemplateNumber === 46) { // Average, accumulation, and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for aerosol. (see Template 4.46)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[63], SectionNumbers[64], SectionNumbers[65], SectionNumbers[66]);
} else if (this.ProductDefinitionTemplateNumber === 47) { // Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval for aerosol. (see Template 4.47)
this.ForecastTimeInDefinedUnits += uNumX4(SectionNumbers[66], SectionNumbers[67], SectionNumbers[68], SectionNumbers[69]);
}
println(this.ForecastTimeInDefinedUnits);
this.ForecastConvertedTime = this.ForecastTimeInDefinedUnits * DayPortion;
printst("Type of first fixed surface:\t");
this.TypeOfFirstFixedSurface = SectionNumbers[23];
info.TypeOfFirstFixedSurface(lThis);
}
SectionNumbers = this.getGrib2Section(5); // Section 5: Data Representation Section
if (SectionNumbers.length > 1) {
printst("Number of data points:\t");
this.NumberOfDataPoints = uNumX4(SectionNumbers[6], SectionNumbers[7], SectionNumbers[8], SectionNumbers[9]);
println(this.NumberOfDataPoints);
printst("Data Representation Template Number:\t");
this.DataRepresentationTemplateNumber = uNumX2(SectionNumbers[10], SectionNumbers[11]);
info.DataRepresentationTemplateNumber(lThis);
printst("Reference value (R):\t");
this.ReferenceValue = IEEE32(IntToBinary32(uNumX4(SectionNumbers[12], SectionNumbers[13], SectionNumbers[14], SectionNumbers[15])));
println(this.ReferenceValue);
printst("Binary Scale Factor (E):\t");
this.BinaryScaleFactor = sNumX2(SectionNumbers[16], SectionNumbers[17]);
println(this.BinaryScaleFactor);
printst("Decimal Scale Factor (D):\t");
this.DecimalScaleFactor = sNumX2(SectionNumbers[18], SectionNumbers[19]);
println(this.DecimalScaleFactor);
printst("Number of bits used for each packed value:\t");
this.NumberOfBitsUsedForEachPackedValue = SectionNumbers[20];
println(this.NumberOfBitsUsedForEachPackedValue);
printst("Type of original field values:\t");
jpeg2000TypeOfOriginalFieldValues = SectionNumbers[21];
switch (jpeg2000TypeOfOriginalFieldValues) {
case 0: println("Floating point"); break;
case 1: println("Integer"); break;
case 255: println("Missing"); break;
default: println(jpeg2000TypeOfOriginalFieldValues); break;
}
// parameters over 21 used in Complex Packings e.g JPEG-2000
jpeg2000TypeOfCompression = -1;
jpeg2000TargetCompressionRatio = -1;
if (this.DataRepresentationTemplateNumber === 40) { // Grid point data – JPEG 2000 Code Stream Format
printst("JPEG-2000/Type of Compression:\t");
jpeg2000TypeOfCompression = SectionNumbers[22];
switch (jpeg2000TypeOfCompression) {
case 0: println("Lossless"); break;
case 1: println("Lossy"); break;
case 255: println("Missing"); break;
default: println(jpeg2000TypeOfCompression); break;
}
printst("JPEG-2000/Target compression ratio (M):\t");
jpeg2000TargetCompressionRatio = SectionNumbers[23];
println(jpeg2000TargetCompressionRatio);
//The compression ratio M:1 (e.g. 20:1) specifies that the encoded stream should be less than ((1/M) x depth x number of data points) bits,
//where depth is specified in octet 20 and number of data points is specified in octets 6-9 of the Data Representation Section.
} else if ((this.DataRepresentationTemplateNumber === 2) || // Grid point data - complex packing
(this.DataRepresentationTemplateNumber === 3)) { // Grid point data - complex packing and spatial differencing
printst("ComplexPacking/Type of Compression:\t");
ComplexPackingGroupSplittingMethodUsed = SectionNumbers[22];
switch (ComplexPackingGroupSplittingMethodUsed) {
case 0: println("Row by row splitting"); break;
case 1: println("General group splitting"); break;
case 255: println("Missing"); break;
default: println(ComplexPackingGroupSplittingMethodUsed); break;
}
printst("ComplexPacking/Missing value management used:\t");
ComplexPackingMissingValueManagementUsed = SectionNumbers[23];
switch (ComplexPackingMissingValueManagementUsed) {
case 0: println("No explicit missing values included within data values"); break;
case 1: println("Primary missing values included within data values"); break;
case 2: println("Primary and secondary missing values included within data values"); break;
case 255: println("Missing"); break;
default: println(ComplexPackingMissingValueManagementUsed); break;
}
printst("ComplexPacking/Primary missing value substitute:\t");
ComplexPackingPrimaryMissingValueSubstitute = IEEE32(IntToBinary32(uNumX4(SectionNumbers[24], SectionNumbers[25], SectionNumbers[26], SectionNumbers[27])));
println(ComplexPackingPrimaryMissingValueSubstitute);
printst("ComplexPacking/Secondary missing value substitute:\t");
ComplexPackingSecondaryMissingValueSubstitute = IEEE32(IntToBinary32(uNumX4(SectionNumbers[28], SectionNumbers[29], SectionNumbers[30], SectionNumbers[31])));
println(ComplexPackingSecondaryMissingValueSubstitute);
printst("ComplexPacking/Number of groups of data values into which field is split:\t");
ComplexPackingNumberOfGroupsOfDataValues = uNumX4(SectionNumbers[32], SectionNumbers[33], SectionNumbers[34], SectionNumbers[35]);
println(ComplexPackingNumberOfGroupsOfDataValues);
printst("ComplexPacking/Reference for group widths:\t");
ComplexPackingReferenceForGroupWidths = SectionNumbers[36];
println(ComplexPackingReferenceForGroupWidths);
printst("ComplexPacking/Number of bits used for group widths:\t");
ComplexPackingNumberOfBitsUsedForGroupWidths = SectionNumbers[37];
println(ComplexPackingNumberOfBitsUsedForGroupWidths);
printst("ComplexPacking/Reference for group lengths:\t");
ComplexPackingReferenceForGroupLengths = uNumX4(SectionNumbers[38], SectionNumbers[39], SectionNumbers[40], SectionNumbers[41]);
println(ComplexPackingReferenceForGroupLengths);