~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/lib/libciomr/init_matrix.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
** \file
 
3
** \brief Initialize a matrix of doubles
 
4
** \ingroup CIOMR
 
5
*/ 
 
6
 
 
7
#include <psifiles.h>
 
8
#include <cstdio>
 
9
#include <cstdlib>
 
10
#include <strings.h>
 
11
#include <cstring>
 
12
 
 
13
extern "C" {
 
14
 
 
15
/*!
 
16
** init_matrix(): Initialize an nxm matrix of doubles and return a pointer to
 
17
** the first row.  Note that this does not form a matrix which is 
 
18
** necessarily contiguous in memory.  Use block_matrix() for that.
 
19
** 
 
20
** \param n = number of rows (unsigned long to allow large matrices)
 
21
** \param m = number of columns (unsigned long to allow large matrices)
 
22
**
 
23
** Returns: pointer to first row
 
24
**
 
25
** \ingroup CIOMR
 
26
*/
 
27
double ** init_matrix(unsigned long int n, unsigned long int m)
 
28
{
 
29
  double **array=NULL;
 
30
  unsigned long int i;
 
31
 
 
32
  if ((array = (double **) malloc(n*(unsigned long int)sizeof(double *)))
 
33
    ==NULL) {
 
34
    fprintf(stderr,"init_matrix: trouble allocating memory \n");
 
35
    fprintf(stderr,"n = %ld\n",n);
 
36
    exit(PSI_RETURN_FAILURE);
 
37
  }
 
38
 
 
39
  for (i = 0; i < n; i++) {
 
40
    if ((array[i] = (double *) malloc(m*(unsigned long int)sizeof(double)))
 
41
      ==NULL) {
 
42
      fprintf(stderr,"init_matrix: trouble allocating memory \n");
 
43
      fprintf(stderr,"i = %ld m = %ld\n",i,m);
 
44
      exit(PSI_RETURN_FAILURE);
 
45
    }
 
46
    //bzero(array[i],m*(unsigned long int)sizeof(double));
 
47
    memset(array[i],'\0',m*(unsigned long int)sizeof(double));
 
48
  }
 
49
  return(array);
 
50
}
 
51
 
 
52
 
 
53
/*!
 
54
** free_matrix(): Free a 2D matrix allocated with init_matrix().
 
55
**
 
56
** \param array = matrix to free
 
57
** \param size = number of rows (unsigned long to allow large matrices)
 
58
**
 
59
** Returns: none
 
60
**
 
61
** \ingroup CIOMR
 
62
*/
 
63
void free_matrix(double **array, unsigned long int size)
 
64
{
 
65
  unsigned long int i;
 
66
 
 
67
  for (i=0; i < size ; i++) {
 
68
    free(array[i]);
 
69
  }
 
70
 
 
71
  free(array);
 
72
}
 
73
 
 
74
} /* extern "C" */