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

Ydayarith.c cleanup

parent c075f943
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.68 for cdo 1.7.1rc2.
# Generated by GNU Autoconf 2.68 for cdo 1.7.1.
#
# Report bugs to <http://mpimet.mpg.de/cdo>.
#
......@@ -570,8 +570,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='cdo'
PACKAGE_TARNAME='cdo'
PACKAGE_VERSION='1.7.1rc2'
PACKAGE_STRING='cdo 1.7.1rc2'
PACKAGE_VERSION='1.7.1'
PACKAGE_STRING='cdo 1.7.1'
PACKAGE_BUGREPORT='http://mpimet.mpg.de/cdo'
PACKAGE_URL=''
 
......@@ -1398,7 +1398,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures cdo 1.7.1rc2 to adapt to many kinds of systems.
\`configure' configures cdo 1.7.1 to adapt to many kinds of systems.
 
Usage: $0 [OPTION]... [VAR=VALUE]...
 
......@@ -1468,7 +1468,7 @@ fi
 
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of cdo 1.7.1rc2:";;
short | recursive ) echo "Configuration of cdo 1.7.1:";;
esac
cat <<\_ACEOF
 
......@@ -1620,7 +1620,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
cdo configure 1.7.1rc2
cdo configure 1.7.1
generated by GNU Autoconf 2.68
 
Copyright (C) 2010 Free Software Foundation, Inc.
......@@ -2213,7 +2213,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
 
It was created by cdo $as_me 1.7.1rc2, which was
It was created by cdo $as_me 1.7.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
 
$ $0 $@
......@@ -3162,7 +3162,7 @@ fi
 
# Define the identity of the package.
PACKAGE='cdo'
VERSION='1.7.1rc2'
VERSION='1.7.1'
 
 
cat >>confdefs.h <<_ACEOF
......@@ -21898,7 +21898,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by cdo $as_me 1.7.1rc2, which was
This file was extended by cdo $as_me 1.7.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
 
CONFIG_FILES = $CONFIG_FILES
......@@ -21964,7 +21964,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
cdo config.status 1.7.1rc2
cdo config.status 1.7.1
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"
 
......
......@@ -4,7 +4,7 @@
# autoconf 2.68
# libtool 2.4.2
AC_INIT([cdo], [1.7.1rc2], [http://mpimet.mpg.de/cdo])
AC_INIT([cdo], [1.7.1], [http://mpimet.mpg.de/cdo])
AC_DEFINE_UNQUOTED(CDO, ["$PACKAGE_VERSION"], [CDO version])
......
......@@ -30,17 +30,16 @@
#include "pstream.h"
#define MAX_DAY 1232
#define MAX_DOY 373
void *Ydayarith(void *argument)
{
int nrecs, nlev, recID;
int nrecs;
int varID, levelID;
int offset;
int nmiss;
int vdate, year, mon, day;
int **varnmiss2[MAX_DAY];
double **vardata2[MAX_DAY];
int year, month, day;
int **varnmiss2[MAX_DOY];
double **vardata2[MAX_DOY];
cdoInitialize(argument);
......@@ -80,39 +79,43 @@ void *Ydayarith(void *argument)
int nvars = vlistNvars(vlistID2);
for ( day = 0; day < MAX_DAY ; day++ ) vardata2[day] = NULL;
for ( int dayoy = 0; dayoy < MAX_DOY ; dayoy++ ) vardata2[dayoy] = NULL;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID2, tsID)) )
{
vdate = taxisInqVdate(taxisID2);
int vdate = taxisInqVdate(taxisID2);
cdiDecodeDate(vdate, &year, &mon, &day);
day += mon*100;
if ( day < 0 || day >= MAX_DAY ) cdoAbort("Day %d out of range!", day);
cdiDecodeDate(vdate, &year, &month, &day);
if ( vardata2[day] != NULL ) cdoAbort("Day %d already allocatd!", day);
int dayoy = 0;
if ( month >= 1 && month <= 12 ) dayoy = (month-1)*31 + day;
vardata2[day] = (double **) Malloc(nvars*sizeof(double *));
varnmiss2[day] = (int **) Malloc(nvars*sizeof(int *));
if ( dayoy < 0 || dayoy >= MAX_DOY )
cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
if ( vardata2[dayoy] != NULL ) cdoAbort("Day of year %d already allocatd (date=%d)!", dayoy, vdate);
vardata2[dayoy] = (double **) Malloc(nvars*sizeof(double *));
varnmiss2[dayoy] = (int **) Malloc(nvars*sizeof(int *));
for ( varID = 0; varID < nvars; varID++ )
{
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
nlev = zaxisInqSize(vlistInqVarZaxis(vlistID2, varID));
vardata2[day][varID] = (double*) Malloc(nlev*gridsize*sizeof(double));
varnmiss2[day][varID] = (int*) Malloc(nlev*sizeof(int));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
size_t nlev = zaxisInqSize(vlistInqVarZaxis(vlistID2, varID));
vardata2[dayoy][varID] = (double*) Malloc(nlev*gridsize*sizeof(double));
varnmiss2[dayoy][varID] = (int*) Malloc(nlev*sizeof(int));
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
offset = gridsize*levelID;
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
size_t offset = gridsize*levelID;
streamReadRecord(streamID2, vardata2[day][varID]+offset, &nmiss);
varnmiss2[day][varID][levelID] = nmiss;
streamReadRecord(streamID2, vardata2[dayoy][varID]+offset, &nmiss);
varnmiss2[dayoy][varID][levelID] = nmiss;
}
tsID++;
......@@ -122,27 +125,31 @@ void *Ydayarith(void *argument)
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
vdate = taxisInqVdate(taxisID1);
int vdate = taxisInqVdate(taxisID1);
cdiDecodeDate(vdate, &year, &month, &day);
int dayoy = 0;
if ( month >= 1 && month <= 12 ) dayoy = (month-1)*31 + day;
cdiDecodeDate(vdate, &year, &mon, &day);
day += mon*100;
if ( day < 0 || day >= MAX_DAY ) cdoAbort("Day %d out of range!", day);
if ( dayoy < 0 || dayoy >= MAX_DOY )
cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
taxisCopyTimestep(taxisID3, taxisID1);
streamDefTimestep(streamID3, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, field1.ptr, &nmiss);
field1.nmiss = (size_t) nmiss;
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
offset = gridsize*levelID;
if ( vardata2[day] == NULL ) cdoAbort("Day %d not found!", day);
memcpy(field2.ptr, vardata2[day][varID]+offset, gridsize*sizeof(double));
field2.nmiss = varnmiss2[day][varID][levelID];
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
size_t offset = gridsize*levelID;
if ( vardata2[dayoy] == NULL ) cdoAbort("Day of year %d not found (date=%d)!", dayoy, vdate);
memcpy(field2.ptr, vardata2[dayoy][varID]+offset, gridsize*sizeof(double));
field2.nmiss = varnmiss2[dayoy][varID][levelID];
field1.grid = vlistInqVarGrid(vlistID1, varID);
field1.missval = vlistInqVarMissval(vlistID1, varID);
......@@ -163,17 +170,17 @@ void *Ydayarith(void *argument)
streamClose(streamID2);
streamClose(streamID1);
for ( day = 0; day < MAX_DAY ; day++ )
if ( vardata2[day] )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
if ( vardata2[dayoy] )
{
for ( varID = 0; varID < nvars; varID++ )
{
Free(vardata2[day][varID]);
Free(varnmiss2[day][varID]);
Free(vardata2[dayoy][varID]);
Free(varnmiss2[dayoy][varID]);
}
Free(vardata2[day]);
Free(varnmiss2[day]);
Free(vardata2[dayoy]);
Free(varnmiss2[dayoy]);
}
if ( field1.ptr ) Free(field1.ptr);
......
......@@ -35,23 +35,19 @@
#include "pstream.h"
#define NDAY 373
#define MAX_DOY 373
void *Ydaystat(void *argument)
{
int i;
int varID;
int recID;
int vdate, vtime;
int year, month, day, dayoy;
int varID, levelID;
int year, month, day;
int nrecs;
int levelID;
int nsets[NDAY];
int nsets[MAX_DOY];
int nmiss;
int nlevel;
int vdates[NDAY], vtimes[NDAY];
field_t **vars1[NDAY], **vars2[NDAY], **samp1[NDAY];
int vdates[MAX_DOY], vtimes[MAX_DOY];
field_t **vars1[MAX_DOY], **vars2[MAX_DOY], **samp1[MAX_DOY];
cdoInitialize(argument);
......@@ -73,7 +69,7 @@ void *Ydaystat(void *argument)
int lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
{
vars1[dayoy] = NULL;
vars2[dayoy] = NULL;
......@@ -111,20 +107,18 @@ void *Ydaystat(void *argument)
int otsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
int vdate = taxisInqVdate(taxisID1);
int vtime = taxisInqVtime(taxisID1);
if ( cdoVerbose ) cdoPrint("process timestep: %d %d %d", tsID+1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
if ( month >= 1 && month <= 12 )
dayoy = (month-1)*31 + day;
else
dayoy = 0;
int dayoy = 0;
if ( month >= 1 && month <= 12 ) dayoy = (month-1)*31 + day;
if ( dayoy < 0 || dayoy >= NDAY )
cdoAbort("day of year %d out of range (date=%d)!", dayoy, vdate);
if ( dayoy < 0 || dayoy >= MAX_DOY )
cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
vdates[dayoy] = vdate;
vtimes[dayoy] = vtime;
......@@ -137,7 +131,7 @@ void *Ydaystat(void *argument)
vars2[dayoy] = field_malloc(vlistID1, FIELD_PTR);
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -159,7 +153,7 @@ void *Ydaystat(void *argument)
if ( samp1[dayoy][varID][levelID].ptr == NULL )
samp1[dayoy][varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double));
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(vars1[dayoy][varID][levelID].ptr[i],
vars1[dayoy][varID][levelID].missval) )
samp1[dayoy][varID][levelID].ptr[i] = 0;
......@@ -179,11 +173,11 @@ void *Ydaystat(void *argument)
if ( samp1[dayoy][varID][levelID].ptr == NULL )
{
samp1[dayoy][varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double));
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
samp1[dayoy][varID][levelID].ptr[i] = nsets[dayoy];
}
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
if ( !DBL_IS_EQUAL(field.ptr[i], vars1[dayoy][varID][levelID].missval) )
samp1[dayoy][varID][levelID].ptr[i]++;
}
......@@ -215,13 +209,13 @@ void *Ydaystat(void *argument)
// set the year to the minimum of years found on output timestep
int outyear = 1e9;
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
if ( nsets[dayoy] )
{
cdiDecodeDate(vdates[dayoy], &year, &month, &day);
if ( year < outyear ) outyear = year;
}
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
if ( nsets[dayoy] )
{
cdiDecodeDate(vdates[dayoy], &year, &month, &day);
......@@ -229,7 +223,7 @@ void *Ydaystat(void *argument)
// printf("vdates[%d] = %d nsets = %d\n", dayoy, vdates[dayoy], nsets[dayoy]);
}
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
if ( nsets[dayoy] )
{
if ( lmean )
......@@ -273,7 +267,7 @@ void *Ydaystat(void *argument)
taxisDefVtime(taxisID2, vtimes[dayoy]);
streamDefTimestep(streamID2, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......@@ -288,7 +282,7 @@ void *Ydaystat(void *argument)
otsID++;
}
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
{
if ( vars1[dayoy] != NULL )
{
......
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