Linter to c files

milestone_5_without_improvements
chortas 3 years ago
parent 3210b268aa
commit 83d7d29273

@ -1,16 +1,16 @@
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "Py_py-api.h" #include "Py_py-api.h"
#include "genlib.h" #include "genlib.h"
#include "simpio.h"
#include "geostat.h" #include "geostat.h"
#include "pressure.h" #include "pressure.h"
#include "simpio.h"
#include "toolsIO.h" #include "toolsIO.h"
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject #define PyIntObject PyLongObject
@ -40,7 +40,6 @@
#endif #endif
#endif #endif
int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat) int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat)
{ {
int i, varioNargs = 12, j = 0; int i, varioNargs = 12, j = 0;
@ -51,10 +50,11 @@ int Py_getvalues(PyObject* args, long* seed,struct grid_mod* grid,struct vario_m
stat->nblock_mean = 1; stat->nblock_mean = 1;
stat->nblock_var = 1; stat->nblock_var = 1;
stat->mean = (double*)malloc(stat->nblock_mean * sizeof(double)); stat->mean = (double*)malloc(stat->nblock_mean * sizeof(double));
if (stat->mean == NULL) return 0; if (stat->mean == NULL)
return 0;
stat->variance = (double*)malloc(stat->nblock_var * sizeof(double)); stat->variance = (double*)malloc(stat->nblock_var * sizeof(double));
if (stat->variance == NULL) return 0; if (stat->variance == NULL)
return 0;
if (!PyArg_ParseTuple(args, "iiidddlO!ddi", /*"iiidddslO!ddi",*/ if (!PyArg_ParseTuple(args, "iiidddlO!ddi", /*"iiidddslO!ddi",*/
&(grid->NX), &(grid->NX),
@ -68,25 +68,30 @@ int Py_getvalues(PyObject* args, long* seed,struct grid_mod* grid,struct vario_m
&PyList_Type, &listvario, &PyList_Type, &listvario,
stat->mean + 0, stat->mean + 0,
stat->variance + 0, stat->variance + 0,
&(stat->type))) return 0; &(stat->type)))
return 0;
variogram->Nvario = PyList_Size(listvario); variogram->Nvario = PyList_Size(listvario);
variogram->var = (double*)malloc(variogram->Nvario * sizeof(double)); variogram->var = (double*)malloc(variogram->Nvario * sizeof(double));
if(variogram->var==NULL) return 0; if (variogram->var == NULL)
return 0;
variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int)); variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int));
if(variogram->vario==NULL) return 0; if (variogram->vario == NULL)
return 0;
variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double)); variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double));
if(variogram->alpha==NULL) return 0; if (variogram->alpha == NULL)
return 0;
variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double)); variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double));
if(variogram->var==NULL) return 0; if (variogram->var == NULL)
return 0;
variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double)); variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double));
if(variogram->var==NULL) return 0; if (variogram->var == NULL)
for(i=0;i<variogram->Nvario;i++) return 0;
{ for (i = 0; i < variogram->Nvario; i++) {
vgr = PyList_GetItem(listvario, i); vgr = PyList_GetItem(listvario, i);
if(PyTuple_Size(vgr)!=12) return 0; if (PyTuple_Size(vgr) != 12)
return 0;
(variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->vario)[i] = (int)PyInt_AsLong(PyTuple_GetItem(vgr, j++)); (variogram->vario)[i] = (int)PyInt_AsLong(PyTuple_GetItem(vgr, j++));
(variogram->alpha)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->alpha)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
@ -101,10 +106,5 @@ int Py_getvalues(PyObject* args, long* seed,struct grid_mod* grid,struct vario_m
(variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
} }
return 1; return 1;
} }

@ -1,16 +1,16 @@
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "Py_py-api.h" #include "Py_py-api.h"
#include "genlib.h" #include "genlib.h"
#include "simpio.h"
#include "geostat.h" #include "geostat.h"
#include "toolsIO.h" #include "simpio.h"
#include "toolsFFTMA.h" #include "toolsFFTMA.h"
#include "toolsIO.h"
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* kgeneration */ /* kgeneration */
/* Z is the GWN with 0-mean and 1-variance */ /* Z is the GWN with 0-mean and 1-variance */
@ -28,13 +28,8 @@ void Py_kgeneration(long seed,struct grid_mod grid,struct statistic_mod stat,st
n[1] = 0; n[1] = 0;
n[2] = 0; n[2] = 0;
generate(&seed, N, Z); generate(&seed, N, Z);
/*FFTMA*/ /*FFTMA*/
FFTMA2(variogram, grid, n, Z, Y); FFTMA2(variogram, grid, n, Z, Y);

@ -7,7 +7,6 @@ void axes(double *ap,double *scf,int N)
double sclpdt, r, eps = 1.E-6; double sclpdt, r, eps = 1.E-6;
int i, j, k; int i, j, k;
for (k = 0; k < N; k++) { for (k = 0; k < N; k++) {
r = sqrt(ap[9 * k] * ap[9 * k] + ap[9 * k + 1] * ap[9 * k + 1] + ap[9 * k + 2] * ap[9 * k + 2]); r = sqrt(ap[9 * k] * ap[9 * k] + ap[9 * k + 1] * ap[9 * k + 1] + ap[9 * k + 2] * ap[9 * k + 2]);
@ -34,8 +33,6 @@ void axes(double *ap,double *scf,int N)
} }
} }
} }
} }
return; return;
} }

@ -1,10 +1,10 @@
#include <stdio.h> #include "geostat.h"
#include <stddef.h> #include <math.h>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <string.h>
#include "geostat.h"
/* build_real */ /* build_real */
/* build a realization in the spectral domain */ /* build a realization in the spectral domain */

@ -1,6 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*cardsin covariance function*/ /*cardsin covariance function*/
double cardsin(double h) double cardsin(double h)

@ -1,6 +1,5 @@
#include <stdlib.h>
#include "geostat.h" #include "geostat.h"
#include <stdlib.h>
/*computes the size of the grid for FFTs*/ /*computes the size of the grid for FFTs*/
/*input: */ /*input: */

