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

Replaced variable length array by std::vector.

parent a3edfe8a
......@@ -93,14 +93,13 @@ void *CDIwrite(void *argument)
int nvars = 10, nlevs = 0, ntimesteps = 30;
const char *defaultgrid = "global_.2";
int tsID, varID, levelID;
int gridsize, i;
int i;
int vlistID;
int zaxisID, taxisID;
int vdate, vtime, julday;
int vdate, vtime;
int filetype = -1, datatype = -1;
int irun, nruns = 1;
unsigned int seed = 1;
const char *gridfile;
char sinfo[64];
off_t nvalues = 0;
double file_size = 0, data_size = 0;
......@@ -117,7 +116,7 @@ void *CDIwrite(void *argument)
if ( operatorArgc() > 5 ) cdoAbort("Too many arguments!");
gridfile = defaultgrid;
const char *gridfile = defaultgrid;
if ( operatorArgc() >= 1 ) nruns = parameter2int(operatorArgv()[0]);
if ( operatorArgc() >= 2 ) gridfile = operatorArgv()[1];
if ( operatorArgc() >= 3 ) nlevs = parameter2int(operatorArgv()[2]);
......@@ -133,16 +132,17 @@ void *CDIwrite(void *argument)
if ( nvars <= 0 ) nvars = 1;
int gridID = cdoDefineGrid(gridfile);
gridsize = gridInqSize(gridID);
int gridsize = gridInqSize(gridID);
if ( nlevs == 1 )
zaxisID = zaxisCreate(ZAXIS_SURFACE, 1);
else
{
double levels[nlevs];
double *levels = (double *) Malloc(nlevs*sizeof(double));
for ( i = 0; i < nlevs; ++i ) levels[i] = 100*i;
zaxisID = zaxisCreate(ZAXIS_HEIGHT, nlevs);
zaxisDefLevels(zaxisID, levels);
Free(levels);
}
if ( cdoVerbose )
......@@ -222,7 +222,7 @@ void *CDIwrite(void *argument)
datatype = vlistInqVarDatatype(vlistID, 0);
if ( datatype == CDI_UNDEFID ) datatype = CDI_DATATYPE_FLT32;
julday = date_to_julday(CALENDAR_PROLEPTIC, 19870101);
int julday = date_to_julday(CALENDAR_PROLEPTIC, 19870101);
t0 = timer_val(timer_write);
......
......@@ -313,18 +313,10 @@ void setmisstodis(field_type *field1, field_type *field2, int num_neighbors)
gridInqYunits(gridID, units);
grid_to_radian(units, gridsize, yvals, "grid center lat");
unsigned *mindex = NULL;
unsigned *vindex = NULL;
double *lons = NULL;
double *lats = NULL;
if ( nmiss ) mindex = (unsigned *) Calloc(1, nmiss*sizeof(unsigned));
if ( nvals )
{
vindex = (unsigned *) Calloc(1, nvals*sizeof(unsigned));
lons = (double *) Malloc(nvals*sizeof(double));
lats = (double *) Malloc(nvals*sizeof(double));
}
unsigned *mindex = nmiss ? (unsigned *) Calloc(1, nmiss*sizeof(unsigned)) : NULL;
unsigned *vindex = nvals ? (unsigned *) Calloc(1, nvals*sizeof(unsigned)) : NULL;
double *lons = nvals ? (double *) Malloc(nvals*sizeof(double)) : NULL;
double *lats = nvals ? (double *) Malloc(nvals*sizeof(double)) : NULL;
unsigned nv = 0, nm = 0;
for ( unsigned i = 0; i < gridsize; ++i )
......
......@@ -41,15 +41,19 @@ void invertLevDes(int vlistID)
if ( zaxisInqLevels(zaxisID1, NULL) )
{
double yv1[nlev], yv2[nlev];
double *yv1 = (double*) Malloc(nlev*sizeof(double));
double *yv2 = (double*) Malloc(nlev*sizeof(double));
zaxisInqLevels(zaxisID1, yv1);
for ( int ilev = 0; ilev < nlev; ++ilev ) yv2[nlev-ilev-1] = yv1[ilev];
zaxisDefLevels(zaxisID2, yv2);
Free(yv1);
Free(yv2);
}
if ( zaxisInqLbounds(zaxisID1, NULL) && zaxisInqUbounds(zaxisID1, NULL) )
{
double yb1[nlev], yb2[nlev];
double *yb1 = (double*) Malloc(nlev*sizeof(double));
double *yb2 = (double*) Malloc(nlev*sizeof(double));
zaxisInqLbounds(zaxisID1, yb1);
for ( int ilev = 0; ilev < nlev; ++ilev ) yb2[nlev-ilev-1] = yb1[ilev];
zaxisDefLbounds(zaxisID2, yb2);
......@@ -57,6 +61,8 @@ void invertLevDes(int vlistID)
zaxisInqUbounds(zaxisID1, yb1);
for ( int ilev = 0; ilev < nlev; ++ilev ) yb2[nlev-ilev-1] = yb1[ilev];
zaxisDefUbounds(zaxisID2, yb2);
Free(yb1);
Free(yb2);
}
if ( zaxistype == ZAXIS_HYBRID || zaxistype == ZAXIS_HYBRID_HALF )
......@@ -64,8 +70,8 @@ void invertLevDes(int vlistID)
int vctsize = zaxisInqVctSize(zaxisID1);
if ( vctsize && vctsize%2 == 0 )
{
double vct1[vctsize];
double vct2[vctsize];
double *vct1 = (double*) Malloc(vctsize*sizeof(double));
double *vct2 = (double*) Malloc(vctsize*sizeof(double));
zaxisInqVct(zaxisID1, vct1);
for ( int i = 0; i < vctsize/2; ++i )
{
......@@ -73,6 +79,8 @@ void invertLevDes(int vlistID)
vct2[vctsize-1-i] = vct1[vctsize/2+i];
}
zaxisDefVct(zaxisID2, vctsize, vct2);
Free(vct1);
Free(vct2);
}
}
......
......@@ -35,6 +35,7 @@
Remap remap SCRIP grid remapping
*/
#include <vector>
#include <cdi.h>
#include "cdo.h"
#include "cdo_int.h"
......@@ -489,7 +490,7 @@ void scale_gridbox_area(long gridsize, const double *restrict array1, long grids
}
static
int set_remapgrids(int filetype, int vlistID, int ngrids, bool *remapgrids)
int set_remapgrids(int filetype, int vlistID, int ngrids, std::vector<bool>& remapgrids)
{
int index;
for ( index = 0; index < ngrids; index++ )
......@@ -840,7 +841,7 @@ void *Remap(void *argument)
vlistDefTaxis(vlistID2, taxisID2);
int ngrids = vlistNgrids(vlistID1);
bool remapgrids[ngrids];
std::vector<bool> remapgrids(ngrids);
int index = set_remapgrids(filetype, vlistID1, ngrids, remapgrids);
gridID1 = vlistGrid(vlistID1, index);
......
......@@ -21,6 +21,7 @@
*/
#include <vector>
#include "hetaeta.h"
#include <cdi.h>
#include "cdo.h"
......@@ -63,13 +64,13 @@ long ncctop(double cptop, long nlev, long nlevp1, double *vct_a, double *vct_b)
*/
/* local variables */
long nctop = 0;
long jk;
double za, zb, zph[nlevp1], zp[nlev];
double za, zb;
std::vector<double> zph(nlevp1), zp(nlev);
// double cptop = 1000.; /* min. pressure level for cond. */
/* half level pressure values, assuming 101320. Pa surface pressure */
for ( jk = 0; jk < nlevp1; ++jk )
for ( long jk = 0; jk < nlevp1; ++jk )
{
za = vct_a[jk];
zb = vct_b[jk];
......@@ -78,12 +79,12 @@ long ncctop(double cptop, long nlev, long nlevp1, double *vct_a, double *vct_b)
/* full level pressure */
for ( jk = 0; jk < nlev; ++jk )
for ( long jk = 0; jk < nlev; ++jk )
zp[jk] = (zph[jk] + zph[jk+1])*0.5;
/* search for pressure level cptop (Pa) */
for ( jk = 0; jk < nlev; ++jk )
for ( long jk = 0; jk < nlev; ++jk )
{
nctop = jk;
if ( zp[jk] >= cptop ) break;
......
#include <vector>
#include <cdi.h>
#include "cdo_int.h"
#include "grid.h"
......@@ -300,7 +301,7 @@ void *Samplegridicon(void *argument)
int nsamplegrids = operatorArgc();
if ( nsamplegrids < 2 ) cdoAbort("Parameter missing!");
cellindex_type *cellindex[nsamplegrids];
std::vector<cellindex_type *> cellindex(nsamplegrids);
for ( int i = 0; i < nsamplegrids; ++i )
{
......@@ -374,7 +375,7 @@ void *Samplegridicon(void *argument)
double missval = vlistInqVarMissval(vlistID1, varID);
samplegrid(missval, nsamplegrids, cellindex, array1, array2, array3);
samplegrid(missval, nsamplegrids, cellindex.data(), array1, array2, array3);
nmiss = 0;
for ( int i = 0; i < gridsize2; ++i )
......
......@@ -28,6 +28,7 @@
*/
#include <vector>
#include <cdi.h>
#include "cdo.h"
#include "cdo_int.h"
......@@ -55,7 +56,6 @@ void *Split(void *argument)
char filesuffix[32];
char filename[8192];
int nsplit = 0;
int gridsize;
int nmiss;
bool swap_obase = false;
const char *uuid_attribute = NULL;
......@@ -122,15 +122,15 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
int codes[nsplit];
memcpy(codes, itmp, nsplit*sizeof(int));
std::vector<int> codes(nsplit);
for ( int index = 0; index < nsplit; ++index ) codes[index] = itmp[index];
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
{
int code = vlistInqVarCode(vlistID1, varID);
int code = vlistInqVarCode(vlistID1, varID);
if ( codes[index] == code )
{
int nlevs = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
......@@ -187,10 +187,10 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
int params[nsplit];
memcpy(params, itmp, nsplit*sizeof(int));
std::vector<int> params(nsplit);
for ( int index = 0; index < nsplit; ++index ) params[index] = itmp[index];
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
......@@ -241,10 +241,10 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
int tabnums[nsplit];
memcpy(tabnums, itmp, nsplit*sizeof(int));
std::vector<int> tabnums(nsplit);
for ( int index = 0; index < nsplit; ++index ) tabnums[index] = itmp[index];
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
......@@ -327,10 +327,10 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
double levels[nsplit];
memcpy(levels, ftmp, nsplit*sizeof(double));
std::vector<double> levels(nsplit);
for ( int index = 0; index < nsplit; ++index ) levels[index] = ftmp[index];
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
......@@ -367,11 +367,11 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
int gridIDs[nsplit];
for ( int index = 0; index < nsplit; index++ )
std::vector<int> gridIDs(nsplit);
for ( int index = 0; index < nsplit; ++index )
gridIDs[index] = vlistGrid(vlistID1, index);
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
......@@ -405,11 +405,11 @@ void *Split(void *argument)
vlistIDs = (int*) Malloc(nsplit*sizeof(int));
streamIDs = (int*) Malloc(nsplit*sizeof(int));
int zaxisIDs[nsplit];
for ( int index = 0; index < nsplit; index++ )
std::vector<int> zaxisIDs(nsplit);
for ( int index = 0; index < nsplit; ++index )
zaxisIDs[index] = vlistZaxis(vlistID1, index);
for ( int index = 0; index < nsplit; index++ )
for ( int index = 0; index < nsplit; ++index )
{
vlistClearFlag(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
......@@ -452,7 +452,7 @@ void *Split(void *argument)
double *array = NULL;
if ( ! lcopy )
{
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
if ( vlistNumber(vlistID1) != CDI_REAL ) gridsize *= 2;
array = (double *) Malloc(gridsize*sizeof(double));
}
......@@ -468,7 +468,7 @@ void *Split(void *argument)
{
pstreamInqRecord(streamID1, &varID, &levelID);
int index = vlistInqIndex(vlistID1, varID, levelID);
int index = vlistInqIndex(vlistID1, varID, levelID);
vlistID2 = vlistIDs[index];
varID2 = vlistFindVar(vlistID2, varID);
levelID2 = vlistFindLevel(vlistID2, varID, levelID);
......
......@@ -23,6 +23,7 @@
*/
#include <vector>
#include <cdi.h>
#include "cdo.h"
#include "cdo_int.h"
......@@ -176,8 +177,8 @@ void *Vertintml(void *argument)
if ( linvertvct )
{
double vctbuf[nvct];
memcpy(vctbuf, vct, nvct*sizeof(double));
std::vector<double> vctbuf(nvct);
for ( int i = 0; i < nvct; ++i ) vctbuf[i] = vct[i];
for ( int i = 0; i < nvct/2; i++ )
{
vct[nvct/2-1-i] = vctbuf[i];
......@@ -187,11 +188,11 @@ void *Vertintml(void *argument)
int nvars = vlistNvars(vlistID1);
bool vars[nvars];
bool varinterp[nvars];
int *varnmiss[nvars];
double *vardata1[nvars];
double *vardata2[nvars];
std::vector<bool> vars(nvars);
std::vector<bool> varinterp(nvars);
std::vector<int *> varnmiss(nvars);
std::vector<double *> vardata1(nvars);
std::vector<double *> vardata2(nvars);
int maxlev = nhlevh > nplev ? nhlevh : nplev;
......@@ -202,8 +203,8 @@ void *Vertintml(void *argument)
{
int nlev = zaxisInqSize(zaxisIDh);
if ( nlev != nhlev ) cdoAbort("Internal error, wrong number of hybrid level!");
double levels[nlev];
cdoZaxisInqLevels(zaxisIDh, levels);
std::vector<double> levels(nlev);
cdoZaxisInqLevels(zaxisIDh, levels.data());
for ( int ilev = 0; ilev < nlev; ++ilev )
{
......@@ -229,14 +230,14 @@ void *Vertintml(void *argument)
if ( operfunc == func_hl )
{
double phlev[nplev];
height2pressure(phlev, plev, nplev);
std::vector<double> phlev(nplev);
height2pressure(phlev.data(), plev, nplev);
if ( cdoVerbose )
for ( int i = 0; i < nplev; ++i )
cdoPrint("level = %d height = %g pressure = %g", i+1, plev[i], phlev[i]);
memcpy(plev, phlev, nplev*sizeof(double));
memcpy(plev, phlev.data(), nplev*sizeof(double));
}
if ( opertype == type_log )
......
#include <vector>
#include "cdo.h"
#include "cdo_int.h"
#include "grid.h"
......@@ -760,7 +761,7 @@ void remap_conserv_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
}
struct grid_cell *tgt_grid_cell2[ompNumThreads];
std::vector<struct grid_cell *> tgt_grid_cell2(ompNumThreads);
for ( int i = 0; i < ompNumThreads; ++i )
{
tgt_grid_cell2[i] = (struct grid_cell*) Malloc(sizeof(struct grid_cell));
......@@ -772,7 +773,7 @@ void remap_conserv_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
tgt_grid_cell2[i]->coordinates_xyz = (double*) Malloc(3*tgt_num_cell_corners*sizeof(double));
}
search_t search[ompNumThreads];
std::vector<search_t> search(ompNumThreads);
for ( int i = 0; i < ompNumThreads; ++i )
{
search[i].srch_corners = src_num_cell_corners;
......@@ -784,7 +785,7 @@ void remap_conserv_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
search[i].overlap_buffer = NULL;
}
int *srch_add2[ompNumThreads];
std::vector<int *> srch_add2(ompNumThreads);
for ( int i = 0; i < ompNumThreads; ++i )
srch_add2[i] = (int*) Malloc(src_grid_size*sizeof(int));
......
......@@ -2,6 +2,7 @@
# include "config.h"
#endif
#include <vector>
#include <limits.h>
#include <time.h>
......@@ -1258,7 +1259,7 @@ void scrip_remap_conserv_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r
long srch_corners; /* num of corners of srch cells */
long nsrch_corners;
int* srch_add; /* global address of cells in srch arrays */
int* srch_add2[ompNumThreads];
std::vector<int *> srch_add2(ompNumThreads);
int i;
double *srch_corner_lat; /* lat of each corner of srch cells */
double *srch_corner_lon; /* lon of each corner of srch cells */
......@@ -1354,9 +1355,9 @@ void scrip_remap_conserv_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r
tgt_centroid_lon[n] = 0;
}
double* srch_corner_lat2[ompNumThreads];
double* srch_corner_lon2[ompNumThreads];
long max_srch_cells2[ompNumThreads];
std::vector<double *> srch_corner_lat2(ompNumThreads);
std::vector<double *> srch_corner_lon2(ompNumThreads);
std::vector<long> max_srch_cells2(ompNumThreads);
/* Integrate around each cell on source grid */
......
......@@ -35,11 +35,12 @@ int defineTable(const char *tablearg)
if ( tablepath )
{
int len = sizeof(tablepath) + sizeof(tablename) + 3;
char tablefile[len];
char *tablefile = (char*) malloc(len*sizeof(char));
strcpy(tablefile, tablepath);
strcat(tablefile, "/");
strcat(tablefile, tablename);
if ( fileExists(tablename) ) tableID = tableRead(tablefile);
free(tablefile);
}
}
......
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