Commit 699d33ae authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

FC: added error handling.

parent 7c3d6837
......@@ -26,6 +26,7 @@
#include <cdi.h>
#include "cdo_vlist.h"
#include "process_int.h"
#include <mpim_grid.h>
#include "specspace.h"
......@@ -37,10 +38,7 @@ FC(void *process)
{
int nrecs;
int varID, levelID;
int index;
int gridIDsp = -1, gridIDgp = -1, gridIDfc = -1;
int gridID1 = -1, gridID2 = -1;
int gridID;
size_t nmiss;
size_t nlon = 0, nlat = 0;
int ntr = 0;
......@@ -66,37 +64,9 @@ FC(void *process)
const auto taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
const auto ngrids = vlistNgrids(vlistID1);
// find first spectral grid
for (index = 0; index < ngrids; index++)
{
gridID = vlistGrid(vlistID1, index);
if (gridInqType(gridID) == GRID_SPECTRAL)
{
gridIDsp = gridID;
break;
}
}
// find first gaussian grid
for (index = 0; index < ngrids; index++)
{
gridID = vlistGrid(vlistID1, index);
if (gridInqType(gridID) == GRID_GAUSSIAN)
{
gridIDgp = gridID;
break;
}
}
// find first fourier grid
for (index = 0; index < ngrids; index++)
{
gridID = vlistGrid(vlistID1, index);
if (gridInqType(gridID) == GRID_FOURIER)
{
gridIDfc = gridID;
break;
}
}
auto gridIDsp = vlistGetFirstSpectralGrid(vlistID1);
auto gridIDgp = vlistGetFirstGaussianGrid(vlistID1);
auto gridIDfc = vlistGetFirstFourierGrid(vlistID1);
// define output grid
if (operatorID == FC2SP)
......@@ -211,7 +181,7 @@ FC(void *process)
}
SPTRANS sptrans;
sptrans.init(nlon, nlat, ntr, 0);
if (nlon > 0) sptrans.init(nlon, nlat, ntr, 0);
// printf("nfc %d, ntr %d, nlat %zu, nlon %zu\n", nfc, ntr, nlat, nlon);
......
......@@ -140,7 +140,7 @@ Fourier(void *process)
}
else
{
if (isPower2) /* nts is a power of 2 */
if (isPower2) // nts is a power of 2
fft(ompmem[ompthID].real.data(), ompmem[ompthID].imag.data(), nts, sign);
else
ft_r(ompmem[ompthID].real.data(), ompmem[ompthID].imag.data(), nts, sign, ompmem[ompthID].work_r.data(),
......@@ -164,7 +164,7 @@ Fourier(void *process)
for (varID = 0; varID < nvars; varID++)
{
const int nlevels = varList[varID].nlevels;
const auto nlevels = varList[varID].nlevels;
for (levelID = 0; levelID < nlevels; levelID++)
{
if (!vars[tsID][varID][levelID].empty())
......
......@@ -28,6 +28,7 @@
#include <cdi.h>
#include "cdo_vlist.h"
#include "process_int.h"
#include "param_conversion.h"
#include <mpim_grid.h>
......@@ -35,12 +36,12 @@
#include "specspace.h"
#include "listarray.h"
void *
Spectral(void *process)
{
int nrecs;
int varID, levelID;
int gridIDsp = -1, gridIDgp = -1;
int gridID1 = -1, gridID2 = -1;
size_t nmiss;
std::vector<int> waves;
......@@ -87,27 +88,8 @@ Spectral(void *process)
const auto taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
const auto ngrids = vlistNgrids(vlistID1);
// find first spectral grid
for (int index = 0; index < ngrids; index++)
{
const auto gridID = vlistGrid(vlistID1, index);
if (gridInqType(gridID) == GRID_SPECTRAL)
{
gridIDsp = gridID;
break;
}
}
// find first gaussian grid
for (int index = 0; index < ngrids; index++)
{
const auto gridID = vlistGrid(vlistID1, index);
if (gridInqType(gridID) == GRID_GAUSSIAN)
{
gridIDgp = gridID;
break;
}
}
auto gridIDsp = vlistGetFirstSpectralGrid(vlistID1);
auto gridIDgp = vlistGetFirstGaussianGrid(vlistID1);
// define output grid
if (lgp2sp)
......@@ -228,8 +210,7 @@ Spectral(void *process)
cdoDefVlist(streamID2, vlistID2);
const auto gridsizemax = vlistGridsizeMax(vlistID1);
Varray<double> array1(gridsizemax);
Varray<double> array2;
Varray<double> array1(gridsizemax), array2;
if (gridID2 != -1) array2.resize(gridInqSize(gridID2));
int tsID = 0;
......
......@@ -51,6 +51,12 @@
int
fft_set(double *trigs, long *ifax, long n)
{
if (n == 0 || trigs == nullptr || ifax == nullptr)
{
fprintf(stderr, "fft_set: parameter not initialized!\n");
return -2;
}
const long len = n;
const long nhl = n / 2;
const double del = 4.0 * std::asin(1.0) / n;
......
......@@ -731,3 +731,46 @@ varListInit(VarList &vl, int vlistID)
vl[varID].timetype = vlistInqVarTimetype(vlistID, varID);
}
}
int
vlistGetFirstSpectralGrid(int vlistID)
{
// find first spectral grid
const auto ngrids = vlistNgrids(vlistID);
for (int index = 0; index < ngrids; index++)
{
const auto gridID = vlistGrid(vlistID, index);
if (gridInqType(gridID) == GRID_SPECTRAL) return gridID;
}
return -1;
}
int
vlistGetFirstGaussianGrid(int vlistID)
{
// find first gaussian grid
const auto ngrids = vlistNgrids(vlistID);
for (int index = 0; index < ngrids; index++)
{
const auto gridID = vlistGrid(vlistID, index);
if (gridInqType(gridID) == GRID_GAUSSIAN) return gridID;
}
return -1;
}
int
vlistGetFirstFourierGrid(int vlistID)
{
// find first fourier grid
const auto ngrids = vlistNgrids(vlistID);
for (int index = 0; index < ngrids; index++)
{
const auto gridID = vlistGrid(vlistID, index);
if (gridInqType(gridID) == GRID_FOURIER) return gridID;
}
return -1;
}
......@@ -49,5 +49,9 @@ struct ListVar
using VarList = std::vector<ListVar>;
void varListInit(VarList &vl, int vlistID);
int vlistGetFirstGaussianGrid(int vlistID);
int vlistGetFirstSpectralGrid(int vlistID);
int vlistGetFirstFourierGrid(int vlistID);
#endif
......@@ -41,6 +41,12 @@ public:
void
init(long _nlon, long _nlat, long _ntr, int _flag)
{
if (_nlon <= 0 || _nlat <= 0 || _ntr <= 0)
{
fprintf(stderr, "SPTRANS.init(): parameter not initialized\n");
return;
}
nlon = _nlon;
nlat = _nlat;
ntr = _ntr;
......
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