LCOV - code coverage report
Current view: directory - frmts/grib/degrib18/g2clib-1.0.4 - gridtemplates.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 46 20 43.5 %
Date: 2012-04-28 Functions: 4 3 75.0 %

       1                 : #include <stdlib.h>
       2                 : #include "grib2.h"
       3                 : #include "gridtemplates.h"
       4                 : 
       5                 : 
       6                 : static const struct gridtemplate templatesgrid[MAXGRIDTEMP] = {
       7                 :              // 3.0: Lat/Lon grid
       8                 :          { 0, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
       9                 :              // 3.1: Rotated Lat/Lon grid
      10                 :          { 1, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} },
      11                 :              // 3.2: Stretched Lat/Lon grid
      12                 :          { 2, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} },
      13                 :              // 3.3: Stretched & Rotated Lat/Lon grid
      14                 :          { 3, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} },
      15                 :              // 3.10: Mercator
      16                 : //       {10, 19, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,-4,4,1,4,4,4} },
      17                 :          {10, 19, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,-4,1,4,4,4} },
      18                 :              // 3.20: Polar Stereographic Projection
      19                 : //       {20, 18, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1} },
      20                 :          {20, 18, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,4,4,1,1} },
      21                 :              // 3.30: Lambert Conformal
      22                 : //       {30, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4} },
      23                 :          {30, 22, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,4,4,1,1,-4,-4,-4,-4} },
      24                 :              // 3.31: Albers equal area
      25                 :          {31, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4} },
      26                 :              // 3.40: Guassian Lat/Lon
      27                 :          {40, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
      28                 :              // 3.41: Rotated Gaussian Lat/Lon
      29                 :          {41, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} },
      30                 :              // 3.42: Stretched Gaussian Lat/Lon
      31                 :          {42, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} },
      32                 :              // 3.43: Stretched and Rotated Gaussian Lat/Lon
      33                 :          {43, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} },
      34                 :              // 3.50: Spherical Harmonic Coefficients
      35                 :          {50, 5, 0, {4,4,4,1,1} },
      36                 :              // 3.51: Rotated Spherical Harmonic Coefficients
      37                 :          {51, 8, 0, {4,4,4,1,1,-4,4,4} },
      38                 :              // 3.52: Stretched Spherical Harmonic Coefficients
      39                 :          {52, 8, 0, {4,4,4,1,1,-4,4,-4} },
      40                 :              // 3.53: Stretched and Rotated Spherical Harmonic Coefficients
      41                 :          {53, 11, 0, {4,4,4,1,1,-4,4,4,-4,4,-4} },
      42                 :              // 3.90: Space View Perspective or orthographic
      43                 :          {90, 21, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,4,4,1,4,4,4,4} },
      44                 :              // 3.100: Triangular grid based on an icosahedron
      45                 :          {100, 11, 0, {1,1,2,1,-4,4,4,1,1,1,4} },
      46                 :              // 3.110: Equatorial Azimuthal equidistant
      47                 :          {110, 16, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,1,1} },
      48                 :              // 3.120: Azimuth-range projection
      49                 :          {120, 7, 1, {4,4,-4,4,4,4,1} },
      50                 :              // 3.1000: Cross Section Grid
      51                 :          {1000, 20, 1, {1,1,4,1,4,1,4,4,4,4,-4,4,1,4,4,1,2,1,1,2} },
      52                 :              // 3.1100: Hovmoller Diagram Grid
      53                 :          {1100, 28, 0, {1,1,4,1,4,1,4,4,4,4,-4,4,1,-4,4,1,4,1,-4,1,1,-4,2,1,1,1,1,1} },
      54                 :              // 3.1200: Time Section Grid
      55                 :          {1200, 16, 1, {4,1,-4,1,1,-4,2,1,1,1,1,1,2,1,1,2} }
      56                 : 
      57                 :       } ;
      58                 : 
      59             114 : const struct gridtemplate *get_templatesgrid()
      60                 : 
      61                 : {
      62             114 :     return templatesgrid;
      63                 : }
      64                 : 
      65              12 : g2int getgridindex(g2int number)
      66                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
      67                 : !                .      .    .                                       .
      68                 : ! SUBPROGRAM:    getgridindex
      69                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2001-06-28
      70                 : !
      71                 : ! ABSTRACT: This function returns the index of specified Grid
      72                 : !   Definition Template 3.NN (NN=number) in array templates.
      73                 : !
      74                 : ! PROGRAM HISTORY LOG:
      75                 : ! 2001-06-28  Gilbert
      76                 : !
      77                 : ! USAGE:    index=getgridindex(number)
      78                 : !   INPUT ARGUMENT LIST:
      79                 : !     number   - NN, indicating the number of the Grid Definition
      80                 : !                Template 3.NN that is being requested.
      81                 : !
      82                 : ! RETURNS:  Index of GDT 3.NN in array templates, if template exists.
      83                 : !           = -1, otherwise.
      84                 : !
      85                 : ! REMARKS: None
      86                 : !
      87                 : ! ATTRIBUTES:
      88                 : !   LANGUAGE: C
      89                 : !   MACHINE:  IBM SP
      90                 : !
      91                 : !$$$*/
      92                 : {
      93              12 :            g2int j,getgridindex=-1;
      94                 : 
      95              60 :            for (j=0;j<MAXGRIDTEMP;j++) {
      96              60 :               if (number == templatesgrid[j].template_num) {
      97              12 :                  getgridindex=j;
      98              12 :                  return(getgridindex);
      99                 :               }
     100                 :            }
     101                 : 
     102               0 :            return(getgridindex);
     103                 : }
     104                 : 
     105               6 : xxtemplate *getgridtemplate(g2int number)
     106                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
     107                 : !                .      .    .                                       .
     108                 : ! SUBPROGRAM:    getgridtemplate 
     109                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-09
     110                 : !
     111                 : ! ABSTRACT: This subroutine returns grid template information for a 
     112                 : !   specified Grid Definition Template 3.NN.
     113                 : !   The number of entries in the template is returned along with a map
     114                 : !   of the number of octets occupied by each entry.  Also, a flag is
     115                 : !   returned to indicate whether the template would need to be extended.
     116                 : !
     117                 : ! PROGRAM HISTORY LOG:
     118                 : ! 2000-05-09  Gilbert
     119                 : !
     120                 : ! USAGE:    template *getgridtemplate(number)
     121                 : !   INPUT ARGUMENT LIST:
     122                 : !     number   - NN, indicating the number of the Grid Definition 
     123                 : !                Template 3.NN that is being requested.
     124                 : !
     125                 : !   RETURN VALUE:
     126                 : !        - Pointer to the returned template struct.
     127                 : !          Returns NULL pointer, if template not found.
     128                 : !
     129                 : ! REMARKS: None
     130                 : !
     131                 : ! ATTRIBUTES:
     132                 : !   LANGUAGE: C
     133                 : !   MACHINE:  IBM SP
     134                 : !
     135                 : !$$$*/
     136                 : {
     137                 :            g2int index;
     138                 :            xxtemplate *new;
     139                 : 
     140               6 :            index=getgridindex(number);
     141                 : 
     142               6 :            if (index != -1) {
     143               6 :               new=(xxtemplate *)malloc(sizeof(xxtemplate));
     144               6 :               new->type=3;
     145               6 :               new->num=templatesgrid[index].template_num;
     146               6 :               new->maplen=templatesgrid[index].mapgridlen;
     147               6 :               new->needext=templatesgrid[index].needext;
     148               6 :               new->map=(g2int *)templatesgrid[index].mapgrid;
     149               6 :               new->extlen=0;
     150               6 :               new->ext=0;        //NULL
     151               6 :               return(new);
     152                 :            }
     153                 :            else {
     154               0 :              printf("getgridtemplate: GDT Template 3.%d not defined.\n",(int)number);
     155               0 :              return(0);        //NULL
     156                 :            }
     157                 : 
     158                 :          return(0);        //NULL
     159                 : }
     160                 : 
     161                 : 
     162               0 : xxtemplate *extgridtemplate(g2int number,g2int *list)
     163                 : /*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
     164                 : !                .      .    .                                       .
     165                 : ! SUBPROGRAM:    extgridtemplate 
     166                 : !   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-09
     167                 : !
     168                 : ! ABSTRACT: This subroutine generates the remaining octet map for a 
     169                 : !   given Grid Definition Template, if required.  Some Templates can 
     170                 : !   vary depending on data values given in an earlier part of the 
     171                 : !   Template, and it is necessary to know some of the earlier entry
     172                 : !   values to generate the full octet map of the Template.
     173                 : !
     174                 : ! PROGRAM HISTORY LOG:
     175                 : ! 2000-05-09  Gilbert
     176                 : !
     177                 : ! USAGE:    CALL extgridtemplate(number,list)
     178                 : !   INPUT ARGUMENT LIST:
     179                 : !     number   - NN, indicating the number of the Grid Definition 
     180                 : !                Template 3.NN that is being requested.
     181                 : !     list()   - The list of values for each entry in 
     182                 : !                the Grid Definition Template.
     183                 : !
     184                 : !   RETURN VALUE:
     185                 : !        - Pointer to the returned template struct.
     186                 : !          Returns NULL pointer, if template not found.
     187                 : !
     188                 : ! ATTRIBUTES:
     189                 : !   LANGUAGE: C
     190                 : !   MACHINE:  IBM SP
     191                 : !
     192                 : !$$$*/
     193                 : {
     194                 :            xxtemplate *new;
     195                 :            g2int index,i;
     196                 : 
     197               0 :            index=getgridindex(number);
     198               0 :            if (index == -1) return(0);
     199                 : 
     200               0 :            new=getgridtemplate(number);
     201                 : 
     202               0 :            if ( ! new->needext ) return(new);
     203                 : 
     204               0 :            if ( number == 120 ) {
     205               0 :               new->extlen=list[1]*2;
     206               0 :               new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
     207               0 :               for (i=0;i<new->extlen;i++) {
     208               0 :                  if ( i%2 == 0 ) {
     209               0 :                     new->ext[i]=2;
     210                 :                  }
     211                 :                  else {
     212               0 :                     new->ext[i]=-2;
     213                 :                  }
     214                 :               }
     215                 :            }
     216               0 :            else if ( number == 1000 ) {
     217               0 :               new->extlen=list[19];
     218               0 :               new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
     219               0 :               for (i=0;i<new->extlen;i++) {
     220               0 :                  new->ext[i]=4;
     221                 :               }
     222                 :            }
     223               0 :            else if ( number == 1200 ) {
     224               0 :               new->extlen=list[15];
     225               0 :               new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
     226               0 :               for (i=0;i<new->extlen;i++) {
     227               0 :                  new->ext[i]=4;
     228                 :               }
     229                 :            }
     230                 : 
     231               0 :            return(new);
     232                 : 
     233                 : }

Generated by: LCOV version 1.7