GRASS Programmer's Manual
6.4.1(2011)
|
00001 00002 /*--------------------------------------------------------------------------*/ 00003 00004 /* inititializes the random file with descriptor "fd" with "nofRows" rows 00005 of zero values columns. each row consists of "nofCols" columns. 00006 assumes that the file is rewound and empty. 00007 00008 returns 1 if successful and 0 for any kind of error. */ 00009 00010 #include "G.h" 00011 00012 /*--------------------------------------------------------------------------*/ 00013 00014 int G__random_d_initialize_0(int fd, int nofRows, int nofCols) 00015 { 00016 struct fileinfo *fcb = &G__.fileinfo[fd]; 00017 int row, col; 00018 double zeroVal, *zeroValP; 00019 register XDR *xdrs; 00020 00021 xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */ 00022 xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */ 00023 00024 zeroVal = 0; 00025 zeroValP = &zeroVal; 00026 00027 for (col = nofCols; col--;) 00028 if (!xdr_double(xdrs, zeroValP)) { 00029 G_warning 00030 ("G_random_d_initialize_0: xdr_double failed for index %d.\n", 00031 col); 00032 return -1; 00033 } 00034 00035 for (row = 0; row < nofRows; row++) 00036 if (G__write_data(fd, row, nofCols) == -1) { 00037 G_warning("G_random_d_initialize_0: write failed in row %d.\n", 00038 row); 00039 return -1; 00040 } 00041 00042 return 1; 00043 } 00044 00045 /*--------------------------------------------------------------------------*/ 00046 00047 /* inititializes the random file with descriptor "fd" with "nofRows" rows 00048 of zero values columns. each row consists of "nofCols" columns. 00049 assumes that the file is rewound and empty. 00050 00051 returns 1 if successful and 0 for any kind of error. */ 00052 00053 00054 int G__random_f_initialize_0(int fd, int nofRows, int nofCols) 00055 { 00056 struct fileinfo *fcb = &G__.fileinfo[fd]; 00057 int row, col; 00058 float zeroVal, *zeroValP; 00059 register XDR *xdrs; 00060 00061 00062 xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */ 00063 xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */ 00064 00065 zeroVal = 0; 00066 zeroValP = &zeroVal; 00067 00068 for (col = nofCols; col--;) 00069 if (!xdr_float(xdrs, zeroValP)) { 00070 G_warning 00071 ("G_random_f_initialize_0: xdr_float failed for index %d.\n", 00072 col); 00073 return 0; 00074 } 00075 00076 for (row = 0; row < nofRows; row++) 00077 if (G__write_data(fd, row, nofCols) == -1) { 00078 G_warning("G_random_f_initialize_0: write failed in row %d.\n", 00079 row); 00080 return 0; 00081 } 00082 00083 return 1; 00084 } 00085 00086 /*--------------------------------------------------------------------------*/