Linter to c files

milestone_5_without_improvements
chortas 3 years ago
parent 3210b268aa
commit 83d7d29273

@ -1,62 +1,62 @@
#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
#define PyInt_Type PyLong_Type #define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op) #define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op)
#define PyInt_FromString PyLong_FromString #define PyInt_FromString PyLong_FromString
#define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromUnicode PyLong_FromUnicode
#define PyInt_FromLong PyLong_FromLong #define PyInt_FromLong PyLong_FromLong
#define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSize_t PyLong_FromSize_t
#define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_FromSsize_t PyLong_FromSsize_t
#define PyInt_AsLong PyLong_AsLong #define PyInt_AsLong PyLong_AsLong
#define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AS_LONG PyLong_AS_LONG
#define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsSsize_t PyLong_AsSsize_t
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#define PyNumber_Int PyNumber_Long #define PyNumber_Int PyNumber_Long
#endif #endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyBoolObject PyLongObject #define PyBoolObject PyLongObject
#endif #endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
#ifndef PyUnicode_InternFromString #ifndef PyUnicode_InternFromString
#define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
#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;
PyObject* listvario; PyObject* listvario;
PyObject* vgr; PyObject* vgr;
//char* gwnfilename; //char* gwnfilename;
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)
stat->variance=(double*)malloc(stat->nblock_var * sizeof(double)); return 0;
if (stat->variance == NULL) return 0; stat->variance = (double*)malloc(stat->nblock_var * sizeof(double));
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),
&(grid->NY), &(grid->NY),
&(grid->NZ), &(grid->NZ),
@ -66,45 +66,45 @@ int Py_getvalues(PyObject* args, long* seed,struct grid_mod* grid,struct vario_m
/*gwnfilename,*/ /*gwnfilename,*/
seed, seed,
&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)
variogram->vario=(int*)malloc(variogram->Nvario*sizeof(int)); return 0;
if(variogram->vario==NULL) return 0; variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int));
variogram->alpha=(double*)malloc(variogram->Nvario*sizeof(double)); if (variogram->vario == NULL)
if(variogram->alpha==NULL) return 0; return 0;
variogram->scf=(double*)malloc(3*variogram->Nvario*sizeof(double)); variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double));
if(variogram->var==NULL) return 0; if (variogram->alpha == NULL)
variogram->ap=(double*)malloc(9*variogram->Nvario*sizeof(double)); return 0;
if(variogram->var==NULL) return 0; variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double));
for(i=0;i<variogram->Nvario;i++) if (variogram->var == NULL)
{ return 0;
vgr=PyList_GetItem(listvario,i); variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double));
if(PyTuple_Size(vgr)!=12) return 0; if (variogram->var == NULL)
(variogram->var)[i]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); return 0;
(variogram->vario)[i]=(int)PyInt_AsLong(PyTuple_GetItem(vgr,j++)); for (i = 0; i < variogram->Nvario; i++) {
(variogram->alpha)[i]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); vgr = PyList_GetItem(listvario, i);
(variogram->scf)[i*3+0]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); if (PyTuple_Size(vgr) != 12)
(variogram->scf)[i*3+1]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); return 0;
(variogram->scf)[i*3+2]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+0]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->vario)[i] = (int)PyInt_AsLong(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+1]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->alpha)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+2]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->scf)[i * 3 + 0] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+3]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->scf)[i * 3 + 1] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+4]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->scf)[i * 3 + 2] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i*9+5]=PyFloat_AsDouble(PyTuple_GetItem(vgr,j++)); (variogram->ap)[i * 9 + 0] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i * 9 + 1] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i * 9 + 2] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i * 9 + 3] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i * 9 + 4] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
} }
return 1; return 1;
} }

@ -1,54 +1,49 @@
#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 */
/* Y1 is the realization with 0-mean and variance wanted */ /* Y1 is the realization with 0-mean and variance wanted */
/* Y is the realization with mean and variance wanted */ /* Y is the realization with mean and variance wanted */
void Py_kgeneration(long seed,struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,struct realization_mod *Z,struct realization_mod *Y,struct realization_mod *Y1, int n[3]) void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat, struct vario_mod variogram, struct realization_mod* Z, struct realization_mod* Y, struct realization_mod* Y1, int n[3])
{ {
int i,N; int i, N;
int typelog; int typelog;
/*generate Gaussian white noise*/ /*generate Gaussian white noise*/
N = grid.NX*grid.NY*grid.NZ; N = grid.NX * grid.NY * grid.NZ;
n[0] = 0; n[0] = 0;
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);
/*add the statistics*/ /*add the statistics*/
//if (stat.mean[0] != 0 || stat.variance[0]!= 1) //if (stat.mean[0] != 0 || stat.variance[0]!= 1)
//addstat2(Y,stat,Y1,Y); //addstat2(Y,stat,Y1,Y);
/* make a log normal realization */ /* make a log normal realization */
if (stat.type==1 || stat.type==2){ if (stat.type == 1 || stat.type == 2) {
typelog=stat.type+2; typelog = stat.type + 2;
/* nor2log(Y1,typelog,Y1); */ /* nor2log(Y1,typelog,Y1); */
nor2log(Y,typelog,Y); nor2log(Y, typelog, Y);
} }
return; return;
} }

@ -2,40 +2,37 @@
#include <stdlib.h> #include <stdlib.h>
/*normalizes anisotropy axes*/ /*normalizes anisotropy axes*/
void axes(double *ap,double *scf,int N) 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]);
ap[9*k] /= r; ap[9 * k] /= r;
ap[9*k+1] /= r; ap[9 * k + 1] /= r;
ap[9*k+2] /= r; ap[9 * k + 2] /= r;
sclpdt = ap[9*k]*ap[9*k+3]+ap[9*k+1]*ap[9*k+4]+ap[9*k+2]*ap[9*k+5]; sclpdt = ap[9 * k] * ap[9 * k + 3] + ap[9 * k + 1] * ap[9 * k + 4] + ap[9 * k + 2] * ap[9 * k + 5];
if (sclpdt > eps) { if (sclpdt > eps) {
printf("Non orthogonal axes"); printf("Non orthogonal axes");
exit; exit;
} else { } else {
r = sqrt(ap[9*k+3]*ap[9*k+3]+ap[9*k+4]*ap[9*k+4]+ap[9*k+5]*ap[9*k+5]); r = sqrt(ap[9 * k + 3] * ap[9 * k + 3] + ap[9 * k + 4] * ap[9 * k + 4] + ap[9 * k + 5] * ap[9 * k + 5]);
ap[9*k+3] /= r; ap[9 * k + 3] /= r;
ap[9*k+4] /= r; ap[9 * k + 4] /= r;
ap[9*k+5] /= r; ap[9 * k + 5] /= r;
ap[9*k+6] = ap[9*k+1]*ap[9*k+5]-ap[9*k+2]*ap[9*k+4]; ap[9 * k + 6] = ap[9 * k + 1] * ap[9 * k + 5] - ap[9 * k + 2] * ap[9 * k + 4];
ap[9*k+7] = ap[9*k+2]*ap[9*k+3]-ap[9*k]*ap[9*k+5]; ap[9 * k + 7] = ap[9 * k + 2] * ap[9 * k + 3] - ap[9 * k] * ap[9 * k + 5];
ap[9*k+8] = ap[9*k]*ap[9*k+4]-ap[9*k+1]*ap[9*k+3]; ap[9 * k + 8] = ap[9 * k] * ap[9 * k + 4] - ap[9 * k + 1] * ap[9 * k + 3];
for (i=0; i<3; i++) { for (i = 0; i < 3; i++) {
for (j=0; j<3; j++) { for (j = 0; j < 3; j++) {
if (scf[3*k+j] == 0.) if (scf[3 * k + j] == 0.)
scf[3*k+j] = 1.; scf[3 * k + j] = 1.;
ap[9*k+3*j+i] /= scf[3*k+j]; ap[9 * k + 3 * j + i] /= scf[3 * k + j];
} }
} }
} }
} }
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 */
@ -18,21 +18,21 @@
/*realization: vector defining the real part */ /*realization: vector defining the real part */
/*ireal: vector defining the i-part */ /*ireal: vector defining the i-part */
void build_real(int n[3],int NTOT,double *covar,double *realization,double *ireal) void build_real(int n[3], int NTOT, double* covar, double* realization, double* ireal)
{ {
int i,j,k,maille1; int i, j, k, maille1;
double temp; double temp;
/*decomposition and multiplication in the spectral domain*/ /*decomposition and multiplication in the spectral domain*/
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++) {
maille1 = i+(j-1+(k-1)*n[1])*n[0]; maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0];
temp = covar[maille1]; temp = covar[maille1];
if (temp > 0.) { if (temp > 0.) {
temp = sqrt(temp)/(double) NTOT; temp = sqrt(temp) / (double)NTOT;
} else if (temp < 0.) { } else if (temp < 0.) {
temp = sqrt(-temp)/(double) NTOT; temp = sqrt(-temp) / (double)NTOT;
} }
realization[maille1] *= temp; realization[maille1] *= temp;
ireal[maille1] *= temp; ireal[maille1] *= temp;

@ -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)
@ -9,10 +9,10 @@ double cardsin(double h)
double z; double z;
if (h != 0) { if (h != 0) {
z = (double)(h*delta); z = (double)(h * delta);
z = sin(z)/z; z = sin(z) / z;
} else { } else {
z = 1.; z = 1.;
} }
return(z); return (z);
} }

