Commit 532d4f31 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

moved cdoDebug and cdoDebugExt into CdoDebug namespace (into file cdoDebugOutput.h)

parent 2c0607d1
File added
......@@ -31,6 +31,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "grid.h"
#include "cdoDebugOutput.h"
/* read only the first data variable from input filename into a given double
* pointer */
......@@ -88,7 +89,7 @@ void *MapReduce(void *argument)
int inputGridID = cdoDefineGrid(operatorArgv()[0]);
size_t inputGridSize = gridInqSize(inputGridID);
int inputGridType = gridInqType(inputGridID);
if ( cdoDebug ) cdoPrint("MapReduce: input gridSize:%d", inputGridSize);
if ( CdoDebug::cdoDebug ) cdoPrint("MapReduce: input gridSize:%d", inputGridSize);
/* creata an index list of the relevant locations {{{ */
double *inputMaskField = (double*) Malloc(inputGridSize*sizeof(double));
......@@ -96,7 +97,7 @@ void *MapReduce(void *argument)
/* non-zero values mark the relevant points */
int maskSize = countMask(inputMaskField, inputGridSize, 0.0);
if ( cdoDebug ) cdoPrint("MapReduce: maskSize = %d",maskSize);
if ( CdoDebug::cdoDebug ) cdoPrint("MapReduce: maskSize = %d",maskSize);
int *maskIndexList = (int *) Malloc(maskSize*sizeof(int));
for (int m = 0; m < maskSize; m++) maskIndexList[m] = -1;
......
......@@ -7,6 +7,7 @@
*/
#include <cdi.h>
#include "cdoDebugOutput.h"
#include "cdo_int.h"
#include "pstream.h"
#include "grid.h"
......@@ -21,7 +22,7 @@ void sampleData(double *array1, int gridID1, double *array2, int gridID2, int re
long nlon2 = gridInqXsize(gridID2);
long nlat2 = gridInqYsize(gridID2);
if ( cdoDebugExt >= 100 )
if ( CdoDebug::cdoDebugExt >= 100 )
cdoPrint("%s(): (nlon1: %d; nlat1: %d) => (nlon2: %d; nlat2: %d); gridID1: %d; gridID2: %d; resampleFactor: %d)",
__func__, nlon1, nlat1, nlon2,nlat2, gridID1, gridID2, resampleFactor);
......@@ -40,7 +41,7 @@ void cropData(double *array1, int gridID1, double *array2, int gridID2, int subI
if ( rowLen!= nlon2 )
cdoAbort("cropData() rowLen!= nlon2 [%d != %d]", rowLen, nlon2);
if ( cdoDebugExt>=10 ) cdoPrint("cropData(%d,%d,%d,%d) ...", subI0, subI1, subJ0, subJ1 );
if ( CdoDebug::cdoDebugExt>=10 ) cdoPrint("cropData(%d,%d,%d,%d) ...", subI0, subI1, subJ0, subJ1 );
long array2Idx = 0;
for ( long ilat1 = subJ0; ilat1 <= subJ1; ilat1++ ) // copy the last row as well..
......@@ -76,15 +77,15 @@ void *Samplegrid(void *argument)
if ( operatorID == SAMPLEGRID )
{
if ( cdoDebugExt ) cdoPrint("samplegrid operator requested..");
if ( CdoDebug::cdoDebugExt ) cdoPrint("samplegrid operator requested..");
if ( nch < 1 ) cdoAbort("Number of input arguments < 1; At least 1 argument needed: resample-factor (2,3,4, .. etc)");
resampleFactor = parameter2int(operatorArgv()[0]);
if ( cdoDebugExt ) cdoPrint("resampleFactor = %d", resampleFactor);
if ( CdoDebug::cdoDebugExt ) cdoPrint("resampleFactor = %d", resampleFactor);
}
else if ( operatorID == SUBGRID )
{
if ( cdoDebugExt ) cdoPrint("subgrid operator requested..");
if ( CdoDebug::cdoDebugExt ) cdoPrint("subgrid operator requested..");
if ( nch < 4 ) cdoAbort("Number of input arguments < 4; Must specify sub-grid indices: i0,i1,j0,j1; This works only with LCC grid. For other grids use: selindexbox");
subI0 = parameter2int(operatorArgv()[0]);
subI1 = parameter2int(operatorArgv()[1]);
......@@ -109,7 +110,7 @@ void *Samplegrid(void *argument)
int ngrids = vlistNgrids(vlistID1);
if ( cdoDebugExt ) cdoPrint("ngrids = %d", ngrids);
if ( CdoDebug::cdoDebugExt ) cdoPrint("ngrids = %d", ngrids);
sbox_t *sbox = (sbox_t *) Malloc(ngrids*sizeof(sbox_t));
......@@ -137,8 +138,8 @@ void *Samplegrid(void *argument)
sbox[index].gridSrcID = gridSrcID;
sbox[index].gridIDsampled = gridIDsampled;
// if ( cdoDebugExt>=10 ) cdo_print_grid(gridSrcID, 1);
// if ( cdoDebugExt>=10 ) cdo_print_grid(gridIDsampled, 1);
// if ( CdoDebug::cdoDebugExt>=10 ) cdo_print_grid(gridSrcID, 1);
// if ( CdoDebug::cdoDebugExt>=10 ) cdo_print_grid(gridIDsampled, 1);
vlistChangeGridIndex(vlistID2, index, gridIDsampled);
......@@ -147,7 +148,7 @@ void *Samplegrid(void *argument)
vars[varID] = true;
}
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
if ( operatorID == SAMPLEGRID ) cdoPrint("Resampled grid has been created.");
if ( operatorID == SUBGRID ) cdoPrint("Sub-grid has been created.");
......@@ -164,7 +165,7 @@ void *Samplegrid(void *argument)
if ( vlistNumber(vlistID2) != CDI_REAL ) gridsize2 *= 2;
double *array2 = (double *) Malloc(gridsize2*sizeof(double));
if ( cdoDebugExt ) cdoPrint("gridsize = %ld, gridsize2 = %ld", gridsize, gridsize2);
if ( CdoDebug::cdoDebugExt ) cdoPrint("gridsize = %ld, gridsize2 = %ld", gridsize, gridsize2);
int tsID = 0;
while ( (nrecs = pstreamInqTimestep(streamID1, tsID)) )
......@@ -179,7 +180,7 @@ void *Samplegrid(void *argument)
pstreamDefRecord(streamID2, varID, levelID);
if ( cdoDebugExt>=20 ) cdoPrint("Processing record (%d) of %d.",recID, nrecs);
if ( CdoDebug::cdoDebugExt>=20 ) cdoPrint("Processing record (%d) of %d.",recID, nrecs);
if ( vars[varID] )
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -397,7 +397,7 @@ void cdoSetDebug(int level)
*/
cdiDebug(level);
if ( level == 1 || (level & 32) ) cdoDebug = 1;
if ( level == 1 || (level & 32) ) CdoDebug::cdoDebug = 1;
if ( level == 1 || (level & 64) ) CdoDebug::PSTREAM = 1;
if ( level == 1 || (level & 512) ) CdoDebug::PROCESS = 1;
#if defined(HAVE_LIBPTHREAD)
......@@ -1276,14 +1276,14 @@ int parse_options_long(int argc, char *argv[])
if ( newDebLevelVal > 0 )
{
extern int cdiDebugExt;
cdoDebugExt = newDebLevelVal;
CdoDebug::cdoDebugExt = newDebLevelVal;
cdiDebugExt = newDebLevelVal;
}
}
else if ( lscmode )
{
int scanningModeValue = atoi(CDO_optarg);
if ( cdoDebugExt ) printf("scanningModeValue=%d\n", scanningModeValue);
if ( CdoDebug::cdoDebugExt ) printf("scanningModeValue=%d\n", scanningModeValue);
if ( (scanningModeValue==0) || (scanningModeValue==64) || (scanningModeValue==96) )
{
......@@ -1429,8 +1429,6 @@ int parse_options_long(int argc, char *argv[])
#ifdef DEBUG
CdoDebug::outfile = CDO_optarg;
CdoDebug::print_to_seperate_file = true;
CdoDebug::PSTREAM = 1;
CdoDebug::PROCESS = 1;
#endif
break;
}
......@@ -1620,7 +1618,8 @@ int main(int argc, char *argv[])
if ( Debug )
{
if ( DebugLevel == 0 ) DebugLevel = 1;
cdoSetDebug(DebugLevel);
cdiDebug(DebugLevel);
CdoDebug::SetDebug(DebugLevel);
}
timer_total = timer_new("total");
......
#include "cdoDebugOutput.h"
namespace CdoLog
namespace CdoDebug
{
void StdOut(std::stringstream & p_message)
void SetDebug(int p_debug_level)
{
std::cout << p_message.str();
}
}
/*
p_debug_level 0: off
p_debug_level 1: on
p_debug_level 2: cdi
p_debug_level 4: memory
p_debug_level 8: file
p_debug_level 16: format
p_debug_level 32: cdo
p_debug_level 64: stream
p_debug_level 128: pipe
p_debug_level 256: pthread
p_debug_level 512: process
*/
namespace CdoDebug
{
int PTHREAD;
int PSTREAM;
bool PROCESS;
bool PIPE;
int ARGUMENT;
if ( p_debug_level == 1 || (p_debug_level & 32) ) cdoDebug = 1;
if ( p_debug_level == 1 || (p_debug_level & 64) ) PSTREAM = 1;
if ( p_debug_level == 1 || (p_debug_level & 512) ) PROCESS = 1;
#if defined(HAVE_LIBPTHREAD)
if ( p_debug_level == 1 || (p_debug_level & 128) ) PIPE = 1;
if ( p_debug_level == 1 || (p_debug_level & 256) ) PTHREAD = 1;
#endif
}
std::string outfile = "";
bool print_to_seperate_file = false;
std::fstream outfile_stream;
//Debug Switches
int cdoDebug;
int cdoDebugExt = 0; // Debug level for the KNMI extensions
//Subsystem Debug Switches
int PSTREAM;
bool PROCESS;
bool PIPE;
int ARGUMENT;
int PTHREAD;
//File switches and streams
std::string outfile;
bool print_to_seperate_file;
std::fstream outfile_stream;
std::string
get_padding(const char *p_func)
{
......@@ -46,3 +67,10 @@ namespace CdoDebug
outfile_stream.close();
}
}
namespace CdoLog
{
void StdOut(std::stringstream & p_message)
{
std::cout << p_message.str();
}
}
......@@ -40,19 +40,27 @@ namespace CdoLog
namespace CdoDebug
{
//Debug Switches
extern int cdoDebug;
extern int cdoDebugExt; // Debug level for the KNMI extensions
//Subsystem Debug Switches
extern int PSTREAM;
extern bool PROCESS;
extern bool PIPE;
extern int ARGUMENT;
extern int PTHREAD;
//File switches and streams
extern std::string outfile;
extern bool print_to_seperate_file;
extern std::fstream outfile_stream;
extern int PTHREAD;
std::string get_padding(const char *p_func);
void CdoStartMessage();
void CdoEndMessage();
void SetDebug(int p_debug_level);
namespace{
void printMessage(std::stringstream &p_message)
......
#include <cdi.h>
#include "cdoDebugOutput.h"
#include "cdo_int.h"
#include "grid.h"
......@@ -34,11 +35,11 @@ int cdo_define_destagered_grid(int gridID_u_stag, int gridID_v_stag, double *des
rlat : first = -30.8 last = 24.1 inc = 0.1 degrees
northpole : lon = -195 lat = 30
*/
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
cdoPrint("%s(gridID_u=%d,gridID_v=%d,destagGridOffsets(%02.1f,%02.1f)) ...\n",
__func__, gridID_u_stag, gridID_v_stag, destagGridOffsets[0],destagGridOffsets[1]);
if ( cdoDebugExt > 1 )
if ( CdoDebug::cdoDebugExt > 1 )
{
cdo_print_grid(gridID_u_stag, 1);
cdo_print_grid(gridID_v_stag, 1);
......@@ -61,7 +62,7 @@ int cdo_define_destagered_grid(int gridID_u_stag, int gridID_v_stag, double *des
int gridID_uv_destag = gridDuplicate(gridID_u_stag);
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
cdo_print_grid(gridID_uv_destag, 1);
......@@ -100,7 +101,7 @@ int cdo_define_destagered_grid(int gridID_u_stag, int gridID_v_stag, double *des
gridDefYvals(gridID_uv_destag, yvals);
Free(yvals);
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
cdoPrint("%s():", __func__);
cdo_print_grid(gridID_uv_destag, 1);
......@@ -168,7 +169,7 @@ int cdo_define_sample_grid(int gridSrcID, int sampleFactor)
longitudeOfFirstGridPointInDegrees = -7.89
latitudeOfFirstGridPointInDegrees = 42.935
*/
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
cdoPrint("%s(gridSrcID=%d, sampleFactor=%d) ...", __func__, gridSrcID, sampleFactor);
int gridtype = gridInqType(gridSrcID);
......@@ -183,7 +184,7 @@ int cdo_define_sample_grid(int gridSrcID, int sampleFactor)
cdoAbort("%s(): Unsupported sampleFactor (%d)! Note that: gridXsize = %d, gridYsize = %d",
__func__, sampleFactor, gridXsize, gridYsize);
if ( cdoDebugExt>20 ) cdo_print_grid(gridSrcID, 1);
if ( CdoDebug::cdoDebugExt>20 ) cdo_print_grid(gridSrcID, 1);
int xsize = (gridXsize + (sampleFactor-1)) / sampleFactor; // HARM36_L25: (789 + 2-1) / 2 = 395
int ysize = (gridYsize + (sampleFactor-1)) / sampleFactor;
......@@ -237,7 +238,7 @@ int cdo_define_sample_grid(int gridSrcID, int sampleFactor)
}
}
if ( cdoDebugExt>20 )
if ( CdoDebug::cdoDebugExt>20 )
{
cdoPrint("cdo SampleGrid: define_sample_grid(): ");
cdo_print_grid(gridID_sampled, 1);
......@@ -306,7 +307,7 @@ int cdo_define_subgrid_grid(int gridSrcID, int subI0, int subI1, int subJ0, int
longitudeOfFirstGridPointInDegrees = ...
latitudeOfFirstGridPointInDegrees = ...
*/
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
cdoPrint("%s(gridSrcID=%d, (subI0,subI1,subJ0,subJ1) = (%d,%d,%d,%d) ...",
__func__, gridSrcID, subI0,subI1, subJ0, subJ1 );
......@@ -331,9 +332,9 @@ int cdo_define_subgrid_grid(int gridSrcID, int subI0, int subI1, int subJ0, int
x_0 = grid_missval;
y_0 = grid_missval;
if ( cdoDebugExt>20 ) cdo_print_grid(gridSrcID, 1);
if ( CdoDebug::cdoDebugExt>20 ) cdo_print_grid(gridSrcID, 1);
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
cdoPrint("%s() Original LCC grid:", __func__);
cdoPrint("grid Xsize %d, grid Ysize %d", gridXsize, gridYsize);
......@@ -345,7 +346,7 @@ int cdo_define_subgrid_grid(int gridSrcID, int subI0, int subI1, int subJ0, int
xval_0 = gridInqXval(gridIDcurvl, 0);
yval_0 = gridInqYval(gridIDcurvl, 0);
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
cdoPrint("%s() Original LCC grid as curvilinear (with lats-lons computed):", __func__);
cdoPrint("grid Xsize %d, grid Ysize %d", gridInqXsize(gridIDcurvl), gridInqYsize(gridIDcurvl));
......@@ -383,7 +384,7 @@ int cdo_define_subgrid_grid(int gridSrcID, int subI0, int subI1, int subJ0, int
xval_0 = gridInqXval(gridIDcurvl, subJ0*gridXsize + subI0);
yval_0 = gridInqYval(gridIDcurvl, subJ0*gridXsize + subI0);
if ( cdoDebugExt )
if ( CdoDebug::cdoDebugExt )
{
cdoPrint("%s() Sub-grid:", __func__);
cdoPrint("grid Xsize %d, grid Ysize %d", gridInqXsize(gridID_sampled), gridInqYsize(gridID_sampled));
......@@ -394,7 +395,7 @@ int cdo_define_subgrid_grid(int gridSrcID, int subI0, int subI1, int subJ0, int
gridDestroy(gridIDcurvl);
if ( cdoDebugExt>20 )
if ( CdoDebug::cdoDebugExt>20 )
{
cdoPrint("%s(): ", __func__);
cdo_print_grid(gridID_sampled, 1);
......
......@@ -25,6 +25,7 @@
#include "grid.h"
#include "griddes.h"
#include "error.h"
#include "cdoDebugOutput.h"
int grid_read(FILE *gfp, const char *dname);
......@@ -344,7 +345,7 @@ int cdoDefineGrid(const char *gridfile)
if ( cmpstrlen(buffer, "CDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from NetCDF file");
if ( CdoDebug::cdoDebug ) cdoPrint("Grid from NetCDF file");
gridID = gridFromNCfile(filename);
}
......@@ -352,7 +353,7 @@ int cdoDefineGrid(const char *gridfile)
{
if ( cmpstrlen(buffer+1, "HDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from HDF5 file");
if ( CdoDebug::cdoDebug ) cdoPrint("Grid from HDF5 file");
gridID = gridFromH5file(filename);
}
}
......@@ -361,14 +362,14 @@ int cdoDefineGrid(const char *gridfile)
{
if ( cmpstrlen(buffer+1, "HDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from NetCDF4 file");
if ( CdoDebug::cdoDebug ) cdoPrint("Grid from NetCDF4 file");
gridID = gridFromNCfile(filename);
}
}
if ( gridID == -1 )
{
if ( cdoDebug ) cdoPrint("Grid from CDI file");
if ( CdoDebug::cdoDebug ) cdoPrint("Grid from CDI file");
openLock();
int streamID = streamOpenRead(filename);
openUnlock();
......@@ -382,7 +383,7 @@ int cdoDefineGrid(const char *gridfile)
if ( gridID == -1 )
{
if ( cdoDebug ) cdoPrint("grid from ASCII file");
if ( CdoDebug::cdoDebug ) cdoPrint("grid from ASCII file");
FILE *gfp = fopen(filename, "r");
//size_t buffersize = 20*1024*1024;
//char *buffer = (char*) Malloc(buffersize);
......@@ -394,7 +395,7 @@ int cdoDefineGrid(const char *gridfile)
if ( gridID == -1 )
{
if ( cdoDebug ) cdoPrint("grid from PINGO file");
if ( CdoDebug::cdoDebug ) cdoPrint("grid from PINGO file");
FILE *gfp = fopen(filename, "r");
gridID = grid_read_pingo(gfp, filename);
fclose(gfp);
......
......@@ -1221,7 +1221,7 @@ processClosePipes(void)
pstream_t *pstreamptr = processInqInputStream(sindex);
if (CdoDebug::PROCESS)
Message("process %d stream %d close streamID %d", processSelf().m_ID, sindex, pstreamptr->self);
MESSAGE("process ",processSelf().m_ID," instream ",sindex," close streamID ", pstreamptr->self);
if (pstreamptr)
pstreamptr->close();
......@@ -1233,17 +1233,14 @@ processClosePipes(void)
pstream_t *pstreamptr = processInqOutputStream(sindex);
if (CdoDebug::PROCESS)
Message("process %d stream %d close streamID %d", processSelf().m_ID, sindex, pstreamptr->self);
MESSAGE("process ",processSelf().m_ID," outstream ",sindex," close streamID ", pstreamptr->self);
if (pstreamptr)
pstreamptr->close();
}
}
extern "C" {
size_t getPeakRSS( );
}
void
cdoFinish(void)
{
......@@ -1257,7 +1254,7 @@ cdoFinish(void)
#if defined(HAVE_LIBPTHREAD)
if (CdoDebug::PROCESS)
Message("process %d thread %ld", processID, pthread_self());
MESSAGE("process ",processID," thread %ld", pthread_self());
#endif
int64_t nvals = processInqNvals(processID);
......@@ -1330,8 +1327,9 @@ cdoFinish(void)
{
int mu[] = { 'b', 'k', 'm', 'g', 't' };
int muindex = 0;
// size_t memmax = memTotal();
size_t memmax = getPeakRSS();
long memmax;
memmax = memTotal();
while (memmax > 9999)
{
memmax /= 1024;
......@@ -1339,7 +1337,7 @@ cdoFinish(void)
}
if (memmax)
snprintf(memstring, sizeof(memstring), " %zu%c", memmax, mu[muindex]);
snprintf(memstring, sizeof(memstring), " %ld%c ", memmax, mu[muindex]);
processEndTime(&p_usertime, &p_systime);
p_cputime = p_usertime + p_systime;
......@@ -1354,11 +1352,11 @@ cdoFinish(void)
#if defined(HAVE_SYS_TIMES_H)
if (cdoBenchmark)
fprintf(stderr, " ( %.2fs %.2fs %.2fs%s )\n", c_usertime, c_systime, c_cputime, memstring);
fprintf(stderr, " ( %.2fs %.2fs %.2fs %s)\n", c_usertime, c_systime, c_cputime, memstring);
else
{
if (!cdoSilentMode)
fprintf(stderr, " ( %.2fs%s )\n", c_cputime, memstring);
fprintf(stderr, " ( %.2fs )\n", c_cputime);
}
if (cdoBenchmark && processID == 0)
fprintf(stderr, "total: user %.2fs sys %.2fs cpu %.2fs mem%s\n", p_usertime, p_systime, p_cputime, memstring);
......
......@@ -101,7 +101,6 @@ int cdoCompress = FALSE;
int cdoInteractive = FALSE;
int cdoParIO = FALSE;
int cdoRegulargrid = FALSE;
int cdoDebugExt = 0; // Debug level for the KNMI extensions
int cdoNumVarnames = 0;
char **cdoVarnames = NULL;
......
......@@ -90,11 +90,9 @@ extern int cdoRegulargrid;
extern int cdoBenchmark;
extern int cdoTimer;
extern int cdoVerbose;
extern int cdoDebug;
extern int cdoCompress;
extern int cdoInteractive;
extern int cdoParIO;
extern int cdoDebugExt;
extern int cdoCompType;
extern int cdoCompLevel;
......
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