You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simulacion-permeabilidad/fftma_module/gen/lib_src/gasdev.c

47 lines
1.4 KiB
C

#include "genlib.h"
#include "log.h"
#include <math.h>
#include <time.h>
#define NTAB 32
double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB]) {
/*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran2(idum) as the source */
/*of uniform deviates */
clock_t t = clock();
log_info("RESULT = in progress, idum = %f, idum2 = %f, iy = %f", *idum, *idum2, *iy);
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]);
static int iset = 0;
static double gset;
double fac, rsq, v1, v2;
if (iset == 0) {
do {
v1 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
v2 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
rsq = v1 * v1 + v2 * v2;
} while (rsq >= 1.0 || rsq == 0.0);
fac = sqrt(-2.0 * log(rsq) / rsq);
gset = v1 * fac;
iset = 1;
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
log_info("RESULT = success, gset = %f, fac = %f, v1 = %f, ELAPSED = %f seconds", gset, fac, v1, time_taken);
return (v2 * fac);
} else {
iset = 0;
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
log_info("RESULT = success, gset = %f, ELAPSED = %f seconds", gset, time_taken);
return gset;
}
}