File: drstemplates.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 (157 lines) | stat: -rwxr-xr-x 4,748 bytes parent folder | download | duplicates (23)
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
#include <stdlib.h>
#include "grib2.h"
#include "drstemplates.h"

g2int getdrsindex(g2int number)
/*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
!                .      .    .                                       .
! SUBPROGRAM:    getdrsindex 
!   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2001-06-28
!
! ABSTRACT: This function returns the index of specified Data 
!   Representation Template 5.NN (NN=number) in array templates.
!
! PROGRAM HISTORY LOG:
! 2001-06-28  Gilbert
! 2009-01-14  Vuong     Changed structure name template to gtemplate
!
! USAGE:    index=getdrsindex(number)
!   INPUT ARGUMENT LIST:
!     number   - NN, indicating the number of the Data Representation 
!                Template 5.NN that is being requested.
!
! RETURNS:  Index of DRT 5.NN in array gtemplates, if gtemplate exists.
!           = -1, otherwise.
!
! REMARKS: None
!
! ATTRIBUTES:
!   LANGUAGE: C
!   MACHINE:  IBM SP
!
!$$$*/
{
           g2int j,getdrsindex=-1;

           for (j=0;j<MAXDRSTEMP;j++) {
              if (number == templatesdrs[j].template_num) {
                 getdrsindex=j;
                 return(getdrsindex);
              }
           }

           return(getdrsindex);
}


gtemplate *getdrstemplate(g2int number)
/*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
!                .      .    .                                       .
! SUBPROGRAM:    getdrstemplate 
!   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-11
!
! ABSTRACT: This subroutine returns DRS template information for a 
!   specified Data Representation Template 5.NN.
!   The number of entries in the template is returned along with a map
!   of the number of octets occupied by each entry.  Also, a flag is
!   returned to indicate whether the template would need to be extended.
!
! PROGRAM HISTORY LOG:
! 2000-05-11  Gilbert
! 2009-01-14  Vuong     Changed structure name template to gtemplate
!
! USAGE:    new=getdrstemplate(number);
!   INPUT ARGUMENT LIST:
!     number   - NN, indicating the number of the Data Representation 
!                Template 5.NN that is being requested.
!
!   RETURN VALUE:      
!        - Pointer to the returned template struct. 
!          Returns NULL pointer, if template not found.
!
! REMARKS: None
!
! ATTRIBUTES:
!   LANGUAGE: C
!   MACHINE:  IBM SP
!
!$$$*/
{
           g2int index;
           gtemplate *new;

           index=getdrsindex(number);

           if (index != -1) {
              new=(gtemplate *)malloc(sizeof(gtemplate));
              new->type=5;
              new->num=templatesdrs[index].template_num;
              new->maplen=templatesdrs[index].mapdrslen;
              new->needext=templatesdrs[index].needext;
              new->map=(g2int *)templatesdrs[index].mapdrs;
              new->extlen=0;
              new->ext=0;        //NULL
              return(new);
           }
           else {
             printf("getdrstemplate: DRS Template 5.%d not defined.\n",(int)number);
             return(0);        //NULL
           }

         return(0);        //NULL
}

gtemplate *extdrstemplate(g2int number,g2int *list)
/*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
!                .      .    .                                       .
! SUBPROGRAM:    extdrstemplate 
!   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-11
!
! ABSTRACT: This subroutine generates the remaining octet map for a
!   given Data Representation Template, if required.  Some Templates can
!   vary depending on data values given in an earlier part of the 
!   Template, and it is necessary to know some of the earlier entry
!   values to generate the full octet map of the Template.
!
! PROGRAM HISTORY LOG:
! 2000-05-11  Gilbert
! 2009-01-14  Vuong     Changed structure name template to gtemplate
!
! USAGE:    new=extdrstemplate(number,list);
!   INPUT ARGUMENT LIST:
!     number   - NN, indicating the number of the Data Representation 
!                Template 5.NN that is being requested.
!     list()   - The list of values for each entry in the 
!                the Data Representation Template 5.NN.
!
!   RETURN VALUE:      
!        - Pointer to the returned template struct. 
!          Returns NULL pointer, if template not found.
!
! ATTRIBUTES:
!   LANGUAGE: C
!   MACHINE:  IBM SP
!
!$$$*/
{
           gtemplate *new;
           g2int index,i;

           index=getdrsindex(number);
           if (index == -1) return(0);

           new=getdrstemplate(number);

           if ( ! new->needext ) return(new);

           if ( number == 1 ) {
              new->extlen=list[10]+list[12];
              new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
              for (i=0;i<new->extlen;i++) {
                new->ext[i]=4;
              }
           }
           return(new);

}