Commit 51433d1d authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

cdi and tests now compile in c++

parents c2ce442d 3fa82ee1
......@@ -884,6 +884,7 @@ enable_iso_c_interface
enable_swig
enable_ruby
enable_python
enable_cf_interface
'
ac_precious_vars='build_alias
host_alias
......@@ -1578,6 +1579,7 @@ Optional Features:
(EXPERIMENTAL)
--enable-ruby ruby language bindings [default=no] (EXPERIMENTAL)
--enable-python python language bindings [default=no] (EXPERIMENTAL)
--disable-cf-interface Omit building of cfortran Interface
 
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
......@@ -30103,6 +30105,17 @@ else
CREATE_INTERFACES_FALSE=
fi
 
# ----------------------------------------------------------------------
# Create the CDI Fortran77 Interface via cfortran.h
# Check whether --enable-cf-interface was given.
if test "${enable_cf_interface+set}" = set; then :
enableval=$enable_cf_interface; enable_cfinterface=${enableval}
else
enable_cfinterface=yes
fi
if test "x${enable_cfinterface}" = "xyes"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking C preprocessor flags for Fortran calling convention cfortran.h" >&5
$as_echo_n "checking C preprocessor flags for Fortran calling convention cfortran.h... " >&6; }
if ${acx_cv_cf_flag+:} false; then :
......@@ -30524,6 +30537,8 @@ $as_echo "$as_me: Disabling cfortran.h bindings generation" >&6;}
acx_cv_cfortran_works=no
fi
 
