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

79 lines
1.7 KiB
C

#include <stdlib.h>
#include <math.h>
#include "geostat.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)
{
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:
printf("Unexpected case in nor2log");
return;
break;
}
}
return;
}