Debian Codegraph @

frmts/grib/degrib/g2clib/getpoly.c

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