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.
89 lines
2.4 KiB
C
89 lines
2.4 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) {
|
|
double* used_ram_t0 = malloc(sizeof(double));
|
|
getVirtualMemUsed(used_ram_t0);
|
|
|
|
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:
|
|
log_error("RESULT = failed - Unexpected case 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;
|
|
}
|
|
}
|
|
|
|
t = clock() - t;
|
|
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
|
|
|
|
double* used_ram_tf = malloc(sizeof(double));
|
|
getVirtualMemUsed(used_ram_tf);
|
|
|
|
log_info("RESULT = success, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", time_taken, *used_ram_tf - *used_ram_t0);
|
|
|
|
free(used_ram_t0);
|
|
free(used_ram_tf);
|
|
}
|