LCOV - code coverage report
Current view: directory - frmts/grib/degrib18/g2clib-1.0.4 - drstemplates.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 34 20 58.8 %
Date: 2011-12-18 Functions: 4 3 75.0 %

       1                 : #include <stdlib.h>
       2                 : #include "grib2.h"
       3                 : #include "drstemplates.h"
       4                 : 
       5                 : 
       6                 : static const struct drstemplate templatesdrs[MAXDRSTEMP] = {
       7                 :              // 5.0: Grid point data - Simple Packing
       8                 :          { 0, 5, 0, {4,-2,-2,1,1} },
       9                 :              // 5.2: Grid point data - Complex Packing
      10                 :          { 2, 16, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1} },
      11                 :              // 5.3: Grid point data - Complex Packing and spatial differencing
      12                 :          { 3, 18, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1,1,1} },
      13                 :              // 5.50: Spectral Data - Simple Packing
      14                 :          { 50, 5, 0, {4,-2,-2,1,4} },
      15                 :              // 5.51: Spherical Harmonics data - Complex packing 
      16                 :          { 51, 10, 0, {4,-2,-2,1,-4,2,2,2,4,1} },
      17                 : //           // 5.1: Matrix values at gridpoint - Simple packing
      18                 : //         { 1, 15, 1, {4,-2,-2,1,1,1,4,2,2,1,1,1,1,1,1} },
      19                 :              // 5.40: Grid point data - JPEG2000 encoding
      20                 :          { 40, 7, 0, {4,-2,-2,1,1,1,1} },
      21                 :              // 5.41: Grid point data - PNG encoding
      22                 :          { 41, 5, 0, {4,-2,-2,1,1} },
      23                 :              // 5.40000: Grid point data - JPEG2000 encoding
      24                 :          { 40000, 7, 0, {4,-2,-2,1,1,1,1} },
      25                 :              // 5.40010: Grid point data - PNG encoding
      26                 :          { 40010, 5, 0, {4,-2,-2,1,1} }
      27                 :       } ;
      28                 : 
      29              36 : const struct drstemplate *get_templatesdrs()
      30                 : {
      31              36 :     return templatesdrs;
      32                 : }
      33                 : 
      34                 : 
      35               4 : g2int getdrsindex(g2int number)
      36                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
      37                 : !                .      .    .                                       .
      38                 : ! SUBPROGRAM:    getdrsindex 
      39                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2001-06-28
      40                 : !
      41                 : ! ABSTRACT: This function returns the index of specified Data 
      42                 : !   Representation Template 5.NN (NN=number) in array templates.
      43                 : !
      44                 : ! PROGRAM HISTORY LOG:
      45                 : ! 2001-06-28  Gilbert
      46                 : !
      47                 : ! USAGE:    index=getdrsindex(number)
      48                 : !   INPUT ARGUMENT LIST:
      49                 : !     number   - NN, indicating the number of the Data Representation 
      50                 : !                Template 5.NN that is being requested.
      51                 : !
      52                 : ! RETURNS:  Index of DRT 5.NN in array templates, if template exists.
      53                 : !           = -1, otherwise.
      54                 : !
      55                 : ! REMARKS: None
      56                 : !
      57                 : ! ATTRIBUTES:
      58                 : !   LANGUAGE: C
      59                 : !   MACHINE:  IBM SP
      60                 : !
      61                 : !$$$*/
      62                 : {
      63               4 :            g2int j,getdrsindex=-1;
      64                 : 
      65              12 :            for (j=0;j<MAXDRSTEMP;j++) {
      66              12 :               if (number == templatesdrs[j].template_num) {
      67               4 :                  getdrsindex=j;
      68               4 :                  return(getdrsindex);
      69                 :               }
      70                 :            }
      71                 : 
      72               0 :            return(getdrsindex);
      73                 : }
      74                 : 
      75                 : 
      76               2 : xxtemplate *getdrstemplate(g2int number)
      77                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
      78                 : !                .      .    .                                       .
      79                 : ! SUBPROGRAM:    getdrstemplate 
      80                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-11
      81                 : !
      82                 : ! ABSTRACT: This subroutine returns DRS template information for a 
      83                 : !   specified Data Representation Template 5.NN.
      84                 : !   The number of entries in the template is returned along with a map
      85                 : !   of the number of octets occupied by each entry.  Also, a flag is
      86                 : !   returned to indicate whether the template would need to be extended.
      87                 : !
      88                 : ! PROGRAM HISTORY LOG:
      89                 : ! 2000-05-11  Gilbert
      90                 : !
      91                 : ! USAGE:    new=getdrstemplate(number);
      92                 : !   INPUT ARGUMENT LIST:
      93                 : !     number   - NN, indicating the number of the Data Representation 
      94                 : !                Template 5.NN that is being requested.
      95                 : !
      96                 : !   RETURN VALUE:      
      97                 : !        - Pointer to the returned template struct. 
      98                 : !          Returns NULL pointer, if template not found.
      99                 : !
     100                 : ! REMARKS: None
     101                 : !
     102                 : ! ATTRIBUTES:
     103                 : !   LANGUAGE: C
     104                 : !   MACHINE:  IBM SP
     105                 : !
     106                 : !$$$*/
     107                 : {
     108                 :            g2int index;
     109                 :            xxtemplate *new;
     110                 : 
     111               2 :            index=getdrsindex(number);
     112                 : 
     113               2 :            if (index != -1) {
     114               2 :               new=(xxtemplate *)malloc(sizeof(xxtemplate));
     115               2 :               new->type=5;
     116               2 :               new->num=templatesdrs[index].template_num;
     117               2 :               new->maplen=templatesdrs[index].mapdrslen;
     118               2 :               new->needext=templatesdrs[index].needext;
     119               2 :               new->map=(g2int *)templatesdrs[index].mapdrs;
     120               2 :               new->extlen=0;
     121               2 :               new->ext=0;        //NULL
     122               2 :               return(new);
     123                 :            }
     124                 :            else {
     125               0 :              printf("getdrstemplate: DRS Template 5.%d not defined.\n",(int)number);
     126               0 :              return(0);        //NULL
     127                 :            }
     128                 : 
     129                 :          return(0);        //NULL
     130                 : }
     131                 : 
     132               0 : xxtemplate *extdrstemplate(g2int number,g2int *list)
     133                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
     134                 : !                .      .    .                                       .
     135                 : ! SUBPROGRAM:    extdrstemplate 
     136                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-11
     137                 : !
     138                 : ! ABSTRACT: This subroutine generates the remaining octet map for a
     139                 : !   given Data Representation Template, if required.  Some Templates can
     140                 : !   vary depending on data values given in an earlier part of the 
     141                 : !   Template, and it is necessary to know some of the earlier entry
     142                 : !   values to generate the full octet map of the Template.
     143                 : !
     144                 : ! PROGRAM HISTORY LOG:
     145                 : ! 2000-05-11  Gilbert
     146                 : !
     147                 : ! USAGE:    new=extdrstemplate(number,list);
     148                 : !   INPUT ARGUMENT LIST:
     149                 : !     number   - NN, indicating the number of the Data Representation 
     150                 : !                Template 5.NN that is being requested.
     151                 : !     list()   - The list of values for each entry in the 
     152                 : !                the Data Representation Template 5.NN.
     153                 : !
     154                 : !   RETURN VALUE:      
     155                 : !        - Pointer to the returned template struct. 
     156                 : !          Returns NULL pointer, if template not found.
     157                 : !
     158                 : ! ATTRIBUTES:
     159                 : !   LANGUAGE: C
     160                 : !   MACHINE:  IBM SP
     161                 : !
     162                 : !$$$*/
     163                 : {
     164                 :            xxtemplate *new;
     165                 :            g2int index,i;
     166                 : 
     167               0 :            index=getdrsindex(number);
     168               0 :            if (index == -1) return(0);
     169                 : 
     170               0 :            new=getdrstemplate(number);
     171                 : 
     172               0 :            if ( ! new->needext ) return(new);
     173                 : 
     174               0 :            if ( number == 1 ) {
     175               0 :               new->extlen=list[10]+list[12];
     176               0 :               new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
     177               0 :               for (i=0;i<new->extlen;i++) {
     178               0 :                 new->ext[i]=4;
     179                 :               }
     180                 :            }
     181               0 :            return(new);
     182                 : 
     183                 : }
     184                 : 

Generated by: LCOV version 1.7