Commit 3cd3f0ec authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent eb69abac
......@@ -54,26 +54,22 @@ double adisit_1(double tpot, double sal, double p)
a_d = 4.1057E-9,
a_e1 = 1.6056E-10, a_e2 = 5.0484E-12;
double dc, dv, dvs, fne, fst, qc, qn3, qnq, qv, qvs, t, tpo;
qc = p * (a_a1 + p * (a_c1 - a_e1 * p));
qv = p * (a_b1 - a_d * p);
dc = 1. + p * (-a_a2 + p * (a_c2 - a_e2 * p));
dv = a_b2 * p;
qnq = -p * (-a_a3 + p * a_c3);
qn3 = -p * a_a4;
{
tpo = tpot;
qvs = qv*(sal - 35.) + qc;
dvs = dv*(sal - 35.) + dc;
t = (tpo + qvs)/dvs;
fne = - qvs + t*(dvs + t*(qnq + t*qn3)) - tpo;
fst = dvs + t*(2.*qnq + 3.*qn3*t);
t = t - fne/fst;
}
return (t);
double qc = p * (a_a1 + p * (a_c1 - a_e1 * p));
double qv = p * (a_b1 - a_d * p);
double dc = 1. + p * (-a_a2 + p * (a_c2 - a_e2 * p));
double dv = a_b2 * p;
double qnq = -p * (-a_a3 + p * a_c3);
double qn3 = -p * a_a4;
double tpo = tpot;
double qvs = qv*(sal - 35.) + qc;
double dvs = dv*(sal - 35.) + dc;
double t = (tpo + qvs)/dvs;
double fne = - qvs + t*(dvs + t*(qnq + t*qn3)) - tpo;
double fst = dvs + t*(2.*qnq + 3.*qn3*t);
t = t - fne/fst;
return t;
}
/* compute potential temperature from insitu temperature */
......@@ -87,19 +83,17 @@ double adipot(double t, double s, double p)
a_d = 4.1057E-9,
a_e1 = 1.6056E-10, a_e2 = 5.0484E-12;
double aa,bb,cc,cc1,dd,tpot,s_rel;
double s_rel = s - 35.0;
s_rel = s - 35.0;
double aa = (a_a1+ t*(a_a2 - t*(a_a3 - a_a4*t)));
double bb = s_rel*(a_b1 -a_b2*t) ;
double cc = (a_c1 + t*(-a_c2 + a_c3*t));
double cc1 = a_d*s_rel;
double dd = (-a_e1 + a_e2*t);
aa = (a_a1+ t*(a_a2 - t*(a_a3 - a_a4*t)));
bb = s_rel*(a_b1 -a_b2*t) ;
cc = (a_c1 + t*(-a_c2 + a_c3*t));
cc1 = a_d*s_rel;
dd = (-a_e1 + a_e2*t);
double tpot = t-p*(aa + bb + p*(cc - cc1 + p*dd));
tpot=t-p*(aa + bb + p*(cc - cc1 + p*dd));
return (tpot);
return tpot;
}
static
......@@ -109,17 +103,14 @@ void calc_adisit(long gridsize, long nlevel, double *pressure, field_t tho, fiel
/* tho units: Celsius */
/* sao units: psu */
long i, levelID, offset;
double *tisptr, *thoptr, *saoptr;
for ( levelID = 0; levelID < nlevel; ++levelID )
for ( long levelID = 0; levelID < nlevel; ++levelID )
{
offset = gridsize*levelID;
thoptr = tho.ptr + offset;
saoptr = sao.ptr + offset;
tisptr = tis.ptr + offset;
long offset = gridsize*levelID;
double *thoptr = tho.ptr + offset;
double *saoptr = sao.ptr + offset;
double *tisptr = tis.ptr + offset;
for ( i = 0; i < gridsize; ++i )
for ( long i = 0; i < gridsize; ++i )
{
if ( DBL_IS_EQUAL(thoptr[i], tho.missval) ||
DBL_IS_EQUAL(saoptr[i], sao.missval) )
......@@ -141,17 +132,14 @@ void calc_adipot(long gridsize, long nlevel, double *pressure, field_t t, field_
/* t units: Celsius */
/* s units: psu */
long i, levelID, offset;
double *tpotptr, *tptr, *sptr;
for ( levelID = 0; levelID < nlevel; ++levelID )
for ( long levelID = 0; levelID < nlevel; ++levelID )
{
offset = gridsize*levelID;
tptr = t.ptr + offset;
sptr = s.ptr + offset;
tpotptr = tpot.ptr + offset;
long offset = gridsize*levelID;
double *tptr = t.ptr + offset;
double *sptr = s.ptr + offset;
double *tpotptr = tpot.ptr + offset;
for ( i = 0; i < gridsize; ++i )
for ( long i = 0; i < gridsize; ++i )
{
if ( DBL_IS_EQUAL(tptr[i], t.missval) ||
DBL_IS_EQUAL(sptr[i], s.missval) )
......@@ -331,13 +319,9 @@ void *Adisit(void *argument)
}
if ( operatorID == ADISIT )
{
calc_adisit(gridsize, nlevel, pressure, tho, sao, tis);
}
calc_adisit(gridsize, nlevel, pressure, tho, sao, tis);
else
{
calc_adipot(gridsize, nlevel, pressure, tho, sao, tis);
}
calc_adipot(gridsize, nlevel, pressure, tho, sao, tis);
for ( levelID = 0; levelID < nlevel; ++levelID )
......
......@@ -88,7 +88,7 @@ int valid_argument (char *caller, char *arg)
fprintf (stderr, "%s: Argument required.\n", caller);
return 0;
}
return (1);
return 1;
}
/* Print out help for ARG, or for all of the commands if ARG is not present. */
......@@ -226,13 +226,11 @@ int com_vars(const char *arg)
command. Return a NULL pointer if NAME isn't a command name. */
command_t *find_command(char *name)
{
int i;
for ( i = 0; commands[i].name; i++ )
for ( int i = 0; commands[i].name; i++ )
if ( strcmp(name, commands[i].name) == 0)
return (&commands[i]);
return &commands[i];
return ((command_t *)NULL);
return (command_t *)NULL;
}
/* Execute a command line. */
......@@ -261,7 +259,7 @@ int execute_line(char *line)
word = line + i;
/* Call the function. */
return ((*(command->func)) (word));
return (*(command->func)) (word);
}
/* Strip isspace from the start and end of STRING. Return a pointer into STRING. */
......@@ -271,7 +269,7 @@ char *stripwhite(char *string)
for (s = string; isspace(*s); s++)
;
if (*s == 0)
return (s);
return s;
t = s + strlen (s) - 1;
while (t > s && isspace(*t))
t--;
......
......@@ -271,7 +271,7 @@ int import_e5ml(const char *filename, VAR **vars)
cdoAbort("NetCDF support not compiled in!");
#endif
return (nvars);
return nvars;
}
static
......@@ -1078,7 +1078,7 @@ int import_e5res(const char *filename, VAR **vars, ATTS *atts)
cdoAbort("NetCDF support not compiled in!");
#endif
return (nvars);
return nvars;
}
static
......
......@@ -165,7 +165,7 @@ int getDate(const char *name)
if ( pname ) date = atoi(pname+1);
return(date);
return date;
}
......
......@@ -167,7 +167,7 @@ int defLonLatGrid(int nx, int ny, double c0, double lts, double re)
if ( nx != nrx || ny != nry )
{
printf("nrx=%d nry=%d\n", nrx, nry);
return(-1);
return -1;
}
double *xvals = (double*) Malloc(nx*sizeof(double));
......
......@@ -112,7 +112,7 @@ int vlistConstVars(int vlistID)
for ( int varID = 0; varID < nvars; ++varID )
if ( vlistInqVarTsteptype(vlistID, varID) != TSTEP_CONSTANT ) return 0;
return (1);
return 1;
}
*/
......
......@@ -164,7 +164,7 @@ int datelist(LIST *flist)
nsel = 2;
}
return (nsel);
return nsel;
}
......
......@@ -172,7 +172,7 @@ int gentpngrid(int gridID1)
}
}
return (gridID2);
return gridID2;
}
static
......@@ -374,15 +374,12 @@ int gengrid(int gridID1, int lhalo, int rhalo)
static
int genindexgrid(int gridID1, int *lhalo, int *rhalo)
{
int gridID2;
int nlon1;
operatorCheckArgc(2);
*lhalo = parameter2int(operatorArgv()[0]);
*rhalo = parameter2int(operatorArgv()[1]);
nlon1 = gridInqXsize(gridID1);
int nlon1 = gridInqXsize(gridID1);
if ( *lhalo > nlon1 )
{
......@@ -408,36 +405,32 @@ int genindexgrid(int gridID1, int *lhalo, int *rhalo)
cdoWarning("right halo out of range. Set to %d.", rhalo);
}
gridID2 = gengrid(gridID1, *lhalo, *rhalo);
int gridID2 = gengrid(gridID1, *lhalo, *rhalo);
return (gridID2);
return gridID2;
}
static
void halo(double *array1, int gridID1, double *array2, int lhalo, int rhalo)
{
int nlon1, nlat;
int ilat, ilon;
int nmin, nmax;
int nlon1 = gridInqXsize(gridID1);
int nlat = gridInqYsize(gridID1);
nlon1 = gridInqXsize(gridID1);
nlat = gridInqYsize(gridID1);
nmin = 0;
nmax = nlon1;
int nmin = 0;
int nmax = nlon1;
if ( lhalo < 0 ) nmin = -lhalo;
if ( rhalo < 0 ) nmax += rhalo;
for ( ilat = 0; ilat < nlat; ilat++ )
for ( int ilat = 0; ilat < nlat; ilat++ )
{
for ( ilon = nlon1-lhalo; ilon < nlon1; ilon++ )
for ( int ilon = nlon1-lhalo; ilon < nlon1; ilon++ )
*array2++ = array1[ilat*nlon1 + ilon];
for ( ilon = nmin; ilon < nmax; ilon++ )
for ( int ilon = nmin; ilon < nmax; ilon++ )
*array2++ = array1[ilat*nlon1 + ilon];
for ( ilon = 0; ilon < rhalo; ilon++ )
for ( int ilon = 0; ilon < rhalo; ilon++ )
*array2++ = array1[ilat*nlon1 + ilon];
}
}
......@@ -446,21 +439,16 @@ void halo(double *array1, int gridID1, double *array2, int lhalo, int rhalo)
static
void tpnhalo(double *array1, int gridID1, double *array2)
{
int nlon, nlat;
int ilat, ilon, ilonr;
int nlon = gridInqXsize(gridID1);
int nlat = gridInqYsize(gridID1);
nlon = gridInqXsize(gridID1);
nlat = gridInqYsize(gridID1);
for ( ilat = 0; ilat < nlat; ilat++ )
{
for ( ilon = 0; ilon < nlon; ilon++ )
array2[(ilat+2)*nlon + ilon] = array1[ilat*nlon + ilon];
}
for ( int ilat = 0; ilat < nlat; ilat++ )
for ( int ilon = 0; ilon < nlon; ilon++ )
array2[(ilat+2)*nlon + ilon] = array1[ilat*nlon + ilon];
for ( ilon = 0; ilon < nlon; ilon++ )
for ( int ilon = 0; ilon < nlon; ilon++ )
{
ilonr = nlon - ilon - 1;
int ilonr = nlon - ilon - 1;
array2[1*nlon + ilon] = array2[2*nlon + ilonr]; /* syncronise line 2 with line 3 */
array2[0*nlon + ilon] = array2[3*nlon + ilonr]; /* syncronise line 1 with line 4 */
}
......
......@@ -168,7 +168,7 @@ void *get_converter(char *src_unit_str, char *tgt_unit_str, int *rstatus)
return NULL;
}
return ((void *) ut_units_converter);
return (void *) ut_units_converter;
}
#endif
......
......@@ -107,15 +107,14 @@ static int compnlon(int nlat)
}
static int nlat2nlon(int nlat)
static
int nlat2nlon(int nlat)
{
int nlon, m, ierr;
if ( nlat == 0 )
cdoAbort("nlat = 0!");
if ( nlat == 0 ) cdoAbort("nlat = 0!");
nlon = 2*nlat;
int nlon = 2*nlat;
int m, ierr;
fac(nlon, &m, &ierr);
/* adjust till fft is possible */
while (ierr != 0)
......@@ -126,7 +125,7 @@ static int nlat2nlon(int nlat)
fac(nlon, &m, &ierr);
}
return (nlon);
return nlon;
}
......@@ -138,16 +137,15 @@ int ngp2ntr(int ngp)
ntr = (2*nlatl-1)/2;
return (ntr);
return ntr;
}
int ipow(int i1, int i2)
{
int i;
int i3 = 1;
for ( i = 0; i < i2; ++i ) i3 *= i1;
for ( int i = 0; i < i2; ++i ) i3 *= i1;
return i3;
}
......
......@@ -209,7 +209,7 @@ int fill_gap(int ngaps, int ntsm[MAX_NTSM], int rangetsm[MAX_GAPS][2],
ntsm[ngaps] = its;
}
return (its);
return its;
}
......
......@@ -36,7 +36,7 @@ double tstepcount(long nts, double missval1, double *array1, double refval)
long j;
long n = 0;
if ( DBL_IS_EQUAL(refval, missval1) ) return (missval1);
if ( DBL_IS_EQUAL(refval, missval1) ) return missval1;
for ( j = 0; j < nts; j++ )
{
......
......@@ -54,7 +54,7 @@ int hour_of_year(int vdate, int vtime)
cdoAbort("Hour of year %d out of range (%s %s)!", houroy, vdatestr, vtimestr);
}
return (houroy);
return houroy;
}
......
......@@ -59,7 +59,7 @@ int hour_of_year(int vdate, int vtime)
cdoAbort("Hour of year %d out of range (%s %s)!", houroy, vdatestr, vtimestr);
}
return (houroy);
return houroy;
}
......
......@@ -49,7 +49,7 @@ int cmpint(const void *s1, const void *s2)
if ( *x < *y ) cmp = -1;
else if ( *x > *y ) cmp = 1;
return (cmp);
return cmp;
}
*/
......
......@@ -40,7 +40,7 @@
long get_nfft(void)
{
return ((long) NFFT);
return (long) NFFT;
}
......
......@@ -8,12 +8,10 @@
static
char *amatch(char *msr, const char *sub)
{
int i,nm,ns;
int nm = strlen(msr);
int ns = strlen(sub);
nm = strlen(msr);
ns = strlen(sub);
for (i = 0; i < nm-ns; i++)
for ( int i = 0; i < nm-ns; i++ )
if (strncmp (msr+i,sub,ns) == 0) return (msr+i+ns);
return NULL;
......@@ -22,28 +20,26 @@ char *amatch(char *msr, const char *sub)
int scan_par_obsolate(char *namelist, const char *name, int def)
{
char *cp;
int value;
cp = amatch(namelist, name);
char *cp = amatch(namelist, name);
if ( cp == NULL ) value = def;
else value = atoi (cp);
else value = atoi(cp);
/*
fprintf(stdout, " %16.16s = %6d ", name, value);
if ( value == def ) fprintf(stdout, " (default)\n");
else fprintf(stdout, " \n");
*/
return (value);
return value;
}
int scan_par(int verbose, char *namelist, const char *name, int def)
{
char *cp;
int value;
cp = amatch(namelist, name);
char *cp = amatch(namelist, name);
if ( cp == NULL ) value = def;
else value = atoi (cp);
......@@ -55,17 +51,16 @@ int scan_par(int verbose, char *namelist, const char *name, int def)
else fprintf(stdout, " \n");
}
return (value);
return value;
}
int scan_time(int verbose, char *namelist, int *hours, int max_hours)
{
char *cp, *icp;
int time;
char *icp;
int nrqh = 0;
cp = amatch (namelist, "timesel");
char *cp = amatch (namelist, "timesel");
if ( cp == NULL )
{
hours[nrqh++] = -1;
......@@ -73,7 +68,7 @@ int scan_time(int verbose, char *namelist, int *hours, int max_hours)
return (nrqh);
}
time = (int) strtol (cp, &icp, 10);
int time = (int) strtol (cp, &icp, 10);
while ((char *)icp != (char *)cp && nrqh < max_hours)
{
......@@ -89,19 +84,19 @@ int scan_time(int verbose, char *namelist, int *hours, int max_hours)
fprintf(stdout, "\n");
}
return (nrqh);
return nrqh;
}
void scan_code(char *namelist, struct Variable *vars, int maxCodes, int *numCodes)
{
char *cp, *icp;
int code, ncodes = 0;
char *icp;
int ncodes = 0;
cp = amatch(namelist, "code");
char *cp = amatch(namelist, "code");
if ( cp != NULL )
{
code = (int) strtol(cp,&icp,10);
int code = (int) strtol(cp,&icp,10);
while ( code > 0 && code < maxCodes )
{
ncodes++;
......@@ -117,11 +112,11 @@ void scan_code(char *namelist, struct Variable *vars, int maxCodes, int *numCode
void scan_darray(char *namelist, const char *name, double *values, int maxValues, int *numValues)
{
char *cp,*icp;
char *icp;
double val;
int nval = 0;
cp = amatch(namelist, name);
char *cp = amatch(namelist, name);
if ( cp != NULL )
{
......
......@@ -160,7 +160,7 @@ int cmpnames(const void *s1, const void *s2)
void vlistCompare(int vlistID1, int vlistID2, int flag)
{
int varID;
int lchecknames = FALSE;
bool lchecknames = false;
if ( vlistNvars(vlistID1) != vlistNvars(vlistID2) )
cdoAbort("Input streams have different number of variables per timestep!");
......@@ -184,7 +184,7 @@ void vlistCompare(int vlistID1, int vlistID2, int flag)
if ( strcmp(name1, name2) != 0 )
{
cdoWarning("Input streams have different parameters!");
lchecknames = TRUE;
lchecknames = true;
flag -= CMP_NAME;
// break;
}
......@@ -214,16 +214,16 @@ void vlistCompare(int vlistID1, int vlistID2, int flag)
zaxisInqLevels(zaxisID1, lev1);
zaxisInqLevels(zaxisID2, lev2);
int ldiffer = FALSE;
bool ldiffer = false;
for ( int i = 0; i < nlev1; ++i )
if ( IS_NOT_EQUAL(lev1[i], lev2[i]) )
{ ldiffer = TRUE; break; }
{ ldiffer = true; break; }
if ( ldiffer )
{
ldiffer = FALSE;
ldiffer = false;
for ( int i = 0; i < nlev1; ++i )
if ( IS_NOT_EQUAL(lev1[i], lev2[nlev1-1-i]) )
{ ldiffer = TRUE; break; }
{ ldiffer = true; break; }
if ( ldiffer )
cdoWarning("Input parameters have different levels!");
......@@ -239,10 +239,8 @@ void vlistCompare(int vlistID1, int vlistID2, int flag)
if ( flag & CMP_GRID )
{
int gridID1, gridID2;
gridID1 = vlistInqVarGrid(vlistID1, 0);
gridID2 = vlistInqVarGrid(vlistID2, 0);
int gridID1 = vlistInqVarGrid(vlistID1, 0);
int gridID2 = vlistInqVarGrid(vlistID2, 0);
compareGrids(gridID1, gridID2);
}
......@@ -294,10 +292,8 @@ int vlistCompareX(int vlistID1, int vlistID2, int flag)