Commit 5c11a77d authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Move common functions of test model simulations to separate source file.

parent f30be35d
...@@ -350,6 +350,8 @@ tests/pio_write.h -text ...@@ -350,6 +350,8 @@ tests/pio_write.h -text
tests/pio_write_deco2d_run.in -text tests/pio_write_deco2d_run.in -text
tests/pio_write_run.in -text tests/pio_write_run.in -text
tests/simple_model.c -text tests/simple_model.c -text
tests/simple_model_helper.c -text
tests/simple_model_helper.h -text
tests/stream_cksum.c -text tests/stream_cksum.c -text
tests/stream_cksum.h -text tests/stream_cksum.h -text
tests/test_chunk_cksum.in -text tests/test_chunk_cksum.in -text
......
...@@ -19,8 +19,10 @@ cksum_read_SOURCES = cksum_read.c \ ...@@ -19,8 +19,10 @@ cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \ var_cksum.c var_cksum.h \
stream_cksum.c stream_cksum.h \ stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c simple_model_helper.h simple_model_helper.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c
test_resource_copy_SOURCES = test_resource_copy.c \ test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c $(top_srcdir)/src/resource_unpack.c
test_resource_copy_mpi_SOURCES = test_resource_copy.c test_resource_copy_mpi_SOURCES = test_resource_copy.c
......
...@@ -116,13 +116,14 @@ am_cksum_write_chunk_OBJECTS = cksum_write_chunk.$(OBJEXT) ...@@ -116,13 +116,14 @@ am_cksum_write_chunk_OBJECTS = cksum_write_chunk.$(OBJEXT)
cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS) cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS)
cksum_write_chunk_LDADD = $(LDADD) cksum_write_chunk_LDADD = $(LDADD)
cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la
am_pio_write_OBJECTS = pio_write.$(OBJEXT) simple_model.$(OBJEXT) am_pio_write_OBJECTS = pio_write.$(OBJEXT) simple_model.$(OBJEXT) \
simple_model_helper.$(OBJEXT)
pio_write_OBJECTS = $(am_pio_write_OBJECTS) pio_write_OBJECTS = $(am_pio_write_OBJECTS)
am__DEPENDENCIES_1 = ../src/libcdi.la am__DEPENDENCIES_1 = ../src/libcdi.la
@USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1) @USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la @USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la
am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \ am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
deco2d_model.$(OBJEXT) deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT)
pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS) pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
@USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1) @USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la @USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la
...@@ -386,8 +387,12 @@ cksum_read_SOURCES = cksum_read.c \ ...@@ -386,8 +387,12 @@ cksum_read_SOURCES = cksum_read.c \
stream_cksum.c stream_cksum.h \ stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c simple_model_helper.h simple_model_helper.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c
test_resource_copy_SOURCES = test_resource_copy.c \ test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c $(top_srcdir)/src/resource_unpack.c
...@@ -526,6 +531,7 @@ distclean-compile: ...@@ -526,6 +531,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_unpack.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_unpack.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simple_model.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simple_model.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simple_model_helper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cksum.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cksum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy.Po@am__quote@
......
...@@ -25,25 +25,12 @@ typedef int MPI_Comm; ...@@ -25,25 +25,12 @@ typedef int MPI_Comm;
#include "error.h" #include "error.h"
#include "pio_write.h" #include "pio_write.h"
#include "simple_model_helper.h"
enum { enum {
ntfiles = 2, ntfiles = 2,
}; };
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;
}
static time_t
cditime2time_t(int date, int timeofday);
static void
time_t2cditime(time_t t, int *date, int *timeofday);
static void static void
modelRegionCompute(double region[], size_t offset, size_t len, modelRegionCompute(double region[], size_t offset, size_t len,
...@@ -67,11 +54,6 @@ modelRegionCompute(double region[], size_t offset, size_t len, ...@@ -67,11 +54,6 @@ modelRegionCompute(double region[], size_t offset, size_t len,
} }
} }
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx);
#endif
void void
modelRun(struct model_config setup, MPI_Comm comm) modelRun(struct model_config setup, MPI_Comm comm)
{ {
...@@ -338,82 +320,6 @@ modelRun(struct model_config setup, MPI_Comm comm) ...@@ -338,82 +320,6 @@ modelRun(struct model_config setup, MPI_Comm comm)
free(lons); free(lons);
} }
static time_t
cditime2time_t(int date, int timeofday)
{
struct tm t_s;
time_t t;
t_s.tm_year = date / 10000;
t_s.tm_mon = (date - t_s.tm_year * 10000)/100;
t_s.tm_mday = date % 100;
t_s.tm_year -= 1900;
t_s.tm_hour = timeofday/10000;
t_s.tm_min = (timeofday%10000)/100;
t_s.tm_sec = timeofday%100;
t_s.tm_isdst = 0;
t = mktime(&t_s);
/*
* fprintf(stderr, "converted %d,%d to %s to %lld.\n", date, timeofday,
* asctime(&t_s), (long long)t);
*/
return t;
}
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 = INT64_C(1) << mant_bits;
*mrscale = 1.0 / *mscale;
}
static void
time_t2cditime(time_t t, int *date, int *timeofday)
{
struct tm *t_s;
t_s = localtime(&t);
/* fprintf(stderr, "converted %lld to %s.\n", (long long)t, asctime(t_s)); */
*date = (t_s->tm_year + 1900) * 10000 + t_s->tm_mon * 100 + t_s->tm_mday;
*timeofday = t_s->tm_hour * 10000 + t_s->tm_min * 100 + t_s->tm_sec;
}
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx)
{
int part_offset
= (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
* (long long)part_idx) / (long long)nparts;
int start = set_interval[0] + part_offset;
return start;
}
#endif
/* /*
* Local Variables: * Local Variables:
* c-file-style: "Java" * c-file-style: "Java"
......
...@@ -25,25 +25,12 @@ typedef int MPI_Comm; ...@@ -25,25 +25,12 @@ typedef int MPI_Comm;
#include "error.h" #include "error.h"
#include "pio_write.h" #include "pio_write.h"
#include "simple_model_helper.h"
enum { enum {
ntfiles = 2, ntfiles = 2,
}; };
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;
}
static time_t
cditime2time_t(int date, int timeofday);
static void
time_t2cditime(time_t t, int *date, int *timeofday);
static void static void
modelRegionCompute(double region[], size_t offset, size_t len, modelRegionCompute(double region[], size_t offset, size_t len,
...@@ -67,11 +54,6 @@ modelRegionCompute(double region[], size_t offset, size_t len, ...@@ -67,11 +54,6 @@ modelRegionCompute(double region[], size_t offset, size_t len,
} }
} }
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx);
#endif
void void
modelRun(struct model_config setup, MPI_Comm comm) modelRun(struct model_config setup, MPI_Comm comm)
{ {
...@@ -338,82 +320,6 @@ modelRun(struct model_config setup, MPI_Comm comm) ...@@ -338,82 +320,6 @@ modelRun(struct model_config setup, MPI_Comm comm)
free(lons); free(lons);
} }
static time_t
cditime2time_t(int date, int timeofday)
{
struct tm t_s;
time_t t;
t_s.tm_year = date / 10000;
t_s.tm_mon = (date - t_s.tm_year * 10000)/100;
t_s.tm_mday = date % 100;
t_s.tm_year -= 1900;
t_s.tm_hour = timeofday/10000;
t_s.tm_min = (timeofday%10000)/100;
t_s.tm_sec = timeofday%100;
t_s.tm_isdst = 0;
t = mktime(&t_s);
/*
* fprintf(stderr, "converted %d,%d to %s to %lld.\n", date, timeofday,
* asctime(&t_s), (long long)t);
*/
return t;
}
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 = INT64_C(1) << mant_bits;
*mrscale = 1.0 / *mscale;
}
static void
time_t2cditime(time_t t, int *date, int *timeofday)
{
struct tm *t_s;
t_s = localtime(&t);
/* fprintf(stderr, "converted %lld to %s.\n", (long long)t, asctime(t_s)); */
*date = (t_s->tm_year + 1900) * 10000 + t_s->tm_mon * 100 + t_s->tm_mday;
*timeofday = t_s->tm_hour * 10000 + t_s->tm_min * 100 + t_s->tm_sec;
}
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx)
{
int part_offset
= (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
* (long long)part_idx) / (long long)nparts;
int start = set_interval[0] + part_offset;
return start;
}
#endif
/* /*
* Local Variables: * Local Variables:
* c-file-style: "Java" * c-file-style: "Java"
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "cdi.h"
#include "simple_model_helper.h"
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 = INT64_C(1) << mant_bits;
*mrscale = 1.0 / *mscale;
}
/**
* Compute UNIX epoch-based time_t from CDI's decimal encoding of date.
*/
time_t
cditime2time_t(int date, int timeofday)
{
struct tm t_s;
time_t t;
t_s.tm_year = date / 10000;
t_s.tm_mon = (date - t_s.tm_year * 10000)/100;
t_s.tm_mday = date % 100;
t_s.tm_year -= 1900;
t_s.tm_hour = timeofday/10000;
t_s.tm_min = (timeofday%10000)/100;
t_s.tm_sec = timeofday%100;
t_s.tm_isdst = 0;
t = mktime(&t_s);
return t;
}
/**
* Build decimal encoding of date from UNIX epoch-based time_t.
*/
void
time_t2cditime(time_t t, int *date, int *timeofday)
{
struct tm *t_s;
t_s = localtime(&t);
*date = (t_s->tm_year + 1900) * 10000 + t_s->tm_mon * 100 + t_s->tm_mday;
*timeofday = t_s->tm_hour * 10000 + t_s->tm_min * 100 + t_s->tm_sec;
}
#ifdef USE_MPI
int
uniform_partition_start(int set_interval[2], int nparts, int part_idx)
{
int part_offset
= (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
* (long long)part_idx) / (long long)nparts;
int start = set_interval[0] + part_offset;
return start;
}
#endif
#ifndef SIMPLE_MODEL_HELPER_H
#define SIMPLE_MODEL_HELPER_H
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <time.h>
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;
}
time_t
cditime2time_t(int date, int timeofday);
void
time_t2cditime(time_t t, int *date, int *timeofday);
#ifdef USE_MPI
int
uniform_partition_start(int set_interval[2], int nparts, int part_idx);
#endif
#endif
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