init_map.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*--------------------------------------------------------------------------*/
  2. /* inititializes the random file with descriptor "fd" with "nofRows" rows
  3. of zero values columns. each row consists of "nofCols" columns.
  4. assumes that the file is rewound and empty.
  5. returns 1 if successful and 0 for any kind of error. */
  6. #include "G.h"
  7. /*--------------------------------------------------------------------------*/
  8. int G__random_d_initialize_0(int fd, int nofRows, int nofCols)
  9. {
  10. struct fileinfo *fcb = &G__.fileinfo[fd];
  11. int row, col;
  12. double zeroVal, *zeroValP;
  13. register XDR *xdrs;
  14. xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */
  15. xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */
  16. zeroVal = 0;
  17. zeroValP = &zeroVal;
  18. for (col = nofCols; col--;)
  19. if (!xdr_double(xdrs, zeroValP)) {
  20. G_warning
  21. ("G_random_d_initialize_0: xdr_double failed for index %d.\n",
  22. col);
  23. return -1;
  24. }
  25. for (row = 0; row < nofRows; row++)
  26. if (G__write_data(fd, row, nofCols) == -1) {
  27. G_warning("G_random_d_initialize_0: write failed in row %d.\n",
  28. row);
  29. return -1;
  30. }
  31. return 1;
  32. }
  33. /*--------------------------------------------------------------------------*/
  34. /* inititializes the random file with descriptor "fd" with "nofRows" rows
  35. of zero values columns. each row consists of "nofCols" columns.
  36. assumes that the file is rewound and empty.
  37. returns 1 if successful and 0 for any kind of error. */
  38. int G__random_f_initialize_0(int fd, int nofRows, int nofCols)
  39. {
  40. struct fileinfo *fcb = &G__.fileinfo[fd];
  41. int row, col;
  42. float zeroVal, *zeroValP;
  43. register XDR *xdrs;
  44. xdrs = &fcb->xdrstream; /* xdr stream is initialized to write into */
  45. xdr_setpos(xdrs, 0); /* G__.work_buf in 'opencell.c' */
  46. zeroVal = 0;
  47. zeroValP = &zeroVal;
  48. for (col = nofCols; col--;)
  49. if (!xdr_float(xdrs, zeroValP)) {
  50. G_warning
  51. ("G_random_f_initialize_0: xdr_float failed for index %d.\n",
  52. col);
  53. return 0;
  54. }
  55. for (row = 0; row < nofRows; row++)
  56. if (G__write_data(fd, row, nofCols) == -1) {
  57. G_warning("G_random_f_initialize_0: write failed in row %d.\n",
  58. row);
  59. return 0;
  60. }
  61. return 1;
  62. }
  63. /*--------------------------------------------------------------------------*/