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/nor2log.c

80 lines
2.2 KiB
C

#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
/*TURNS NORMAL NUMBERS INTO LOGNORMAL NUMBERS */
/*input: */
/*realin: structure defining a realization - */
/* normal numbers */
/*typelog: --> 3: lognormal (natural) */
/* --> 4: lognormal (log10) */
/*output: */
/*realout: structure defining a realization - */
/* lognormal numbers */
void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout) {
clock_t t = clock();
log_info("RESULT = in progress");
int i;
double coeff;
coeff = log(10.0);
/*Is the output realization allocated ?*/
/*is its length equal to realin.n?*/
if ((*realout).vector == NULL || (*realout).n != (*realin).n) {
(*realout).vector = (double*)malloc((*realin).n * sizeof(double));
if ((*realout).vector == NULL) {
printf("No memory available");
return;
}
}
(*realout).n = (*realin).n;
switch ((*realin).code) {
case 0:
case 1:
case 2:
(*realout).code = typelog;
break;
case 6:
case 7:
if (typelog == 3) {
(*realout).code = 8;
} else if (typelog == 4) {
(*realout).code = 9;
}
break;
default:
printf("Input is not normal in nor2log");
return;
break;
}
/*anamorphose*/
for (i = 0; i < (*realin).n; i++) {
switch (typelog) {
case 3:
/*natural logarithm*/
(*realout).vector[i] = exp((*realin).vector[i]);
break;
case 4:
/*log10*/
(*realout).vector[i] = exp((*realin).vector[i] * coeff);
break;
default:
log_error("RESULT = failed - Unexpected case in nor2log");
return;
break;
}
}
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
log_info("RESULT = success, ELAPSED = %f seconds", time_taken);
}