#include "geostat.h" #include "log.h" #include #include #include #include #include #include #include void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout) { double* used_ram_t0 = malloc(sizeof(double)); getVirtualMemUsed(used_ram_t0); clock_t t = clock(); int i, j, k, maille0, maille1; double NTOT; NTOT = n[0] * n[1] * n[2]; /*is the output realization already allocated?*/ /*if not, memory allocation*/ log_info("RESULT = in progress, NTOT = %f", NTOT); if (realout->vector == NULL || realout->n != realin->n) { realout->vector = (double*)malloc(realin->n * sizeof(double)); if (realout->vector == NULL) { log_error("RESULT = failed - No memory available"); exit; } } realout->n = realin->n; realout->code = 1; for (k = 1; k <= grid.NZ; k++) { for (j = 1; j <= grid.NY; j++) { for (i = 1; i <= grid.NX; i++) { maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0]; maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX; /* Modif du 18 juin 2003 */ /*realout->vector[maille0] = vectorresult[maille1]/(double) NTOT;*/ realout->vector[maille0] = vectorresult[maille1]; } } } 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); }