GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
init_map.c
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------*/
3 
4 /* inititializes the random file with descriptor "fd" with "nofRows" rows
5  of zero values columns. each row consists of "nofCols" columns.
6  assumes that the file is rewound and empty.
7 
8  returns 1 if successful and 0 for any kind of error. */
9 
10 #include "G.h"
11 
12 /*--------------------------------------------------------------------------*/
13 
14 int G__random_d_initialize_0(int fd, int nofRows, int nofCols)
15 {
16  struct fileinfo *fcb = &G__.fileinfo[fd];
17  int row, col;
18  double zeroVal, *zeroValP;
19  register XDR *xdrs;
20 
21  xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */
22  xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */
23 
24  zeroVal = 0;
25  zeroValP = &zeroVal;
26 
27  for (col = nofCols; col--;)
28  if (!xdr_double(xdrs, zeroValP)) {
29  G_warning
30  ("G_random_d_initialize_0: xdr_double failed for index %d.\n",
31  col);
32  return -1;
33  }
34 
35  for (row = 0; row < nofRows; row++)
36  if (G__write_data(fd, row, nofCols) == -1) {
37  G_warning("G_random_d_initialize_0: write failed in row %d.\n",
38  row);
39  return -1;
40  }
41 
42  return 1;
43 }
44 
45 /*--------------------------------------------------------------------------*/
46 
47 /* inititializes the random file with descriptor "fd" with "nofRows" rows
48  of zero values columns. each row consists of "nofCols" columns.
49  assumes that the file is rewound and empty.
50 
51  returns 1 if successful and 0 for any kind of error. */
52 
53 
54 int G__random_f_initialize_0(int fd, int nofRows, int nofCols)
55 {
56  struct fileinfo *fcb = &G__.fileinfo[fd];
57  int row, col;
58  float zeroVal, *zeroValP;
59  register XDR *xdrs;
60 
61 
62  xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */
63  xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */
64 
65  zeroVal = 0;
66  zeroValP = &zeroVal;
67 
68  for (col = nofCols; col--;)
69  if (!xdr_float(xdrs, zeroValP)) {
70  G_warning
71  ("G_random_f_initialize_0: xdr_float failed for index %d.\n",
72  col);
73  return 0;
74  }
75 
76  for (row = 0; row < nofRows; row++)
77  if (G__write_data(fd, row, nofCols) == -1) {
78  G_warning("G_random_f_initialize_0: write failed in row %d.\n",
79  row);
80  return 0;
81  }
82 
83  return 1;
84 }
85 
86 /*--------------------------------------------------------------------------*/
FILE * fd
Definition: g3dcolor.c:368
int G__random_f_initialize_0(int fd, int nofRows, int nofCols)
Definition: init_map.c:54
Definition: G.h:74
int G__write_data(int fd, int row, int n)
Definition: gis/put_row.c:319
int G__random_d_initialize_0(int fd, int nofRows, int nofCols)
Definition: init_map.c:14
struct fileinfo * fileinfo
Definition: G.h:95
XDR xdrstream
Definition: G.h:66
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
Definition: G.h:41