1 #include <stdlib.h>
2 #include <grass/gis.h>
3 #include <grass/raster.h>
4 #include <grass/glocale.h>
5 #include "local_proto.h"
6 
7 
rdwr_gridatb(void)8 void rdwr_gridatb(void)
9 {
10     char buf[1024];
11     FILE *fp;
12     int fd, i, j, retval;
13     float idx;
14 
15     fp = fopen(file, "r");
16 
17     buf[0] = 0;
18     fscanf(fp, "%[^\n]", buf);
19     if (!buf[0])
20 	getc(fp);
21 
22     fscanf(fp, "%d %d %lf\n", &cellhd.cols, &cellhd.rows, &cellhd.ns_res);
23     cellhd.ew_res = cellhd.ns_res;
24     cellhd.south = 0;
25     cellhd.north = cellhd.south + cellhd.ns_res * cellhd.rows;
26     cellhd.west = 0;
27     cellhd.east = cellhd.west + cellhd.ew_res * cellhd.cols;
28     cellhd.format = -1;
29     cellhd.compressed = 1;
30 
31     if (retval = adjcellhd(&cellhd)) {
32 	fclose(fp);
33 	switch (retval) {
34 	case 1:
35 	    G_fatal_error(_("Setting window header failed"));
36 	    break;
37 	case 2:
38 	    G_fatal_error(_("Rows changed"));
39 	    break;
40 	case 3:
41 	    G_fatal_error(_("Cols changed"));
42 	    break;
43 	}
44     }
45 
46     fd = Rast_open_new(oname, FCELL_TYPE);
47 
48     cell = (FCELL *) G_malloc(sizeof(FCELL) * cellhd.cols);
49 
50     for (i = 0; i < cellhd.rows; i++) {
51 	G_percent(i, cellhd.rows, 2);
52 
53 	for (j = 0; j < cellhd.cols; j++) {
54 	    idx = 9999.0;
55 	    fscanf(fp, "%f", &idx);
56 	    if (idx >= 9999.0) {
57 		Rast_set_f_null_value(&(cell[j]), 1);
58 	    }
59 	    else {
60 		cell[j] = idx;
61 	    }
62 	}
63 	Rast_put_f_row(fd, cell);
64     }
65     G_percent(i, cellhd.rows, 2);
66     if(fp)
67 	fclose(fp);
68     Rast_close(fd);
69 
70     Rast_put_cell_title(oname, buf);
71     Rast_put_cellhd(oname, &cellhd);
72 
73     return;
74 }
75