Commit d05725bc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added pio_util.c pio_util.h

parent a1018ceb
......@@ -183,6 +183,8 @@ src/make_cdilib -text
src/make_fint.c -text
src/mo_cdi.f90 -text
src/model.c -text
src/pio_util.c -text
src/pio_util.h -text
src/pkgconfig/cdi.pc.in -text
src/service.h -text
src/servicelib.c -text
......
......@@ -49,6 +49,8 @@ libcdi_la_SOURCES = \
ieglib.c \
institution.c \
model.c \
pio_util.c \
pio_util.h \
service.h \
servicelib.c \
stream_cdf.c \
......
......@@ -89,12 +89,13 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
cdf_int.lo cdi_error.lo cdi_util.lo cdiFortran.lo \
cgribexlib.lo dmemory.lo error.lo extralib.lo file.lo \
gaussgrid.lo gribapi.lo grid.lo ieglib.lo institution.lo \
model.lo servicelib.lo stream_cdf.lo stream_cgribex.lo \
stream_ext.lo stream_grb.lo stream_gribapi.lo \
stream_history.lo stream_ieg.lo stream_int.lo stream_record.lo \
stream_srv.lo stream_var.lo table.lo taxis.lo timebase.lo \
tsteps.lo util.lo varscan.lo version.lo vlist.lo vlist_att.lo \
vlist_var.lo zaxis.lo stream.lo swap.lo
model.lo pio_util.lo servicelib.lo stream_cdf.lo \
stream_cgribex.lo stream_ext.lo stream_grb.lo \
stream_gribapi.lo stream_history.lo stream_ieg.lo \
stream_int.lo stream_record.lo stream_srv.lo stream_var.lo \
table.lo taxis.lo timebase.lo tsteps.lo util.lo varscan.lo \
version.lo vlist.lo vlist_att.lo vlist_var.lo zaxis.lo \
stream.lo swap.lo
libcdi_la_OBJECTS = $(am_libcdi_la_OBJECTS)
@ENABLE_CDI_LIB_FALSE@am_libcdi_la_rpath =
@ENABLE_CDI_LIB_TRUE@am_libcdi_la_rpath = -rpath $(libdir)
......@@ -335,6 +336,8 @@ libcdi_la_SOURCES = \
ieglib.c \
institution.c \
model.c \
pio_util.c \
pio_util.h \
service.h \
servicelib.c \
stream_cdf.c \
......@@ -500,6 +503,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ieglib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/institution.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_util.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/servicelib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cdf.Plo@am__quote@
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include "pio_util.h"
#include "cdi.h"
char commands[][13] = { "FINALIZE\0",
"RESOURCES\0",
"WINCREATE\0",
"WRITETS\0"};
void pcdiAssert ( bool assumption, const char * filename,
const char * functionname, int line )
{
if ( !assumption )
{
#ifdef USE_MPI
int rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
fprintf ( stderr, "ERROR, ASSUMPTION FALSE: PE%d in %s, %s, line %d\n",
rank, functionname, filename, line );
fflush ( stderr );
MPI_Abort ( MPI_COMM_WORLD, 1 );
#else
fprintf ( stderr, "ERROR ASSUMPTION FALSE, %s, %s, line %d\n",
functionname, filename, line );
fflush ( stderr );
abort();
#endif
}
}
/****************************************************/
void pcdiAbort ( char * errorString, const char * filename,
const char *functionname, int line )
{
#ifdef USE_MPI
int rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
fprintf ( stderr, "ERROR, pe%d in %s, %s, line %d, errorString: \"%s\"\n",
rank, functionname, filename, line, errorString );
MPI_Abort ( MPI_COMM_WORLD, 1 );
#else
fprintf ( stderr, "ERROR, %s, %s, line %d, errorString: \"%s\"\n",
functionname, filename, line, errorString );
abort();
#endif
}
/*****************************************************************************/
void * pcdiXmalloc ( size_t size, const char *filename, const char *functionname,
int line )
{
void * value = calloc (1, size );
if ( value == NULL )
pcdiAbort ( "malloc failed", filename, functionname, line );
return value;
}
void * pcdiXcalloc ( size_t nmemb, size_t size, const char *filename,
const char *functionname, int line )
{
void * value = calloc ( nmemb, size );
if ( value == NULL )
pcdiAbort ( "calloc failed", filename, functionname, line );
return value;
}
void * pcdiXrealloc ( void *p, size_t size, const char *functionname,
const char *filename, int line )
{
void * value = realloc ( p, size );
if ( value == NULL )
pcdiAbort ( "realloc failed", filename, functionname, line );
return value;
}
/***************************************************************/
#ifdef USE_MPI
void pcdiXMPI ( int iret, const char *filename, int line )
{
char errorString1[MPI_MAX_ERROR_STRING + 1];
char errorString2[MPI_MAX_ERROR_STRING + 1];
int len, errorClass, rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
if ( iret != MPI_SUCCESS )
{
MPI_Error_class ( iret, &errorClass );
MPI_Error_string ( errorClass, errorString1, &len );
errorString1[len] = '\0';
MPI_Error_string ( iret, errorString2, &len);
errorString2[len] = '\0';
fprintf ( stderr, "MPI ERROR, pe%d, %s, line %d,"
"errorClass: \"%s\""
"errorString: \"%s\"\n",
rank, filename, line,
errorString1, errorString2);
MPI_Abort ( MPI_COMM_WORLD, iret );
}
}
/*****************************************************************************/
void pcdiXMPIStat ( int iret, const char *filename, int line, MPI_Status *status )
{
char errorString[MPI_MAX_ERROR_STRING + 1];
int len, rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
if ( iret == MPI_ERR_IN_STATUS )
{
switch ( status->MPI_ERROR )
{
fprintf ( stderr, "------- checking error in request ----------\n" );
case MPI_SUCCESS :
fprintf ( stderr, "-------- mpi_success -----------\n" );
break;
case MPI_ERR_PENDING:
fprintf ( stderr, "-------- mpi_err_pending ----------\n");
break;
default:
MPI_Error_string ( status->MPI_ERROR, errorString, &len );
errorString[len] = '\0';
fprintf ( stderr,"MPI ERROR in request, pe%d, %s, line %d,"
"return value: %d, error_string: %s\n",
rank, filename, line, iret, errorString );
MPI_Abort ( MPI_COMM_WORLD, iret );
}
}
else
xmpi ( iret );
return;
}
#endif
/****************************************************/
#ifdef USE_MPI
void pcdiDebugComm ( const char *filename, const char *functionname, int line, MPI_Comm *comm )
{
int rank, size, len, rankGlob;
char *name;
name = ( char * ) xmalloc ( MPI_MAX_OBJECT_NAME );
memset ( name, 0, ( MPI_MAX_OBJECT_NAME ) * sizeof ( char ));
MPI_Comm_get_name ( * comm, name, &len );
MPI_Comm_size ( * comm, &size );
MPI_Comm_rank ( * comm, &rank );
MPI_Comm_rank ( MPI_COMM_WORLD, &rankGlob );
fprintf ( stdout,
"pe%d in %s, %s, line %d: comm: name=%s, size=%d, rank=%d\n",
rankGlob, functionname, filename, line,
name, size, rank );
free ( name );
}
#endif
/****************************************************/
#ifdef USE_MPI
void pcdiDebugMsg ( const char * cdiPioDebugString, const char *filename,
const char *functionname, int line, int tag, int source,
int nfinished )
{
int rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
fprintf ( stdout,
"%s pe%d in %s, %s, line %d: command %s, source %d, finalized=%d\n",
cdiPioDebugString, rank, functionname, filename, line,
&commands[tag][0], source, nfinished );
}
#endif
/****************************************************/
#ifdef USE_MPI
void pcdiDebugMsg2 ( const char *filename, const char *functionname, int line,
int tag, int source, char * text )
{
int rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
fprintf ( stdout,
"pe%d in %s, %s, line %d: command %s, source %d, %s\n",
rank, functionname, filename, line,
&commands[tag][0], source, text );
}
#endif
/****************************************************/
int xmaxInt ( int a, int b )
{
return a >= b ? a : b;
}
/****************************************************/
int xminInt ( int a, int b )
{
return a <= b ? a : b;
}
/****************************************************/
int xsum ( int n, int * argarray )
{
int i, sum = 0;
for ( i = 0; i < n; i++ )
sum += * ( argarray + i );
return sum;
}
/****************************************************/
double xchecksum ( int type, int count, void * buffer )
{
return 0.0;
}
/****************************************************/
void printArray ( const char * cdiPioDebugString, char * ps, const void * array, int n,
int datatype, const char * funname, const char * filename, int line )
{
int i, rank;
int * iArray;
double * dArray;
#ifdef USE_MPI
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
fprintf ( stdout, "%s pe%d in %s, %s, line %d: %s = ",
cdiPioDebugString, rank, funname, filename, line, ps );
#else
fprintf ( stdout, "%s %s, %s, line %d: %s = ",
cdiPioDebugString, funname, filename, line, ps );
#endif
switch ( datatype )
{
case DATATYPE_INT:
iArray = ( int * ) array;
for ( i = 0; i < n-1; i++ )
fprintf ( stdout, "%d ", * ( iArray + i ));
fprintf ( stdout, "%d\n", * ( iArray + n - 1 ));
break;
case DATATYPE_FLT:
dArray = ( double * ) array;
for ( i = 0; i < n-1; i++ )
fprintf ( stdout, "%.2f ", * ( dArray + i ));
fprintf ( stdout, "%.2f\n", * ( dArray + n-1 ));
break;
default:
fprintf ( stdout, " ... no datatype defined\n" );
}
return;
}
/****************************************************/
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
#ifndef PIO_UTIL_
#define PIO_UTIL_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef USE_MPI
#include "mpi.h"
#endif
#define MAXSTRLNNETCDF 32
#define MAXBUFFERSIZE 32
#define MAXVALUE 10
#define MAXDEBUG 3
#define MAXLEVELINFOS 10
#define MAXVARS 10
#define MAXLEVEL 10
#define MAXLEVELIDX 10
#define MAXRECORDS 10
#define MAXRECIDS 10
#define MAXVARS 10
#define MAXTSTEPS 10
#define MAXFNAMES 10
#define MAXGHBUFFERSIZE_0 10
#define MAXGHBUFFERSIZE_1 10
#define MAXSTRING 256
#define MINFILETYPE 1
#define MAXFILETYPE 9
#define ddebug 0
static char * debugString = "#####";
void pcdiAssert ( bool, const char *, const char *, int );
#define xassert(arg) pcdiAssert ( arg, __FILE__, __func__, __LINE__ );
#ifdef USE_MPI
#define xdebug(fmt, ...) \
if ( ddebug ){ \
int rank; \
MPI_Comm_rank ( MPI_COMM_WORLD, &rank ); \
fprintf ( stderr, "%s pe%d in %s, %s, line %d: " fmt "\n", \
debugString, rank, __func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#else
#define xdebug(fmt, ...) \
if ( ddebug ){ \
fprintf ( stderr, "%s, %s, line %d: " fmt "\n", \
__func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#endif
#ifdef USE_MPI
#define xdebug3(fmt, ...) \
if ( ddebug == MAXDEBUG ){ \
int rank; \
MPI_Comm_rank ( MPI_COMM_WORLD, &rank ); \
fprintf ( stderr, "pe%d in %s, %s, line %d: " fmt "\n", \
rank, __func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#else
#define xdebug3(fmt, ...) \
if ( ddebug == MAXDEBUG ){ \
fprintf ( stderr, "%s, %s, line %d: " fmt "\n", \
__func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#endif
/*
#ifdef USE_MPI
char * outTextComm ( MPI_Comm * );
#define xdebugComm(comm,fmt, ...) \
if ( ddebug ){ \
fprintf ( stderr, "%s%s, %s, line %d%s: " fmt "\n", \
outTextRank (), __func__, __FILE__, __LINE__, \
outTextComm ( comm ), \
## __VA_ARGS__ ); \
}
#endif
*/
#ifdef USE_MPI
#define xwarning(fmt, ...) \
if ( ddebug ){ \
int rank; \
MPI_Comm_rank ( MPI_COMM_WORLD, &rank ); \
fprintf ( stderr, "WARNING: pe%d in %s, %s, line %d: " fmt "\n", \
rank, __func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#else
#define xwarning(fmt, ...) \
if ( ddebug ){ \
fprintf ( stderr, "WARNING: %s, %s, line %d: " fmt "\n", \
__func__, __FILE__, __LINE__, \
## __VA_ARGS__ ); \
}
#endif
void pcdiAbort ( char *, const char *, const char *, int );
#define xabort(text) pcdiAbort ( text, __FILE__, __func__, __LINE__ );
void * pcdiXmalloc ( size_t, const char *, const char *, int );
#define xmalloc(size) pcdiXmalloc ( size, __FILE__, __func__, __LINE__ )
void * pcdiXcalloc ( size_t, size_t, const char *, const char *, int );
#define xcalloc(nmemb,size) pcdiXcalloc(nmemb, size, \
__FILE__, __func__, __LINE__)
void * pcdiXrealloc ( void *, size_t, const char *, const char *, int );
#define xrealloc(p,size) pcdiXrealloc(p, size, \
__FILE__, __func__, __LINE__)
void pcdiXMPI ( int, const char *, int );
#define xmpi(ret) pcdiXMPI ( ret, __FILE__, __LINE__ )
#ifdef USE_MPI
void pcdiXMPIStat ( int, const char *, int, MPI_Status * );
#define xmpiStat(ret,stat) pcdiXMPIStat ( ret, __FILE__, __LINE__, stat )
void pcdiDebugComm ( const char *filename, const char *functionname, int line, \
MPI_Comm *comm );
#define xdebugComm(comm)\
if ( ddebug ) pcdiDebugComm ( __FILE__, __func__, __LINE__, comm )
#endif
void pcdiDebugMsg ( const char * cdiDebugString, const char *filename, const char *functionname, int line, \
int tag, int source, int nfinished );
#define xdebugMsg(tag,source,nfinished) \
if ( ddebug ) \
pcdiDebugMsg ( debugString, __FILE__, __func__, __LINE__, tag, source, nfinished )
void pcdiDebugMsg2 ( const char *filename, const char *functionname, int line, \
int tag, int source, char * text );
#define xdebugMsg2(tag,source,text) \
if ( ddebug ) pcdiDebugMsg ( __FILE__, __func__, __LINE__, tag, source, text )
int xmaxInt ( int, int );
int xminInt ( int, int );
int xsum ( int, int * );
double xchecksum ( int, int, void * );
void printArray ( const char *, char *, const void *, int, int, const char *, const char *, int );
#define xprintArray(ps,array,n,datatype) \
if ( ddebug ) \
printArray ( debugString, ps, array, n, datatype, __func__, __FILE__, __LINE__ )
#define xprintArray3(ps,array,n,datatype) \
if ( ddebug == MAXDEBUG ) \
printArray ( debugString, ps, array, n, datatype, __func__, __FILE__, __LINE__ )
void reshArrayPrint ( char * );
#endif
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
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