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

cdiwrite: added support for memtype float

parent f043066e
......@@ -85,6 +85,7 @@ off_t filesize(const char *filename)
void *CDIwrite(void *argument)
{
int memtype = MEMTYPE_DOUBLE;
int nvars = 10, nlevs = 0, ntimesteps = 30;
char *defaultgrid = "global_.2";
int operatorID;
......@@ -103,6 +104,7 @@ void *CDIwrite(void *argument)
double tw, t0;
double *levels = NULL;
double ***vars = NULL;
float *farray = NULL;
extern int timer_write;
srand(seed);
......@@ -149,6 +151,8 @@ void *CDIwrite(void *argument)
}
}
if ( memtype == MEMTYPE_FLOAT ) farray = (float *) malloc(gridsize*sizeof(float));
vlistID = vlistCreate();
for ( i = 0; i < nvars; ++i )
......@@ -188,8 +192,17 @@ void *CDIwrite(void *argument)
for ( levelID = 0; levelID < nlevs; levelID++ )
{
streamDefRecord(streamID, varID, levelID);
streamWriteRecord(streamID, vars[varID][levelID], 0);
data_size += gridsize*8;
if ( memtype == MEMTYPE_FLOAT )
{
for ( i = 0; i < gridsize; ++i ) farray[i] = vars[varID][levelID][i];
streamWriteRecordFloat(streamID, farray, 0);
data_size += gridsize*4;
}
else
{
streamWriteRecord(streamID, vars[varID][levelID], 0);
data_size += gridsize*8;
}
}
}
......@@ -206,7 +219,10 @@ void *CDIwrite(void *argument)
tw = timer_val(timer_write);
data_size /= 1024.*1024.*1024.;
cdoPrint("Wrote %.1f GB of 64 bit floats to %s %s", data_size, datatypestr(datatype), filetypestr(filetype));
if ( memtype == MEMTYPE_FLOAT )
cdoPrint("Wrote %.1f GB of 32 bit floats to %s %s", data_size, datatypestr(datatype), filetypestr(filetype));
else
cdoPrint("Wrote %.1f GB of 64 bit floats to %s %s", data_size, datatypestr(datatype), filetypestr(filetype));
fsize = filesize(cdoStreamName(0));
file_size = fsize;
......@@ -222,6 +238,8 @@ void *CDIwrite(void *argument)
}
free(vars);
if ( farray ) free(farray);
cdoFinish();
return (0);
......
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2011 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Copyright (C) 2003-2012 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
......@@ -104,9 +104,11 @@ char *strdup(const char *s);
#define IX2D(y,x,nx) ((y)*(nx)+(x))
#define MEMTYPE_DOUBLE 1
#define MEMTYPE_FLOAT 2
#define CDO_EXP_LOCAL 1
#define CDO_EXP_REMOTE 2
#define CDO_EXP_LOCAL 1
#define CDO_EXP_REMOTE 2
enum {DATE_FIRST, DATE_LAST, DATE_MIDDLE};
......
......@@ -1214,6 +1214,36 @@ void pstreamWriteRecord(int pstreamID, double *data, int nmiss)
}
void pstreamWriteRecordFloat(int pstreamID, float *data, int nmiss)
{
pstream_t *pstreamptr;
if ( data == NULL ) cdoAbort("Data pointer not allocated (pstreamWriteRecord)!");
pstreamptr = pstream_to_pointer(pstreamID);
#if defined (HAVE_LIBPTHREAD)
if ( pstreamptr->ispipe )
{
cdoAbort("pipeWriteRecord not implemented for memtype float!");
//pipeWriteRecord(pstreamptr, data, nmiss);
}
else
#endif
{
int varID = pstreamptr->varID;
timer_start(timer_write);
/*
if ( pstreamptr->varlist )
if ( pstreamptr->varlist[varID].check_datarange )
pstreamCheckDatarange(pstreamptr, varID, data, nmiss);
*/
streamWriteRecordFloat(pstreamptr->fileID, data, nmiss);
timer_stop(timer_write);
}
}
int pstreamInqTimestep(int pstreamID, int tsID)
{
int nrecs = 0;
......
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2009 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Copyright (C) 2003-2012 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
......@@ -18,24 +18,25 @@
#ifndef _PSTREAM_H
#define _PSTREAM_H
#define streamOpenWrite pstreamOpenWrite
#define streamOpenRead pstreamOpenRead
#define streamOpenAppend pstreamOpenAppend
#define streamClose pstreamClose
#define streamOpenWrite pstreamOpenWrite
#define streamOpenRead pstreamOpenRead
#define streamOpenAppend pstreamOpenAppend
#define streamClose pstreamClose
#define streamInqFiletype pstreamInqFiletype
#define streamInqFiletype pstreamInqFiletype
#define streamInqVlist pstreamInqVlist
#define streamDefVlist pstreamDefVlist
#define streamInqVlist pstreamInqVlist
#define streamDefVlist pstreamDefVlist
#define streamDefTimestep pstreamDefTimestep
#define streamInqTimestep pstreamInqTimestep
#define streamDefTimestep pstreamDefTimestep
#define streamInqTimestep pstreamInqTimestep
#define streamDefRecord pstreamDefRecord
#define streamInqRecord pstreamInqRecord
#define streamDefRecord pstreamDefRecord
#define streamInqRecord pstreamInqRecord
#define streamWriteRecord pstreamWriteRecord
#define streamReadRecord pstreamReadRecord
#define streamWriteRecord pstreamWriteRecord
#define streamWriteRecordFloat pstreamWriteRecordFloat
#define streamReadRecord pstreamReadRecord
/*
#define streamCopyRecord pstreamCopyRecord
*/
......@@ -57,6 +58,7 @@ void pstreamDefRecord(int pstreamID, int varID, int levelID);
int pstreamInqRecord(int pstreamID, int *varID, int *levelID);
void pstreamWriteRecord(int pstreamID, double *data, int nmiss);
void pstreamWriteRecordFloat(int pstreamID, float *data, int nmiss);
void pstreamReadRecord(int pstreamID, double *data, int *nmiss);
void pstreamCopyRecord(int pstreamIDdest, int pstreamIDsrc);
......
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