Commit 72ce3032 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add test for parallel writing via CDI-pio.

parent 5dc673c3
......@@ -301,6 +301,8 @@ tests/cksum.c -text
tests/cksum.h -text
tests/cksum_read.c -text
tests/cksum_write.c -text
tests/pio_write.c -text
tests/pio_write_run.in -text
tests/test_cksum_extra.in -text
tests/test_cksum_grib.in -text
tests/test_cksum_ieg.in -text
......@@ -310,6 +312,7 @@ tests/test_cksum_nc4.in -text
tests/test_cksum_service.in -text
tests/test_grib.c -text
tests/test_grib.sh -text
util/serialrun.in -text
util/sunf95preproc-wrapper -text
util/sxpreproc-wrapper -text
util/xlfpreproc-wrapper -text
......
......@@ -37,10 +37,10 @@ subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/cdi.settings.in \
$(top_srcdir)/configure $(top_srcdir)/src/pkgconfig/cdi.pc.in \
AUTHORS COPYING ChangeLog INSTALL NEWS config/compile \
config/config.guess config/config.sub config/depcomp \
config/install-sh config/ltmain.sh config/missing \
config/mkinstalldirs
$(top_srcdir)/util/serialrun.in AUTHORS COPYING ChangeLog \
INSTALL NEWS config/compile config/config.guess \
config/config.sub config/depcomp config/install-sh \
config/ltmain.sh config/missing config/mkinstalldirs
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
......@@ -60,7 +60,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno config.status.lineno
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES = cdi.settings src/pkgconfig/cdi.pc
CONFIG_CLEAN_FILES = util/serialrun cdi.settings src/pkgconfig/cdi.pc
CONFIG_CLEAN_VPATH_FILES =
SOURCES =
DIST_SOURCES =
......@@ -193,6 +193,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......@@ -334,6 +335,8 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
$(am__aclocal_m4_deps):
util/serialrun: $(top_builddir)/config.status $(top_srcdir)/util/serialrun.in
cd $(top_builddir) && $(SHELL) ./config.status $@
cdi.settings: $(top_builddir)/config.status $(srcdir)/cdi.settings.in
cd $(top_builddir) && $(SHELL) ./config.status $@
src/pkgconfig/cdi.pc: $(top_builddir)/config.status $(top_srcdir)/src/pkgconfig/cdi.pc.in
......
......@@ -171,6 +171,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......
......@@ -637,6 +637,7 @@ CREATE_ISOC_FALSE
CREATE_ISOC_TRUE
USE_MPI_FALSE
USE_MPI_TRUE
MPI_LAUNCH
ENABLE_ALL_STATIC_FALSE
ENABLE_ALL_STATIC_TRUE
ENABLE_CDI_LIB
......@@ -26222,6 +26223,54 @@ if test x"$USE_MPI" = xyes; then :
 
$as_echo "#define USE_MPI 1" >>confdefs.h
 
for ac_prog in mpirun mpiexec
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_MPI_LAUNCH+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$MPI_LAUNCH"; then
ac_cv_prog_MPI_LAUNCH="$MPI_LAUNCH" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
ac_cv_prog_MPI_LAUNCH="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
MPI_LAUNCH=$ac_cv_prog_MPI_LAUNCH
if test -n "$MPI_LAUNCH"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MPI_LAUNCH" >&5
$as_echo "$MPI_LAUNCH" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$MPI_LAUNCH" && break
done
if test x$MPI_LAUNCH = x; then :
fi
else
MPI_LAUNCH="`pwd`/util/serialrun"
fi
if test x"$USE_MPI" = xyes; then
USE_MPI_TRUE=
......@@ -26688,7 +26737,7 @@ fi
 
 
 
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg"
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/pio_write_run util/serialrun"
 
 
ac_config_files="$ac_config_files Makefile src/Makefile interfaces/Makefile app/Makefile tests/Makefile examples/Makefile cdi.settings pioExamples/Makefile src/pkgconfig/cdi.pc"
......@@ -28029,6 +28078,8 @@ do
"tests/test_cksum_extra") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_extra" ;;
"tests/test_cksum_service") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_service" ;;
"tests/test_cksum_ieg") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_ieg" ;;
"tests/pio_write_run") CONFIG_FILES="$CONFIG_FILES tests/pio_write_run" ;;
"util/serialrun") CONFIG_FILES="$CONFIG_FILES util/serialrun" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
"interfaces/Makefile") CONFIG_FILES="$CONFIG_FILES interfaces/Makefile" ;;
......@@ -29851,6 +29902,8 @@ _LT_EOF
"tests/test_cksum_extra":F) chmod a+x "$ac_file" ;;
"tests/test_cksum_service":F) chmod a+x "$ac_file" ;;
"tests/test_cksum_ieg":F) chmod a+x "$ac_file" ;;
"tests/pio_write_run":F) chmod a+x "$ac_file" ;;
"util/serialrun":F) chmod a+x "$ac_file" ;;
 
