init_map.c

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

Generated on Wed Dec 19 14:59:06 2007 for GRASS by  doxygen 1.5.4