File: getpoly.c

package info (click to toggle)
g2clib 1.4.0-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 608 kB
  • ctags: 226
  • sloc: ansic: 4,995; makefile: 194
file content (80 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download | duplicates (31)
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
#include <stdio.h>
#include <stdlib.h>
#include "grib2.h"

g2int g2_unpack3(unsigned char *,g2int *,g2int **,g2int **,
                         g2int *,g2int **,g2int *);

g2int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm)
//$$$  SUBPROGRAM DOCUMENTATION BLOCK
//                .      .    .                                       .
// SUBPROGRAM:    getpoly 
//   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2002-12-11
//
// ABSTRACT: This subroutine returns the J, K, and M pentagonal resolution
//   parameters specified in a GRIB Grid Definition Section used
//   spherical harmonic coefficients using GDT 5.50 through 5.53
//
// PROGRAM HISTORY LOG:
// 2002-12-11  Gilbert
//
// USAGE:    int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm)
//   INPUT ARGUMENTS:
//     csec3    - Character array that contains the packed GRIB2 GDS
//
//   OUTPUT ARGUMENTS:      
//         JJ   = J - pentagonal resolution parameter
//         KK   = K - pentagonal resolution parameter
//         MM   = M - pentagonal resolution parameter
//
// REMARKS:  Returns JJ, KK, and MM set to zero, if grid template
//           not recognized.
//
// ATTRIBUTES:
//   LANGUAGE: C
//   MACHINE:  IBM SP
//
//$$$
{
    
      g2int   *igdstmpl,*list_opt;
      g2int   *igds;
      g2int   iofst,igdtlen,num_opt,jerr;

      iofst=0;       // set offset to beginning of section
      jerr=g2_unpack3(csec3,&iofst,&igds,&igdstmpl,
                      &igdtlen,&list_opt,&num_opt);
      if (jerr == 0) {
         switch ( igds[4] )     //  Template number
         {
           case 50:     // Spherical harmonic coefficients
           case 51:
           case 52:
           case 53:
           {
              *jj=igdstmpl[0];
              *kk=igdstmpl[1];
              *mm=igdstmpl[2];
              break;
           }
           default:
           {
              *jj=0;
              *kk=0;
              *mm=0;
              break;
           }
         }     // end switch
      }
      else {
         *jj=0;
         *kk=0;
         *mm=0;
      }
        
      if (igds != 0) free(igds);
      if (igdstmpl != 0) free(igdstmpl);
      if (list_opt != 0) free(list_opt);

      return 0;
}