21 #include <grass/segment.h>
41 int main(
int argc,
char **argv)
50 fprintf(stdout,
"creating seg.file\n");
51 fd = creat(
"seg.file", 0666);
59 fprintf(stdout,
"opening seg.file\n");
60 fd = open(
"seg.file", 2);
67 fprintf(stdout,
"rows %d, cols %d (len %d)\n", seg.nrows, seg.ncols,
69 if (seg.nrows !=
NROWS || seg.ncols !=
NCOLS || seg.len !=
LEN) {
70 fprintf(stdout,
"OOPS - wrong segment file\n");
74 fprintf(stdout,
"writing seg.file\n");
75 for (row = 0; row <
NROWS; row++) {
76 for (col = 0; col <
NCOLS; col++) {
78 data[col * 2 + 1] = col;
84 for (i = 0; i < seg.nseg; i++)
85 if (seg.scb[i].n >= 0) {
86 fprintf(stdout,
"segment %d age %d",
87 seg.scb[i].n, seg.scb[i].age);
89 fprintf(stdout,
" current");
90 fprintf(stdout,
"\n");
92 fprintf(stdout,
"\nenter row col: ");
93 if (!fgets(data, 20, stdin))
95 if (sscanf(data,
"%1s", junk) != 1)
97 if (sscanf(data,
"%d%d", &row, &col) != 2)
98 fprintf(stdout,
"??\n");
99 else if (row < 0 || row >= NROWS || col < 0 || col >=
NCOLS)
100 fprintf(stdout,
"bad row/col value(s)\n");
103 fprintf(stdout,
"data = %d %d\n", data[0], data[1]);
int segment_init(SEGMENT *SEG, int fd, int nseg)
Initialize segment structure.
int main(int argc, char *argv[])
int segment_put_row(const SEGMENT *SEG, const void *buf, int row)
int segment_release(SEGMENT *SEG)
Free memory allocated to segment.
int segment_get(SEGMENT *SEG, void *buf, int row, int col)
Get value from segment file.