/* output.c (simlib), 20.nov.2002, JH */ #include #include #include #include #include #include #include #include int output_data(int tt, double ft) { FCELL *cell6, *cell7, *cell8; FCELL *cell14, *cell15, *cell16; int fd6, fd7, fd8; int fd14, fd15,fd16; int i,iarc,j; float gsmax=0,dismax=0.,gmax=0.,ermax=-1.e+12,ermin=1.e+12; double zx, zy, zd, sinsl; struct Colors colors; struct History hist, hist1; /* hist2, hist3, hist4, hist5*/ char *depth0=NULL,*disch0=NULL,*err0=NULL; char *conc0=NULL,*flux0=NULL; char *erdep0=NULL,*outwalk0=NULL; char *mapst = NULL; char *type; char buf[256]; int ndigit; FCELL dat1, dat2; float a1,a2; Site_head walkershead; Site *sd; ndigit=2; if(timesec >= 10) ndigit=3; if(timesec >= 100) ndigit=4; if(timesec >= 1000) ndigit=5; if(timesec >= 10000) ndigit=6; if (outwalk != NULL) { if (ts == 1) { sprintf(buf,"%s%.*d",outwalk,ndigit,tt); outwalk0 = G_store(buf); fdoutwalk = G_fopen_sites_new (outwalk0); } else fdoutwalk = G_fopen_sites_new (outwalk); if (fdoutwalk == NULL) G_fatal_error ("Cannot open %s", outwalk); else { if(NULL == (sd = G_site_new_struct(-1,2,0,1))) G_fatal_error("memory allocation failed for site"); if (ts == 1) walkershead.name = outwalk0; else walkershead.name = outwalk; walkershead.desc = G_strdup ("output walkers"); walkershead.desc = (char *) G_malloc (128 * sizeof (char)); sprintf (walkershead.desc, "output walkers of %s [raster]", depth); walkershead.time = NULL; walkershead.stime = NULL; walkershead.labels = NULL; walkershead.form = NULL; G_site_put_head (fdoutwalk, &walkershead); for (i = 0; i < nstack; i++) { sd->east = (float)stack[i][1]; sd->north = (float)stack[i][2]; sd->fcat = (float)stack[i][3]; G_site_put(fdoutwalk, sd); } } } if (depth != NULL) { cell6 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",depth,ndigit,tt); depth0 = G_store(buf); fd6 = G_open_fp_cell_new (depth0); } else fd6 = G_open_fp_cell_new (depth); if (fd6 < 0) G_fatal_error ("unable to create raster map %s", depth); } if (disch != NULL) { cell7 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",disch,ndigit,tt); disch0 = G_store(buf); fd7 = G_open_fp_cell_new (disch0); } else fd7 = G_open_fp_cell_new (disch); if (fd7 < 0) G_fatal_error("unable to create raster map %s", disch); } if (err != NULL) { cell8 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",err,ndigit,tt); err0 = G_store(buf); fd8 = G_open_fp_cell_new (err0); } else fd8 = G_open_fp_cell_new (err); if (fd8 < 0) G_fatal_error ("unable to create raster map %s", err); } if (conc != NULL) { cell14 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",conc,ndigit,tt); conc0 = G_store(buf); fd14 = G_open_fp_cell_new (conc0); } else fd14 = G_open_fp_cell_new (conc); if (fd14 < 0) G_fatal_error ("unable to create raster map %s", conc); } if (flux != NULL) { cell15 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",flux,ndigit,tt); flux0 = G_store(buf); fd15 = G_open_fp_cell_new (flux0); } else fd15 = G_open_fp_cell_new (flux); if (fd15 < 0) G_fatal_error ("unable to create raster map %s", flux); } if (erdep != NULL) { cell16 = G_allocate_f_raster_buf(); if (ts == 1) { sprintf(buf,"%s.%.*d",erdep,ndigit,tt); erdep0 = G_store(buf); fd16 = G_open_fp_cell_new (erdep0); } else fd16 = G_open_fp_cell_new (erdep); if (fd16 < 0) G_fatal_error ("unable to create raster map %s", erdep); } if(G_set_window (&cellhd) < 0) exit(3); if (my != G_window_rows()) G_fatal_error ("OOPS: rows changed from %d to %d\n", mx, G_window_rows()); if (mx != G_window_cols()) G_fatal_error ("OOPS: cols changed from %d to %d\n", my, G_window_cols()); for(iarc=0;iarc