Commit 49cabaf5 authored by Deike Kleberg's avatar Deike Kleberg
Browse files

Encoding for namespace and index, use feature in grid.c and zaxis.c.

parent f9658f13
......@@ -61,7 +61,7 @@ void modelRun ()
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
double var1[nlon*nlat];
double var2[nlon*nlat*nlev];
int gridID2, gridID3;
int gridID2, gridID3, zaxisID3;
if ( ddebug >= 3 ) xdebug ( fnName );
......@@ -102,8 +102,8 @@ void modelRun ()
// Test namespaces: Create a 2. zaxis list
namespaceSetActive ( 1 );
zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, 3);
zaxisDefLevels(zaxisID2, levs);
zaxisID3 = zaxisCreate(ZAXIS_PRESSURE, 3);
zaxisDefLevels(zaxisID3, levs);
zaxisTestNamespace ();
namespaceSetActive ( 0 );
......
......@@ -50,6 +50,7 @@ libcdi_la_SOURCES = \
institution.c \
model.c \
namespace.c \
namespace.h \
pio.c \
pio.h \
pio_c_temp.h \
......
......@@ -300,6 +300,7 @@ libcdi_la_SOURCES = \
institution.c \
model.c \
namespace.c \
namespace.h \
pio.c \
pio.h \
pio_c_temp.h \
......
......@@ -10,6 +10,7 @@
#include "grid.h"
#include "gaussgrid.h"
#include "pio_util.h"
#include "namespace.h"
#ifndef RAD2DEG
......@@ -140,7 +141,8 @@ void grid_list_delete(void)
static
void grid_init_pointer(void)
{
int nnsp, i, j;
int nnsp, i, j, code;
namespaceTuple_t nspt;
nnsp = namespaceGetNumber ();
......@@ -148,8 +150,11 @@ void grid_init_pointer(void)
{
for ( j = 0; j < _grid_max; j++ )
{
nspt.nsp = i;
nspt.idx = j;
code = namespaceIdxEncode ( nspt );
_gridList[i][j].next = _gridList[i] + j + 1;
_gridList[i][j].idx = j;
_gridList[i][j].idx = code;
_gridList[i][j].ptr = 0;
}
......@@ -164,21 +169,29 @@ grid_t *grid_to_pointer(int idx)
{
grid_t *gridptr = NULL;
int nsp;
namespaceTuple_t nspT;
nsp = namespaceGetActive ();
nspT = namespaceIdxDecode ( idx );
if ( nspT.nsp != nsp )
Error ( "idx %d from namespace %d not available in active namespace %d !\n",
idx, nspT.nsp, nsp );
GRID_INIT();
if ( idx >= 0 && idx < _grid_max )
if ( nspT.idx >= 0 && nspT.idx < _grid_max )
{
GRID_LOCK();
gridptr = _gridList[nsp][idx].ptr;
gridptr = _gridList[nsp][nspT.idx].ptr;
GRID_UNLOCK();
}
else
Error("grid index %d undefined!", idx);
Error("grid index %d undefined!", nspT.idx);
return (gridptr);
}
......
#include <stdlib.h>
#include <stdio.h>
#include "cdi.h"
#include "namespace.h"
enum { MAX_NAMESPACES = 16 };
......@@ -7,6 +9,40 @@ static int nNamespaces = 1;
static int activeNamespace;
void namespaceShowbits ( int n, char *name )
{
int i, bit = 0, andmask;
fprintf (stdout, "%s: ", name );
for ( i = 0; i < 32; i++ )
{
andmask = 1 << i;
bit = n & andmask;
fprintf ( stdout, "%d", bit == 0 ? 0 : 1 );
}
fprintf (stdout, "\n" );
}
int namespaceIdxEncode ( namespaceTuple_t tin )
{
return ( tin.nsp << 28 ) + tin.idx;
}
namespaceTuple_t namespaceIdxDecode ( int code )
{
namespaceTuple_t tin;
tin.idx = code & ~( 15 << 28 );
tin.nsp = ( code & ( 15 << 28 )) >> 28;
return tin;
}
void namespaceSetNumber ( int nspn )
{
if ( nspn > MAX_NAMESPACES || nspn <= 1 )
......@@ -29,6 +65,7 @@ void namespaceSetActive ( int nId )
activeNamespace = nId;
}
int namespaceGetActive ()
{
return activeNamespace;
......
......@@ -11,6 +11,7 @@
#include "cdi.h"
#include "stream_int.h"
#include "pio_util.h"
#include "namespace.h"
static struct {
......@@ -156,7 +157,8 @@ void zaxis_list_delete(void)
static
void zaxis_init_pointer(void)
{
int nnsp, i, j;
int nnsp, i, j, code;
namespaceTuple_t nspt;
nnsp = namespaceGetNumber ();
......@@ -164,8 +166,11 @@ void zaxis_init_pointer(void)
{
for ( j = 0; j < _zaxis_max; j++ )
{
nspt.nsp = i;
nspt.idx = j;
code = namespaceIdxEncode ( nspt );
_zaxisList[i][j].next = _zaxisList[i] + j + 1;
_zaxisList[i][j].idx = j;
_zaxisList[i][j].idx = code;
_zaxisList[i][j].ptr = 0;
}
......@@ -180,21 +185,28 @@ zaxis_t *zaxis_to_pointer(int idx)
{
zaxis_t *zaxisptr = NULL;
int nsp;
namespaceTuple_t nspT;
nsp = namespaceGetActive ();
nspT = namespaceIdxDecode ( idx );
if ( nspT.nsp != nsp )
Error ( "idx %d from namespace %d not available in active namespace %d !\n",
idx, nspT.nsp, nsp );
ZAXIS_INIT();
if ( idx >= 0 && idx < _zaxis_max )
if ( nspT.idx >= 0 && nspT.idx < _zaxis_max )
{
ZAXIS_LOCK();
zaxisptr = _zaxisList[nsp][idx].ptr;
zaxisptr = _zaxisList[nsp][nspT.idx].ptr;
ZAXIS_UNLOCK();
}
else
Error("zaxis index %d undefined!", idx);
Error("zaxis index %d undefined!", nspT.idx);
return (zaxisptr);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment