#include "geostat.h" #include #include #include /*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: return; break; } } }