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

« back to all changes in this revision

Viewing changes to src/bin/cctriples/init_3d_array.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
#include <stdlib.h>
 
3
 
 
4
double ***init_3d_array(int p, int q, int r)
 
5
{
 
6
  double ***A;
 
7
  int i,j,k;
 
8
 
 
9
  A = (double ***) malloc(p * sizeof(double **));
 
10
  for(i=0; i < p; i++) {
 
11
    A[i] = (double **) malloc(q * sizeof(double *));
 
12
    for(j=0; j < q; j++) {
 
13
      A[i][j] = (double *) malloc(r * sizeof(double));
 
14
      for(k=0; k < r; k++) {
 
15
        A[i][j][k] = 0.0;
 
16
      }
 
17
    }
 
18
  }
 
19
 
 
20
  return A;
 
21
}
 
22
 
 
23
void free_3d_array(double ***A, int p, int q)
 
24
{
 
25
  int i,j;
 
26
 
 
27
  for(i=0; i < p; i++)
 
28
    for(j=0; j < q; j++)
 
29
      free(A[i][j]);
 
30
 
 
31
  for(i=0; i < p; i++) free(A[i]);
 
32
 
 
33
  free(A);
 
34
}