Skip to content

Commit cf40028

Browse files
Update test_same_sec.c
1 parent 88b94b6 commit cf40028

1 file changed

Lines changed: 158 additions & 0 deletions

File tree

tests/test_same_sec.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,165 @@ main()
626626
return 1;
627627
}
628628
}
629+
printf("Testing same_sec4_for_merge()...\n");
630+
{
631+
unsigned char sec1[21] = {0};
632+
unsigned char sec4_a[58] = {
633+
0, 0, 0, 58, /* Section length */
634+
4, /* Section number */
635+
0, 0, /* Num coord values after template */
636+
0, 8, /* Product definition template number */
637+
/* Product Definition Template 8 */
638+
0, 0, /* Parameter category and number */
639+
0, 0, 0, /* Generating process info */
640+
0, 0, /* Hours after ref time cutoff */
641+
0, /* Minutes after ref time cutoff */
642+
0, /* Indicator of unit of time range */
643+
0, 0, 0, 0, /* Forecast time in units specified by PDT */
644+
0, 0, 0, 0, 0, 0, /* Type, scale factor, scaled value of first fixed surface */
645+
0, 0, 0, 0, 0, 0, /* Type, scale factor, scaled value of second fixed surface */
646+
/* Time of end of overall time interval */
647+
(2025 >> 8) & 0xff, (2025 & 0xff), /* Year */
648+
3, 15, 12, 0, 0, /* Month, day, hour, minute, second */
649+
/* Rest of Template */
650+
0, 0, 0, 0, 0, 0,
651+
0, 0, 0, 0, 0, 0,
652+
0, 0, 0, 0, 0
653+
};
654+
unsigned char sec4_b[58] = {0};
655+
unsigned char *sec_a[10] = {0};
656+
unsigned char *sec_b[10] = {0};
657+
658+
for (int i = 0; i < 58; i++) sec4_b[i] = sec4_a[i];
659+
660+
sec_a[1] = sec1; /* Section 1 is accessed for Center */
661+
sec_b[1] = sec1;
662+
sec_a[4] = sec4_a;
663+
sec_b[4] = sec4_b;
664+
665+
if (!same_sec4_for_merge(1, sec_a, sec_b)) {
666+
printf("same_sec4_for_merge: sections should be the same\n");
667+
return 1;
668+
}
669+
670+
/* different section length */
671+
sec4_b[3] = 57;
672+
if (same_sec4_for_merge(1, sec_a, sec_b)) {
673+
printf("same_sec4_for_merge: different section length should return 0\n");
674+
return 1;
675+
}
676+
sec4_b[3] = sec4_a[3];
677+
678+
for (int i = 4; i < 57; i++) {
679+
sec4_b[i] = 255;
680+
if (i >= 17 && i < 22) {
681+
if (!same_sec4_for_merge(1, sec_a, sec_b)) {
682+
printf("same_sec4_for_merge: different forecast time should return 1\n");
683+
return 1;
684+
}
685+
}
686+
else if (i >= 34 && i < 41) {
687+
if (!same_sec4_for_merge(1, sec_a, sec_b)) {
688+
printf("same_sec4_for_merge: different end of overall time interval should return 1\n");
689+
return 1;
690+
}
691+
}
692+
else {
693+
if (same_sec4_for_merge(1, sec_a, sec_b)) {
694+
printf("same_sec4_for_merge: sections should be different at byte %d\n", i);
695+
return 1;
696+
}
697+
}
698+
sec4_b[i] = sec4_a[i];
699+
}
700+
701+
/* Now testing on PDT without stat time (PDT 7) */
702+
sec4_a[3] = 34; /* section length */
703+
sec4_b[3] = 34;
704+
705+
sec4_a[8] = 7; /* PDT Number */
706+
sec4_b[8] = 7;
707+
708+
if (same_sec4_for_merge(1, sec_a, sec_b)) {
709+
printf("same_sec4_for_merge: PDT without stat time should return 0\n");
710+
return 1;
711+
}
712+
}
713+
printf("Testing same_sec4_but_ensemble()...\n");
714+
{
715+
unsigned char sec1[21] = {0};
716+
unsigned char sec4_a[39] = {
717+
0, 0, 0, 39, /* Section length */
718+
4, /* Section number */
719+
0, 0, /* Num coord values after template */
720+
0, 41, /* Product definition template number */
721+
/* Product Definition Template 41 */
722+
0, 0, /* Parameter category and number */
723+
0, 0, /* Atmospheric Chemical Constituent Type */
724+
0, 0, 0, /* Generating process info */
725+
0, 0, /* Hours after ref time cutoff */
726+
0, /* Minutes after ref time cutoff */
727+
0, /* Indicator of unit of time range (Code Table 4.4) */
728+
0, 0, 0, 0, /* Forecast time in units specified by PDT */
729+
0, 0, 0, 0, 0, 0, /* Type, scale factor, scaled value of first fixed surface */
730+
0, 0, 0, 0, 0, 0, /* Type, scale factor, scaled value of second fixed surface */
731+
0, /* Type of ensemble forecast */
732+
0, /* Perturbation number */
733+
0, /* Number of forecasts in ensemble */
734+
};
735+
unsigned char sec4_b[58] = {0};
736+
unsigned char *sec_a[10] = {0};
737+
unsigned char *sec_b[10] = {0};
738+
739+
for (int i = 0; i < 58; i++) sec4_b[i] = sec4_a[i];
740+
741+
sec_a[1] = sec1; /* Section 1 is accessed for Center */
742+
sec_b[1] = sec1;
743+
sec_a[4] = sec4_a;
744+
sec_b[4] = sec4_b;
745+
746+
/* use mode = 98 for coverage */
747+
if (!same_sec4_but_ensemble(98, sec_a, sec_b)) {
748+
printf("same_sec4_but_ensemble: sections should be the same\n");
749+
return 1;
750+
}
751+
752+
/* different section length */
753+
sec4_b[3] = 38;
754+
if (same_sec4_but_ensemble(1, sec_a, sec_b)) {
755+
printf("same_sec4_but_ensemble: different section length should return 0\n");
756+
return 1;
757+
}
758+
759+
for (int i = 4; i < 39; i++) {
760+
sec4_b[i] = 255;
761+
if (i == 19 || (i >= 20 && i < 24) || i == 36 || i == 37) {
762+
if (!same_sec4_but_ensemble(1, sec_a, sec_b)) {
763+
if (i == 19) {
764+
printf("same_sec4_but_ensemble: different indicator of unit time range should return 1\n");
765+
}
766+
else if (i >= 20 && i < 24) {
767+
printf("same_sec4_but_ensemble: different forecast time should return 1\n");
768+
}
769+
else if (i == 36) {
770+
printf("same_sec4_but_ensemble: different type of ensemble forecast should return 1\n");
771+
}
772+
else {
773+
printf("same_sec4_but_ensemble: different perturbation number should return 1\n");
774+
}
775+
return 1;
776+
}
777+
}
778+
else {
779+
if (same_sec4_but_ensemble(1, sec_a, sec_b)) {
780+
printf("same_sec4_but_ensemble: sections should be different at byte %d\n", i);
781+
return 1;
782+
}
783+
}
784+
sec4_b[i] = sec4_a[i];
785+
}
629786

787+
}
630788
printf("SUCCESS!\n");
631789
return 0;
632790
}

0 commit comments

Comments
 (0)