gsl_block__fprintf_source.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* block/fprintf_source.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #if !(USES_LONGDOUBLE && !HAVE_PRINTF_LONGDOUBLE)
  20. int
  21. FUNCTION (gsl_block, fprintf) (FILE * stream, const TYPE(gsl_block) * b, const char *format)
  22. {
  23. size_t n = b->size ;
  24. ATOMIC * data = b->data ;
  25. size_t i;
  26. for (i = 0; i < n; i++)
  27. {
  28. int k;
  29. int status;
  30. for (k = 0; k < MULTIPLICITY; k++)
  31. {
  32. if (k > 0)
  33. {
  34. status = putc (' ', stream);
  35. if (status == EOF)
  36. {
  37. GSL_ERROR ("putc failed", GSL_EFAILED);
  38. }
  39. }
  40. status = fprintf (stream,
  41. format,
  42. data[MULTIPLICITY * i + k]);
  43. if (status < 0)
  44. {
  45. GSL_ERROR ("fprintf failed", GSL_EFAILED);
  46. }
  47. }
  48. status = putc ('\n', stream);
  49. if (status == EOF)
  50. {
  51. GSL_ERROR ("putc failed", GSL_EFAILED);
  52. }
  53. }
  54. return 0;
  55. }
  56. int
  57. FUNCTION (gsl_block, fscanf) (FILE * stream, TYPE(gsl_block) * b)
  58. {
  59. size_t n = b->size ;
  60. ATOMIC * data = b->data ;
  61. size_t i;
  62. for (i = 0; i < n; i++)
  63. {
  64. int k;
  65. for (k = 0; k < MULTIPLICITY; k++)
  66. {
  67. ATOMIC_IO tmp ;
  68. int status = fscanf (stream, IN_FORMAT, &tmp) ;
  69. data [MULTIPLICITY * i + k] = tmp;
  70. if (status != 1)
  71. {
  72. GSL_ERROR ("fscanf failed", GSL_EFAILED);
  73. }
  74. }
  75. }
  76. return GSL_SUCCESS;
  77. }
  78. int
  79. FUNCTION (gsl_block, raw_fprintf) (FILE * stream,
  80. const ATOMIC * data,
  81. const size_t n,
  82. const size_t stride,
  83. const char *format)
  84. {
  85. size_t i;
  86. for (i = 0; i < n; i++)
  87. {
  88. int k;
  89. int status;
  90. for (k = 0; k < MULTIPLICITY; k++)
  91. {
  92. if (k > 0)
  93. {
  94. status = putc (' ', stream);
  95. if (status == EOF)
  96. {
  97. GSL_ERROR ("putc failed", GSL_EFAILED);
  98. }
  99. }
  100. status = fprintf (stream,
  101. format,
  102. data[MULTIPLICITY * i * stride + k]);
  103. if (status < 0)
  104. {
  105. GSL_ERROR ("fprintf failed", GSL_EFAILED);
  106. }
  107. }
  108. status = putc ('\n', stream);
  109. if (status == EOF)
  110. {
  111. GSL_ERROR ("putc failed", GSL_EFAILED);
  112. }
  113. }
  114. return 0;
  115. }
  116. int
  117. FUNCTION (gsl_block, raw_fscanf) (FILE * stream,
  118. ATOMIC * data,
  119. const size_t n,
  120. const size_t stride)
  121. {
  122. size_t i;
  123. for (i = 0; i < n; i++)
  124. {
  125. int k;
  126. for (k = 0; k < MULTIPLICITY; k++)
  127. {
  128. ATOMIC_IO tmp;
  129. int status = fscanf (stream, IN_FORMAT, &tmp) ;
  130. data [MULTIPLICITY * i * stride + k] = tmp;
  131. if (status != 1)
  132. GSL_ERROR ("fscanf failed", GSL_EFAILED);
  133. }
  134. }
  135. return GSL_SUCCESS;
  136. }
  137. #endif