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

Added cdo_varlist.cc cdo_varlist.h.

parent 5e7e76ac
......@@ -43,6 +43,8 @@ libcdo_la_SOURCES = after_dvtrans.cc \
cdo_season.h \
cdo_task.cc \
cdo_task.h \
cdo_varlist.cc \
cdo_varlist.h \
cdo_vlist.cc \
cdo_vlist.h \
cdo_wtime.h \
......
......@@ -304,16 +304,14 @@ Vertintap(void *process)
{
vert_index.resize(gridsize * nplev);
ListVar var3Df, var3Dh;
CdoVar var3Df, var3Dh;
var3Df.gridsize = gridsize;
var3Df.nlevels = nhlevf;
var3Df.nwpv = 1;
var3Df.memType = memtype;
full_press.init(var3Df);
var3Dh.gridsize = gridsize;
var3Dh.nlevels = nhlevf;
var3Dh.nwpv = 1;
var3Dh.memType = memtype;
half_press.init(var3Dh);
}
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2020 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "cdo_varlist.h"
void
varListInit(VarList &vl, int vlistID)
{
const auto nvars = vlistNvars(vlistID);
vl.resize(nvars);
for (int varID = 0; varID < nvars; ++varID)
{
vlistInqVarName(vlistID, varID, vl[varID].name);
vl[varID].gridID = vlistInqVarGrid(vlistID, varID);
vl[varID].zaxisID = vlistInqVarZaxis(vlistID, varID);
vl[varID].gridsize = gridInqSize(vl[varID].gridID);
vl[varID].nlevels = zaxisInqSize(vl[varID].zaxisID);
vl[varID].datatype = vlistInqVarDatatype(vlistID, varID);
vl[varID].missval = vlistInqVarMissval(vlistID, varID);
vl[varID].timetype = vlistInqVarTimetype(vlistID, varID);
vl[varID].code = vlistInqVarCode(vlistID, varID);
vl[varID].param = vlistInqVarParam(vlistID, varID);
vl[varID].nwpv = vlistInqVarNumber(vlistID, varID);
if (Options::CDO_Memtype == MemType::Native)
vl[varID].memType = (vl[varID].datatype == CDI_DATATYPE_FLT32 || vl[varID].datatype == CDI_DATATYPE_CPX32) ?
MemType::Float : MemType::Double;
else
vl[varID].memType = Options::CDO_Memtype;
}
}
void
varListSetUniqueMemtype(VarList &vl)
{
const int nvars = vl.size();
if (nvars)
{
const auto memtype = vl[0].memType;
int varID;
for (varID = 1; varID < nvars; ++varID)
{
if (vl[varID].memType != memtype) break;
}
if (varID < nvars) varListSetMemtype(vl, MemType::Double);
}
}
void
varListSetMemtype(VarList &vl, MemType memType)
{
for (auto &var : vl) var.memType = memType;
}
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2020 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef CDO_VARLIST_H
#define CDO_VARLIST_H
#include <vector>
#include <cdi.h>
#include "cdo_varlist.h"
#include "cdo_options.h"
struct CdoVar
{
char name[CDI_MAX_NAME];
MemType memType;
int gridID;
int zaxisID;
size_t gridsize;
int nlevels;
int datatype;
double missval;
int timetype;
int code;
int param;
int nwpv; // number of words per value; real:1 complex:2
CdoVar() : memType(MemType::Native), gridID(-1), zaxisID(-1), nlevels(0), datatype(-1), missval(0), timetype(-1), code(0), param(0), nwpv(1)
{
name[0] = 0;
};
};
using VarList = std::vector<CdoVar>;
void varListInit(VarList &vl, int vlistID);
void varListSetUniqueMemtype(VarList &vl);
void varListSetMemtype(VarList &vl, MemType memType);
#endif
......@@ -683,60 +683,6 @@ vlist_get_psvarid(int vlistID, int zaxisID)
return -1;
}
void
varListInit(VarList &vl, int vlistID)
{
const auto nvars = vlistNvars(vlistID);
vl.resize(nvars);
for (int varID = 0; varID < nvars; ++varID)
{
vlistInqVarName(vlistID, varID, vl[varID].name);
vl[varID].gridID = vlistInqVarGrid(vlistID, varID);
vl[varID].zaxisID = vlistInqVarZaxis(vlistID, varID);
vl[varID].gridsize = gridInqSize(vl[varID].gridID);
vl[varID].nlevels = zaxisInqSize(vl[varID].zaxisID);
vl[varID].datatype = vlistInqVarDatatype(vlistID, varID);
vl[varID].missval = vlistInqVarMissval(vlistID, varID);
vl[varID].timetype = vlistInqVarTimetype(vlistID, varID);
vl[varID].code = vlistInqVarCode(vlistID, varID);
vl[varID].param = vlistInqVarParam(vlistID, varID);
vl[varID].nwpv = vlistInqVarNumber(vlistID, varID);
if (Options::CDO_Memtype == MemType::Native)
vl[varID].memType = (vl[varID].datatype == CDI_DATATYPE_FLT32 || vl[varID].datatype == CDI_DATATYPE_CPX32) ?
MemType::Float : MemType::Double;
else
vl[varID].memType = Options::CDO_Memtype;
}
}
void
varListSetUniqueMemtype(VarList &vl)
{
const auto nvars = vl.size();
if (nvars)
{
const auto memtype = vl[0].memType;
int varID;
for (varID = 1; varID < nvars; ++varID)
{
if (vl[varID].memType != memtype) break;
}
if (varID < nvars)
{
for (varID = 0; varID < nvars; ++varID) vl[varID].memType = MemType::Double;
}
}
}
void
varListSetMemtype(VarList &vl, MemType memType)
{
const auto nvars = vl.size();
for (int varID = 0; varID < nvars; ++varID) vl[varID].memType = memType;
}
int
vlistGetFirstSpectralGrid(int vlistID)
{
......
......@@ -21,6 +21,7 @@
#include <cdi.h>
#include "cdo_varlist.h"
#include "cdo_options.h"
#include "array.h"
......@@ -39,27 +40,6 @@ void vlist_change_hybrid_zaxis(int vlistID1, int vlistID2, int zaxisID1, int zax
void cdoCompareGrids(int gridID1, int gridID2); // TODO: Check if this belongs here or if it should be in griddes.*
struct ListVar
{
char name[CDI_MAX_NAME];
MemType memType;
int gridID;
int zaxisID;
size_t gridsize;
int nlevels;
int datatype;
double missval;
int timetype;
int code;
int param;
int nwpv; // number of words per value; real:1 complex:2
};
using VarList = std::vector<ListVar>;
void varListInit(VarList &vl, int vlistID);
void varListSetUniqueMemtype(VarList &vl);
void varListSetMemtype(VarList &vl, MemType memType);
int vlistGetFirstGaussianGrid(int vlistID);
int vlistGetFirstSpectralGrid(int vlistID);
int vlistGetFirstFourierGrid(int vlistID);
......
......@@ -31,13 +31,13 @@ Field::Field() : fpeRaised(0), nwpv(1), memType(MemType::Native), grid(-1), grid
Field3D::Field3D() : nlevels(0) {}
void
Field::init(const ListVar &listVar)
Field::init(const CdoVar &var)
{
grid = listVar.gridID;
gridsize = listVar.gridsize;
missval = listVar.missval;
memType = listVar.memType;
size = listVar.gridsize * listVar.nwpv;
grid = var.gridID;
gridsize = var.gridsize;
missval = var.missval;
memType = var.memType;
size = var.gridsize * var.nwpv;
if (memType == MemType::Float)
vec_f.resize(size);
else
......@@ -90,14 +90,14 @@ Field::check_gridsize() const
}
void
Field3D::init(const ListVar &listVar)
{
nlevels = listVar.nlevels;
grid = listVar.gridID;
gridsize = listVar.gridsize;
missval = listVar.missval;
memType = listVar.memType;
size = listVar.nlevels * listVar.gridsize * listVar.nwpv;
Field3D::init(const CdoVar &var)
{
nlevels = var.nlevels;
grid = var.gridID;
gridsize = var.gridsize;
missval = var.missval;
memType = var.memType;
size = var.nlevels * var.gridsize * var.nwpv;
if (memType == MemType::Float)
vec_f.resize(size);
else
......
......@@ -53,7 +53,7 @@ public:
Varray<double> weightv;
Field();
void init(const ListVar &listVar);
void init(const CdoVar &var);
void resize(size_t count);
void resize(size_t count, double value);
void resizef(size_t count);
......@@ -71,7 +71,7 @@ public:
size_t nlevels;
Field3D();
void init(const ListVar &listVar);
void init(const CdoVar &var);
};
struct RecordInfo
......
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