esac
done # for ac_tag
......
......@@ -117,7 +117,11 @@ AC_ARG_ENABLE(mpi,AS_HELP_STRING([--enable-mpi],[Compile with MPI compiler [defa
AS_IF([test x"${enable_mpi}" = x"yes"],
[USE_MPI=yes])
AS_IF([test x"$USE_MPI" = xyes],
[AC_DEFINE([USE_MPI],[1],[parallel I/O requested and available])])
[AC_DEFINE([USE_MPI],[1],[parallel I/O requested and available])
AC_CHECK_PROGS([MPI_LAUNCH],[mpirun mpiexec],[])
AS_IF([test x$MPI_LAUNCH = x],[])],
[MPI_LAUNCH="`pwd`/util/serialrun"
AC_SUBST([MPI_LAUNCH])])
AM_CONDITIONAL([USE_MPI],[test x"$USE_MPI" = xyes])
# ----------------------------------------------------------------------
# Create the Fortran Interface via iso_c_binding module (Fortran 2003 Standard)
......@@ -204,7 +208,9 @@ AC_CONFIG_FILES([tests/test_cksum_grib \
tests/test_cksum_nc4 \
tests/test_cksum_extra \
tests/test_cksum_service \
tests/test_cksum_ieg],[chmod a+x "$ac_file"])
tests/test_cksum_ieg \
tests/pio_write_run \
util/serialrun],[chmod a+x "$ac_file"])
AC_OUTPUT([Makefile src/Makefile interfaces/Makefile app/Makefile \
tests/Makefile examples/Makefile cdi.settings \
......
......@@ -200,6 +200,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......
......@@ -188,6 +188,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......
......@@ -183,6 +183,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......
......@@ -200,6 +200,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......
......@@ -77,7 +77,7 @@ size_t pioFileWrite ( int fileID, int tsID, const void *buffer, size_t len )
case PIO_ASYNCH:
iret = fwPOSIXASYNCH ( fileID, tsID, buffer, len );
break;
#endif
#endif
case PIO_FPGUARD:
iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
break;
......
## Process this file with automake to produce Makefile.in
#
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg
check_PROGRAMS = test_grib cksum_write cksum_read
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
pio_write_run
check_PROGRAMS = test_grib cksum_write cksum_read pio_write
#
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c cksum.c cksum.h
pio_write_SOURCES = pio_write.c
#
LDADD = -L../src -lcdi -lm
AM_LDFLAGS = -L$(top_srcdir)/src
......
......@@ -34,13 +34,13 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
check_PROGRAMS = test_grib$(EXEEXT) cksum_write$(EXEEXT) \
cksum_read$(EXEEXT)
cksum_read$(EXEEXT) pio_write$(EXEEXT)
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/test_cksum_extra.in $(srcdir)/test_cksum_grib.in \
$(srcdir)/test_cksum_ieg.in $(srcdir)/test_cksum_nc.in \
$(srcdir)/test_cksum_nc2.in $(srcdir)/test_cksum_nc4.in \
$(srcdir)/test_cksum_service.in
$(srcdir)/pio_write_run.in $(srcdir)/test_cksum_extra.in \
$(srcdir)/test_cksum_grib.in $(srcdir)/test_cksum_ieg.in \
$(srcdir)/test_cksum_nc.in $(srcdir)/test_cksum_nc2.in \
$(srcdir)/test_cksum_nc4.in $(srcdir)/test_cksum_service.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
......@@ -60,7 +60,7 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES = test_cksum_grib test_cksum_nc test_cksum_nc2 \
test_cksum_nc4 test_cksum_extra test_cksum_service \
test_cksum_ieg
test_cksum_ieg pio_write_run
CONFIG_CLEAN_VPATH_FILES =
am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) cksum.$(OBJEXT)
cksum_read_OBJECTS = $(am_cksum_read_OBJECTS)
......@@ -70,6 +70,10 @@ am_cksum_write_OBJECTS = cksum_write.$(OBJEXT) cksum.$(OBJEXT)
cksum_write_OBJECTS = $(am_cksum_write_OBJECTS)
cksum_write_LDADD = $(LDADD)
cksum_write_DEPENDENCIES =
am_pio_write_OBJECTS = pio_write.$(OBJEXT)
pio_write_OBJECTS = $(am_pio_write_OBJECTS)
pio_write_LDADD = $(LDADD)
pio_write_DEPENDENCIES =
am_test_grib_OBJECTS = test_grib.$(OBJEXT)
test_grib_OBJECTS = $(am_test_grib_OBJECTS)
test_grib_LDADD = $(LDADD)
......@@ -88,9 +92,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(test_grib_SOURCES)
$(pio_write_SOURCES) $(test_grib_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(test_grib_SOURCES)
$(pio_write_SOURCES) $(test_grib_SOURCES)
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
......@@ -174,6 +178,7 @@ MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MPI_LAUNCH = @MPI_LAUNCH@
NC_CONFIG = @NC_CONFIG@
NETCDF_INCLUDE = @NETCDF_INCLUDE@
NETCDF_LIBS = @NETCDF_LIBS@
......@@ -272,12 +277,14 @@ top_srcdir = @top_srcdir@
#
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
pio_write_run
#
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c cksum.c cksum.h
pio_write_SOURCES = pio_write.c
#
LDADD = -L../src -lcdi -lm
AM_LDFLAGS = -L$(top_srcdir)/src
......@@ -334,6 +341,8 @@ test_cksum_service: $(top_builddir)/config.status $(srcdir)/test_cksum_service.i
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
test_cksum_ieg: $(top_builddir)/config.status $(srcdir)/test_cksum_ieg.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_write_run: $(top_builddir)/config.status $(srcdir)/pio_write_run.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
clean-checkPROGRAMS:
@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
......@@ -349,6 +358,9 @@ cksum_read$(EXEEXT): $(cksum_read_OBJECTS) $(cksum_read_DEPENDENCIES)
cksum_write$(EXEEXT): $(cksum_write_OBJECTS) $(cksum_write_DEPENDENCIES)
@rm -f cksum_write$(EXEEXT)
$(LINK) $(cksum_write_OBJECTS) $(cksum_write_LDADD) $(LIBS)
pio_write$(EXEEXT): $(pio_write_OBJECTS) $(pio_write_DEPENDENCIES)
@rm -f pio_write$(EXEEXT)
$(LINK) $(pio_write_OBJECTS) $(pio_write_LDADD) $(LIBS)
test_grib$(EXEEXT): $(test_grib_OBJECTS) $(test_grib_DEPENDENCIES)
@rm -f test_grib$(EXEEXT)
$(LINK) $(test_grib_OBJECTS) $(test_grib_LDADD) $(LIBS)
......@@ -362,6 +374,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_read.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@
.c.o:
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#ifdef USE_MPI
#include <mpi.h>
#include "pio_c_temp.h"
#endif
#include "cdi.h"
#include "pio_util.h"
struct model_config
{
int nlon, nlat, nts;
int filetype, datatype;
const char *suffix;
};
struct model_config default_setup
= { .nlon = 12, .nts = 3, .nlat = 6,
.filetype = FILETYPE_GRB, .datatype = DATATYPE_PACK24,
.suffix = "grb"
};
static void
var_scale(int datatype, double *mscale, double *mrscale);
static inline double
sign_flat(double v)
{
if (v == 0.0)
return 0.0;
return v;
}
void modelRun (struct model_config setup)
{
enum {
ntfiles = 2,
nVars = 5,
maxlev = 5
};
static int nlev[nVars] = {1,1,5,5,2};
static char * name = "example";
int gridID, zaxisID[nVars], taxisID;
int vlistID, varIDs[nVars], streamID, tsID, tfID = 0;
int i, j, k, varID, nmiss = 0, rank;
double *lons, *lats;
double levs[maxlev] = {101300, 92500, 85000, 50000, 20000};
double *var, *varslice;
double mscale, mrscale;
int vdate = 19850101, vtime = 120000;
int start = CDI_UNDEFID, chunk = CDI_UNDEFID, stop = CDI_UNDEFID;
char filename[1024];
int nlon = setup.nlon, nlat = setup.nlat;
var_scale(setup.datatype, &mscale, &mrscale);
gridID = gridCreate ( GRID_LONLAT, nlon*nlat );
gridDefXsize ( gridID, nlon );
gridDefYsize ( gridID, nlat );
lons = malloc(nlon * sizeof (lons[0]));
for (i = 0; i < nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
lats = malloc(nlat * sizeof (lats[0]));
for (i = 0; i < nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefXvals ( gridID, lons );
gridDefYvals ( gridID, lats );
for ( i = 0; i < nVars; i++ )
{
zaxisID[i] = zaxisCreate ( ZAXIS_PRESSURE, nlev[i] );
zaxisDefLevels ( zaxisID[i], levs );
}
var = malloc(nlon * nlat * maxlev * sizeof(var[0]));
varslice = NULL;
vlistID = vlistCreate ();
for ( i = 0; i < nVars; i++ )
varIDs[i] = vlistDefVar ( vlistID, gridID, zaxisID[i], TIME_VARIABLE );
taxisID = taxisCreate ( TAXIS_ABSOLUTE );
vlistDefTaxis ( vlistID, taxisID );
sprintf ( &filename[0], "%s_%d.%s", name, tfID, setup.suffix );
streamID = streamOpenWrite ( filename, setup.filetype );
xassert ( streamID >= 0 );
streamDefVlist ( streamID, vlistID);
pioEndDef ();
for ( tfID = 0; tfID < ntfiles; tfID++ )
{
if ( tfID > 0 )
{
streamClose ( streamID );
sprintf ( &filename[0], "%s_%d.%s", name, tfID, setup.suffix );
streamID = streamOpenWrite ( filename, setup.filetype );
xassert ( streamID >= 0 );
streamDefVlist ( streamID, vlistID );
}
for ( tsID = 0; tsID < setup.nts; tsID++ )
{
taxisDefVdate ( taxisID, vdate );
taxisDefVtime ( taxisID, vtime );
streamDefTimestep ( streamID, tsID );
for ( varID = 0; varID < nVars; varID++ )
{
for (k = 0; k < nlev[varID]; ++k)
for (j = 0; j < nlat; ++j)
for (i = 0; i < nlon; ++i)
var[i+j*nlon+k*nlon*nlat]
= sign_flat(round(
(cos(2.0 * M_PI * (lons[(i + tsID)%nlon] - lons[0])
/ (lons[nlon-1] - lons[0]))
* sin(2.0 * M_PI * (lats[j] - lats[0])
/ (lats[nlat-1] - lats[0]))
) * mscale)) * mrscale;
start = pioInqVarDecoOff ( vlistID, varIDs[varID] );
chunk = pioInqVarDecoChunk ( vlistID, varIDs[varID] );
varslice = realloc(varslice, chunk * sizeof (var[0]));
memcpy(varslice, var + start, chunk * sizeof (var[0]));
streamWriteVar ( streamID, varIDs[varID], varslice, nmiss );
start = CDI_UNDEFID;
chunk = CDI_UNDEFID;
}
pioWriteTimestep ( tsID, vdate, vtime );
}
}
pioEndTimestepping ();
streamClose ( streamID );
vlistDestroy ( vlistID );
taxisDestroy ( taxisID );
for ( i = 0; i < nVars; i++ )
zaxisDestroy ( zaxisID[i] );
gridDestroy ( gridID );
free(lats);
free(lons);
}
struct {
char *text;
int mode;
} mode_map[] = {
{ "PIO_MPI", PIO_MPI },
{ "PIO_FPGUARD", PIO_FPGUARD },
{ "PIO_ASYNCH", PIO_ASYNCH },
{ "PIO_WRITER", PIO_WRITER }
};
static const struct {
char suffix[4];
int type, defaultDT, defaultGrid;
} suffix2type[] = {
{ "nc", FILETYPE_NC, DATATYPE_FLT64, GRID_LONLAT },
{ "grb", FILETYPE_GRB, DATATYPE_PACK24, GRID_LONLAT },
{ "nc2", FILETYPE_NC2, DATATYPE_FLT64, GRID_LONLAT },
{ "nc4", FILETYPE_NC4, DATATYPE_FLT64, GRID_LONLAT },
{ "ext", FILETYPE_EXT, DATATYPE_FLT64, GRID_GENERIC, },
{ "svc", FILETYPE_SRV, DATATYPE_FLT64, GRID_GENERIC, },
{ "ieg", FILETYPE_IEG, DATATYPE_FLT64, GRID_LONLAT },
};
static int
parse_intarg(const char msg[])
{
char *end;
long temp = strtol(optarg, &end, 0);
if ((errno == ERANGE && (temp == LONG_MAX || temp == LONG_MIN))
|| (errno != 0 && temp == 0)) {
perror(msg);
exit(EXIT_FAILURE);
}
if (temp > INT_MAX || temp < INT_MIN)
{
fprintf(stderr, "range error: %ld\n", temp);
exit(EXIT_FAILURE);
}
return (int)temp;
}
static void
var_scale(int datatype, double *mscale, double *mrscale)
{
int mant_bits;
switch (datatype)
{
case DATATYPE_PACK8:
mant_bits = 7;
break;
case DATATYPE_PACK16:
mant_bits = 15;
break;
case DATATYPE_PACK24:
mant_bits = 23;
break;
case DATATYPE_FLT32:
mant_bits = 24;
break;
case DATATYPE_FLT64:
mant_bits = 53;
break;
case DATATYPE_INT8:
case DATATYPE_INT16:
case DATATYPE_INT32:
default:
fprintf(stderr, "Unexpected or unusable content format: %d\n",
datatype);
exit(EXIT_FAILURE);
}
*mscale = 1 << mant_bits;
*mrscale = 1.0 / *mscale;
}
int main (int argc, char *argv[])
{
enum {
nNamespaces = 1 };
static int hasLocalFile[nNamespaces] = { 0 };
struct model_config setup = default_setup;
#ifdef USE_MPI
MPI_Comm commGlob, commModel;
int sizeGlob;
int rankGlob;
int IOMode = PIO_MPI;
int nProcsIO = 2;
xmpi ( MPI_Init ( &argc, &argv));
xmpi ( MPI_Comm_dup ( MPI_COMM_WORLD, &commGlob ));
xmpi ( MPI_Comm_set_errhandler ( commGlob, MPI_ERRORS_RETURN ));
xmpi ( MPI_Comm_size ( commGlob, &sizeGlob ));
xmpi ( MPI_Comm_rank ( commGlob, &rankGlob ));
#endif
{
int opt;
while ((opt = getopt(argc, argv, "f:m:n:t:"
#ifdef USE_MPI
"p:w:"
#endif
)) != -1)
switch (opt) {
#ifdef USE_MPI
case 'p':
{
int i, found=0;
for (i = 0;
i < sizeof (mode_map) / sizeof (mode_map[0]);
++i)
if (!strcmp(optarg, mode_map[i].text))
{
found = 1;
IOMode = mode_map[i].mode;
}
if (!found)
{
fprintf(stderr, "Unsupported PIO mode requested: %s\n", optarg);
exit(EXIT_FAILURE);
}
}
break;
case 'w':
nProcsIO = strtol(optarg, NULL, 0);
break;
#endif
case 'f':
{
int i, found = 0;
for (i = 0;
i < sizeof (suffix2type) / sizeof (suffix2type[0]);
++i)
if (!strcmp(optarg, suffix2type[i].suffix))
{
found = 1;
setup.filetype = suffix2type[i].type;