@ -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: */
@ -12,11 +11,11 @@
/* i = [0 1 2] */ /* i = [0 1 2] */
void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3]) void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3])
{ {
int i,N; int i, N;
double D; double D;
if (n == NULL || n[0] == 0 || n[1] == 0 || n[2] == 0) { if (n == NULL || n[0] == 0 || n[1] == 0 || n[2] == 0) {
for (i = 0; i<3; i++) { for (i = 0; i < 3; i++) {
switch (i) { switch (i) {
case 0: case 0:
N = grid.NX; N = grid.NX;
@ -31,10 +30,10 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3])
D = grid.DZ; D = grid.DZ;
break; break;
} }
n[i] = length(N,i,variogram.scf,variogram.ap,D,variogram.Nvario); n[i] = length(N, i, variogram.scf, variogram.ap, D, variogram.Nvario);
} }
} else { } else {
if ((n[0]<grid.NX) || (n[1]<grid.NY) || (n[2]<grid.NZ)) { if ((n[0] < grid.NX) || (n[1] < grid.NY) || (n[2] < grid.NZ)) {
printf("Indicated dimensions are inappropriate in cgrid"); printf("Indicated dimensions are inappropriate in cgrid");
exit; exit;
} }

@ -1,25 +1,23 @@
#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)
{ {
int i,j,k,maille0,maille1; int i, j, k, maille0, maille1;
double NTOT; double NTOT;
NTOT=n[0]*n[1]*n[2]; NTOT = n[0] * n[1] * n[2];
/*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;
} }
@ -27,11 +25,11 @@ void clean_real(struct realization_mod *realin,int n[3],struct grid_mod grid,dou
(*realout).n = (*realin).n; (*realout).n = (*realin).n;
(*realout).code = 1; (*realout).code = 1;
for ( k = 1; k <= grid.NZ; k++) { for (k = 1; k <= grid.NZ; k++) {
for (j = 1; j <= grid.NY; j++) { for (j = 1; j <= grid.NY; j++) {
for (i = 1; i <= grid.NX; i++) { for (i = 1; i <= grid.NX; i++) {
maille1 = i+(j-1+(k-1)*n[1])*n[0]; maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0];
maille0 = i-1+(j-1+(k-1)*grid.NY)*grid.NX; maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX;
/* Modif du 18 juin 2003 */ /* Modif du 18 juin 2003 */
/*(*realout).vector[maille0] = vectorresult[maille1]/(double) NTOT;*/ /*(*realout).vector[maille0] = vectorresult[maille1]/(double) NTOT;*/
(*realout).vector[maille0] = vectorresult[maille1]; (*realout).vector[maille0] = vectorresult[maille1];

@ -1,11 +1,11 @@
#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)
{ {
double hx,hy,hz,h; double hx, hy, hz, h;
double cov; double cov;
int k; int k;
@ -13,39 +13,38 @@ double cov_value(struct vario_mod variogram,double di,double dj,double dk)
for (k = 0; k < variogram.Nvario; k++) { for (k = 0; k < variogram.Nvario; k++) {
hx = di*variogram.ap[9*k]+dj*variogram.ap[9*k+1]+dk*variogram.ap[9*k+2]; hx = di * variogram.ap[9 * k] + dj * variogram.ap[9 * k + 1] + dk * variogram.ap[9 * k + 2];
hy = di*variogram.ap[9*k+3]+dj*variogram.ap[9*k+4]+dk*variogram.ap[9*k+5]; hy = di * variogram.ap[9 * k + 3] + dj * variogram.ap[9 * k + 4] + dk * variogram.ap[9 * k + 5];
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);
break; break;
case 2: case 2:
cov += variogram.var[k]*gaussian(h); cov += variogram.var[k] * gaussian(h);
break; break;
case 3: case 3:
cov += variogram.var[k]*spherical(h); cov += variogram.var[k] * spherical(h);
break; break;
case 4: case 4:
cov += variogram.var[k]*cardsin(h); cov += variogram.var[k] * cardsin(h);
break; break;
case 5: case 5:
cov += variogram.var[k]*stable(h,variogram.alpha[k]); cov += variogram.var[k] * stable(h, variogram.alpha[k]);
break; break;
case 6: case 6:
cov += variogram.var[k]*gammf(h,variogram.alpha[k]); cov += variogram.var[k] * gammf(h, variogram.alpha[k]);
break; break;
case 7: case 7:
cov += variogram.var[k]*cubic(h); cov += variogram.var[k] * cubic(h);
break; break;
case 8: case 8:
cov += variogram.var[k]*nugget(h); cov += variogram.var[k] * nugget(h);
break; break;
case 9: case 9:
cov += variogram.var[k]*power(h,variogram.alpha[k]); cov += variogram.var[k] * power(h, variogram.alpha[k]);
break; break;
} }
} }

@ -2,85 +2,76 @@
/*builds the sampled covariance function*/ /*builds the sampled covariance function*/
/*dimensions are even*/ /*dimensions are even*/
void covariance(double *covar, struct vario_mod variogram, struct grid_mod mesh, int n[3]) void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3])
{ {
int i,j,k,maille,n2[3],symmetric; int i, j, k, maille, n2[3], symmetric;
double di,dj,dk; double di, dj, dk;
for (i=0;i<3;i++) for (i = 0; i < 3; i++)
n2[i] = n[i]/2; n2[i] = n[i] / 2;
for (i=0; i<= n2[0]; i++) {
for (j=0; j<= n2[1]; j++) {
for (k=0; k<= n2[2]; k++) {
for (i = 0; i <= n2[0]; i++) {
for (j = 0; j <= n2[1]; j++) {
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;
dj = (double)j*mesh.DY; dj = (double)j * mesh.DY;
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;
dj = (double)j*mesh.DY; dj = (double)j * mesh.DY;
dk = (double)k*mesh.DZ; dk = (double)k * mesh.DZ;
maille = 1+(n[0]-i)+n[0]*(j+n[1]*k); maille = 1 + (n[0] - i) + n[0] * (j + n[1] * k);
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;
dj = -(double)j*mesh.DY; dj = -(double)j * mesh.DY;
dk = (double)k*mesh.DZ; dk = (double)k * mesh.DZ;
maille = 1+(n[0]-i)+n[0]*(n[1]-j+n[1]*k); maille = 1 + (n[0] - i) + n[0] * (n[1] - j + n[1] * k);
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;
dj = -(double)j*mesh.DY; dj = -(double)j * mesh.DY;
dk = (double)k*mesh.DZ; dk = (double)k * mesh.DZ;
maille = 1+i+n[0]*(n[1]-j+n[1]*k); maille = 1 + i + n[0] * (n[1] - j + n[1] * k);
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)
@ -11,7 +10,7 @@ double cubic(double h)
if (h >= 1.) { if (h >= 1.) {
z = 0.; z = 0.;
} else { } else {
z = 1.-7.*(double)(h*h)+(35./4.)*(double)(h*h*h)-3.5*(double)(h*h*h*h*h)+.75*(double)(h*h*h*h*h*h*h); z = 1. - 7. * (double)(h * h) + (35. / 4.) * (double)(h * h * h) - 3.5 * (double)(h * h * h * h * h) + .75 * (double)(h * h * h * h * h * h * h);
} }
return (z); return (z);
} }

@ -1,9 +1,9 @@
#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)
{ {
return (exp(-3.*(double)h)); return (exp(-3. * (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 */
@ -22,84 +21,79 @@
/*output: */ /*output: */
/*realout: structure defining a realization - */ /*realout: structure defining a realization - */
void FFTMA2(struct vario_mod variogram,struct grid_mod grid,int n[3],struct realization_mod *realin,struct realization_mod *realout) void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout)
{ {
int NTOT,i,j,k,NMAX,NDIM,ntot,nmax,NXYZ,nxyz,maille0,maille1; int NTOT, i, j, k, NMAX, NDIM, ntot, nmax, NXYZ, nxyz, maille0, maille1;
int solver; int solver;
double temp; double temp;
double *ireal,*covar,*workr,*worki,*realization; double *ireal, *covar, *workr, *worki, *realization;
/*covariance axis normalization*/ /*covariance axis normalization*/
axes(variogram.ap,variogram.scf,variogram.Nvario); axes(variogram.ap, variogram.scf, variogram.Nvario);
/*pseudo-grid definition*/ /*pseudo-grid definition*/
cgrid(variogram,grid,n); cgrid(variogram, grid, n);
/*constant definition*/ /*constant definition*/
NTOT = n[0]*n[1]*n[2]; NTOT = n[0] * n[1] * n[2];
ntot = NTOT+1; ntot = NTOT + 1;
NMAX = n[0]; NMAX = n[0];
NDIM = 3; NDIM = 3;
for (i=1;i<3;i++) { for (i = 1; i < 3; i++) {
if (n[i] > NMAX) if (n[i] > NMAX)
NMAX = n[i]; NMAX = n[i];
if (n[i] == 1) if (n[i] == 1)
NDIM--; NDIM--;
} }
nmax = NMAX+1; nmax = NMAX + 1;
NXYZ = grid.NX*grid.NY*grid.NZ; NXYZ = grid.NX * grid.NY * grid.NZ;
nxyz = NXYZ+1; nxyz = NXYZ + 1;
/*array initialization*/ /*array initialization*/
covar = (double *) malloc(ntot * sizeof(double)); covar = (double*)malloc(ntot * sizeof(double));
testmemory(covar); testmemory(covar);
ireal = (double *) malloc(ntot * sizeof(double)); ireal = (double*)malloc(ntot * sizeof(double));
testmemory(ireal); testmemory(ireal);
realization = (double *) malloc(ntot * sizeof(double)); realization = (double*)malloc(ntot * sizeof(double));
testmemory(realization); testmemory(realization);
workr = (double *) malloc(nmax * sizeof(double)); workr = (double*)malloc(nmax * sizeof(double));
testmemory(workr); testmemory(workr);
worki = (double *) malloc(nmax * sizeof(double)); worki = (double*)malloc(nmax * sizeof(double));
testmemory(worki); testmemory(worki);
/*covariance function creation*/ /*covariance function creation*/
covariance(covar,variogram,grid,n); covariance(covar, variogram, grid, n);
/*power spectrum*/ /*power spectrum*/
fourt(covar,ireal,n,NDIM,1,0,workr,worki); fourt(covar, ireal, n, NDIM, 1, 0, workr, worki);
/*organization of the input Gaussian white noise*/ /*organization of the input Gaussian white noise*/
solver=0; solver = 0;
prebuild_gwn(grid,n,realin,realization,solver); prebuild_gwn(grid, n, realin, realization, solver);
/*forward fourier transform of the GWN*/ /*forward fourier transform of the GWN*/
fourt(realization,ireal,n,NDIM,1,0,workr,worki); fourt(realization, ireal, n, NDIM, 1, 0, workr, worki);
/* build realization in spectral domain */ /* build realization in spectral domain */
build_real(n,NTOT,covar,realization,ireal); build_real(n, NTOT, covar, realization, ireal);
free(covar); free(covar);
/*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);
/*output realization*/ /*output realization*/
clean_real(realin,n,grid,realization,realout); clean_real(realin, n, grid, realization, realout);
free(realization); free(realization);
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,11 +89,10 @@
/* 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;
double theta,wstpr,wstpi,wminr,wmini,wr,wi,wtemp,thetm,wmstr,wmsti,twowr,sr,si,oldsr,oldsi,stmpr,stmpi,tempr,tempi,difi,difr,sumr,sumi,TWOPI = 6.283185307179586476925286766559; double theta, wstpr, wstpi, wminr, wmini, wr, wi, wtemp, thetm, wmstr, wmsti, twowr, sr, si, oldsr, oldsi, stmpr, stmpi, tempr, tempi, difi, difr, sumr, sumi, TWOPI = 6.283185307179586476925286766559;
ntot = 1; ntot = 1;
for (idim = 0; idim < ndim; idim++) { for (idim = 0; idim < ndim; idim++) {
@ -103,8 +102,8 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
/*main loop for each dimension*/ /*main loop for each dimension*/
np1 = 1; np1 = 1;
for (idim = 1; idim <= ndim; idim++) { for (idim = 1; idim <= ndim; idim++) {
n = nn[idim-1]; n = nn[idim - 1];
np2 = np1*n; np2 = np1 * n;
if (n < 1) { if (n < 1) {
goto L920; goto L920;
@ -119,23 +118,23 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
idiv = 2; idiv = 2;
L10: L10:
iquot = m/idiv; iquot = m / idiv;
irem = m-idiv*iquot; irem = m - idiv * iquot;
if (iquot < idiv) if (iquot < idiv)
goto L50; goto L50;
if (irem == 0) { if (irem == 0) {
ntwo *= 2; ntwo *= 2;
ifact[iff] = idiv; ifact[iff] = idiv;
iff++; iff++;
m= iquot; m = iquot;
goto L10; goto L10;
} }
idiv = 3; idiv = 3;
inon2 = iff; inon2 = iff;
L30: L30:
iquot = m/idiv; iquot = m / idiv;
irem = m-idiv*iquot; irem = m - idiv * iquot;
if (iquot < idiv) if (iquot < idiv)
goto L60; goto L60;
if (irem == 0) { if (irem == 0) {
@ -159,8 +158,7 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
ifact[iff] = m; ifact[iff] = m;
L70: L70:
non2p = np2/ntwo; non2p = np2 / ntwo;
/*SEPARATE FOUR CASES-- /*SEPARATE FOUR CASES--
1. COMPLEX TRANSFORM 1. COMPLEX TRANSFORM
@ -187,7 +185,7 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
i = 1; i = 1;
for (j = 1; j <= ntot; j++) { for (j = 1; j <= ntot; j++) {
datar[j] = datar[i]; datar[j] = datar[i];
datai[j] = datar[i+1]; datai[j] = datar[i + 1];
i += 2; i += 2;
} }
@ -195,15 +193,15 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L100: L100:
if (non2p > 1) if (non2p > 1)
goto L200; goto L200;
np2hf = np2/2; np2hf = np2 / 2;
j = 1; j = 1;
for (i2 = 1; i2 <= np2; i2 += np1) { for (i2 = 1; i2 <= np2; i2 += np1) {
if (j >= i2) if (j >= i2)
goto L130; goto L130;
i1max = i2+np1-1; i1max = i2 + np1 - 1;
for (i1 = i2; i1 <= i1max; i1++) { for (i1 = i2; i1 <= i1max; i1++) {
for (i3 = i1; i3 <= ntot; i3 += np2) { for (i3 = i1; i3 <= ntot; i3 += np2) {
j3 = j+i3-i2; j3 = j + i3 - i2;
tempr = datar[i3]; tempr = datar[i3];
tempi = datai[i3]; tempi = datai[i3];
datar[i3] = datar[j3]; datar[i3] = datar[j3];
@ -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;
@ -245,9 +242,9 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
ifp2 = np2; ifp2 = np2;
iff = ifmin; iff = ifmin;
L250: L250:
ifp1 = ifp2/ifact[iff]; ifp1 = ifp2 / ifact[iff];
j += ifp1; j += ifp1;
if (j >= i3+ifp2) { if (j >= i3 + ifp2) {
j -= ifp2; j -= ifp2;
ifp2 = ifp1; ifp2 = ifp1;
iff += 1; iff += 1;
@ -255,14 +252,13 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
goto L250; goto L250;
} }
} }
i2max = i3+np2-np1; i2max = i3 + np2 - np1;
i = 1; i = 1;
for (i2 = i3; i2 <= i2max; i2 += np1) { for (i2 = i3; i2 <= i2max; i2 += np1) {
datar[i2] = workr[i]; datar[i2] = workr[i];
datai[i2] = worki[i]; datai[i2] = worki[i];
i++; i++;
} }
} }
} }
@ -270,12 +266,12 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L300: L300:
i1rng = np1; i1rng = np1;
if (icase == 2) if (icase == 2)
i1rng = np0*(1+nprev/2); i1rng = np0 * (1 + nprev / 2);
if (ntwo <= np1) if (ntwo <= np1)
goto L600; goto L600;
for (i1 = 1; i1 <= i1rng; i1++) { for (i1 = 1; i1 <= i1rng; i1++) {
imin = np1+i1; imin = np1 + i1;
istep = 2*np1; istep = 2 * np1;
goto L330; goto L330;
L310: L310:
@ -283,13 +279,13 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
for (i = imin; i <= ntot; i += istep) { for (i = imin; i <= ntot; i += istep) {
tempr = datar[i]; tempr = datar[i];
tempi = datai[i]; tempi = datai[i];
datar[i] = datar[j]-tempr; datar[i] = datar[j] - tempr;
datai[i] = datai[j]-tempi; datai[i] = datai[j] - tempi;
datar[j] = datar[j]+tempr; datar[j] = datar[j] + tempr;
datai[j] = datai[j]+tempi; datai[j] = datai[j] + tempi;
j += istep; j += istep;
} }
imin = 2*imin-i1; imin = 2 * imin - i1;
istep *= 2; istep *= 2;
L330: L330:
@ -297,12 +293,12 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
goto L310; goto L310;
/*special case-- W = -sqrt(-1)*/ /*special case-- W = -sqrt(-1)*/
imin = 3*np1+i1; imin = 3 * np1 + i1;
istep = 4*np1; istep = 4 * np1;
goto L420; goto L420;
L400: L400:
j = imin-istep/2; j = imin - istep / 2;
for (i = imin; i <= ntot; i += istep) { for (i = imin; i <= ntot; i += istep) {
if (ifrwd != 0) { if (ifrwd != 0) {
tempr = datai[i]; tempr = datai[i];
@ -311,14 +307,14 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
tempr = -datai[i]; tempr = -datai[i];
tempi = datar[i]; tempi = datar[i];
} }
datar[i] = datar[j]-tempr; datar[i] = datar[j] - tempr;
datai[i] = datai[j]-tempi; datai[i] = datai[j] - tempi;
datar[j] += tempr; datar[j] += tempr;
datai[j] += tempi; datai[j] += tempi;
j += istep; j += istep;
} }
imin = 2*imin-i1; imin = 2 * imin - i1;
istep *= 2; istep *= 2;
L420: L420:
@ -327,14 +323,14 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
} }
/*main loop for factors of 2. W=EXP(-2*PI*SQRT(-1)*m/mmax) */ /*main loop for factors of 2. W=EXP(-2*PI*SQRT(-1)*m/mmax) */
theta = -TWOPI/8.; theta = -TWOPI / 8.;
wstpr = 0.; wstpr = 0.;
wstpi = -1.; wstpi = -1.;
if (ifrwd == 0) { if (ifrwd == 0) {
theta = -theta; theta = -theta;
wstpi = 1.; wstpi = 1.;
} }
mmax = 8*np1; mmax = 8 * np1;
goto L540; goto L540;
L500: L500:
@ -342,31 +338,31 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
wmini = sin(theta); wmini = sin(theta);
wr = wminr; wr = wminr;
wi = wmini; wi = wmini;
mmin = mmax/2+np1; mmin = mmax / 2 + np1;
mstep = np1*2; mstep = np1 * 2;
for (m = mmin; m <= mmax; m += mstep) { for (m = mmin; m <= mmax; m += mstep) {
for (i1 = 1; i1 <= i1rng; i1++) { for (i1 = 1; i1 <= i1rng; i1++) {
istep = mmax; istep = mmax;
imin = m+i1; imin = m + i1;
L510: L510:
j = imin-istep/2; j = imin - istep / 2;
for (i = imin; i <= ntot; i += istep) { for (i = imin; i <= ntot; i += istep) {
tempr = datar[i]*wr-datai[i]*wi; tempr = datar[i] * wr - datai[i] * wi;
tempi = datar[i]*wi+datai[i]*wr; tempi = datar[i] * wi + datai[i] * wr;
datar[i] = datar[j]-tempr; datar[i] = datar[j] - tempr;
datai[i] = datai[j]-tempi; datai[i] = datai[j] - tempi;
datar[j] += tempr; datar[j] += tempr;
datai[j] += tempi; datai[j] += tempi;
j += istep; j += istep;
} }
imin = 2*imin-i1; imin = 2 * imin - i1;
istep *= 2; istep *= 2;
if (istep <= ntwo) if (istep <= ntwo)
goto L510; goto L510;
} }
wtemp = wr*wstpi; wtemp = wr * wstpi;
wr = wr*wstpr-wi*wstpi; wr = wr * wstpr - wi * wstpi;
wi = wi*wstpr+wtemp; wi = wi * wstpr + wtemp;
} }
wstpr = wminr; wstpr = wminr;
wstpi = wmini; wstpi = wmini;
@ -383,11 +379,11 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
ifp1 = ntwo; ifp1 = ntwo;
iff = inon2; iff = inon2;
L610: L610:
ifp2 = ifact[iff]*ifp1; ifp2 = ifact[iff] * ifp1;
theta = -TWOPI/ (double)ifact[iff]; theta = -TWOPI / (double)ifact[iff];
if (ifrwd == 0) if (ifrwd == 0)
theta = -theta; theta = -theta;
thetm = theta/ (double)(ifp1/np1); thetm = theta / (double)(ifp1 / np1);
wstpr = cos(theta); wstpr = cos(theta);
wstpi = sin(theta); wstpi = sin(theta);
wmstr = cos(thetm); wmstr = cos(thetm);
@ -396,19 +392,19 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
wmini = 0.; wmini = 0.;
for (j1 = 1; j1 <= ifp1; j1 += np1) { for (j1 = 1; j1 <= ifp1; j1 += np1) {
i1max = j1+i1rng-1; i1max = j1 + i1rng - 1;
for (i1 = j1; i1 <= i1max; i1++) { for (i1 = j1; i1 <= i1max; i1++) {
for (i3 = i1; i3 <= ntot; i3 += np2) { for (i3 = i1; i3 <= ntot; i3 += np2) {
i = 1; i = 1;
wr = wminr; wr = wminr;
wi = wmini; wi = wmini;
j2max = i3+ifp2-ifp1; j2max = i3 + ifp2 - ifp1;
for (j2 = i3; j2 <= j2max; j2 += ifp1) { for (j2 = i3; j2 <= j2max; j2 += ifp1) {
twowr = 2.*wr; twowr = 2. * wr;
jmin = i3; jmin = i3;
j3max = j2+np2-ifp2; j3max = j2 + np2 - ifp2;
for (j3 = j2 ; j3 <= j3max; j3 += ifp2) { for (j3 = j2; j3 <= j3max; j3 += ifp2) {
j = jmin+ifp2-ifp1; j = jmin + ifp2 - ifp1;
sr = datar[j]; sr = datar[j];
si = datai[j]; si = datai[j];
oldsr = 0.; oldsr = 0.;
@ -417,25 +413,25 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L620: L620:
stmpr = sr; stmpr = sr;
stmpi = si; stmpi = si;
sr = twowr*sr-oldsr+datar[j]; sr = twowr * sr - oldsr + datar[j];
si = twowr*si-oldsi+datai[j]; si = twowr * si - oldsi + datai[j];
oldsr = stmpr; oldsr = stmpr;
oldsi = stmpi; oldsi = stmpi;
j -= ifp1; j -= ifp1;
if (j > jmin) if (j > jmin)
goto L620; goto L620;
workr[i] = wr*sr-wi*si-oldsr+datar[j]; workr[i] = wr * sr - wi * si - oldsr + datar[j];
worki[i] = wi*sr+wr*si-oldsi+datai[j]; worki[i] = wi * sr + wr * si - oldsi + datai[j];
jmin += ifp2; jmin += ifp2;
i++; i++;
} }
wtemp = wr*wstpi; wtemp = wr * wstpi;
wr = wr*wstpr-wi*wstpi; wr = wr * wstpr - wi * wstpi;
wi = wi*wstpr+wtemp; wi = wi * wstpr + wtemp;
} }
i = 1; i = 1;
for (j2 = i3; j2 <= j2max; j2 += ifp1) { for (j2 = i3; j2 <= j2max; j2 += ifp1) {
j3max = j2+np2-ifp2; j3max = j2 + np2 - ifp2;
for (j3 = j2; j3 <= j3max; j3 += ifp2) { for (j3 = j2; j3 <= j3max; j3 += ifp2) {
datar[j3] = workr[i]; datar[j3] = workr[i];
datai[j3] = worki[i]; datai[j3] = worki[i];
@ -444,9 +440,9 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
} }
} }
} }
wtemp = wminr*wmsti; wtemp = wminr * wmsti;
wminr = wminr*wmstr-wmini*wmsti; wminr = wminr * wmstr - wmini * wmsti;
wmini = wmini*wmstr+wtemp; wmini = wmini * wmstr + wtemp;
} }
iff++; iff++;
ifp1 = ifp2; ifp1 = ifp2;
@ -469,7 +465,7 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
nhalf = n; nhalf = n;
n += n; n += n;
theta = -TWOPI/ (double) n; theta = -TWOPI / (double)n;
if (ifrwd == 0) if (ifrwd == 0)
theta = -theta; theta = -theta;
wstpr = cos(theta); wstpr = cos(theta);
@ -482,23 +478,23 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L710: L710:
j = jmin; j = jmin;
for (i = imin; i <= ntot; i += np2) { for (i = imin; i <= ntot; i += np2) {
sumr = (datar[i]+datar[j])/2.; sumr = (datar[i] + datar[j]) / 2.;
sumi = (datai[i]+datai[j])/2.; sumi = (datai[i] + datai[j]) / 2.;
difr = (datar[i]-datar[j])/2.; difr = (datar[i] - datar[j]) / 2.;
difi = (datai[i]-datai[j])/2.; difi = (datai[i] - datai[j]) / 2.;
tempr = wr*sumi+wi*difr; tempr = wr * sumi + wi * difr;
tempi = wi*sumi-wr*difr; tempi = wi * sumi - wr * difr;
datar[i] = sumr+tempr; datar[i] = sumr + tempr;
datai[i] = difi+tempi; datai[i] = difi + tempi;
datar[j] = sumr-tempr; datar[j] = sumr - tempr;
datai[j] = tempi-difi; datai[j] = tempi - difi;
j += np2; j += np2;
} }
imin++; imin++;
jmin--; jmin--;
wtemp = wr*wstpi; wtemp = wr * wstpi;
wr = wr*wstpr-wi*wstpi; wr = wr * wstpr - wi * wstpi;
wi = wi*wstpr+wtemp; wi = wi * wstpr + wtemp;
L725: L725:
if (imin < jmin) { if (imin < jmin) {
goto L710; goto L710;
@ -513,10 +509,10 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
L740: L740:
np2 *= 2; np2 *= 2;
ntot *= 2; ntot *= 2;
j = ntot+1; j = ntot + 1;
imax = ntot/2+1; imax = ntot / 2 + 1;
L745: L745:
imin = imax-nhalf; imin = imax - nhalf;
i = imin; i = imin;
goto L755; goto L755;
L750: L750:
@ -527,7 +523,7 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
j--; j--;
if (i < imax) if (i < imax)
goto L750; goto L750;
datar[j] = datar[imin]-datai[imin]; datar[j] = datar[imin] - datai[imin];
datai[j] = 0.; datai[j] = 0.;
if (i >= j) { if (i >= j) {
goto L780; goto L780;
@ -542,7 +538,7 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
j--; j--;
if (i > imin) if (i > imin)
goto L765; goto L765;
datar[j] = datar[imin]+datai[imin]; datar[j] = datar[imin] + datai[imin];
datai[j] = 0.; datai[j] = 0.;
imax = imin; imax = imin;
goto L745; goto L745;
@ -556,15 +552,15 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
if (nprev <= 2) if (nprev <= 2)
goto L900; goto L900;
for (i3 = 1; i3 <= ntot; i3 += np2) { for (i3 = 1; i3 <= ntot; i3 += np2) {
i2max = i3+np2-np1; i2max = i3 + np2 - np1;
for (i2 = i3; i2 <= i2max; i2 += np1) { for (i2 = i3; i2 <= i2max; i2 += np1) {
imax = i2+np1-1; imax = i2 + np1 - 1;
imin = i2+i1rng; imin = i2 + i1rng;
jmax = 2*i3+np1-imin; jmax = 2 * i3 + np1 - imin;
if (i2 > i3) if (i2 > i3)
jmax += np2; jmax += np2;
if (idim > 2) { if (idim > 2) {
j = jmax+np0; j = jmax + np0;
for (i = imin; i <= imax; i++) { for (i = imin; i <= imax; i++) {
datar[i] = datar[j]; datar[i] = datar[j];
datai[i] = -datai[j]; datai[i] = -datai[j];
@ -586,6 +582,6 @@ void fourt(double *datar,double *datai, int nn[3], int ndim, int ifrwd, int icpl
np1 = np2; np1 = np2;
nprev = n; nprev = n;
} }
L920: L920:
return; return;
} }

@ -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)
@ -9,8 +8,7 @@ double gammf(double h, double alpha)
float delta; float delta;
double z; double z;
delta = pow(20.,1./alpha)-1.; delta = pow(20., 1. / alpha) - 1.;
z = 1./(double)(pow(1.+h*delta,alpha)); z = 1. / (double)(pow(1. + h * delta, alpha));
return(z); return (z);
} }

@ -1,29 +1,29 @@
#include <math.h>
#include "genlib.h" #include "genlib.h"
#include <math.h>
#define NTAB 32 #define NTAB 32
double gasdev(long *idum,long *idum2, long *iy, long iv[NTAB]) double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB])
/*returns a normally distributed deviate with 0 mean*/ /*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran2(idum) as the source */ /*and unit variance, using ran2(idum) as the source */
/*of uniform deviates */ /*of uniform deviates */
{ {
double ran2(long *idum,long *idum2, long *iy, long iv[NTAB]); double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]);
static int iset = 0; static int iset = 0;
static double gset; static double gset;
double fac,rsq,v1,v2; double fac, rsq, v1, v2;
if (iset == 0) { if (iset == 0) {
do { do {
v1 = 2.0*ran2(idum,idum2,iy,iv)-1.0; v1 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
v2 = 2.0*ran2(idum,idum2,iy,iv)-1.0; v2 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
rsq = v1*v1+v2*v2; rsq = v1 * v1 + v2 * v2;
} while (rsq >= 1.0 || rsq == 0.0); } while (rsq >= 1.0 || rsq == 0.0);
fac = sqrt(-2.0*log(rsq)/rsq); fac = sqrt(-2.0 * log(rsq) / rsq);
gset = v1*fac; gset = v1 * fac;
iset = 1; iset = 1;
return (v2*fac); return (v2 * fac);
} else { } else {
iset = 0; iset = 0;
return (gset); return (gset);

@ -1,10 +1,9 @@
#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)
{ {
return (exp(-3.*(double)(h*h))); return (exp(-3. * (double)(h * 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: */
@ -10,14 +9,14 @@
/*output: */ /*output: */
/* realization: structure defining the realization*/ /* realization: structure defining the realization*/
void generate(long *seed, int n, struct realization_mod *realization) void generate(long* seed, int n, struct realization_mod* realization)
{ {
int i; int i;
long idum2 = 123456789,iy = 0; long idum2 = 123456789, iy = 0;
long *iv; long* iv;
int iset =0; int iset = 0;
iv = (long *) malloc(NTAB * sizeof(long)); iv = (long*)malloc(NTAB * sizeof(long));
/*negative seed*/ /*negative seed*/
if (*seed > 0.0) if (*seed > 0.0)
@ -26,18 +25,15 @@ void generate(long *seed, int n, struct realization_mod *realization)
/*realization definition*/ /*realization definition*/
(*realization).n = n; (*realization).n = n;
(*realization).code = 0; (*realization).code = 0;
(*realization).vector = (double *) malloc(n * sizeof(double)); (*realization).vector = (double*)malloc(n * sizeof(double));
if ((*realization).vector == NULL) { if ((*realization).vector == NULL) {
printf("No memory available in generate"); printf("No memory available in generate");
exit; exit;
} }
/*Gaussian white noise generation*/ /*Gaussian white noise generation*/
for (i=0; i < n; i++) for (i = 0; i < n; i++)
(*realization).vector[i] = gasdev(seed,&idum2,&iy,iv,&iset); (*realization).vector[i] = gasdev(seed, &idum2, &iy, iv, &iset);
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"
@ -34,16 +34,17 @@ char undefined_object[] = "UNDEFINED";
/* Section 2 -- Memory allocation */ /* Section 2 -- Memory allocation */
void *GetBlock(size_t nbytes) 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);
} }
void FreeBlock(void *ptr) void FreeBlock(void* ptr)
{ {
free(ptr); free(ptr);
} }

@ -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 */
@ -45,20 +45,21 @@
*/ */
#ifdef THINK_C #ifdef THINK_C
typedef int bool; typedef int bool;
#else
#ifdef TRUE
#ifndef bool
#define bool int
#endif
#else #else
# ifdef TRUE #ifdef bool
# ifndef bool #define FALSE 0
# define bool int #define TRUE 1
# endif #else
# else typedef enum { FALSE,
# ifdef bool TRUE } bool;
# define FALSE 0 #endif
# define TRUE 1 #endif
# else
typedef enum {FALSE, TRUE} bool;
# endif
# endif
#endif #endif
/* /*
@ -72,7 +73,7 @@
* Declaring it as a string emphasizes this atomicity. * Declaring it as a string emphasizes this atomicity.
*/ */
typedef char *string; typedef char* string;
/* /*
* Constant: UNDEFINED * Constant: UNDEFINED
@ -84,7 +85,7 @@ typedef char *string;
* therefore inappropriate as a sentinel. * therefore inappropriate as a sentinel.
*/ */
#define UNDEFINED ((void *) undefined_object) #define UNDEFINED ((void*)undefined_object)
extern char undefined_object[]; extern char undefined_object[];
@ -111,7 +112,7 @@ extern char undefined_object[];
* no memory is available, GetBlock generates an error. * no memory is available, GetBlock generates an error.
*/ */
void *GetBlock(size_t nbytes); void* GetBlock(size_t nbytes);
/* /*
* Function: FreeBlock * Function: FreeBlock
@ -121,7 +122,7 @@ void *GetBlock(size_t nbytes);
* have been allocated using GetBlock, New, or NewArray. * have been allocated using GetBlock, New, or NewArray.
*/ */
void FreeBlock(void *ptr); void FreeBlock(void* ptr);
/* /*
* Macro: New * Macro: New
@ -135,7 +136,7 @@ void FreeBlock(void *ptr);
* target type. * target type.
*/ */
#define New(type) ((type) GetBlock(sizeof *((type) NULL))) #define New(type) ((type)GetBlock(sizeof *((type)NULL)))
/* /*
* Macro: NewArray * Macro: NewArray
@ -145,7 +146,7 @@ void FreeBlock(void *ptr);
* values of the specified element type. * values of the specified element type.
*/ */
#define NewArray(n, type) ((type *) GetBlock((n) * sizeof(type))) #define NewArray(n, type) ((type*)GetBlock((n) * sizeof(type)))
/* Section 3 -- Basic error handling */ /* Section 3 -- Basic error handling */

@ -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 */
@ -68,15 +63,13 @@
/*var: normalized variance per variogram model(sum = 1)*/ /*var: normalized variance per variogram model(sum = 1)*/
struct vario_mod { struct vario_mod {
int Nvario; int Nvario;
int *vario; int* vario;
double *alpha; double* alpha;
double *ap; double* ap;
double *scf; double* scf;
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 */
@ -96,17 +89,14 @@ struct vario_mod {
/*var: normalized variance per variogram model(sum = 1)*/ /*var: normalized variance per variogram model(sum = 1)*/
struct variotable_mod { struct variotable_mod {
int number_of_variograms; int number_of_variograms;
int *Nvario; int* Nvario;
int *vario; int* vario;
float *alpha; float* alpha;
float *ap; float* ap;
float *scf; float* scf;
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*/
@ -119,11 +109,10 @@ struct variotable_mod {
/*Zo: Z-cell number of the origin cell */ /*Zo: Z-cell number of the origin cell */
struct grid_mod { struct grid_mod {
int NX, NY, NZ; int NX, NY, NZ;
double DX,DY,DZ; double DX, DY, DZ;
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 */
@ -154,17 +143,15 @@ struct grid_mod {
struct welldata_mod { struct welldata_mod {
int nwell; int nwell;
int *n; int* n;
int ntype; int ntype;
int *code; int* code;
float *x; float* x;
float *y; float* y;
float *z; float* z;
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 */
@ -176,10 +163,9 @@ struct welldata_mod {
struct statfacies_mod { struct statfacies_mod {
int ncat; int ncat;
int nblock; int nblock;
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 */
@ -204,12 +190,11 @@ struct statfacies_mod {
struct inequalities_mod { struct inequalities_mod {
int nsY1; int nsY1;
int nsY2; int nsY2;
float *thresholds; float* thresholds;
int *address_sY1; int* address_sY1;
int *address_sY2; int* address_sY2;
}; };
/*statistical data */ /*statistical data */
/*type --> 0 : normal */ /*type --> 0 : normal */
/* --> 1 : natural log */ /* --> 1 : natural log */
@ -229,12 +214,11 @@ struct inequalities_mod {
struct statistic_mod { struct statistic_mod {
int type; int type;
int nblock_mean; int nblock_mean;
double *mean; double* mean;
int nblock_var; int nblock_var;
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 */
@ -246,11 +230,10 @@ struct statistic_mod {
/*for subregions along axes X,Y,Z */ /*for subregions along axes X,Y,Z */
struct grad_mod { struct grad_mod {
int Nadded, NZONES; int Nadded, NZONES;
float *rho; float* rho;
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 */
@ -263,12 +246,10 @@ struct grad_mod {
/* Ncells....2*Ncells-1 for the second parameter */ /* Ncells....2*Ncells-1 for the second parameter */
/* and so on */ /* and so on */
struct gradients_mod { struct gradients_mod {
int Nparam,Ncells; int Nparam, Ncells;
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] */
@ -276,11 +257,10 @@ struct gradients_mod {
/* distribution i = [0...n-1] */ /* distribution i = [0...n-1] */
struct cdf_mod { struct cdf_mod {
int n; int n;
float *x; float* x;
float *fx; float* fx;
}; };
/*realization */ /*realization */
/*n: number of components */ /*n: number of components */
/*code: status of the realization */ /*code: status of the realization */
@ -303,7 +283,7 @@ struct cdf_mod {
struct realization_mod { struct realization_mod {
int n; int n;
int code; int code;
double *vector; double* vector;
}; };
/*=====================================================*/ /*=====================================================*/
@ -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 */
@ -330,8 +307,7 @@ double cardsin(double h);
/* n : dimension of matrix Cij */ /* n : dimension of matrix Cij */
/* */ /* */
/* 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*/
@ -341,8 +317,7 @@ void choldc(double *C, int n);
/*grid: structure defining the grid */ /*grid: structure defining the grid */
/*output: */ /*output: */
/*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 */
@ -351,7 +326,7 @@ void coordinates(int maille, int i[3],struct grid_mod grid);
/*variogram: structure defined above */ /*variogram: structure defined above */
/*grid: structure defined above */ /*grid: structure defined above */
/*n: number of gridblocks along X,Y and Z*/ /*n: number of gridblocks along X,Y and Z*/
void covariance(double *covar,struct vario_mod variogram, struct grid_mod grid, int n[3]); void covariance(double* covar, struct vario_mod variogram, struct grid_mod grid, int n[3]);
/*computation of the covariance matrix for the well data*/ /*computation of the covariance matrix for the well data*/
/*well coordinates are given as a number of cells */ /*well coordinates are given as a number of cells */
@ -362,8 +337,7 @@ void covariance(double *covar,struct vario_mod variogram, struct grid_mod grid,
/*variogram: structure defined above */ /*variogram: structure defined above */
/*well: structure defined above */ /*well: structure defined above */
/*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 */
@ -382,12 +356,11 @@ void cov_matrix(double *C, struct vario_mod variogram, struct welldata_mod well,
/*dj: distance along the Y axis */ /*dj: distance along the Y axis */
/*dk: distance along the Z axis */ /*dk: distance along the Z axis */
/* The returned value is the computed covariance value */ /* The returned value is the computed covariance value */
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);
/*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 */
@ -395,8 +368,7 @@ double cubic(double h);
/*ky: number of cells to save along the y-axis */ /*ky: number of cells to save along the y-axis */
/*kz: number of cells to save along the z-axis */ /*kz: number of cells to save along the z-axis */
/*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 */
@ -405,8 +377,7 @@ void cutspectr(float *covar, int kx, int ky, int kz, int n[3]);
/*thresholds: Gaussian threshold vector */ /*thresholds: Gaussian threshold vector */
/*facies: structure defined above */ /*facies: structure defined above */
/*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 */
@ -416,14 +387,11 @@ void deflimit(double *plim_inf, double *plim_sup, float x, float *thresholds, st
/*grid: structure defined above */ /*grid: structure defined above */
/*D: weight vector of length Ndata, Di, i = 0...Ndata-1*/ /*D: weight vector of length Ndata, Di, i = 0...Ndata-1*/
/*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 */
@ -434,44 +402,36 @@ double exponential(double h);
/*workr: utility real part vector for storage */ /*workr: utility real part vector for storage */
/*worki: utility imaginary part vector for storage */ /*worki: utility imaginary part vector for storage */
/*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 */
/*idum: seed */ /*idum: seed */
double gasdev(long *idum, long *idum2, long *iy, long *iv, int *iset); 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 */
@ -482,8 +442,7 @@ void gcf(float *gammcf, float a, float x, float *gln);
/*and k = j+i(i+1)/2 */ /*and k = j+i(i+1)/2 */
/*variogram: structure defined above */ /*variogram: structure defined above */
/*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*/
@ -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 */
@ -510,8 +468,7 @@ float Ginv(float p);
/*n: number of components per realization */ /*n: number of components per realization */
/*NZONES: number of subregions */ /*NZONES: number of subregions */
/*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: */
@ -526,8 +483,7 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3]);
/*incomplete gamma function evaluated by its series*/ /*incomplete gamma function evaluated by its series*/
/*representation as gamser, also returns ln(G(a)) */ /*representation as gamser, also returns ln(G(a)) */
/*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 */
@ -538,18 +494,16 @@ 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 */
/*scf: correlation length */ /*scf: correlation length */
/*ap: normalized anisotropy axes */ /*ap: normalized anisotropy axes */
int length(int N, int i, double *scf, double *ap, double D, int Nvari); int length(int N, int i, double* scf, double* ap, double D, int Nvari);
/*calculates L.Z/ /*calculates L.Z/
/* L : lower triangular matrix recorded */ /* L : lower triangular matrix recorded */
@ -560,7 +514,7 @@ int length(int N, int i, double *scf, double *ap, double D, int Nvari);
/* n : dimension of matrix Lij */ /* n : dimension of matrix Lij */
/* */ /* */
/* The solution vector is returned in b */ /* The solution vector is returned in b */
void LtimeZ(double *L, float *Z, float *b, int n); void LtimeZ(double* L, float* Z, float* b, int n);
/*determines the greatest prime factor of an integer*/ /*determines the greatest prime factor of an integer*/
int maxfactor(int n); int maxfactor(int n);
@ -570,40 +524,32 @@ int maxfactor(int n);
/*defined by the probability ratio "ratio". */ /*defined by the probability ratio "ratio". */
/*If ratio >= 1, metrop = 1(true), while if ratio < 1, */ /*If ratio >= 1, metrop = 1(true), while if ratio < 1, */
/*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 */
@ -614,32 +560,26 @@ double scal_vec(double *b,int n);
/* */ /* */
/* The solution vector is returned in D */ /* The solution vector is returned in D */
/* 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 */
@ -648,29 +588,25 @@ 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 */
double trungasdev(long *idum,double lim_inf,double lim_sup,long *idum2, long *iy, long iv[NTAB]); double trungasdev(long* idum, double lim_inf, double lim_sup, long* idum2, long* iy, long iv[NTAB]);
/* tb1.b2 */ /* tb1.b2 */
/* b1 : vector */ /* b1 : vector */
/* b2 : vector */ /* b2 : vector */
/* n : length of b1 and b2, bi, i = [0...n-1]*/ /* n : length of b1 and b2, bi, i = [0...n-1]*/
/*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]*/
/*where n is the number of facies-1 */ /*where n is the number of facies-1 */
/*USES normal*/ /*USES normal*/
void vf2gthres(struct statfacies_mod facies,float *thresholds); 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,7 @@
#include <math.h> #include <math.h>
/* compute the length for one dimension*/ /* compute the length for one dimension*/
int length(int N, int i, double *scf, double *ap, double D, int Nvari) int length(int N, int i, double* scf, double* ap, double D, int Nvari)
{ {
int maxfactor(int n); int maxfactor(int n);
double temp1, temp2; double temp1, temp2;
@ -13,22 +13,22 @@ int length(int N, int i, double *scf, double *ap, double D, int Nvari)
} else { } else {
for (k = 0; k < Nvari; k++) { for (k = 0; k < Nvari; k++) {
temp1 = fabs(ap[9*k+i])*scf[3*k]*scf[3*k]; temp1 = fabs(ap[9 * k + i]) * scf[3 * k] * scf[3 * k];
for (j = 1; j <3; j++) { for (j = 1; j < 3; j++) {
temp2 = fabs(ap[9*k+3*j+i])*scf[3*k+j]*scf[3*k+j]; temp2 = fabs(ap[9 * k + 3 * j + i]) * scf[3 * k + j] * scf[3 * k + j];
if (temp2 > temp1) if (temp2 > temp1)
temp1 = temp2; temp1 = temp2;
} }
} }
temp1 = sqrt(temp1); temp1 = sqrt(temp1);
temp1 /= (double)D; temp1 /= (double)D;
if ((double)N/temp1 < 2.) { if ((double)N / temp1 < 2.) {
n = N+(int)(2*temp1); n = N + (int)(2 * temp1);
} else { } else {
n = N+(int)temp1; n = N + (int)temp1;
} }
if ((n % 2) != 0) if ((n % 2) != 0)
n = n+1; n = n + 1;
nmax = maxfactor(n); nmax = maxfactor(n);
while (nmax > nlimit) { while (nmax > nlimit) {
n += 2; n += 2;

@ -3,30 +3,30 @@
/*determines the greatest prime factor of an integer*/ /*determines the greatest prime factor of an integer*/
int maxfactor(int n) int maxfactor(int n)
{ {
int test_fact(int *pnum, int fact, int *pmaxfac); int test_fact(int* pnum, int fact, int* pmaxfac);
int lnum, fact; int lnum, fact;
int maxfac; int maxfac;
maxfac = 1; maxfac = 1;
lnum = n; lnum = n;
if ( lnum != 0 && lnum != 1 ) { if (lnum != 0 && lnum != 1) {
fact = 2; fact = 2;
if ( test_fact( &lnum, fact,&maxfac)) { if (test_fact(&lnum, fact, &maxfac)) {
fact = 3; fact = 3;
if ( test_fact( &lnum, fact,&maxfac)) { if (test_fact(&lnum, fact, &maxfac)) {
fact = 5; fact = 5;
for (;;) { for (;;) {
if (!test_fact( &lnum, fact,&maxfac)) if (!test_fact(&lnum, fact, &maxfac))
break; break;
fact += 2; fact += 2;
if (!test_fact( &lnum, fact,&maxfac)) if (!test_fact(&lnum, fact, &maxfac))
break; break;
fact += 4; fact += 4;
} }
} }
} }
if ( lnum != 1 ) { if (lnum != 1) {
if (lnum > maxfac) if (lnum > maxfac)
maxfac = lnum; maxfac = lnum;
} }

@ -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: */
@ -13,20 +12,18 @@
/*realout: structure defining a realization - */ /*realout: structure defining a realization - */
/* lognormal numbers */ /* lognormal numbers */
void nor2log(struct realization_mod *realin, int typelog, struct realization_mod *realout) void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout)
{ {
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) {
(*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("No memory available"); printf("No memory available");
return; return;
@ -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) {
@ -65,7 +60,7 @@ void nor2log(struct realization_mod *realin, int typelog, struct realization_mod
break; break;
case 4: case 4:
/*log10*/ /*log10*/
(*realout).vector[i] = exp((*realin).vector[i]*coeff); (*realout).vector[i] = exp((*realin).vector[i] * coeff);
break; break;
default: default:
printf("Unexpected case in nor2log"); printf("Unexpected case in nor2log");

@ -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)
@ -9,6 +8,6 @@ double nugget(double h)
if (h == 0) { if (h == 0) {
return (1.); return (1.);
} else { } else {
return(0.); return (0.);
} }
} }

@ -1,10 +1,9 @@
#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)
{ {
return(pow(h,alpha)); return (pow(h, 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 */
@ -19,29 +19,25 @@
/* must be a Gaussian white noise */ /* must be a Gaussian white noise */
/*realization: structure defining a realization*/ /*realization: structure defining a realization*/
void prebuild_gwn(struct grid_mod grid,int n[3],struct realization_mod *realin,double *realization,int solver) void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver)
{ {
int i,j,k,maille0,maille1; int i, j, k, maille0, maille1;
int ntot; int ntot;
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++) {
maille1 = i+(j-1+(k-1)*n[1])*n[0]; maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0];
if (i <= grid.NX && j <= grid.NY && k <= grid.NZ) { if (i <= grid.NX && j <= grid.NY && k <= grid.NZ) {
maille0 = i-1+(j-1+(k-1)*grid.NY)*grid.NX; maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX;
realization[maille1] = (*realin).vector[maille0]; realization[maille1] = (*realin).vector[maille0];
} else { } else {
realization[maille1] = 0.; realization[maille1] = 0.;
@ -51,4 +47,4 @@ void prebuild_gwn(struct grid_mod grid,int n[3],struct realization_mod *realin,d
} }
} }
return; return;
} }

@ -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
@ -14,8 +14,7 @@
/* y: macroscopic gradient value in x direction */ /* y: macroscopic gradient value in x direction */
/* z: macroscopic gradient value in x direction */ /* z: macroscopic gradient value in x direction */
struct pressure_mod { struct pressure_mod {
double x,y,z; double x, y, z;
}; };
#endif // define _PRESSURE_H #endif // define _PRESSURE_H

@ -2,8 +2,8 @@
#define IM1 2147483563 #define IM1 2147483563
#define IM2 2147483399 #define IM2 2147483399
#define AM (1.0/IM1) #define AM (1.0 / IM1)
#define IMM1 (IM1-1) #define IMM1 (IM1 - 1)
#define IA1 40014 #define IA1 40014
#define IA2 40692 #define IA2 40692
#define IQ1 53668 #define IQ1 53668
@ -11,11 +11,11 @@
#define IR1 12211 #define IR1 12211
#define IR2 3791 #define IR2 3791
#define NTAB 32 #define NTAB 32
#define NDIV (1+IMM1/NTAB) #define NDIV (1 + IMM1 / NTAB)
#define EPS 1.2e-7 #define EPS 1.2e-7
#define RNMX (1.0-EPS) #define RNMX (1.0 - EPS)
double ran2(long *idum, long *idum2, long *iy, long iv[NTAB]) double ran2(long* idum, long* idum2, long* iy, long iv[NTAB])
{ {
int j; int j;
@ -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)
k = *idum2/IQ2; *idum += IM1;
*idum2 = IA2*(*idum2-k*IQ2)-k*IR2; k = *idum2 / IQ2;
if (*idum2 < 0) *idum2 += IM2; *idum2 = IA2 * (*idum2 - k * IQ2) - k * IR2;
j = (*iy)/NDIV; if (*idum2 < 0)
*iy = iv[j]-(*idum2); *idum2 += IM2;
j = (*iy) / NDIV;
*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);
} }

@ -25,7 +25,7 @@
void Randomize(void) void Randomize(void)
{ {
srand((int) time(NULL)); srand((int)time(NULL));
} }
/* /*
@ -44,8 +44,8 @@ int RandomInteger(int low, int high)
int k; int k;
double d; double d;
d = (double) rand() / ((double) RAND_MAX + 1); d = (double)rand() / ((double)RAND_MAX + 1);
k = (int) (d * (high - low + 1)); k = (int)(d * (high - low + 1));
return (low + k); return (low + k);
} }
@ -60,7 +60,7 @@ double RandomReal(double low, double high)
{ {
double d; double d;
d = (double) rand() / ((double) RAND_MAX + 1); d = (double)rand() / ((double)RAND_MAX + 1);
return (low + d * (high - low)); return (low + d * (high - low));
} }

@ -23,7 +23,7 @@
*/ */
#ifndef RAND_MAX #ifndef RAND_MAX
# define RAND_MAX ((int) ((unsigned) ~0 >> 1)) #define RAND_MAX ((int)((unsigned)~0 >> 1))
#endif #endif
/* /*

@ -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);
} }

@ -60,7 +60,7 @@
* internal representation are hidden from the client. * internal representation are hidden from the client.
*/ */
typedef struct scannerCDT *scannerADT; typedef struct scannerCDT* scannerADT;
/* /*
* Function: NewScanner * Function: NewScanner
@ -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:
@ -131,7 +131,7 @@ string GetLine(void)
* twice the size of the previous one is allocated. * twice the size of the previous one is allocated.
*/ */
string ReadLine(FILE *infile) string ReadLine(FILE* infile)
{ {
string line, nline; string line, nline;
int n, ch, size; int n, ch, size;
@ -142,7 +142,7 @@ string ReadLine(FILE *infile)
while ((ch = getc(infile)) != '\n' && ch != EOF) { while ((ch = getc(infile)) != '\n' && ch != EOF) {
if (n == size) { if (n == size) {
size *= 2; size *= 2;
nline = (string) GetBlock(size + 1); nline = (string)GetBlock(size + 1);
strncpy(nline, line, n); strncpy(nline, line, n);
FreeBlock(line); FreeBlock(line);
line = nline; line = nline;
@ -154,7 +154,7 @@ string ReadLine(FILE *infile)
return (NULL); return (NULL);
} }
line[n] = '\0'; line[n] = '\0';
nline = (string) GetBlock(n + 1); nline = (string)GetBlock(n + 1);
strcpy(nline, line); strcpy(nline, line);
FreeBlock(line); FreeBlock(line);
return (nline); return (nline);

@ -70,6 +70,6 @@ string GetLine(void);
* is at the end-of-file position. * is at the end-of-file position.
*/ */
string ReadLine(FILE *infile); string ReadLine(FILE* infile);
#endif #endif

@ -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)
@ -11,7 +10,7 @@ double spherical(double h)
if (h >= 1.) { if (h >= 1.) {
z = 0.; z = 0.;
} else { } else {
z = 1.-1.5*(double)h+0.5*(double)(h*h*h); z = 1. - 1.5 * (double)h + 0.5 * (double)(h * h * h);
} }
return (z); return (z);
} }

@ -1,10 +1,9 @@
#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)
{ {
return(exp(-3.*(double)pow(h,alpha))); return (exp(-3. * (double)pow(h, 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
@ -33,7 +33,7 @@
*/ */
struct stackCDT { struct stackCDT {
stackElementT *elements; stackElementT* elements;
int count; int count;
int size; int size;
}; };
@ -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]);
} }
@ -108,7 +110,7 @@ stackElementT GetStackElement(stackADT stack, int index)
static void ExpandStack(stackADT stack) static void ExpandStack(stackADT stack)
{ {
stackElementT *array; stackElementT* array;
int i, newSize; int i, newSize;
newSize = stack->size * 2; newSize = stack->size * 2;

@ -22,7 +22,7 @@
* be changed by editing this definition line. * be changed by editing this definition line.
*/ */
typedef void *stackElementT; typedef void* stackElementT;
/* /*
* Type: stackADT * Type: stackADT
@ -34,7 +34,7 @@ typedef void *stackElementT;
* the underlying fields. * the underlying fields.
*/ */
typedef struct stackCDT *stackADT; typedef struct stackCDT* stackADT;
/* /*
* Function: NewStack * Function: NewStack

@ -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);
@ -132,27 +139,36 @@ int StringCompare(string s1, string s2)
int FindChar(char ch, string text, int start) 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 ((int) (cptr - text)); return (-1);
return ((int)(cptr - text));
} }
int FindString(string str, string text, int start) 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 ((int) (cptr - text)); return (-1);
return ((int)(cptr - text));
} }
/* Section 4 -- Case-conversion functions */ /* Section 4 -- Case-conversion functions */
@ -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);
} }
@ -242,5 +261,5 @@ double StringToReal(string s)
static string CreateString(int len) static string CreateString(int len)
{ {
return ((string) GetBlock(len + 1)); return ((string)GetBlock(len + 1));
} }

@ -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
@ -25,8 +25,8 @@
typedef struct cellT { typedef struct cellT {
string key; string key;
void *value; void* value;
struct cellT *link; struct cellT* link;
} cellT; } cellT;
/* /*
@ -41,13 +41,13 @@ typedef struct cellT {
*/ */
struct symtabCDT { struct symtabCDT {
cellT *buckets[NBuckets]; cellT* buckets[NBuckets];
}; };
/* Private function declarations */ /* Private function declarations */
static void FreeBucketChain(cellT *cp); static void FreeBucketChain(cellT* cp);
static cellT *FindCell(cellT *cp, string s); static cellT* FindCell(cellT* cp, string s);
static int Hash(string s, int nBuckets); static int Hash(string s, int nBuckets);
/* Public entries */ /* Public entries */
@ -74,15 +74,15 @@ void FreeSymbolTable(symtabADT table)
FreeBlock(table); FreeBlock(table);
} }
void Enter(symtabADT table, string key, void *value) void Enter(symtabADT table, string key, void* value)
{ {
int bucket; int bucket;
cellT *cp; cellT* cp;
bucket = Hash(key, NBuckets); bucket = Hash(key, NBuckets);
cp = FindCell(table->buckets[bucket], key); cp = FindCell(table->buckets[bucket], key);
if (cp == NULL) { if (cp == NULL) {
cp = New(cellT *); cp = New(cellT*);
cp->key = CopyString(key); cp->key = CopyString(key);
cp->link = table->buckets[bucket]; cp->link = table->buckets[bucket];
table->buckets[bucket] = cp; table->buckets[bucket] = cp;
@ -90,22 +90,23 @@ void Enter(symtabADT table, string key, void *value)
cp->value = value; cp->value = value;
} }
void *Lookup(symtabADT table, string key) void* Lookup(symtabADT table, string key)
{ {
int bucket; int bucket;
cellT *cp; cellT* cp;
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);
} }
void MapSymbolTable(symtabFnT fn, symtabADT table, void MapSymbolTable(symtabFnT fn, symtabADT table,
void *clientData) void* clientData)
{ {
int i; int i;
cellT *cp; cellT* cp;
for (i = 0; i < NBuckets; i++) { for (i = 0; i < NBuckets; i++) {
for (cp = table->buckets[i]; cp != NULL; cp = cp->link) { for (cp = table->buckets[i]; cp != NULL; cp = cp->link) {
@ -125,9 +126,9 @@ void MapSymbolTable(symtabFnT fn, symtabADT table,
* this function must free the string storage as well. * this function must free the string storage as well.
*/ */
static void FreeBucketChain(cellT *cp) static void FreeBucketChain(cellT* cp)
{ {
cellT *next; cellT* next;
while (cp != NULL) { while (cp != NULL) {
next = cp->link; next = cp->link;
@ -146,7 +147,7 @@ static void FreeBucketChain(cellT *cp)
* returned. If no match is found, the function returns NULL. * returned. If no match is found, the function returns NULL.
*/ */
static cellT *FindCell(cellT *cp, string key) static cellT* FindCell(cellT* cp, string key)
{ {
while (cp != NULL && !StringEqual(cp->key, key)) { while (cp != NULL && !StringEqual(cp->key, key)) {
cp = cp->link; cp = cp->link;

@ -15,7 +15,7 @@
* This type is the ADT used to represent a symbol table. * This type is the ADT used to represent a symbol table.
*/ */
typedef struct symtabCDT *symtabADT; typedef struct symtabCDT* symtabADT;
/* /*
* Type: symtabFnT * Type: symtabFnT
@ -24,8 +24,8 @@ typedef struct symtabCDT *symtabADT;
* map over the entries in a symbol table. * map over the entries in a symbol table.
*/ */
typedef void (*symtabFnT)(string key, void *value, typedef void (*symtabFnT)(string key, void* value,
void *clientData); void* clientData);
/* Exported entries */ /* Exported entries */
@ -55,7 +55,7 @@ void FreeSymbolTable(symtabADT table);
* Each call to Enter supersedes any previous definition for key. * Each call to Enter supersedes any previous definition for key.
*/ */
void Enter(symtabADT table, string key, void *value); void Enter(symtabADT table, string key, void* value);
/* /*
* Function: Lookup * Function: Lookup
@ -65,7 +65,7 @@ void Enter(symtabADT table, string key, void *value);
* table, or UNDEFINED, if no such value exists. * table, or UNDEFINED, if no such value exists.
*/ */
void *Lookup(symtabADT table, string key); void* Lookup(symtabADT table, string key);
/* /*
* Function: MapSymbolTable * Function: MapSymbolTable
@ -80,6 +80,6 @@ void *Lookup(symtabADT table, string key);
*/ */
void MapSymbolTable(symtabFnT fn, symtabADT table, void MapSymbolTable(symtabFnT fn, symtabADT table,
void *clientData); void* clientData);
#endif #endif

@ -1,26 +1,24 @@
#include "genlib.h" #include "genlib.h"
/*tries factor*/ /*tries factor*/
int test_fact(int *pnum, int fact, int *pmaxfac) int test_fact(int* pnum, int fact, int* pmaxfac)
{ {
int power, t; int power, t;
power = 0; power = 0;
while ( ( t = *pnum / fact ) * fact == *pnum ) { while ((t = *pnum / fact) * fact == *pnum) {
++power; ++power;
*pnum = t; *pnum = t;
} }
if ( power != 0 ) { if (power != 0) {
if (fact > *pmaxfac) if (fact > *pmaxfac)
*pmaxfac = fact; *pmaxfac = fact;
} }
if ( t > fact ) { if (t > fact) {
return (1); return (1);
} }
return (0); return (0);
} }

@ -1,11 +1,11 @@
#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)
{ {
if (realint == NULL) { if (realint == NULL) {
printf("Testmemory.c: No memory available \n"); printf("Testmemory.c: No memory available \n");

Loading…
Cancel
Save