Skip to content
Snippets Groups Projects
Commit c8f2a7e7 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

fixup: Extend CDI-PIO writing of data to float.

parent 11bfc103
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
......@@ -78,11 +79,13 @@ modelRun(struct model_config setup, MPI_Comm comm)
Xt_idxlist partDesc;
Xt_redist redist4gather;
#endif
bool useFloat;
} *varDesc;
int gridID, taxisID, vlistID, tsID, tfID = 0;
enum { nmiss = 0 };
double *levs;
double *var = NULL, *varslice = NULL;
float *varsliceF = NULL;
double mscale, mrscale;
time_t current_time;
int vdate = 19850101, vtime = 120000;
......@@ -90,7 +93,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
char *filename = NULL;
int nlon = setup.nlon, nlat = setup.nlat;
size_t nVars = setup.nvars > 0 ? (size_t)setup.nvars : 0;
size_t varslice_size = 0;
size_t varslice_size = 0, varsliceF_size = 0;;
#if USE_MPI
int comm_size = 1;
int npart[2], rank_coord[2];
......@@ -261,6 +264,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
varDesc[varIdx].code = GRIB_USERDEF + (int)varIdx;
vlistDefVarCode(vlistID, varDesc[varIdx].id, varDesc[varIdx].code);
vlistDefVarDatatype(vlistID, varDesc[varIdx].id, setup.datatype);
varDesc[varIdx].useFloat = (bool)(random()&1);
}
taxisID = taxisCreate ( setup.taxistype );
......@@ -317,6 +321,20 @@ modelRun(struct model_config setup, MPI_Comm comm)
}
modelRegionCompute(varslice, (int)varLevs, nlat, nlon,
start, chunk, tsID, mscale, mrscale);
bool useFloat = varDesc[varIdx].useFloat;
if (useFloat)
{
if (varsliceF_size < chunkSize)
{
varsliceF
= (float *)Realloc(varsliceF,
chunkSize * sizeof (varsliceF[0]));
varsliceF_size = chunkSize;
}
for (size_t i = 0; i < chunkSize; ++i)
varslice[i] = varsliceF[i] = (float)varslice[i];
}
if (setup.flags & PIO_WRITE_CONFIG_CHECKSUM_FLAG)
{
#if USE_MPI
......@@ -356,12 +374,21 @@ modelRun(struct model_config setup, MPI_Comm comm)
blk_displ[k] = (int)(k * (nblk + 1) * nproma);
blk_lens[k] = (int)layerSize;
}
streamWriteScatteredVarPart(streamID, varDesc[varIdx].id,
varslice,
(int)varLevs, blk_lens, blk_displ,
nmiss, varDesc[varIdx].partDesc);
if (useFloat)
streamWriteScatteredVarPartF(streamID, varDesc[varIdx].id,
varsliceF,
(int)varLevs, blk_lens, blk_displ,
nmiss, varDesc[varIdx].partDesc);
else
streamWriteScatteredVarPart(streamID, varDesc[varIdx].id,
varslice,
(int)varLevs, blk_lens, blk_displ,
nmiss, varDesc[varIdx].partDesc);
#else
streamWriteVar(streamID, varDesc[varIdx].id, var, nmiss);
if (useFloat)
streamWriteVarF(streamID, varDesc[varIdx].id, varsliceF, nmiss);
else
streamWriteVar(streamID, varDesc[varIdx].id, varslice, nmiss);
#endif
}
current_time += 86400;
......@@ -379,16 +406,16 @@ modelRun(struct model_config setup, MPI_Comm comm)
perror("failed to open table file");
exit(EXIT_FAILURE);
}
for (size_t i = 0; i < nVars; ++i)
for (size_t varIdx = 0; varIdx < nVars; ++varIdx)
{
uint32_t cksum;
int code;
cksum = memcrc_finish(&varDesc[i].checksum_state,
(off_t)((varDesc[i].size
cksum = memcrc_finish(&varDesc[varIdx].checksum_state,
(off_t)((varDesc[varIdx].size
* sizeof (var[0])
+ sizeof (int) * 2)
* (size_t)setup.nts));
code = vlistInqVarCode(vlistID, varDesc[i].id);
code = vlistInqVarCode(vlistID, varDesc[varIdx].id);
if (fprintf(tablefp, "%08lx %d\n", (unsigned long)cksum,
code) < 0)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment