home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / matrix / file_source.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  4.4 KB  |  158 lines

  1. /* matrix/file_source.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. int
  21. FUNCTION (gsl_matrix, fread) (FILE * stream, TYPE (gsl_matrix) * m)
  22. {
  23.   int status = 0;
  24.  
  25.   const size_t size1 = m->size1; 
  26.   const size_t size2 = m->size2;
  27.  
  28.   const size_t tda = m->tda;
  29.  
  30.   if (tda == size2) /* the rows are contiguous */
  31.     {
  32.       status = FUNCTION (gsl_block, raw_fread) (stream, 
  33.                                                 m->data, 
  34.                                                 size1 * size2, 1);
  35.     }
  36.   else
  37.     {
  38.       size_t i;
  39.  
  40.       for (i = 0 ; i < size1 ; i++)  /* read each row separately */
  41.         {
  42.           status = FUNCTION (gsl_block, raw_fread) (stream, 
  43.                                                     m->data + i * tda, 
  44.                                                     size2, 1);
  45.           if (status)
  46.             break;
  47.         }
  48.     }
  49.  
  50.   return status;
  51. }
  52.  
  53. int
  54. FUNCTION (gsl_matrix, fwrite) (FILE * stream, const TYPE (gsl_matrix) * m)
  55. {
  56.   int status = 0;
  57.  
  58.   const size_t size1 = m->size1; 
  59.   const size_t size2 = m->size2;
  60.  
  61.   const size_t tda = m->tda;
  62.  
  63.   if (tda == size2) /* the rows are contiguous */
  64.     {
  65.       status = FUNCTION (gsl_block, raw_fwrite) (stream, 
  66.                                                  m->data, 
  67.                                                  size1 * size2, 1);
  68.     }
  69.   else
  70.     {
  71.       size_t i;
  72.  
  73.       for (i = 0 ; i < size1 ; i++)  /* write each row separately */
  74.         {
  75.           status = FUNCTION (gsl_block, raw_fwrite) (stream, 
  76.                                                      m->data + i * tda, 
  77.                                                      size2, 1);
  78.           if (status)
  79.             break;
  80.         }
  81.     }
  82.  
  83.   return status;
  84.  
  85. }
  86.  
  87. #if !(defined(USES_LONGDOUBLE) && !defined(HAVE_PRINTF_LONGDOUBLE))
  88. int
  89. FUNCTION (gsl_matrix, fprintf) (FILE * stream, const TYPE (gsl_matrix) * m,
  90.                 const char *format)
  91. {
  92.   int status = 0;
  93.  
  94.   const size_t size1 = m->size1; 
  95.   const size_t size2 = m->size2;
  96.  
  97.   const size_t tda = m->tda;
  98.  
  99.   if (tda == size2) /* the rows are contiguous */
  100.     {
  101.       status = FUNCTION (gsl_block, raw_fprintf) (stream, 
  102.                                                   m->data, 
  103.                                                   size1 * size2, 1,
  104.                                                   format);
  105.     }
  106.   else
  107.     {
  108.       size_t i;
  109.  
  110.       for (i = 0 ; i < size1 ; i++)  /* print each row separately */
  111.         {
  112.           status = FUNCTION (gsl_block, raw_fprintf) (stream, 
  113.                                                       m->data + i * tda, 
  114.                                                       size2, 1,
  115.                                                       format);
  116.           if (status)
  117.             break;
  118.         }
  119.     }
  120.  
  121.   return status;
  122. }
  123.  
  124. int
  125. FUNCTION (gsl_matrix, fscanf) (FILE * stream, TYPE (gsl_matrix) * m)
  126. {
  127.   int status = 0;
  128.  
  129.   const size_t size1 = m->size1; 
  130.   const size_t size2 = m->size2;
  131.  
  132.   const size_t tda = m->tda;
  133.  
  134.   if (tda == size2)  /* the rows are contiguous */
  135.     {
  136.       status = FUNCTION (gsl_block, raw_fscanf) (stream, 
  137.                                                  m->data, 
  138.                                                  size1 * size2, 1);
  139.     }
  140.   else
  141.     {
  142.       size_t i;
  143.  
  144.       for (i = 0 ; i < size1 ; i++)  /* scan each row separately */
  145.         {
  146.           status = FUNCTION (gsl_block, raw_fscanf) (stream, 
  147.                                                      m->data + i * tda, 
  148.                                                      size2, 1);
  149.           if (status)
  150.             break;
  151.         }
  152.     }
  153.  
  154.   return status;
  155. }
  156. #endif
  157.  
  158.