@ -1,10 +1,10 @@
#include <stdio.h> #include "geostat.h"
#include <stddef.h> #include <math.h>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <string.h>
#include "geostat.h"
void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout) void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout)
{ {
@ -15,11 +15,9 @@ void clean_real(struct realization_mod *realin,int n[3],struct grid_mod grid,dou
/*is the output realization already allocated?*/ /*is the output realization already allocated?*/
/*if not, memory allocation*/ /*if not, memory allocation*/
if ((*realout).vector == NULL || (*realout).n != (*realin).n) if ((*realout).vector == NULL || (*realout).n != (*realin).n) {
{
(*realout).vector = (double*)malloc((*realin).n * sizeof(double)); (*realout).vector = (double*)malloc((*realin).n * sizeof(double));
if ((*realout).vector == NULL) if ((*realout).vector == NULL) {
{
printf("Clean_real.c: No memory available\n"); printf("Clean_real.c: No memory available\n");
exit; exit;
} }

@ -1,6 +1,6 @@
#include <math.h>
#include "geostat.h"
#include "genlib.h" #include "genlib.h"
#include "geostat.h"
#include <math.h>
/*selection of model covariance*/ /*selection of model covariance*/
double cov_value(struct vario_mod variogram, double di, double dj, double dk) double cov_value(struct vario_mod variogram, double di, double dj, double dk)
@ -18,7 +18,6 @@ double cov_value(struct vario_mod variogram,double di,double dj,double dk)
hz = di * variogram.ap[9 * k + 6] + dj * variogram.ap[9 * k + 7] + dk * variogram.ap[9 * k + 8]; hz = di * variogram.ap[9 * k + 6] + dj * variogram.ap[9 * k + 7] + dk * variogram.ap[9 * k + 8];
h = sqrt(hx * hx + hy * hy + hz * hz); h = sqrt(hx * hx + hy * hy + hz * hz);
switch (variogram.vario[k]) { switch (variogram.vario[k]) {
case 1: case 1:
cov += variogram.var[k] * exponential(h); cov += variogram.var[k] * exponential(h);

@ -15,7 +15,6 @@ void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh,
for (j = 0; j <= n2[1]; j++) { for (j = 0; j <= n2[1]; j++) {
for (k = 0; k <= n2[2]; k++) { for (k = 0; k <= n2[2]; k++) {
/*area 1*/ /*area 1*/
maille = 1 + i + n[0] * (j + n[1] * k); maille = 1 + i + n[0] * (j + n[1] * k);
di = (double)i * mesh.DX; di = (double)i * mesh.DX;
@ -23,14 +22,12 @@ void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh,
dk = (double)k * mesh.DZ; dk = (double)k * mesh.DZ;
covar[maille] = (double)cov_value(variogram, di, dj, dk); covar[maille] = (double)cov_value(variogram, di, dj, dk);
if (k > 0 && k < n2[2] && j > 0 && j < n2[1] && i > 0 && i < n2[0]) { if (k > 0 && k < n2[2] && j > 0 && j < n2[1] && i > 0 && i < n2[0]) {
/*area 2*/ /*area 2*/
symmetric = 1 + n[0] - i + n[0] * (n[1] - j + n[1] * (n[2] - k)); symmetric = 1 + n[0] - i + n[0] * (n[1] - j + n[1] * (n[2] - k));
covar[symmetric] = covar[maille]; covar[symmetric] = covar[maille];
} }
if (i > 0 && i < n2[0]) { if (i > 0 && i < n2[0]) {
/*area 4*/ /*area 4*/
di = -(double)i * mesh.DX; di = -(double)i * mesh.DX;
@ -40,14 +37,12 @@ void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh,
covar[maille] = (double)cov_value(variogram, di, dj, dk); covar[maille] = (double)cov_value(variogram, di, dj, dk);
} }
if (k > 0 && k < n2[2] && j > 0 && j < n2[1]) { if (k > 0 && k < n2[2] && j > 0 && j < n2[1]) {
/*area 8*/ /*area 8*/
symmetric = 1 + i + n[0] * (n[1] - j + n[1] * (n[2] - k)); symmetric = 1 + i + n[0] * (n[1] - j + n[1] * (n[2] - k));
covar[symmetric] = covar[maille]; covar[symmetric] = covar[maille];
} }
if (i > 0 && i < n2[0] && j > 0 && j < n2[1]) { if (i > 0 && i < n2[0] && j > 0 && j < n2[1]) {
/*area 5*/ /*area 5*/
di = -(double)i * mesh.DX; di = -(double)i * mesh.DX;
@ -57,14 +52,12 @@ void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh,
covar[maille] = (double)cov_value(variogram, di, dj, dk); covar[maille] = (double)cov_value(variogram, di, dj, dk);
} }
if (k > 0 && k < n2[2]) { if (k > 0 && k < n2[2]) {
/*area 6*/ /*area 6*/
symmetric = 1 + i + n[0] * (j + n[1] * (n[2] - k)); symmetric = 1 + i + n[0] * (j + n[1] * (n[2] - k));
covar[symmetric] = covar[maille]; covar[symmetric] = covar[maille];
} }
if (j > 0 && j < n2[1]) { if (j > 0 && j < n2[1]) {
/*area 3*/ /*area 3*/
di = (double)i * mesh.DX; di = (double)i * mesh.DX;
@ -74,13 +67,11 @@ void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh,
covar[maille] = (double)cov_value(variogram, di, dj, dk); covar[maille] = (double)cov_value(variogram, di, dj, dk);
} }
if (k > 0 && k < n2[2] && i > 0 && i < n2[0]) { if (k > 0 && k < n2[2] && i > 0 && i < n2[0]) {
/*area 7*/ /*area 7*/
symmetric = 1 + n[0] - i + n[0] * (j + n[1] * (n[2] - k)); symmetric = 1 + n[0] - i + n[0] * (j + n[1] * (n[2] - k));
covar[symmetric] = covar[maille]; covar[symmetric] = covar[maille];
} }
} }
} }
} }

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*cubic covariance function*/ /*cubic covariance function*/
double cubic(double h) double cubic(double h)

@ -1,6 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*exponential covariance function*/ /*exponential covariance function*/
double exponential(double h) double exponential(double h)

@ -1,8 +1,7 @@
#include "geostat.h"
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
#include "geostat.h"
/*FAST FOURIER TRANSFORM MOVING AVERAGE METHOD */ /*FAST FOURIER TRANSFORM MOVING AVERAGE METHOD */
/*Turns a Gaussian white noise vector into a */ /*Turns a Gaussian white noise vector into a */
@ -87,7 +86,6 @@ void FFTMA2(struct vario_mod variogram,struct grid_mod grid,int n[3],struct real
/*backward fourier transform*/ /*backward fourier transform*/
fourt(realization, ireal, n, NDIM, 0, 1, workr, worki); fourt(realization, ireal, n, NDIM, 0, 1, workr, worki);
free(ireal); free(ireal);
free(workr); free(workr);
free(worki); free(worki);
@ -99,7 +97,3 @@ void FFTMA2(struct vario_mod variogram,struct grid_mod grid,int n[3],struct real
return; return;
} }

@ -1,5 +1,5 @@
#include <stdio.h>
#include <math.h> #include <math.h>
#include <stdio.h>
/*fast fourier transform */ /*fast fourier transform */
/* THE COOLEY-TUKEY FAST FOURIER TRANSFORM */ /* THE COOLEY-TUKEY FAST FOURIER TRANSFORM */
@ -89,7 +89,6 @@
/* PROGRAM MODIFIED FROM A SUBROUTINE OF BRENNER */ /* PROGRAM MODIFIED FROM A SUBROUTINE OF BRENNER */
/* 10-06-2000, MLR */ /* 10-06-2000, MLR */
void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki) void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki)
{ {
int ifact[21], ntot, idim, np1, n, np2, m, ntwo, iff, idiv, iquot, irem, inon2, non2p, np0, nprev, icase, ifmin, i, j, jmax, np2hf, i2, i1max, i3, j3, i1, ifp1, ifp2, i2max, i1rng, istep, imin, imax, mmax, mmin, mstep, j1, j2max, j2, jmin, j3max, nhalf; int ifact[21], ntot, idim, np1, n, np2, m, ntwo, iff, idiv, iquot, irem, inon2, non2p, np0, nprev, icase, ifmin, i, j, jmax, np2hf, i2, i1max, i3, j3, i1, ifp1, ifp2, i2max, i1rng, istep, imin, imax, mmax, mmin, mstep, j1, j2max, j2, jmin, j3max, nhalf;
@ -161,7 +160,6 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L70: L70:
non2p = np2 / ntwo; non2p = np2 / ntwo;
/*SEPARATE FOUR CASES-- /*SEPARATE FOUR CASES--
1. COMPLEX TRANSFORM 1. COMPLEX TRANSFORM
2. REAL TRANSFORM FOR THE 2ND, 3RD, ETC. DIMENSION. METHOD: TRANSFORM HALF THE DATA, SUPPLYING THE OTHER HALF BY CONJUGATE SYMMETRY. 2. REAL TRANSFORM FOR THE 2ND, 3RD, ETC. DIMENSION. METHOD: TRANSFORM HALF THE DATA, SUPPLYING THE OTHER HALF BY CONJUGATE SYMMETRY.
@ -225,7 +223,6 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
if (m >= np1) if (m >= np1)
goto L140; goto L140;
} }
} }
goto L300; goto L300;
@ -262,7 +259,6 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
datai[i2] = worki[i]; datai[i2] = worki[i];
i++; i++;
} }
} }
} }

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*gamma covariance function*/ /*gamma covariance function*/
double gammf(double h, double alpha) double gammf(double h, double alpha)
@ -13,4 +12,3 @@ double gammf(double h, double alpha)
z = 1. / (double)(pow(1. + h * delta, alpha)); z = 1. / (double)(pow(1. + h * delta, alpha));
return (z); return (z);
} }

@ -1,5 +1,5 @@
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#define NTAB 32 #define NTAB 32

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*gaussian covariance function*/ /*gaussian covariance function*/
double gaussian(double h) double gaussian(double h)

@ -1,7 +1,6 @@
#include <stdlib.h>
#include <math.h>
#include "geostat.h" #include "geostat.h"
#include <math.h>
#include <stdlib.h>
/* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */ /* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */
/*input: */ /*input: */
@ -38,6 +37,3 @@ void generate(long *seed, int n, struct realization_mod *realization)
return; return;
} }

@ -7,10 +7,10 @@
* interface description in genlib.h for details. * interface description in genlib.h for details.
*/ */
#include <stdio.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include "genlib.h" #include "genlib.h"
@ -39,7 +39,8 @@ void *GetBlock(size_t nbytes)
void* result; void* result;
result = malloc(nbytes); result = malloc(nbytes);
if (result == NULL) Error("No memory available"); if (result == NULL)
Error("No memory available");
return (result); return (result);
} }

