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

Generated on Sat Jul 22 22:06:15 2006 for GRASS by  doxygen 1.4.7