1 : #include <stdio.h>
2 : #include <stdlib.h>
3 : #include "grib2.h"
4 :
5 : g2int g2_unpack3(unsigned char *,g2int *,g2int **,g2int **,
6 : g2int *,g2int **,g2int *);
7 :
8 0 : g2int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm)
9 : //$$$ SUBPROGRAM DOCUMENTATION BLOCK
10 : // . . . .
11 : // SUBPROGRAM: getpoly
12 : // PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-11
13 : //
14 : // ABSTRACT: This subroutine returns the J, K, and M pentagonal resolution
15 : // parameters specified in a GRIB Grid Definition Section used
16 : // spherical harmonic coefficients using GDT 5.50 through 5.53
17 : //
18 : // PROGRAM HISTORY LOG:
19 : // 2002-12-11 Gilbert
20 : //
21 : // USAGE: int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm)
22 : // INPUT ARGUMENTS:
23 : // csec3 - Character array that contains the packed GRIB2 GDS
24 : //
25 : // OUTPUT ARGUMENTS:
26 : // JJ = J - pentagonal resolution parameter
27 : // KK = K - pentagonal resolution parameter
28 : // MM = M - pentagonal resolution parameter
29 : //
30 : // REMARKS: Returns JJ, KK, and MM set to zero, if grid template
31 : // not recognized.
32 : //
33 : // ATTRIBUTES:
34 : // LANGUAGE: C
35 : // MACHINE: IBM SP
36 : //
37 : //$$$
38 : {
39 :
40 : g2int *igdstmpl,*list_opt;
41 : g2int *igds;
42 : g2int iofst,igdtlen,num_opt,jerr;
43 :
44 0 : iofst=0; // set offset to beginning of section
45 0 : jerr=g2_unpack3(csec3,&iofst,&igds,&igdstmpl,
46 : &igdtlen,&list_opt,&num_opt);
47 0 : if (jerr == 0) {
48 0 : switch ( igds[4] ) // Template number
49 : {
50 : case 50: // Spherical harmonic coefficients
51 : case 51:
52 : case 52:
53 : case 53:
54 : {
55 0 : *jj=igdstmpl[0];
56 0 : *kk=igdstmpl[1];
57 0 : *mm=igdstmpl[2];
58 0 : break;
59 : }
60 : default:
61 : {
62 0 : *jj=0;
63 0 : *kk=0;
64 0 : *mm=0;
65 : break;
66 : }
67 : } // end switch
68 : }
69 : else {
70 0 : *jj=0;
71 0 : *kk=0;
72 0 : *mm=0;
73 : }
74 :
75 0 : if (igds != 0) free(igds);
76 0 : if (igdstmpl != 0) free(igdstmpl);
77 0 : if (list_opt != 0) free(list_opt);
78 :
79 0 : return 0;
80 : }
|