void clamav_stats_flush(struct cl_engine *engine, void *cbdata) { cli_intel_t *intel; cli_flagged_sample_t *sample, *next; int err; if (!(cbdata) || !(engine)) return; intel = (cli_intel_t *)cbdata; #ifdef CL_THREAD_SAFE err = pthread_mutex_lock(&(intel->mutex)); if (err) { cli_warnmsg("clamav_stats_flush: locking mutex failed (err: %d): %s\n", err, strerror(err)); return; } #endif for (sample=intel->samples; sample != NULL; sample = next) { next = sample->next; free_sample(sample); } intel->samples = NULL; intel->nsamples = 0; if (intel->hostid) { free(intel->hostid); intel->hostid = NULL; } #ifdef CL_THREAD_SAFE err = pthread_mutex_unlock(&(intel->mutex)); if (err) cli_warnmsg("clamav_stats_flush: unlocking mutex failed (err: %d): %s\n", err, strerror(err)); #endif }
void clamav_stats_remove_sample(const char *virname, const unsigned char *md5, size_t size, void *cbdata) { cli_intel_t *intel; cli_flagged_sample_t *sample; int err; intel = (cli_intel_t *)cbdata; if (!(intel)) return; #ifdef CL_THREAD_SAFE err = pthread_mutex_lock(&(intel->mutex)); if (err) { cli_warnmsg("clamav_stats_remove_sample: locking mutex failed (err: %d): %s\n", err, strerror(err)); return; } #endif while ((sample = find_sample(intel, virname, md5, size, NULL))) { if (sample->prev) sample->prev->next = sample->next; if (sample->next) sample->next->prev = sample->prev; if (sample == intel->samples) intel->samples = sample->next; free_sample(sample); intel->nsamples--; } #ifdef CL_THREAD_SAFE err = pthread_mutex_unlock(&(intel->mutex)); if (err) { cli_warnmsg("clamav_stats_remove_sample: unlocking mutex failed (err: %d): %s\n", err, strerror(err)); } #endif }
void clamav_stats_submit(struct cl_engine *engine, void *cbdata) { char *json; cli_intel_t *intel, myintel; cli_flagged_sample_t *sample, *next; int err; intel = (cli_intel_t *)cbdata; if (!(intel) || !(engine)) return; if (engine->dconf->stats & DCONF_STATS_DISABLED) return; if (!(engine->cb_stats_get_hostid)) { /* Submitting stats is disabled due to HostID being turned off */ if ((engine->cb_stats_flush)) engine->cb_stats_flush(engine, cbdata); return; } cli_dbgmsg("stats - start\n"); #ifdef CL_THREAD_SAFE err = pthread_mutex_lock(&(intel->mutex)); if (err) { cli_warnmsg("clamav_stats_submit: locking mutex failed (err: %d): %s\n", err, strerror(err)); if ((intel->engine) && (intel->engine->cb_stats_flush)) intel->engine->cb_stats_flush(intel->engine, cbdata); return; } #endif /* Empty out the cached intelligence data so that other threads don't sit waiting to add data to the cache */ memcpy(&myintel, intel, sizeof(cli_intel_t)); intel->samples = NULL; intel->nsamples = 0; json = export_stats_to_json(engine, &myintel); #ifdef CL_THREAD_SAFE err = pthread_mutex_unlock(&(intel->mutex)); if (err) { cli_warnmsg("clamav_stats_submit: unlocking mutex failed (err: %d): %s\n", err, strerror(err)); } #endif for (sample=myintel.samples; sample != NULL; sample = next) { #if DEBUG_STATS print_sample(sample); #endif next = sample->next; free_sample(sample); } if (json) { submit_post(STATS_HOST, STATS_PORT, "PUT", "/clamav/1/submit/stats", json, myintel.timeout); free(json); } if (myintel.hostid && !(intel->hostid)) { free(myintel.hostid); myintel.hostid = NULL; } cli_dbgmsg("stats - end\n"); }
/* Function to be called from R */ void R_epidemics(int *seqLength, double *mutRate, int *npop, int *nHostPerPop, double *beta, int *nStart, int *t1, int *t2, int *Nsample, int *Tsample, int *duration, int *nbnb, int *listnb, double *pdisp){ int i, nstep, counter_sample = 0, tabidx; /* Initialize random number generator */ int j; time_t t; t = time(NULL); // time in seconds, used to change the seed of the random generator gsl_rng * rng; const gsl_rng_type *typ; gsl_rng_env_setup(); typ=gsl_rng_default; rng=gsl_rng_alloc(typ); gsl_rng_set(rng,t); // changes the seed of the random generator /* transfer simulation parameters */ struct param * par; par = (struct param *) malloc(sizeof(struct param)); par->L = *seqLength; par->mu = *mutRate; par->muL = par->mu * par->L; par->rng = rng; par->npop = *npop; par->popsizes = nHostPerPop; par->beta = *beta; par->nstart = *nStart; par->t1 = *t1; par->t2 = *t2; par->t_sample = Tsample; par->n_sample = *Nsample; par->duration = *duration; par->cn_nb_nb = nbnb; par->cn_list_nb = listnb; par->cn_weights = pdisp; /* check/print parameters */ check_param(par); print_param(par); /* dispersal matrix */ struct network *cn = create_network(par); /* print_network(cn, TRUE); */ /* group sizes */ struct ts_groupsizes * grpsizes = create_ts_groupsizes(par); /* initiate population */ struct metapopulation * metapop; metapop = create_metapopulation(par); /* get sampling schemes (timestep+effectives) */ translate_dates(par); struct table_int *tabdates = get_table_int(par->t_sample, par->n_sample); printf("\n\nsampling at timesteps:"); print_table_int(tabdates); /* create sample */ struct sample ** samplist = (struct sample **) malloc(tabdates->n * sizeof(struct sample *)); struct sample *samp; /* MAKE METAPOPULATION EVOLVE */ nstep = 0; while(get_total_nsus(metapop)>0 && (get_total_ninf(metapop)+get_total_nexp(metapop))>0 && nstep<par->duration){ nstep++; /* age metapopulation */ age_metapopulation(metapop, par); /* process infections */ for(j=0;j<get_npop(metapop);j++){ process_infections(get_populations(metapop)[j], metapop, cn, par); } /* draw samples */ if((tabidx = int_in_vec(nstep, tabdates->items, tabdates->n)) > -1){ /* TRUE if step must be sampled */ samplist[counter_sample++] = draw_sample(metapop, tabdates->times[tabidx], par); } fill_ts_groupsizes(grpsizes, metapop, nstep); } /* we stopped after 'nstep' steps */ if(nstep < par->duration){ printf("\nEpidemics ended at time %d, before last sampling time (%d).\n", nstep, par->duration); } else { /* printf("\n\n-- FINAL METAPOPULATION --"); */ /* print_metapopulation(metapop, FALSE); */ /* merge samples */ samp = merge_samples(samplist, tabdates->n, par); /* write sample to file */ printf("\n\nWriting sample to file 'out-sample.txt'\n"); write_sample(samp); /* free memory */ free_sample(samp); } /* write group sizes to file */ printf("\n\nPrinting group sizes to file 'out-popsize.txt'\n"); write_ts_groupsizes(grpsizes); /* free memory */ free_metapopulation(metapop); free_param(par); for(i=0;i<counter_sample;i++) free_sample(samplist[i]); free(samplist); free_table_int(tabdates); free_network(cn); free_ts_groupsizes(grpsizes); }
/* all-in-one function testing epidemics growth, summary statistics, etc. */ void test_epidemics(int seqLength, double mutRate, int npop, int *nHostPerPop, double beta, int nStart, int t1, int t2, int Nsample, int *Tsample, int duration, int *nbnb, int *listnb, double *pdisp){ int i, j, nstep=0, tabidx, counter_sample = 0; /* Initialize random number generator */ time_t t; t = time(NULL); // time in seconds, used to change the seed of the random generator gsl_rng * rng; const gsl_rng_type *typ; gsl_rng_env_setup(); typ=gsl_rng_default; rng=gsl_rng_alloc(typ); gsl_rng_set(rng,t); // changes the seed of the random generator /* transfer simulation parameters */ struct param * par; par = (struct param *) malloc(sizeof(struct param)); par->L = seqLength; par->mu = mutRate; par->muL = par->mu * par->L; par->rng = rng; par->npop = npop; par->npop = npop; par->popsizes = nHostPerPop; par->beta = beta; par->nstart = nStart; par->t1 = t1; par->t2 = t2; par->t_sample = Tsample; par->n_sample = Nsample; par->duration = duration; par->cn_nb_nb = nbnb; par->cn_list_nb = listnb; par->cn_weights = pdisp; /* check/print parameters */ check_param(par); print_param(par); /* dispersal matrix */ struct network *cn = create_network(par); /* group sizes */ struct ts_groupsizes * grpsizes = create_ts_groupsizes(par); /* initiate population */ struct metapopulation * metapop; metapop = create_metapopulation(par); /* get sampling schemes (timestep+effectives) */ translate_dates(par); struct table_int *tabdates = get_table_int(par->t_sample, par->n_sample); printf("\n\nsampling at timesteps:"); print_table_int(tabdates); /* create sample */ struct sample ** samplist = (struct sample **) malloc(tabdates->n * sizeof(struct sample *)); struct sample *samp; /* MAKE METAPOPULATION EVOLVE */ nstep = 0; while(get_total_nsus(metapop)>0 && (get_total_ninf(metapop)+get_total_nexp(metapop))>0 && nstep<par->duration){ nstep++; /* age metapopulation */ age_metapopulation(metapop, par); /* process infections */ for(j=0;j<get_npop(metapop);j++){ process_infections(get_populations(metapop)[j], metapop, cn, par); } /* draw samples */ if((tabidx = int_in_vec(nstep, tabdates->items, tabdates->n)) > -1){ /* TRUE if step must be sampled */ samplist[counter_sample++] = draw_sample(metapop, tabdates->times[tabidx], par); } fill_ts_groupsizes(grpsizes, metapop, nstep); } /* we stopped after 'nstep' steps */ if(nstep < par->duration){ printf("\nEpidemics ended at time %d, before last sampling time (%d).\n", nstep, par->duration); } else { printf("\n\n-- FINAL METAPOPULATION --"); print_metapopulation(metapop, TRUE); /* test samples */ for(i=0;i<tabdates->n;i++) { printf("\nsample %d\n", i); print_sample(samplist[i], TRUE); } samp = merge_samples(samplist, tabdates->n, par) ; print_sample(samp, TRUE); /* test allele listing */ struct snplist *snpbilan; snpbilan = list_snps(samp, par); print_snplist(snpbilan); /* test allele frequencies */ struct allfreq *freq; freq = get_frequencies(samp, par); print_allfreq(freq); /* test Hs*/ double Hs = hs(samp,par); printf("\nHs = %0.3f\n", Hs); /* test Hs full genome */ Hs = hs_full_genome(samp,par); printf("\nHs (full genome) = %0.5f\n", Hs); /* test nb of snps */ int nball = nb_snps(samp,par); printf("\nnumber of SNPs = %d\n", nball); /* test mean nb of snps */ double temp = mean_nb_snps(samp); printf("\nmean number of SNPs = %.2f\n", temp); /* test var nb of snps */ temp = var_nb_snps(samp); printf("\nvariance of number of alleles = %.2f\n", temp); /* test pairwise distances */ struct distmat_int *mat = pairwise_dist(samp, par); print_distmat_int(mat); /* test mean pairwise distances */ temp = mean_pairwise_dist(samp,par); printf("\nmean pairwise distance: %.2f", temp); /* test variance of pairwise distances */ temp = var_pairwise_dist(samp,par); printf("\nvar pairwise distance: %.2f", temp); /* test Fst */ temp = fst(samp,par); printf("\nfst: %.2f", temp); printf("\n\n"); /* free memory */ free_sample(samp); free_snplist(snpbilan); free_allfreq(freq); free_distmat_int(mat); } /* write group sizes to file */ printf("\n\nPrinting group sizes to file 'out-popsize.txt'"); write_ts_groupsizes(grpsizes); /* free memory */ free_metapopulation(metapop); free_param(par); for(i=0;i<counter_sample;i++) free_sample(samplist[i]); free(samplist); free_table_int(tabdates); free_network(cn); free_ts_groupsizes(grpsizes); }
/* Function to be called from R */ void R_monitor_epidemics(int *seqLength, double *mutRate, int *npop, int *nHostPerPop, double *beta, int *nStart, int *t1, int *t2, int *Nsample, int *Tsample, int *duration, int *nbnb, int *listnb, double *pdisp, int *minSize){ int nstep; /* Initialize random number generator */ int j; time_t t; t = time(NULL); // time in seconds, used to change the seed of the random generator gsl_rng * rng; const gsl_rng_type *typ; gsl_rng_env_setup(); typ=gsl_rng_default; rng=gsl_rng_alloc(typ); gsl_rng_set(rng,t); // changes the seed of the random generator /* transfer simulation parameters */ struct param * par; par = (struct param *) malloc(sizeof(struct param)); par->L = *seqLength; par->mu = *mutRate; par->muL = par->mu * par->L; par->rng = rng; par->npop = *npop; par->popsizes = nHostPerPop; par->beta = *beta; par->nstart = *nStart; par->t1 = *t1; par->t2 = *t2; par->t_sample = Tsample; par->n_sample = *Nsample; par->duration = *duration; par->cn_nb_nb = nbnb; par->cn_list_nb = listnb; par->cn_weights = pdisp; /* check/print parameters */ check_param(par); print_param(par); /* dispersal matrix */ struct network *cn = create_network(par); /* print_network(cn, TRUE); */ /* group sizes */ struct ts_groupsizes * grpsizes = create_ts_groupsizes(par); struct ts_sumstat * sumstats = create_ts_sumstat(par); /* initiate population */ struct metapopulation * metapop; metapop = create_metapopulation(par); /* get sampling schemes (timestep+effectives) */ translate_dates(par); struct table_int *tabdates = get_table_int(par->t_sample, par->n_sample); printf("\n\nsampling at timesteps:"); print_table_int(tabdates); /* create sample */ struct sample *samp; /* MAKE METAPOPULATION EVOLVE */ nstep = 0; while(get_total_nsus(metapop)>0 && (get_total_ninf(metapop)+get_total_nexp(metapop))>0 && nstep<par->duration){ nstep++; /* age metapopulation */ age_metapopulation(metapop, par); /* process infections */ for(j=0;j<get_npop(metapop);j++){ process_infections(get_populations(metapop)[j], metapop, cn, par); } /* draw sample */ samp = draw_sample(metapop, par->n_sample, par); /* compute statistics */ if(get_total_ninf(metapop)> *minSize) fill_ts_sumstat(sumstats, samp, nstep, par); /* get group sizes */ fill_ts_groupsizes(grpsizes, metapop, nstep); } /* write group sizes to file */ printf("\n\nWriting results to file..."); write_ts_groupsizes(grpsizes); write_ts_sumstat(sumstats); printf("done.\n\n"); /* free memory */ free_sample(samp); free_metapopulation(metapop); free_param(par); free_network(cn); free_ts_groupsizes(grpsizes); free_ts_sumstat(sumstats); }
void do_calculations_rast (Shypothesis **samples, char **groups, int norm, char* basename, char **outvals, char *hypspec, int quiet_flag, char *logfile, xmlDocPtr doc, Sfp_struct* file_pointers) { long y,x; int i, j, k, l, m; long ymax,xmax; double woc; struct Categories cats, icats; DCELL cmin, cmax; Sresult_struct *result_row; /* one result_struct for each DST value */ BOOL **garbage; int no_hyps; char* val_names[NUMVALS]={"bel","pl","doubt","common","bint","woc","maxbpa","minbpa", "maxsrc","minsrc"}; int error; char **outhyps; int no_sets; /* for keeping min and max statistics */ Uint nsets; double *min_backup, *max_backup; int *minev_backup, *maxev_backup; woc = 0; /* check for output options */ if ( G_legal_filename(basename) != 1 ) { G_fatal_error ("Please provide a legal filename as basename for output maps(s).\n"); } if ( hypspec != NULL ) { /* user specified hyps, let's see if they're valid */ /* create an outhyps array that has as each of its elements the name of one of the hypotheses specified on the command line */ outhyps = parse_hyps (hypspec, &no_hyps); check_hyps ( outhyps, no_hyps, doc ); } else { /* just process all hypotheses */ outhyps = get_hyp_names_XML ( &no_hyps, doc ); } if ( logfile != NULL ) { fprintf (lp,"Writing output RASTER maps for: \n"); } /* create raster rows to store results */ result_row = G_malloc ( NUMVALS * sizeof (Sresult_struct) ); for (i=0; i<NUMVALS; i++) { result_row[i].use = NO; strcpy (result_row[i].valname,val_names[i]); /* individual raster rows will be alloc'd later */ result_row[i].row = (DCELL **) G_malloc ( no_hyps * sizeof (DCELL*) ); result_row[i].crow = (CELL **) G_malloc ( no_hyps * sizeof (CELL*) ); result_row[i].filename = NULL; } j = 0; while ( outvals[j] != NULL ) { if ( !strcmp (outvals[j],"bel") ) { if ( logfile != NULL ) fprintf (lp,"\t'bel' (Believe) values\n"); make_result_row ( BEL, basename, outhyps, no_hyps, &result_row[BEL], doc ); } if ( !strcmp (outvals[j],"pl") ) { if ( logfile != NULL ) fprintf (lp,"\t'pl' (Plausibility) values\n"); make_result_row ( PL, basename, outhyps, no_hyps, &result_row[PL], doc ); } if ( !strcmp (outvals[j],"doubt") ) { if ( logfile != NULL ) fprintf (lp,"\t'doubt' (Doubt) values\n"); make_result_row ( DOUBT, basename, outhyps, no_hyps, &result_row[DOUBT], doc ); } if ( !strcmp (outvals[j],"common") ) { if ( logfile != NULL ) fprintf (lp,"\t'common' (Commonality) values\n"); make_result_row ( COMMON, basename, outhyps, no_hyps, &result_row[COMMON], doc ); } if ( !strcmp (outvals[j],"bint") ) { if ( logfile != NULL ) fprintf (lp,"\t'bint' (Believe interval) values\n"); make_result_row ( BINT, basename, outhyps, no_hyps, &result_row[BINT], doc ); } if ( !strcmp (outvals[j],"woc") ) { if ( logfile != NULL ) fprintf (lp,"\t'woc' (Weight of conflict) values\n"); make_result_row ( WOC, basename, outhyps, no_hyps,&result_row[WOC], doc ); } if ( !strcmp (outvals[j],"maxbpa") ) { if ( logfile != NULL ) fprintf (lp,"\t'maxbpa' (Maximum BPA) values\n"); make_result_row ( MAXBPA, basename, outhyps, no_hyps,&result_row[MAXBPA], doc ); } if ( !strcmp (outvals[j],"minbpa") ) { if ( logfile != NULL ) fprintf (lp,"\t'minbpa' (Minimum BPA) values\n"); make_result_row ( MINBPA, basename, outhyps, no_hyps,&result_row[MINBPA], doc ); } if ( !strcmp (outvals[j],"maxsrc") ) { if ( logfile != NULL ) fprintf (lp,"\t'maxsrc' (source of highest BPA) values\n"); make_result_row ( MAXSRC, basename, outhyps, no_hyps,&result_row[MAXSRC], doc ); } if ( !strcmp (outvals[j],"minsrc") ) { if ( logfile != NULL ) fprintf (lp,"\t'minsrc' (source of lowest BPA) values\n"); make_result_row ( MINSRC, basename, outhyps, no_hyps,&result_row[MINSRC], doc ); } j ++; } /* open output maps to store results */ if ( logfile != NULL ) fprintf (lp,"Opening output maps:\n"); for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC ) { if ( logfile != NULL ) fprintf (lp,"\t%s\n",result_row[i].filename[0]); result_row[i].fd[0] = G_open_raster_new (result_row[i].filename[0],DCELL_TYPE); } else { for (j=0; j < no_hyps; j++) { if ( logfile != NULL ) fprintf (lp,"\t%s\n",result_row[i].filename[j]); if ((i == MAXSRC) || (i == MINSRC)) { result_row[i].fd[j] = G_open_raster_new (result_row[i].filename[j],CELL_TYPE); } else { result_row[i].fd[j] = G_open_raster_new (result_row[i].filename[j],DCELL_TYPE); } /* check fd for errors */ if ( result_row[i].fd[j] < 0 ) { G_fatal_error ("Could not create output map for %s\n", result_row[i].filename[j]); } } } } } if ( logfile != NULL ) { fprintf (lp, "Evidence will be combined for these groups:\n"); for ( i=0; i < N; i++) { fprintf (lp,"\t%s\n",groups[i]); } fprintf (lp, "Output will be stored in mapset '%s'.\n", G_mapset()); fprintf (lp,"\nRead output below carefully to detect potential problems:\n"); } /* set start coordinates for reading from raster maps */ ReadX = 0; ReadY = 0; ymax = G_window_rows (); xmax = G_window_cols (); if ( !quiet_flag ) { fprintf (stdout,"Combining RAST evidence: \n"); fflush (stdout); } /* allocate all file pointers */ /* open raster maps for this group */ /* 0 is the NULL hypothesis, so we start at 1 */ no_sets = (Uint) pow((float) 2, (float) NO_SINGLETONS); for (l=0; l<N; l++) { for ( m = 1; m < no_sets; m ++ ) { file_pointers[l].fp[m] = G_open_cell_old ( file_pointers[l].filename[m], G_find_cell ( file_pointers[l].filename[m],"") ); if ( file_pointers[l].fp[m] < 0 ) { G_fatal_error ("Could not open raster map '%s' for reading.\n", file_pointers[l].filename[m] ); } } } for (y=0; y<ymax; y++) { for (x=0; x<xmax; x++) { garbage = garbage_init (); NULL_SIGNAL = 0; for (i=0; i<N; i++) { samples[i] = get_rast_samples_XML (groups[i],i, norm, &nsets, garbage, doc, file_pointers ); } /* get min and max values */ for (i=0; i<N; i++) { if (NULL_SIGNAL == 0) { for (k=0; k < nsets; k++) { samples[i][k].minbpn = samples[i][k].bpa; samples[i][k].maxbpn = samples[i][k].bpa; samples[i][k].minbpnev = i + 1; samples[i][k].maxbpnev = i + 1; } } } for (i=0; i<N; i++) { if (NULL_SIGNAL == 0) { for (j=0; j < N; j++) { for (k=0; k < nsets; k++) { if (samples[i][k].bpa < samples[j][k].minbpn) { samples[j][k].minbpn = samples[i][k].bpa; samples[j][k].minbpnev = i + 1; } if (samples[i][k].bpa > samples[j][k].maxbpn) { samples[j][k].maxbpn = samples[i][k].bpa; samples[j][k].maxbpnev = i + 1; } } } } } /* initialise: */ /* set belief and plausibility before first combination of evidence */ for(i=0;i<N;i++) { if ( NULL_SIGNAL == 0 ) { set_beliefs(samples[i]); set_plausibilities(samples[i]); } } /* combine evidence and set bel and pl again */ /* AFTER COMBINE_BPN(), VALUES IN SAMPLES[0] WILL ALL BE ALTERED */ /* so we must save min and max values for later use */ min_backup = G_malloc ((unsigned)(nsets * sizeof(double))); max_backup = G_malloc ((unsigned)(nsets * sizeof(double))); minev_backup = G_malloc ((unsigned)(nsets * sizeof(int))); maxev_backup = G_malloc ((unsigned)(nsets * sizeof(int))); for (k=0; k < nsets; k++) { min_backup[k] = samples[0][k].minbpn; max_backup[k] = samples[0][k].maxbpn; minev_backup[k] = samples[0][k].minbpnev; maxev_backup[k] = samples[0][k].maxbpnev; } /* now, do the combination! */ for(i=0;i<N-1;i++) { if ( NULL_SIGNAL == 0 ) { woc = combine_bpn(samples[0], samples[i+1], garbage, RAST_MODE ); set_beliefs(samples[0]); set_plausibilities(samples[0]); } } /* restore min and max values */ for (k=0; k < nsets; k++) { samples[0][k].minbpn = min_backup[k]; samples[0][k].maxbpn = max_backup[k]; samples[0][k].minbpnev = minev_backup[k]; samples[0][k].maxbpnev = maxev_backup[k]; } G_free (min_backup); G_free (max_backup); G_free (minev_backup); G_free (maxev_backup); /* all other metrics can be derived from bel and pl, no need */ /* to combine evidence again! */ if ( NULL_SIGNAL == 0 ) { set_commonalities(samples[0]); set_doubts(samples[0]); set_bint(samples[0]); } if ( NULL_SIGNAL == 1 ) { for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC) { write_row_null (result_row[i].row[0], ReadX); } else { if ((i == MAXSRC)||(i == MINSRC)) { for (j=0; j < no_hyps; j++) { write_crow_null (result_row[i].crow[j], ReadX); } } else { for (j=0; j < no_hyps; j++) { write_row_null (result_row[i].row[j], ReadX); } } } } } } else { for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC ) { write_row_val (result_row[i].row[0], ReadX, samples[0], result_row[i].hyp_idx[0], i, woc); } else { if (( i == MAXSRC ) || ( i == MINSRC )) { for (j=0; j < no_hyps; j++) { write_crow_val (result_row[i].crow[j], ReadX, samples[0], result_row[i].hyp_idx[j], i); } } else { for (j=0; j < no_hyps; j++) { write_row_val (result_row[i].row[j], ReadX, samples[0], result_row[i].hyp_idx[j], i, woc); } } } } } } ReadX ++; garbage_free ( garbage ); for (i=0; i<N; i++) { free_sample (samples[i]); } } ReadY ++; /* go to next row */ ReadX = 0; /* save this row to the result file */ for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC ) { write_row_file ( result_row[i].row[0],result_row[i].fd[0]); } else { if ( ( i == MAXSRC ) || ( i == MINSRC ) ) { for (j=0; j<no_hyps; j++) { write_crow_file ( result_row[i].crow[j],result_row[i].fd[j]); } } else { for (j=0; j<no_hyps; j++) { write_row_file ( result_row[i].row[j],result_row[i].fd[j]); } } } } } if ( !quiet_flag ) { G_percent (ReadY,ymax,1); fflush (stdout); } } if ( !quiet_flag ) { fprintf (stdout,"\n"); fflush (stdout); } for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC ) { G_close_cell (result_row[i].fd[0]); } else { for (j=0; j<no_hyps; j++) { G_close_cell (result_row[i].fd[j]); } } } } /* close raster maps */ /* 0 is the NULL hypothesis, so we start at 1 */ for (l=0; l<N; l++) { for ( m = 1; m < no_sets; m ++ ) { G_close_cell (file_pointers[l].fp[m]); } } /* create a categories structure for output maps */ /* DCELL maps */ G_init_cats (3, "Value ranges", &cats); cmin = 0; cmax = 0.333333; G_set_d_raster_cat (&cmin, &cmax, "low", &cats); cmin = 0.333334; cmax = 0.666666; G_set_d_raster_cat (&cmin, &cmax, "medium", &cats); cmin = 0.666667; cmax = 1; G_set_d_raster_cat (&cmin, &cmax, "high", &cats); /* CELL maps */ G_init_cats (N+1, "Source of evidence", &icats); G_set_cat (0,"no data",&icats); for (i=1; i<=N; i++) { G_set_cat (i,groups[i-1],&icats); } /* write all color tables, categories information and history metadata */ for (i=0; i<NUMVALS;i++) { if (result_row[i].use == YES) { if ( i == WOC ) { error = G_write_colors (result_row[i].filename[0], G_mapset(), result_row[i].colors[0]); if (error == -1) { G_warning ("Could not create color table for map '%s'.\n",result_row[i].filename[j]); } } else { if (( i == MAXSRC ) || ( i == MINSRC )) { for (j=0; j<no_hyps; j++) { G_write_cats (result_row[i].filename[j], &icats); } } else { for (j=0; j<no_hyps; j++) { error = G_write_colors (result_row[i].filename[j], G_mapset(), result_row[i].colors[j]); if (error == -1) { G_warning ("Could not create color table for map '%s'.\n",result_row[i].filename[j]); } G_write_raster_cats (result_row[i].filename[j], &cats); } } } } } G_free (samples); for ( i=0; i < no_hyps; i ++ ) { G_free ( outhyps[i]); } G_free (outhyps); }