@ -25,9 +25,9 @@
#ifndef _genlib_h #ifndef _genlib_h
#define _genlib_h #define _genlib_h
#include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
/* Section 1 -- Define new "primitive" types */ /* Section 1 -- Define new "primitive" types */
@ -56,7 +56,8 @@
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1
#else #else
typedef enum {FALSE, TRUE} bool; typedef enum { FALSE,
TRUE } bool;
#endif #endif
#endif #endif
#endif #endif

@ -1,8 +1,7 @@
#include <stdio.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#ifndef _GEOSTAT_H #ifndef _GEOSTAT_H
#define _GEOSTAT_H #define _GEOSTAT_H
@ -27,7 +26,6 @@
/* cdf_mod */ /* cdf_mod */
/* realization_mod */ /* realization_mod */
/* List of functions: */ /* List of functions: */
/* ------------------ */ /* ------------------ */
@ -44,9 +42,6 @@
/* test_fract, trun1, trungasdev,vec_vec, */ /* test_fract, trun1, trungasdev,vec_vec, */
/* vf2gthres,polint */ /* vf2gthres,polint */
/*STRUCTURES*/ /*STRUCTURES*/
/*----------*/ /*----------*/
/*variogram */ /*variogram */
@ -75,8 +70,6 @@ struct vario_mod {
double* var; double* var;
}; };
/*variogram table */ /*variogram table */
/*Nvario: number of combined variogram models */ /*Nvario: number of combined variogram models */
/*vario: model of variogram per variogram model */ /*vario: model of variogram per variogram model */
@ -104,9 +97,6 @@ struct variotable_mod {
float* var; float* var;
}; };
/*grid */ /*grid */
/*NX: number of gridblocks along the X axis*/ /*NX: number of gridblocks along the X axis*/
/*NY: number of gridblocks along the Y axis*/ /*NY: number of gridblocks along the Y axis*/
@ -123,7 +113,6 @@ struct grid_mod {
double Xo, Yo, Zo; double Xo, Yo, Zo;
}; };
/*well data */ /*well data */
/*nwell: number of wells */ /*nwell: number of wells */
/*n: number of measurement points per well */ /*n: number of measurement points per well */
@ -163,8 +152,6 @@ struct welldata_mod {
float* measure; float* measure;
}; };
/*volume fractions for facies */ /*volume fractions for facies */
/*ncat: number of facies */ /*ncat: number of facies */
/*nblock: number of gridblocks with different */ /*nblock: number of gridblocks with different */
@ -179,7 +166,6 @@ struct statfacies_mod {
float* vf; float* vf;
}; };
/*inequalities for truncated plurigaussian realizations*/ /*inequalities for truncated plurigaussian realizations*/
/*only two basic realizations Y1 and Y2 are considered */ /*only two basic realizations Y1 and Y2 are considered */
/*Y1 and Y2 are independent */ /*Y1 and Y2 are independent */
@ -209,7 +195,6 @@ struct inequalities_mod {
int* address_sY2; int* address_sY2;
}; };
/*statistical data */ /*statistical data */
/*type --> 0 : normal */ /*type --> 0 : normal */
/* --> 1 : natural log */ /* --> 1 : natural log */
@ -234,7 +219,6 @@ struct statistic_mod {
double* variance; double* variance;
}; };
/*gradual deformation parameters */ /*gradual deformation parameters */
/*Nadded: number of complementary realizations */ /*Nadded: number of complementary realizations */
/*NZONES: number of subregions */ /*NZONES: number of subregions */
@ -250,7 +234,6 @@ struct grad_mod {
int *cellini, *cellfin; int *cellini, *cellfin;
}; };
/*gradient structures */ /*gradient structures */
/*Nparam : number of parameters for which gradients are */ /*Nparam : number of parameters for which gradients are */
/* required */ /* required */
@ -267,8 +250,6 @@ struct gradients_mod {
float* grad; float* grad;
}; };
/*description of discretized cumulative distributions */ /*description of discretized cumulative distributions */
/*n: number of points */ /*n: number of points */
/*x: values along the x axis i = [0...n-1] */ /*x: values along the x axis i = [0...n-1] */
@ -280,7 +261,6 @@ struct cdf_mod {
float* fx; float* fx;
}; };
/*realization */ /*realization */
/*n: number of components */ /*n: number of components */
/*code: status of the realization */ /*code: status of the realization */
@ -311,18 +291,15 @@ struct realization_mod {
/*FUNCTIONS*/ /*FUNCTIONS*/
/*---------*/ /*---------*/
/*normalization of the anostropy axes */ /*normalization of the anostropy axes */
/*ap: anisotropy axes */ /*ap: anisotropy axes */
/*scf: correlation lengths */ /*scf: correlation lengths */
/* The returned normalized axes are in ap */ /* The returned normalized axes are in ap */
void axes(double* ap, double* scf, int N); void axes(double* ap, double* scf, int N);
/*cardsin covariance value for lag h*/ /*cardsin covariance value for lag h*/
double cardsin(double h); double cardsin(double h);
/*Cholesky decomposition of matrix C */ /*Cholesky decomposition of matrix C */
/* C : symetric positive-definite matrix recorded */ /* C : symetric positive-definite matrix recorded */
/* (per raws) as a vector with only components */ /* (per raws) as a vector with only components */
@ -332,7 +309,6 @@ double cardsin(double h);
/* C is turned into the lower triangular cholesky matrix*/ /* C is turned into the lower triangular cholesky matrix*/
void choldc(double* C, int n); void choldc(double* C, int n);
/*computes the coordinates of a given cell */ /*computes the coordinates of a given cell */
/*as numbers of cells along the X,Y and Z axes*/ /*as numbers of cells along the X,Y and Z axes*/
/*maille = i[0]+1+i[1]*NX+i[2]*NX*NY */ /*maille = i[0]+1+i[1]*NX+i[2]*NX*NY */
@ -343,7 +319,6 @@ void choldc(double *C, int n);
/*i: vector with the coordinates */ /*i: vector with the coordinates */
void coordinates(int maille, int i[3], struct grid_mod grid); void coordinates(int maille, int i[3], struct grid_mod grid);
/*builds the sampled covariance function */ /*builds the sampled covariance function */
/*dimensions are even */ /*dimensions are even */
/*covar: covariance array, vector of size*/ /*covar: covariance array, vector of size*/
@ -364,7 +339,6 @@ void covariance(double *covar,struct vario_mod variogram, struct grid_mod grid,
/*grid: structure defined above */ /*grid: structure defined above */
void cov_matrix(double* C, struct vario_mod variogram, struct welldata_mod well, struct grid_mod grid); void cov_matrix(double* C, struct vario_mod variogram, struct welldata_mod well, struct grid_mod grid);
/*calculation of the covariance value for a distance h */ /*calculation of the covariance value for a distance h */
/*defined by i,j,k */ /*defined by i,j,k */
/*available variogram model: */ /*available variogram model: */
@ -387,7 +361,6 @@ double cov_value(struct vario_mod variogram,double di,double dj,double dk);
/*cubic covariance value for lag h*/ /*cubic covariance value for lag h*/
double cubic(double h); double cubic(double h);
/*truncation of the power spectrum to remove */ /*truncation of the power spectrum to remove */
/*high frequencies - isotropic case */ /*high frequencies - isotropic case */
/*covar: power spectrum */ /*covar: power spectrum */
@ -397,7 +370,6 @@ double cubic(double h);
/*n[3]: number of cells along the X, Y and Z axes*/ /*n[3]: number of cells along the X, Y and Z axes*/
void cutspectr(float* covar, int kx, int ky, int kz, int n[3]); void cutspectr(float* covar, int kx, int ky, int kz, int n[3]);
/*defines the threshold interval for a facies x*/ /*defines the threshold interval for a facies x*/
/*lim_inf: lower bound */ /*lim_inf: lower bound */
/*lim_sup: upper bound */ /*lim_sup: upper bound */
@ -407,7 +379,6 @@ void cutspectr(float *covar, int kx, int ky, int kz, int n[3]);
/*nblock: gridcell number of point x */ /*nblock: gridcell number of point x */
void deflimit(double* plim_inf, double* plim_sup, float x, float* thresholds, struct statfacies_mod facies, int nblock); void deflimit(double* plim_inf, double* plim_sup, float x, float* thresholds, struct statfacies_mod facies, int nblock);
/*kriges the realization considering weights */ /*kriges the realization considering weights */
/*realin: input realization */ /*realin: input realization */
/*variogram: structure defining the variogram */ /*variogram: structure defining the variogram */
@ -418,12 +389,9 @@ void deflimit(double *plim_inf, double *plim_sup, float x, float *thresholds, st
/*The kriged realization is stored in realout */ /*The kriged realization is stored in realout */
void dual_kri(struct realization_mod* realin, struct vario_mod variogram, struct welldata_mod well, struct grid_mod grid, double* D, struct realization_mod* realout); void dual_kri(struct realization_mod* realin, struct vario_mod variogram, struct welldata_mod well, struct grid_mod grid, double* D, struct realization_mod* realout);
/*exponential covariance value for lag h*/ /*exponential covariance value for lag h*/
double exponential(double h); double exponential(double h);
/*Fast Fourier Transform - Cooley-Tukey algorithm */ /*Fast Fourier Transform - Cooley-Tukey algorithm */
/*datar: real part vector - to be transformed */ /*datar: real part vector - to be transformed */
/*datai: imaginary part vector - to be transformed */ /*datai: imaginary part vector - to be transformed */
@ -436,27 +404,21 @@ double exponential(double h);
/*The transformed data are returned in datar and datai*/ /*The transformed data are returned in datar and datai*/
void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki); void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki);
/*calculates F(x) = (1/a)*exp(-x*x/2)*/ /*calculates F(x) = (1/a)*exp(-x*x/2)*/
double funtrun1(double x); double funtrun1(double x);
/*cumulative standard normal value*/ /*cumulative standard normal value*/
float G(float x); float G(float x);
/*gamma covariance value for lag h and exponent alpha*/ /*gamma covariance value for lag h and exponent alpha*/
double gammf(double h, double alpha); double gammf(double h, double alpha);
/*returns the value ln(G(x))*/ /*returns the value ln(G(x))*/
float gammln(float xx); float gammln(float xx);
/*incomplete gamma fnction*/ /*incomplete gamma fnction*/
float gammp(float a, float x); float gammp(float a, float x);
/*returns a normally distributed deviate with 0 mean*/ /*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran1(idum) as the source */ /*and unit variance, using ran1(idum) as the source */
/*of uniform deviates */ /*of uniform deviates */
@ -466,13 +428,11 @@ double gasdev(long *idum, long *idum2, long *iy, long *iv, int *iset);
/*gaussian covariance value for lag h*/ /*gaussian covariance value for lag h*/
double gaussian(double h); double gaussian(double h);
/*incomplete gamma function evaluated by its continued */ /*incomplete gamma function evaluated by its continued */
/*fraction represented as gammcf, also returns ln(G(a))*/ /*fraction represented as gammcf, also returns ln(G(a))*/
/*as gln */ /*as gln */
void gcf(float* gammcf, float a, float x, float* gln); void gcf(float* gammcf, float a, float x, float* gln);
/*computation of the covariance matrix for the well data*/ /*computation of the covariance matrix for the well data*/
/*well coordinates have no specific unit */ /*well coordinates have no specific unit */
/*The dimension of C is given by n */ /*The dimension of C is given by n */
@ -484,7 +444,6 @@ void gcf(float *gammcf, float a, float x, float *gln);
/*well: structure defined above */ /*well: structure defined above */
void gen_cov_matrix(double* C, struct vario_mod variogram, struct welldata_mod well, int n); void gen_cov_matrix(double* C, struct vario_mod variogram, struct welldata_mod well, int n);
/*Ginv */ /*Ginv */
/*Computes the inverse of the standard normal cumulative*/ /*Computes the inverse of the standard normal cumulative*/
/*distribution function with a numerical approximation */ /*distribution function with a numerical approximation */
@ -494,7 +453,6 @@ void gen_cov_matrix(double *C, struct vario_mod variogram, struct welldata_mod w
/*p: cumulative probability value */ /*p: cumulative probability value */
float Ginv(float p); float Ginv(float p);
/*gradual combination of 1 realization + Nadded */ /*gradual combination of 1 realization + Nadded */
/*complementary realizations */ /*complementary realizations */
/*rho: gradual deformation parameters */ /*rho: gradual deformation parameters */
@ -512,7 +470,6 @@ float Ginv(float p);
/*grid: grid definition */ /*grid: grid definition */
void gradual(struct grad_mod grad, float* Zo, float* Z, float* Zfinal, int n, struct grid_mod grid); void gradual(struct grad_mod grad, float* Zo, float* Z, float* Zfinal, int n, struct grid_mod grid);
/*computes the size of the underlying grid for FFTs*/ /*computes the size of the underlying grid for FFTs*/
/*input: */ /*input: */
/*variogram: structure defining the variogram model*/ /*variogram: structure defining the variogram model*/
@ -528,7 +485,6 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3]);
/*as gln */ /*as gln */
void gser(float* gamser, float a, float x, float* gln); void gser(float* gamser, float a, float x, float* gln);
/*calculates x so that x = invF(u) */ /*calculates x so that x = invF(u) */
/*F is the cumulative density function for the */ /*F is the cumulative density function for the */
/*function approximating the Gaussian function */ /*function approximating the Gaussian function */
@ -538,12 +494,10 @@ void gser(float *gamser, float a, float x, float *gln);
/*C: normalizing constant */ /*C: normalizing constant */
double invtrun1(double u, double lim_inf, double lim_sup, double C); double invtrun1(double u, double lim_inf, double lim_sup, double C);
/*computes the kriging mean and variance*/ /*computes the kriging mean and variance*/
/*for the vector bi, i = [0...n-1] */ /*for the vector bi, i = [0...n-1] */
void krig_stat(float* b, int n, struct vario_mod variogram, struct welldata_mod well, float* mean, float* var); void krig_stat(float* b, int n, struct vario_mod variogram, struct welldata_mod well, float* mean, float* var);
/* computes the number of gridblocks for one dimension*/ /* computes the number of gridblocks for one dimension*/
/*N: initial number of gridblocks */ /*N: initial number of gridblocks */
/*i: considered direction */ /*i: considered direction */
@ -572,39 +526,31 @@ int maxfactor(int n);
/*metrop is only true with probability "ratio" */ /*metrop is only true with probability "ratio" */
int metrop(double ratio, long* idum, long* idum2, long* iy, long* iv); int metrop(double ratio, long* idum, long* idum2, long* iy, long* iv);
/*2-norm of vector b */ /*2-norm of vector b */
/* b : vector */ /* b : vector */
/* n : length of b, bi, i = [0...n-1]*/ /* n : length of b, bi, i = [0...n-1]*/
/*returns the norm of b */ /*returns the norm of b */
double norm(double* b, int n); double norm(double* b, int n);
/*value of g(x) where g is the normal function*/ /*value of g(x) where g is the normal function*/
double normal(double x); double normal(double x);
/*nugget covariance value for lag h*/ /*nugget covariance value for lag h*/
double nugget(double h); double nugget(double h);
/*power covariance value for lag h and exponent alpha*/ /*power covariance value for lag h and exponent alpha*/
double power(double h, double alpha); double power(double h, double alpha);
/*generates uniform deviates between 0 and 1*/ /*generates uniform deviates between 0 and 1*/
/*idum: seed */ /*idum: seed */
double ran2(long* idum, long* idum2, long* iy, long* iv); double ran2(long* idum, long* idum2, long* iy, long* iv);
/*calculates bt.b */ /*calculates bt.b */
/* b : vector, bi, i = [0...n-1] */ /* b : vector, bi, i = [0...n-1] */
/* n : length of b */ /* n : length of b */
/*returns the scalar product of b*/ /*returns the scalar product of b*/
double scal_vec(double* b, int n); double scal_vec(double* b, int n);
/*solves the set of n linear equations Cx = D */ /*solves the set of n linear equations Cx = D */
/* C : symmetric positive-definite matrix recorded */ /* C : symmetric positive-definite matrix recorded */
/* (per raws) as a vector with only components */ /* (per raws) as a vector with only components */
@ -616,31 +562,25 @@ double scal_vec(double *b,int n);
/* CONJUGATE GRADIENT method */ /* CONJUGATE GRADIENT method */
void solve3(double* C, double* D, int n); void solve3(double* C, double* D, int n);
/*sorts an array [0...n-1] into ascending order using */ /*sorts an array [0...n-1] into ascending order using */
/*shell */ /*shell */
void sort(float n, float* arr); void sort(float n, float* arr);
/*spherical covariance value for lag h*/ /*spherical covariance value for lag h*/
double spherical(double h); double spherical(double h);
/*stable covariance value for lag h and exponent alpha*/ /*stable covariance value for lag h and exponent alpha*/
double stable(double h, double alpha); double stable(double h, double alpha);
/*conversion of log mean and variance to nor*/ /*conversion of log mean and variance to nor*/
void statlog2nor(struct statistic_mod* pstat); void statlog2nor(struct statistic_mod* pstat);
/*tries factor */ /*tries factor */
/*pnum: number to be decomposed */ /*pnum: number to be decomposed */
/*fact: suggested factor */ /*fact: suggested factor */
/*pmaxfac: memory to keep the greatest factor*/ /*pmaxfac: memory to keep the greatest factor*/
int test_fact(int* pnum, int fact, int* pmaxfac); int test_fact(int* pnum, int fact, int* pmaxfac);
/*calculates the integrale of an approximate function*/ /*calculates the integrale of an approximate function*/
/*for the Gaussian function over an interval defined */ /*for the Gaussian function over an interval defined */
/*by lim_inf and lim_sup */ /*by lim_inf and lim_sup */
@ -648,7 +588,6 @@ int test_fact(int *pnum, int fact, int *pmaxfac);
/*lim_sup: upper bound of the considered interval */ /*lim_sup: upper bound of the considered interval */
double trun1(double lim_inf, double lim_sup); double trun1(double lim_inf, double lim_sup);
/*draws a truncated gaussian variable between lim_inf*/ /*draws a truncated gaussian variable between lim_inf*/
/*and lim_sup */ /*and lim_sup */
/*idum: seed */ /*idum: seed */
@ -661,7 +600,6 @@ double trungasdev(long *idum,double lim_inf,double lim_sup,long *idum2, long *iy
/*returns the norm the product tb1.b2 */ /*returns the norm the product tb1.b2 */
double vec_vec(double* b1, double* b2, int n); double vec_vec(double* b1, double* b2, int n);
/*turns the volume fractions into Gaussian thresholds */ /*turns the volume fractions into Gaussian thresholds */
/*facies: structure defined above */ /*facies: structure defined above */
/*thresholds: output threshold vector fot i = [0...n-1]*/ /*thresholds: output threshold vector fot i = [0...n-1]*/
@ -671,6 +609,4 @@ void vf2gthres(struct statfacies_mod facies,float *thresholds);
void polint(float xa[], float ya[], int n, float x, float* y, float* dy); void polint(float xa[], float ya[], int n, float x, float* y, float* dy);
#endif #endif

@ -1,7 +1,6 @@
#include <stdlib.h>
#include <math.h>
#include "geostat.h" #include "geostat.h"
#include <math.h>
#include <stdlib.h>
/*TURNS NORMAL NUMBERS INTO LOGNORMAL NUMBERS */ /*TURNS NORMAL NUMBERS INTO LOGNORMAL NUMBERS */
/*input: */ /*input: */
@ -19,10 +18,8 @@ void nor2log(struct realization_mod *realin, int typelog, struct realization_mod
int i; int i;
double coeff; double coeff;
coeff = log(10.0); coeff = log(10.0);
/*Is the output realization allocated ?*/ /*Is the output realization allocated ?*/
/*is its length equal to realin.n?*/ /*is its length equal to realin.n?*/
if ((*realout).vector == NULL || (*realout).n != (*realin).n) { if ((*realout).vector == NULL || (*realout).n != (*realin).n) {
@ -34,7 +31,6 @@ void nor2log(struct realization_mod *realin, int typelog, struct realization_mod
} }
(*realout).n = (*realin).n; (*realout).n = (*realin).n;
switch ((*realin).code) { switch ((*realin).code) {
case 0: case 0:
case 1: case 1:
@ -55,7 +51,6 @@ void nor2log(struct realization_mod *realin, int typelog, struct realization_mod
break; break;
} }
/*anamorphose*/ /*anamorphose*/
for (i = 0; i < (*realin).n; i++) { for (i = 0; i < (*realin).n; i++) {
switch (typelog) { switch (typelog) {

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*nugget covariance function*/ /*nugget covariance function*/
double nugget(double h) double nugget(double h)

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*power covariance function*/ /*power covariance function*/
double power(double h, double alpha) double power(double h, double alpha)

@ -1,10 +1,10 @@
#include <stdio.h> #include "geostat.h"
#include <stddef.h> #include <math.h>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <string.h>
#include "geostat.h"
/* prebuild_gwn */ /* prebuild_gwn */
/* Produce a first construction in real space of the Gaussian white noise */ /* Produce a first construction in real space of the Gaussian white noise */
@ -27,15 +27,11 @@ void prebuild_gwn(struct grid_mod grid,int n[3],struct realization_mod *realin,d
ntot = n[0] * n[1] * n[2]; ntot = n[0] * n[1] * n[2];
realization[0] = 0.; realization[0] = 0.;
if (solver==1) if (solver == 1) {
{ for (i = 0; i < ntot; i++) {
for (i=0;i<ntot;i++)
{
realization[i + 1] = (*realin).vector[i]; realization[i + 1] = (*realin).vector[i];
} }
} } else {
else
{
for (k = 1; k <= n[2]; k++) { for (k = 1; k <= n[2]; k++) {
for (j = 1; j <= n[1]; j++) { for (j = 1; j <= n[1]; j++) {
for (i = 1; i <= n[0]; i++) { for (i = 1; i <= n[0]; i++) {

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include "genlib.h" #include "genlib.h"
#include "geostat.h" #include "geostat.h"
#include <stdlib.h>
#include <string.h>
#ifndef _PRESSURE_H #ifndef _PRESSURE_H
#define _PRESSURE_H #define _PRESSURE_H
@ -17,5 +17,4 @@ struct pressure_mod {
double x, y, z; double x, y, z;
}; };
#endif // define _PRESSURE_H #endif // define _PRESSURE_H

@ -23,28 +23,37 @@ double ran2(long *idum, long *idum2, long *iy, long iv[NTAB])
double temp; double temp;
if (*idum <= 0) { if (*idum <= 0) {
if (-(*idum) < 1) *idum = 1; if (-(*idum) < 1)
else *idum = -(*idum); *idum = 1;
else
*idum = -(*idum);
*idum2 = (*idum); *idum2 = (*idum);
for (j = NTAB + 7; j >= 0; j--) { for (j = NTAB + 7; j >= 0; j--) {
k = (*idum) / IQ1; k = (*idum) / IQ1;
*idum = IA1 * (*idum - k * IQ1) - k * IR1; *idum = IA1 * (*idum - k * IQ1) - k * IR1;
if (*idum < 0) *idum += IM1; if (*idum < 0)
if (j < NTAB) iv[j] = *idum; *idum += IM1;
if (j < NTAB)
iv[j] = *idum;
} }
*iy = iv[0]; *iy = iv[0];
} }
k = (*idum) / IQ1; k = (*idum) / IQ1;
*idum = IA1 * (*idum - k * IQ1) - k * IR1; *idum = IA1 * (*idum - k * IQ1) - k * IR1;
if (*idum < 0) *idum += IM1; if (*idum < 0)
*idum += IM1;
k = *idum2 / IQ2; k = *idum2 / IQ2;
*idum2 = IA2 * (*idum2 - k * IQ2) - k * IR2; *idum2 = IA2 * (*idum2 - k * IQ2) - k * IR2;
if (*idum2 < 0) *idum2 += IM2; if (*idum2 < 0)
*idum2 += IM2;
j = (*iy) / NDIV; j = (*iy) / NDIV;
*iy = iv[j] - (*idum2); *iy = iv[j] - (*idum2);
iv[j] = *idum; iv[j] = *idum;
if (*iy < 1) (*iy) += IMM1; if (*iy < 1)
if ((temp = AM*(*iy)) > RNMX) return (RNMX); (*iy) += IMM1;
else return (temp); if ((temp = AM * (*iy)) > RNMX)
return (RNMX);
else
return (temp);
} }

@ -4,11 +4,11 @@
* This file implements the scanadt.h interface. * This file implements the scanadt.h interface.
*/ */
#include <stdio.h> #include "scanadt.h"
#include <ctype.h>
#include "genlib.h" #include "genlib.h"
#include "strlib.h" #include "strlib.h"
#include "scanadt.h" #include <ctype.h>
#include <stdio.h>
/* /*
* Type: scannerCDT * Type: scannerCDT
@ -53,13 +53,15 @@ scannerADT NewScanner(void)
void FreeScanner(scannerADT scanner) void FreeScanner(scannerADT scanner)
{ {
if (scanner->str != NULL) FreeBlock(scanner->str); if (scanner->str != NULL)
FreeBlock(scanner->str);
FreeBlock(scanner); FreeBlock(scanner);
} }
void SetScannerString(scannerADT scanner, string str) void SetScannerString(scannerADT scanner, string str)
{ {
if (scanner->str != NULL) FreeBlock(scanner->str); if (scanner->str != NULL)
FreeBlock(scanner->str);
scanner->str = CopyString(str); scanner->str = CopyString(str);
scanner->len = StringLength(str); scanner->len = StringLength(str);
scanner->cp = 0; scanner->cp = 0;
@ -80,9 +82,11 @@ string ReadToken(scannerADT scanner)
scanner->savedToken = NULL; scanner->savedToken = NULL;
return (token); return (token);
} }
if (scanner->spaceOption == IgnoreSpaces) SkipSpaces(scanner); if (scanner->spaceOption == IgnoreSpaces)
SkipSpaces(scanner);
start = finish = scanner->cp; start = finish = scanner->cp;
if (start >= scanner->len) return (CopyString("")); if (start >= scanner->len)
return (CopyString(""));
ch = scanner->str[scanner->cp]; ch = scanner->str[scanner->cp];
if (isalnum(ch)) { if (isalnum(ch)) {
finish = ScanToEndOfIdentifier(scanner); finish = ScanToEndOfIdentifier(scanner);
@ -100,7 +104,8 @@ bool MoreTokensExist(scannerADT scanner)
if (scanner->savedToken != NULL) { if (scanner->savedToken != NULL) {
return (!StringEqual(scanner->savedToken, "")); return (!StringEqual(scanner->savedToken, ""));
} }
if (scanner->spaceOption == IgnoreSpaces) SkipSpaces(scanner); if (scanner->spaceOption == IgnoreSpaces)
SkipSpaces(scanner);
return (scanner->cp < scanner->len); return (scanner->cp < scanner->len);
} }

@ -151,7 +151,8 @@ void SaveToken(scannerADT scanner, string token);
* of this option. * of this option.
*/ */
typedef enum { PreserveSpaces, IgnoreSpaces } spaceOptionT; typedef enum { PreserveSpaces,
IgnoreSpaces } spaceOptionT;
void SetScannerSpaceOption(scannerADT scanner, spaceOptionT option); void SetScannerSpaceOption(scannerADT scanner, spaceOptionT option);
spaceOptionT GetScannerSpaceOption(scannerADT scanner); spaceOptionT GetScannerSpaceOption(scannerADT scanner);

@ -10,8 +10,8 @@
#include <string.h> #include <string.h>
#include "genlib.h" #include "genlib.h"
#include "strlib.h"
#include "simpio.h" #include "simpio.h"
#include "strlib.h"
/* /*
* Constants: * Constants:

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*spherical covariance function*/ /*spherical covariance function*/
double spherical(double h) double spherical(double h)

@ -1,7 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#include <stdio.h>
/*stable covariance function*/ /*stable covariance function*/
double stable(double h, double alpha) double stable(double h, double alpha)

@ -7,9 +7,9 @@
* the type name stackElementT. * the type name stackElementT.
*/ */
#include <stdio.h>
#include "genlib.h"
#include "stack.h" #include "stack.h"
#include "genlib.h"
#include <stdio.h>
/* /*
* Constant: InitialStackSize * Constant: InitialStackSize
@ -63,13 +63,15 @@ void FreeStack(stackADT stack)
void Push(stackADT stack, stackElementT element) void Push(stackADT stack, stackElementT element)
{ {
if (stack->count == stack->size) ExpandStack(stack); if (stack->count == stack->size)
ExpandStack(stack);
stack->elements[stack->count++] = element; stack->elements[stack->count++] = element;
} }
stackElementT Pop(stackADT stack) stackElementT Pop(stackADT stack)
{ {
if (StackIsEmpty(stack)) Error("Pop of an empty stack"); if (StackIsEmpty(stack))
Error("Pop of an empty stack");
return (stack->elements[--stack->count]); return (stack->elements[--stack->count]);
} }

@ -17,9 +17,9 @@
* interface. * interface.
*/ */
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "genlib.h" #include "genlib.h"
#include "strlib.h" #include "strlib.h"
@ -59,7 +59,8 @@ char IthChar(string s, int i)
{ {
int len; int len;
if (s == NULL) Error("NULL string passed to IthChar"); if (s == NULL)
Error("NULL string passed to IthChar");
len = strlen(s); len = strlen(s);
if (i < 0 || i > len) { if (i < 0 || i > len) {
Error("Index outside of string range in IthChar"); Error("Index outside of string range in IthChar");
@ -72,12 +73,16 @@ string SubString(string s, int p1, int p2)
int len; int len;
string result; string result;
if (s == NULL) Error("NULL string passed to SubString"); if (s == NULL)
Error("NULL string passed to SubString");
len = strlen(s); len = strlen(s);
if (p1 < 0) p1 = 0; if (p1 < 0)
if (p2 >= len) p2 = len - 1; p1 = 0;
if (p2 >= len)
p2 = len - 1;
len = p2 - p1 + 1; len = p2 - p1 + 1;
if (len < 0) len = 0; if (len < 0)
len = 0;
result = CreateString(len); result = CreateString(len);
strncpy(result, s + p1, len); strncpy(result, s + p1, len);
result[len] = '\0'; result[len] = '\0';
@ -96,7 +101,8 @@ string CharToString(char ch)
int StringLength(string s) int StringLength(string s)
{ {
if (s == NULL) Error("NULL string passed to StringLength"); if (s == NULL)
Error("NULL string passed to StringLength");
return (strlen(s)); return (strlen(s));
} }
@ -104,7 +110,8 @@ string CopyString(string s)
{ {
string newstr; string newstr;
if (s == NULL) Error("NULL string passed to CopyString"); if (s == NULL)
Error("NULL string passed to CopyString");
newstr = CreateString(strlen(s)); newstr = CreateString(strlen(s));
strcpy(newstr, s); strcpy(newstr, s);
return (newstr); return (newstr);
@ -134,11 +141,15 @@ int FindChar(char ch, string text, int start)
{ {
char* cptr; char* cptr;
if (text == NULL) Error("NULL string passed to FindChar"); if (text == NULL)
if (start < 0) start = 0; Error("NULL string passed to FindChar");
if (start > strlen(text)) return (-1); if (start < 0)
start = 0;
if (start > strlen(text))
return (-1);
cptr = strchr(text + start, ch); cptr = strchr(text + start, ch);
if (cptr == NULL) return (-1); if (cptr == NULL)
return (-1);
return ((int)(cptr - text)); return ((int)(cptr - text));
} }
@ -146,12 +157,17 @@ int FindString(string str, string text, int start)
{ {
char* cptr; char* cptr;
if (str == NULL) Error("NULL pattern string in FindString"); if (str == NULL)
if (text == NULL) Error("NULL text string in FindString"); Error("NULL pattern string in FindString");
if (start < 0) start = 0; if (text == NULL)
if (start > strlen(text)) return (-1); Error("NULL text string in FindString");
if (start < 0)
start = 0;
if (start > strlen(text))
return (-1);
cptr = strstr(text + start, str); cptr = strstr(text + start, str);
if (cptr == NULL) return (-1); if (cptr == NULL)
return (-1);
return ((int)(cptr - text)); return ((int)(cptr - text));
} }
@ -166,7 +182,8 @@ string ConvertToLowerCase(string s)
Error("NULL string passed to ConvertToLowerCase"); Error("NULL string passed to ConvertToLowerCase");
} }
result = CreateString(strlen(s)); result = CreateString(strlen(s));
for (i = 0; s[i] != '\0'; i++) result[i] = tolower(s[i]); for (i = 0; s[i] != '\0'; i++)
result[i] = tolower(s[i]);
result[i] = '\0'; result[i] = '\0';
return (result); return (result);
} }
@ -180,7 +197,8 @@ string ConvertToUpperCase(string s)
Error("NULL string passed to ConvertToUpperCase"); Error("NULL string passed to ConvertToUpperCase");
} }
result = CreateString(strlen(s)); result = CreateString(strlen(s));
for (i = 0; s[i] != '\0'; i++) result[i] = toupper(s[i]); for (i = 0; s[i] != '\0'; i++)
result[i] = toupper(s[i]);
result[i] = '\0'; result[i] = '\0';
return (result); return (result);
} }
@ -222,7 +240,8 @@ double StringToReal(string s)
double result; double result;
char dummy; char dummy;
if (s == NULL) Error("NULL string passed to StringToReal"); if (s == NULL)
Error("NULL string passed to StringToReal");
if (sscanf(s, " %lg %c", &result, &dummy) != 1) { if (sscanf(s, " %lg %c", &result, &dummy) != 1) {
Error("StringToReal called on illegal number %s", s); Error("StringToReal called on illegal number %s", s);
} }

@ -4,10 +4,10 @@
* This file implements the symbol table abstraction. * This file implements the symbol table abstraction.
*/ */
#include <stdio.h> #include "symtab.h"
#include "genlib.h" #include "genlib.h"
#include "strlib.h" #include "strlib.h"
#include "symtab.h" #include <stdio.h>
/* /*
* Constants * Constants
@ -97,7 +97,8 @@ void *Lookup(symtabADT table, string key)
bucket = Hash(key, NBuckets); bucket = Hash(key, NBuckets);
cp = FindCell(table->buckets[bucket], key); cp = FindCell(table->buckets[bucket], key);
if (cp == NULL) return(UNDEFINED); if (cp == NULL)
return (UNDEFINED);
return (cp->value); return (cp->value);
} }

@ -22,5 +22,3 @@ int test_fact(int *pnum, int fact, int *pmaxfac)
return (0); return (0);
} }

@ -1,9 +1,9 @@
#include <stdio.h> #include <math.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <string.h>
void testmemory(double* realint) void testmemory(double* realint)
{ {

Loading…
Cancel
Save