fi
fi
if test -n "$FC" -a X"$FC" != Xno -a x"$acx_cv_cfortran_works" = xyes; then
USE_FC_TRUE=
......@@ -316,6 +316,13 @@ AM_CONDITIONAL(ENABLE_PYTHON, [test "x$enable_python" != "xno"])
AS_IF([test "x$enable_python" != "xno"],[AC_SUBST([ENABLE_PYTHON],[true])],[AC_SUBST([ENABLE_PYTHON],[false])])
# ----------------------------------------------------------------------
AM_CONDITIONAL(CREATE_INTERFACES, [test "x$enable_ruby" = "xyes" -o "x$enable_python" = "xyes"])
# ----------------------------------------------------------------------
# Create the CDI Fortran77 Interface via cfortran.h
AC_ARG_ENABLE([cf-interface],
[AS_HELP_STRING([--disable-cf-interface],
[Omit building of cfortran Interface])],
[enable_cfinterface=${enableval}],[enable_cfinterface=yes])
AS_IF([test "x${enable_cfinterface}" = "xyes"], [
dnl ######################################################################
dnl Test whether cfortran.h works correctly
dnl ######################################################################
......@@ -335,6 +342,7 @@ AS_IF([test -n "$FC" -a X"$FC" != Xno -o -n "$F77" -a X"$F77" != Xno],
[AC_MSG_NOTICE([Unexpected error when linking C and Fortran via cfortran.h!])])
AC_MSG_NOTICE([Disabling cfortran.h bindings generation])
acx_cv_cfortran_works=no])])
])
AM_CONDITIONAL([USE_FC],[test -n "$FC" -a X"$FC" != Xno -a x"$acx_cv_cfortran_works" = xyes])dnl
dnl
AC_SUBST([CPPFLAGS])dnl
......
......@@ -990,6 +990,16 @@ Define the parameter number of a Variable.
Define the standard name of a Variable.
\section*{\tt \htmlref{vlistDefVarTiles}{vlistDefVarTiles}}
\begin{verbatim}
int vlistDefVarTiles (int vlistID, int gridID, int zaxisID, int tsteptype,
int tilesetID);
\end{verbatim}
Create a new tile-based variable.
\section*{\tt \htmlref{vlistDefVarUnits}{vlistDefVarUnits}}
\begin{verbatim}
......
......@@ -1002,6 +1002,17 @@ Define the parameter number of a Variable.
Define the standard name of a Variable.
\section*{\tt \htmlref{vlistDefVarTiles}{vlistDefVarTiles}}
\begin{verbatim}
INTEGER FUNCTION vlistDefVarTiles (INTEGER vlistID, INTEGER gridID,
INTEGER zaxisID, INTEGER tsteptype,
INTEGER tilesetID)
\end{verbatim}
Create a new tile-based variable.
\section*{\tt \htmlref{vlistDefVarUnits}{vlistDefVarUnits}}
\begin{verbatim}
......
......@@ -367,10 +367,10 @@ void cdiStreamGetIndexList(unsigned numIDs, int IDs[]);
void cdiInitialize(void);
void uuid2str(const unsigned char *uuid, char *uuidstr);
int str2uuid(const char *uuidstr, unsigned char *uuid);
void uuid2str(const unsigned char uuid[], char uuidstr[]);
int str2uuid(const char *uuidstr, unsigned char uuid[]);
static inline int cdiUUIDIsNull(const unsigned char *uuid)
static inline int cdiUUIDIsNull(const unsigned char uuid[])
{
int isNull = 1;
for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
......
......@@ -319,7 +319,7 @@ decodeForm2(char *pline, char *name, char *longname, char *units)
return (0);
}
int tableRead(char *tablefile)
int tableRead(const char *tablefile)
{
char line[1024], *pline;
int lnr = 0;
......@@ -333,7 +333,7 @@ int tableRead(char *tablefile)
tablefp = fopen(tablefile, "r");
if ( tablefp == NULL ) return (tableID);
tablename = strrchr(tablefile, '/');
tablename = (char* )strrchr(tablefile, '/');
if ( tablename == 0 ) tablename = (char *) tablefile;
else tablename++;
......
......@@ -1063,7 +1063,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
// };
if ((zaxisglobdefined
= (cdiResHFilterApply(&zaxisOps, varDefZAxisSearch, &query)
= (cdiResHFilterApply(getZaxisOps(), varDefZAxisSearch, &query)
== CDI_APPLY_STOP)))
zaxisID = query.resIDValue;
......
......@@ -103,6 +103,11 @@ const resOps zaxisOps = {
zaxisTxCode
};
const resOps *getZaxisOps()
{
return &zaxisOps;
}
static int ZAXIS_Debug = 0; /* If set to 1, debugging */
void zaxisGetTypeDescription(int zaxisType, int* outPositive, const char** outName, const char** outLongName, const char** outStdName, const char** outUnit)
......
......@@ -14,6 +14,8 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
void zaxisDefLtype2(int zaxisID, int ltype2);
extern const resOps zaxisOps;
const resOps *getZaxisOps();
//extern const resOps zaxisOps;
#endif
......@@ -22,8 +22,8 @@ main()
{
unsigned char *test_data, *init_block;
size_t num_blocks = 1000;
if (!(init_block = calloc(block_size * block_size, 1U))
|| !(test_data = calloc((size_t)block_size * num_blocks, 1U)))
if (!(init_block = (unsigned char *)calloc(block_size * block_size, 1U))
|| !(test_data = (unsigned char *)calloc((size_t)block_size * num_blocks, 1U)))
return EXIT_FAILURE;
/* this is supposed to be non-random */
srand48(5L);
......
......@@ -46,7 +46,7 @@ fname_create(const char *prefix, const char *suffix)
{
size_t prefix_len, suffix_len;
char *fname;
if (!(fname = malloc((prefix_len = strlen(prefix)) + 1
if (!(fname = (char *)malloc((prefix_len = strlen(prefix)) + 1
+ (suffix_len = strlen(suffix)) + 1)))
allocError("cannot create string");
strcpy(fname, prefix);
......@@ -189,13 +189,13 @@ main(int argc, char *argv[])
}
}
lons = malloc((size_t)nlon * sizeof (lons[0]));
lons = (double *)malloc((size_t)nlon * sizeof (lons[0]));
for (i = 0; i < nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
lats = malloc((size_t)nlat * sizeof (lats[0]));
lats = (double *)malloc((size_t)nlat * sizeof (lats[0]));
for (i = 0; i < nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
levs = malloc((size_t)nlev * sizeof (levs[0]));
levs = (double *)malloc((size_t)nlev * sizeof (levs[0]));
for (i = 0; i < nlev; ++i)
levs[i] = 101300 - floor(3940.3 * (exp(2.3579 * (double)(i)/(nlev - 1)) - 1.0));
......@@ -255,7 +255,7 @@ main(int argc, char *argv[])
// and set the data type
vlistDefVarDatatype(vlistID, varID[i], datatype);
// create memory for variables
var[i] = malloc(varSize[i] * sizeof (var[i][0]));
var[i] = (double *)malloc(varSize[i] * sizeof (var[i][0]));
}
var_scale(datatype, &mscale, &mrscale);
......@@ -330,7 +330,7 @@ main(int argc, char *argv[])
{
size_t maxChunkSize
= ((size_t)nlon + 1)/2 * (size_t)nlat * (size_t)nlev;
double *chunkBuf = malloc(maxChunkSize * sizeof (double));
double *chunkBuf = (double *)malloc(maxChunkSize * sizeof (double));
int varShape[2][3] = { { nlon, nlat, 1 }, { nlon, nlat, nlev } },
chunk[3][2] = { { 0, nlon/2 - 1 }, { 0, nlat - 1 }, { 0, 0 } };
if (!chunkBuf)
......
......@@ -75,7 +75,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
{
static const char * const fname_prefix = "example";
struct
struct varDesc_t
{
size_t size;
int nlev, zaxisID, id, code;
......@@ -111,7 +111,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
if (rank == 0 && setup.compute_checksum)
{
var = xmalloc((size_t)nlon * (size_t)nlat
var = (double *)xmalloc((size_t)nlon * (size_t)nlat
* (size_t)setup.max_nlev * sizeof(var[0]));
}
......@@ -138,10 +138,10 @@ modelRun(struct model_config setup, MPI_Comm comm)
gridID = gridCreate ( GRID_LONLAT, nlon*nlat );
gridDefXsize ( gridID, nlon );
gridDefYsize ( gridID, nlat );
lons = xmalloc((size_t)nlon * sizeof (lons[0]));
lons = (double *)xmalloc((size_t)nlon * sizeof (lons[0]));
for (i = 0; i < nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
lats = xmalloc((size_t)nlat * sizeof (lats[0]));
lats = (double *)xmalloc((size_t)nlat * sizeof (lats[0]));
for (i = 0; i < nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefXvals ( gridID, lons );
......@@ -155,7 +155,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
#endif
gridDefUUID(gridID, uuid);
}
levs = xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
levs = (double *)xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
{
double lscale = 1.0/(double)(setup.max_nlev - 1);
for (i = 0; i < setup.max_nlev; ++i)
......@@ -163,7 +163,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
}
vlistID = vlistCreate ();
varDesc = xmalloc((size_t)nVars * sizeof (varDesc[0]));
varDesc = (struct varDesc_t *)xmalloc((size_t)nVars * sizeof (varDesc[0]));
for (int varIdx = 0; varIdx < nVars; varIdx++ )
{
int varLevs = (int)random()%4;
......@@ -333,7 +333,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
/ (size_t)nproma) * (size_t)nproma * varLevs;
if (varslice_size < chunkSize)
{
varslice = xrealloc(varslice, chunkSize * sizeof (var[0]));
varslice = (double *)xrealloc(varslice, chunkSize * sizeof (var[0]));
varslice_size = chunkSize;
}
modelRegionCompute(varslice, (int)varLevs, nlat, nlon,
......
......@@ -30,12 +30,16 @@ void
modelRun(struct model_config setup, MPI_Comm comm);
static const struct model_config default_setup
#ifdef __cplusplus
= { 12, 6, 3, 5, 5, FILETYPE_GRB, DATATYPE_PACK24,1,"grb"};
#else
= { .nlon = 12, .nts = 3, .nlat = 6, .nvars = 5,
.filetype = FILETYPE_GRB, .datatype = DATATYPE_PACK24,
.compute_checksum = 1,
.suffix = "grb",
.max_nlev = 5,
};
#endif
#ifdef USE_MPI
static const struct {
......
......@@ -63,7 +63,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
{
static const char * const fname_prefix = "example";
struct
struct varDesc_t
{
size_t size;
int nlev, zaxisID, id, code;
......@@ -106,10 +106,10 @@ modelRun(struct model_config setup, MPI_Comm comm)
gridID = gridCreate ( GRID_LONLAT, nlon*nlat );
gridDefXsize ( gridID, nlon );
gridDefYsize ( gridID, nlat );
lons = xmalloc((size_t)nlon * sizeof (lons[0]));
lons = (double *)xmalloc((size_t)nlon * sizeof (lons[0]));
for (i = 0; i < nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
lats = xmalloc((size_t)nlat * sizeof (lats[0]));
lats = (double *)xmalloc((size_t)nlat * sizeof (lats[0]));
for (i = 0; i < nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefXvals ( gridID, lons );
......@@ -123,7 +123,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
#endif
gridDefUUID(gridID, uuid);
}
levs = xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
levs = (double *)xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
{
double lscale = 1.0/(double)(setup.max_nlev - 1);
for (i = 0; i < setup.max_nlev; ++i)
......@@ -131,7 +131,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
}
vlistID = vlistCreate ();
varDesc = xmalloc((size_t)nVars * sizeof (varDesc[0]));
varDesc = (struct varDesc_t *)xmalloc((size_t)nVars * sizeof (varDesc[0]));
for (int varIdx = 0; varIdx < nVars; varIdx++ )
{
int varLevs = (int)random()%4;
......@@ -250,7 +250,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
#endif
if (varslice_size < (size_t)chunk)
{
varslice = xrealloc(varslice, (size_t)chunk * sizeof (var[0]));
varslice = (double *)xrealloc(varslice, (size_t)chunk * sizeof (var[0]));
varslice_size = (size_t)chunk;
}
modelRegionCompute(varslice, (size_t)start, (size_t)chunk,
......
......@@ -16,7 +16,7 @@ cksum_stream(const char *fname, size_t *table_len)
int nvars, ngrids, nzaxis;
int i;
uint32_t *checksum_state = NULL;
struct
struct var_size_t
{
int x, y, z;
size_t chars;
......@@ -49,8 +49,8 @@ cksum_stream(const char *fname, size_t *table_len)
nvars = -1;
break;
}
checksum_state = xcalloc((size_t)nvars, sizeof (checksum_state[0]));
varSize = xmalloc((size_t)nvars * sizeof (varSize[0]));
checksum_state = (uint32_t *)xcalloc((size_t)nvars, sizeof (checksum_state[0]));
varSize = (struct var_size_t *)xmalloc((size_t)nvars * sizeof (varSize[0]));
for (i = 0; i < nvars; ++i)
{
......@@ -95,7 +95,7 @@ cksum_stream(const char *fname, size_t *table_len)
if (var_size_max_chars < varSize[i].chars)
var_size_max_chars = varSize[i].chars;
}
buf = xmalloc(var_size_max_chars);
buf = (double*)malloc(var_size_max_chars);
if (nvars == -1)
break;
......@@ -121,7 +121,7 @@ cksum_stream(const char *fname, size_t *table_len)
++tsID;
}
file_vars = xmalloc((size_t)nvars * sizeof (file_vars[0]));
file_vars = (struct cksum_table *)xmalloc((size_t)nvars * sizeof (file_vars[0]));
for (i = 0; i < nvars; ++i)
{
file_vars[i].code = vlistInqVarCode(vlistID, i);
......
......@@ -44,7 +44,7 @@ int main(int argc, const char **argv)
int nmiss;
if (memSize > bufSize)
{
double *temp = realloc(buf, memSize);
double *temp = (double *)realloc(buf, memSize);
if (!temp)
{
perror("read buffer reallocation failed");
......@@ -89,14 +89,18 @@ printAtts(int vlistID)
attName, &attType, &attLen);
{
const char *varDesc = varIdx > 0
? (sprintf(buf, "%s%d", varDescPrefix,
vlistInqVarCode(vlistID, varID)), buf)
? (sprintf((char *)buf, "%s%d", varDescPrefix,
vlistInqVarCode(vlistID, varID)), (char *)buf)
: globDesc;
printf("%s attribute \"%s\", value: ",
varDesc, attName);
}
if (attLen < 0)
goto attGetFail;
{
//goto attGetFail;
puts("error retrieving value");
continue;
}
size_t elemSize = 0;
switch (attType)
{
......@@ -125,16 +129,16 @@ printAtts(int vlistID)
{
case DATATYPE_TXT:
rc = vlistInqAttTxt(vlistID, (int)varID, attName,
attLen, buf);
attLen, (char *)buf);
if (rc == CDI_NOERR)
printf("\"%.*s\"", attLen, (char *)buf);
break;
case DATATYPE_FLT:
rc = vlistInqAttFlt(vlistID, (int)varID, attName,
attLen + 1, buf);
attLen + 1, (double *)buf);
if (rc == CDI_NOERR && attLen)
{
const double *restrict dp = buf;
const double *restrict dp = (const double*)buf;
printf("%10g", dp[0]);
for (size_t i = 1; i < (size_t)attLen; ++i)
printf(", %10g", dp[i]);
......@@ -142,10 +146,10 @@ printAtts(int vlistID)
break;
case DATATYPE_INT:
rc = vlistInqAttInt(vlistID, (int)varID, attName,
attLen + 1, buf);
attLen + 1, (int *)buf);
if (rc == CDI_NOERR && attLen)
{
const int *restrict ip = buf;
const int *restrict ip = (const int *)buf;
printf("%d", ip[0]);
for (size_t i = 1; i < (size_t)attLen; ++i)
printf(", %d", ip[i]);
......@@ -159,7 +163,7 @@ printAtts(int vlistID)
}
else
{
attGetFail:
//attGetFail:
puts("error retrieving value");
}
}
......
......@@ -50,10 +50,17 @@ int main(int argc, const char **argv)
{
/* anti-clockwise coordinates around Amazonia */
static struct cart_coord region[4]
= { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
#ifdef __cplusplus
= { { DEG2RAD(-25.0), DEG2RAD(-85.0) },
{ DEG2RAD(-18.0), DEG2RAD(-44.0) },
{ DEG2RAD(-7.0), DEG2RAD(-50.0) },
{ DEG2RAD(10.0), DEG2RAD(-80.0) } };
#else
= { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
{ .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
{ .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
{ .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
#endif
double (*gridCoords)[sizey][sizex]
= (double (*)[sizey][sizex])
malloc(sizeof (*gridCoords) * sizey * sizex * 2);
......@@ -87,7 +94,7 @@ int main(int argc, const char **argv)
(void)streamDefTimestep(streamID, 0);
{
double (*data)[sizex] = malloc(sizeof (**data) * sizex * sizey);
double (*data)[sizex] = (double(*)[80])malloc(sizeof (**data) * sizex * sizey);
if (!data)
{
perror("data values memory allocation failed");
......
......@@ -222,7 +222,7 @@ int modelRun(MPI_Comm comm)
}
reshPackBufferCreate ( &sendBuffer, &bufferSize, &comm );
recvBuffer = xmalloc((size_t)bufferSize);
recvBuffer = (char *)xmalloc((size_t)bufferSize);
#ifdef MPI_MARSHALLING
xmpi(MPI_Sendrecv(sendBuffer, bufferSize, MPI_PACKED, 0, 0,
recvBuffer, bufferSize, MPI_PACKED, 0, 0,
......
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