gribapi.c 1.27 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#if  defined  (HAVE_LIBGRIB_API)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
#  include <grib_api.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
7
8
9
10
#endif

#include <stdio.h>

11
12
13
#include "cdi.h"
#include "stream_int.h"
#include "gribapi.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
15
16
17

#define XSTRING(x)	#x
#define STRING(x)	XSTRING(x)

Uwe Schulzweida's avatar
Uwe Schulzweida committed
18
static char gribapi_libvers[64] = "";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
19
20
21

const char *gribapiLibraryVersion(void)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
22
23
24
25
26
27
28
29
30
31
32
33
#if  defined  (HAVE_LIBGRIB_API)
  long version = grib_get_api_version();
  int major_version, minor_version, revision_version;

  major_version    = version/10000;
  minor_version    = (version-major_version*10000)/100;
  revision_version = (version-major_version*10000-minor_version*100);

  sprintf(gribapi_libvers, "%d.%d.%d",
	  major_version, minor_version, revision_version);
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
35
  return (gribapi_libvers);
}
36
37
38
39


void gribapiDefHandles(int streamID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
40
  static char func[] = "gribapiDefHandles";
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  stream_t *streamptr = NULL;
  int vlistID, ngrids, nzaxis, i;
   
  streamptr = stream_to_pointer(streamID);

  vlistID = streamInqVlist(streamID);
  ngrids = vlistNgrids(vlistID);
  nzaxis = vlistNzaxis(vlistID);

  streamptr->gribHandleNums = ngrids*nzaxis;
  streamptr->gribHandle = (void **) malloc(streamptr->gribHandleNums*sizeof(void *));

  for ( i = 0; i < streamptr->gribHandleNums; ++i )
    streamptr->gribHandle[i] = gribHandleNew();
}