Commit 3ac32e28 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added function streamReadVarF() and streamReadVarSliceF()

parent 2ba3d58f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
2014-07-18 Uwe Schulzweida 2014-07-18 Uwe Schulzweida
* added function streamReadVarF() and streamReadVarSliceF()
* streamWriteVarF, streamWriteVarSliceF: added support for GRIB1 (cgribex) * streamWriteVarF, streamWriteVarSliceF: added support for GRIB1 (cgribex)
2014-07-17 Uwe Schulzweida 2014-07-17 Uwe Schulzweida
......
...@@ -326,6 +326,7 @@ void streamWriteVarF(int streamID, int varID, const float *data_vec, int nmis ...@@ -326,6 +326,7 @@ void streamWriteVarF(int streamID, int varID, const float *data_vec, int nmis
/* streamReadVar: Read a variable */ /* streamReadVar: Read a variable */
void streamReadVar(int streamID, int varID, double *data_vec, int *nmiss); void streamReadVar(int streamID, int varID, double *data_vec, int *nmiss);
void streamReadVarF(int streamID, int varID, float *data_vec, int *nmiss);
/* streamWriteVarSlice: Write a horizontal slice of a variable */ /* streamWriteVarSlice: Write a horizontal slice of a variable */
void streamWriteVarSlice(int streamID, int varID, int levelID, const double *data_vec, int nmiss); void streamWriteVarSlice(int streamID, int varID, int levelID, const double *data_vec, int nmiss);
...@@ -333,6 +334,7 @@ void streamWriteVarSliceF(int streamID, int varID, int levelID, const float * ...@@ -333,6 +334,7 @@ void streamWriteVarSliceF(int streamID, int varID, int levelID, const float *
/* streamReadVarSlice: Read a horizontal slice of a variable */ /* streamReadVarSlice: Read a horizontal slice of a variable */
void streamReadVarSlice(int streamID, int varID, int levelID, double *data_vec, int *nmiss); void streamReadVarSlice(int streamID, int varID, int levelID, double *data_vec, int *nmiss);
void streamReadVarSliceF(int streamID, int varID, int levelID, float *data_vec, int *nmiss);
void streamWriteVarChunk(int streamID, int varID, const int rect[][2], void streamWriteVarChunk(int streamID, int varID, const int rect[][2],
const double *data_vec, int nmiss); const double *data_vec, int nmiss);
......
...@@ -492,6 +492,16 @@ module mo_cdi ...@@ -492,6 +492,16 @@ module mo_cdi
end subroutine streamReadVar end subroutine streamReadVar
end interface end interface
interface
subroutine streamReadVarF(streamID,varID,data_vec,nmiss) bind(c,name='streamReadVarF')
import :: c_int,c_float
integer(c_int), value :: streamID
integer(c_int), value :: varID
real(c_float), intent(out),dimension(*) :: data_vec
integer(c_int), intent(out) :: nmiss
end subroutine streamReadVarF
end interface
interface interface
subroutine streamWriteVarSlice(streamID,varID,levelID,data_vec,nmiss) bind(c,name='streamWriteVarSlice') subroutine streamWriteVarSlice(streamID,varID,levelID,data_vec,nmiss) bind(c,name='streamWriteVarSlice')
import :: c_int,c_double import :: c_int,c_double
...@@ -525,6 +535,17 @@ module mo_cdi ...@@ -525,6 +535,17 @@ module mo_cdi
end subroutine streamReadVarSlice end subroutine streamReadVarSlice
end interface end interface
interface
subroutine streamReadVarSliceF(streamID,varID,levelID,data_vec,nmiss) bind(c,name='streamReadVarSliceF')
import :: c_int,c_float
integer(c_int), value :: streamID
integer(c_int), value :: varID
integer(c_int), value :: levelID
real(c_float), intent(out),dimension(*) :: data_vec
integer(c_int), intent(out) :: nmiss
end subroutine streamReadVarSliceF
end interface
interface interface
subroutine streamDefRecord(streamID,varID,levelID) bind(c,name='streamDefRecord') subroutine streamDefRecord(streamID,varID,levelID) bind(c,name='streamDefRecord')
import :: c_int import :: c_int
...@@ -3178,9 +3199,11 @@ module mo_cdi ...@@ -3178,9 +3199,11 @@ module mo_cdi
public :: streamWriteVar public :: streamWriteVar
public :: streamWriteVarF public :: streamWriteVarF
public :: streamReadVar public :: streamReadVar
public :: streamReadVarF
public :: streamWriteVarSlice public :: streamWriteVarSlice
public :: streamWriteVarSliceF public :: streamWriteVarSliceF
public :: streamReadVarSlice public :: streamReadVarSlice
public :: streamReadVarSliceF
public :: streamDefRecord public :: streamDefRecord
public :: streamInqRecord public :: streamInqRecord
public :: streamWriteRecord public :: streamWriteRecord
......
...@@ -1468,24 +1468,9 @@ int streamInqTimestep(int streamID, int tsID) ...@@ -1468,24 +1468,9 @@ int streamInqTimestep(int streamID, int tsID)
return (nrecs); return (nrecs);
} }
/* /* the single image implementation */
@Function streamReadVar static
@Title Read a variable void cdiStreamReadVar(int streamID, int varID, int memtype, void *data, int *nmiss)
@Prototype void streamReadVar(int streamID, int varID, double *data, int *nmiss)
@Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenRead}.
@Item varID Variable identifier.
@Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values.
@Description
The function streamReadVar reads all the values of one time step of a variable
from an open dataset.
@EndFunction
*/
void streamReadVar(int streamID, int varID, double *data, int *nmiss)
{ {
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
...@@ -1506,6 +1491,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1506,6 +1491,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
case FILETYPE_GRB: case FILETYPE_GRB:
case FILETYPE_GRB2: case FILETYPE_GRB2:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("grbReadVar not implemented for memtype float!");
grbReadVarDP(streamptr, varID, data, nmiss); grbReadVarDP(streamptr, varID, data, nmiss);
break; break;
} }
...@@ -1513,6 +1499,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1513,6 +1499,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
#if defined (HAVE_LIBSERVICE) #if defined (HAVE_LIBSERVICE)
case FILETYPE_SRV: case FILETYPE_SRV:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("srvReadVar not implemented for memtype float!");
srvReadVarDP(streamptr, varID, data, nmiss); srvReadVarDP(streamptr, varID, data, nmiss);
break; break;
} }
...@@ -1520,6 +1507,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1520,6 +1507,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
#if defined (HAVE_LIBEXTRA) #if defined (HAVE_LIBEXTRA)
case FILETYPE_EXT: case FILETYPE_EXT:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("extReadVar not implemented for memtype float!");
extReadVarDP(streamptr, varID, data, nmiss); extReadVarDP(streamptr, varID, data, nmiss);
break; break;
} }
...@@ -1527,6 +1515,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1527,6 +1515,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
#if defined (HAVE_LIBIEG) #if defined (HAVE_LIBIEG)
case FILETYPE_IEG: case FILETYPE_IEG:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("iegReadVar not implemented for memtype float!");
iegReadVarDP(streamptr, varID, data, nmiss); iegReadVarDP(streamptr, varID, data, nmiss);
break; break;
} }
...@@ -1537,6 +1526,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1537,6 +1526,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
case FILETYPE_NC4: case FILETYPE_NC4:
case FILETYPE_NC4C: case FILETYPE_NC4C:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("cdfReadVar not implemented for memtype float!");
cdfReadVarDP(streamptr, varID, data, nmiss); cdfReadVarDP(streamptr, varID, data, nmiss);
break; break;
} }
...@@ -1549,36 +1539,52 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) ...@@ -1549,36 +1539,52 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
} }
} }
/*
@Function streamReadVar
@Title Read a variable
@Prototype void streamReadVar(int streamID, int varID, double *data, int *nmiss)
@Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenRead}.
@Item varID Variable identifier.
@Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values.
@Description
The function streamReadVar reads all the values of one time step of a variable
from an open dataset.
@EndFunction
*/
void streamReadVar(int streamID, int varID, double *data, int *nmiss)
{
cdiStreamReadVar(streamID, varID, MEMTYPE_DOUBLE, data, nmiss);
}
/* /*
@Function streamWriteVar @Function streamReadVarF
@Title Write a variable @Title Read a variable
@Prototype void streamWriteVar(int streamID, int varID, const double *data, int nmiss) @Prototype void streamReadVar(int streamID, int varID, float *data, int *nmiss)
@Parameter @Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenWrite}. @Item streamID Stream ID, from a previous call to @fref{streamOpenRead}.
@Item varID Variable identifier. @Item varID Variable identifier.
@Item data Pointer to a block of double precision floating point data values to be written. @Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values. @Item nmiss Number of missing values.
@Description @Description
The function streamWriteVar writes the values of one time step of a variable to an open dataset. The function streamReadVar reads all the values of one time step of a variable
The values are converted to the external data type of the variable, if necessary. from an open dataset.
@EndFunction @EndFunction
*/ */
void streamWriteVar(int streamID, int varID, const double *data, int nmiss) void streamReadVarF(int streamID, int varID, float *data, int *nmiss)
{ {
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype, cdiStreamReadVar(streamID, varID, MEMTYPE_FLOAT, data, nmiss);
const void *data, int nmiss)
= (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_DOUBLE, data, nmiss);
} }
/* the single image implementation */ /* the single image implementation */
void void cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, int nmiss)
cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data,
int nmiss)
{ {
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
...@@ -1647,50 +1653,58 @@ cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, ...@@ -1647,50 +1653,58 @@ cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data,
} }
/* /*
@Function streamWriteVarF @Function streamWriteVar
@Title Write a variable @Title Write a variable
@Prototype void streamWriteVarF(int streamID, int varID, const float *data, int nmiss) @Prototype void streamWriteVar(int streamID, int varID, const double *data, int nmiss)
@Parameter @Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenWrite}. @Item streamID Stream ID, from a previous call to @fref{streamOpenWrite}.
@Item varID Variable identifier. @Item varID Variable identifier.
@Item data Pointer to a block of single precision floating point data values to be written. @Item data Pointer to a block of double precision floating point data values to be written.
@Item nmiss Number of missing values. @Item nmiss Number of missing values.
@Description @Description
The function streamWriteVarF writes the values of one time step of a variable to an open dataset. The function streamWriteVar writes the values of one time step of a variable to an open dataset.
The values are converted to the external data type of the variable, if necessary. The values are converted to the external data type of the variable, if necessary.
Only support for netCDF was implemented in this function.
@EndFunction @EndFunction
*/ */
void streamWriteVarF(int streamID, int varID, const float *data, int nmiss) void streamWriteVar(int streamID, int varID, const double *data, int nmiss)
{ {
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype, void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss) const void *data, int nmiss)
= (void (*)(int, int, int, const void *, int)) = (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func; namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_FLOAT, data, nmiss); myCdiStreamWriteVar_(streamID, varID, MEMTYPE_DOUBLE, data, nmiss);
} }
/* /*
@Function streamReadVarSlice @Function streamWriteVarF
@Title Read a horizontal slice of a variable @Title Write a variable
@Prototype void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss) @Prototype void streamWriteVarF(int streamID, int varID, const float *data, int nmiss)
@Parameter @Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenRead}. @Item streamID Stream ID, from a previous call to @fref{streamOpenWrite}.
@Item varID Variable identifier. @Item varID Variable identifier.
@Item levelID Level identifier. @Item data Pointer to a block of single precision floating point data values to be written.
@Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values. @Item nmiss Number of missing values.
@Description @Description
The function streamReadVar reads all the values of a horizontal slice of a variable The function streamWriteVarF writes the values of one time step of a variable to an open dataset.
from an open dataset. The values are converted to the external data type of the variable, if necessary.
Only support for netCDF was implemented in this function.
@EndFunction @EndFunction
*/ */
void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss) void streamWriteVarF(int streamID, int varID, const float *data, int nmiss)
{
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss)
= (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_FLOAT, data, nmiss);
}
static
void cdiStreamReadVarSlice(int streamID, int varID, int levelID, int memtype, void *data, int *nmiss)
{ {
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
...@@ -1711,6 +1725,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1711,6 +1725,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
case FILETYPE_GRB: case FILETYPE_GRB:
case FILETYPE_GRB2: case FILETYPE_GRB2:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("grbReadVarSlice not implemented for memtype float!");
grbReadVarSliceDP(streamptr, varID, levelID, data, nmiss); grbReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
break; break;
} }
...@@ -1718,6 +1733,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1718,6 +1733,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
#if defined (HAVE_LIBSERVICE) #if defined (HAVE_LIBSERVICE)
case FILETYPE_SRV: case FILETYPE_SRV:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("srvReadVarSlice not implemented for memtype float!");
srvReadVarSliceDP(streamptr, varID, levelID, data, nmiss); srvReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
break; break;
} }
...@@ -1725,6 +1741,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1725,6 +1741,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
#if defined (HAVE_LIBEXTRA) #if defined (HAVE_LIBEXTRA)
case FILETYPE_EXT: case FILETYPE_EXT:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("extReadVarSlice not implemented for memtype float!");
extReadVarSliceDP(streamptr, varID, levelID, data, nmiss); extReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
break; break;
} }
...@@ -1732,6 +1749,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1732,6 +1749,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
#if defined (HAVE_LIBIEG) #if defined (HAVE_LIBIEG)
case FILETYPE_IEG: case FILETYPE_IEG:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("iegReadVarSlice not implemented for memtype float!");
iegReadVarSliceDP(streamptr, varID, levelID, data, nmiss); iegReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
break; break;
} }
...@@ -1742,6 +1760,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1742,6 +1760,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
case FILETYPE_NC4: case FILETYPE_NC4:
case FILETYPE_NC4C: case FILETYPE_NC4C:
{ {
if ( memtype == MEMTYPE_FLOAT ) Error("cdfReadVarSlice not implemented for memtype float!");
/* FIXME: status value ignored */ /* FIXME: status value ignored */
int ierr = cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss); int ierr = cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
break; break;
...@@ -1755,8 +1774,54 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int ...@@ -1755,8 +1774,54 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
} }
} }
/*
@Function streamReadVarSlice
@Title Read a horizontal slice of a variable
@Prototype void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss)
@Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenRead}.
@Item varID Variable identifier.
@Item levelID Level identifier.
@Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values.
@Description
The function streamReadVarSlice reads all the values of a horizontal slice of a variable
from an open dataset.
@EndFunction
*/
void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss)
{
cdiStreamReadVarSlice(streamID, varID, levelID, MEMTYPE_DOUBLE, data, nmiss);
}
/*
@Function streamReadVarSliceF
@Title Read a horizontal slice of a variable
@Prototype void streamReadVarSliceF(int streamID, int varID, int levelID, float *data, int *nmiss)
@Parameter
@Item streamID Stream ID, from a previous call to @fref{streamOpenRead}.
@Item varID Variable identifier.
@Item levelID Level identifier.
@Item data Pointer to the location into which the data values are read.
The caller must allocate space for the returned values.
@Item nmiss Number of missing values.
@Description
The function streamReadVarSliceF reads all the values of a horizontal slice of a variable
from an open dataset.
@EndFunction
*/
void streamReadVarSliceF(int streamID, int varID, int levelID, float *data, int *nmiss)
{
cdiStreamReadVarSlice(streamID, varID,levelID, MEMTYPE_FLOAT, data, nmiss);
}
static static
void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss) void cdiStreamWriteVarSlice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss)
{ {
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
...@@ -1844,7 +1909,7 @@ The values are converted to the external data type of the variable, if necessary ...@@ -1844,7 +1909,7 @@ The values are converted to the external data type of the variable, if necessary
*/ */
void streamWriteVarSlice(int streamID, int varID, int levelID, const double *data, int nmiss) void streamWriteVarSlice(int streamID, int varID, int levelID, const double *data, int nmiss)
{ {
stream_write_var_slice(streamID, varID, levelID, MEMTYPE_DOUBLE, data, nmiss); cdiStreamWriteVarSlice(streamID, varID, levelID, MEMTYPE_DOUBLE, data, nmiss);
} }
/* /*
...@@ -1867,7 +1932,7 @@ Only support for netCDF was implemented in this function. ...@@ -1867,7 +1932,7 @@ Only support for netCDF was implemented in this function.
*/ */
void streamWriteVarSliceF(int streamID, int varID, int levelID, const float *data, int nmiss) void streamWriteVarSliceF(int streamID, int varID, int levelID, const float *data, int nmiss)
{ {
stream_write_var_slice(streamID, varID, levelID, MEMTYPE_FLOAT, data, nmiss); cdiStreamWriteVarSlice(streamID, varID, levelID, MEMTYPE_FLOAT, data, nmiss);
} }
......
...@@ -619,7 +619,7 @@ int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype ...@@ -619,7 +619,7 @@ int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype
} }
} }
nbytes = grbEncode(filetype, memtype, varID, levelID, vlistID, gridID, zaxisID, date, time, tsteptype, numavg, nbytes = grbEncode(filetype, memtype, varID, levelID, vlistID, gridID, zaxisID, date, time, tsteptype, numavg,
datasize, (const double*) data, nmiss, &gribbuffer, ljpeg, gc); datasize, (const double*) data, nmiss, &gribbuffer, ljpeg, gc);
if ( streamptr->comptype == COMPRESS_SZIP ) if ( streamptr->comptype == COMPRESS_SZIP )
......
Markdown is supported
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