~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libqt/mat_in.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
 
 
3
/*!
 
4
  \file mat_in.c
 
5
  \ingroup (QT)
 
6
*/
 
7
 
 
8
/*!
 
9
** MAT_IN(): Function to read in a matrix.  Simple version for now.
 
10
**
 
11
** Parameters:
 
12
**    \param fp         =  file pointer to input stream
 
13
**    \param array      =  matrix to hold data
 
14
**    \param width      =  number of columns to read
 
15
**    \param max_length =  maximum number of rows to read
 
16
**    \param stat       =  pointer to int to hold status flag 
 
17
**                         (0=read ok, 1=error)
 
18
**
 
19
** Returns: 
 
20
**    number of rows read
 
21
**    Also modifies stat to = error code (0 = ok, 1 = error)
 
22
** \ingroup (QT)
 
23
*/
 
24
 
 
25
int mat_in(FILE *fp, double **array, int width, int max_length, int *stat) 
 
26
{
 
27
   int i=0, j, errcod=0 ;
 
28
   int nr ;
 
29
   double data ;
 
30
 
 
31
   while ( (i < max_length) && (!errcod) ) {
 
32
      for (j=0; j<width; j++) {
 
33
         nr = fscanf(fp, "%lf", &data) ;
 
34
         if (feof(fp)) break ;
 
35
         if (nr != 1) {
 
36
            errcod = 1 ;
 
37
            break ;
 
38
            }
 
39
         else {
 
40
            array[i][j] = data ;
 
41
            }
 
42
         }
 
43
      if (feof(fp)) break ;
 
44
      if (!errcod) i++ ;
 
45
      }
 
46
 
 
47
   *stat = errcod ;
 
48
   return(i) ;
 
49
}
 
50