C_Allocate.c 1.19 KB
Newer Older
1
2
3
4
5
6
7

#include <stdlib.h>
#include <stdio.h>
#include "ISO_Fortran_binding.h"

void C_Allocate ( CFI_cdesc_t *A_DV, CFI_cdesc_t *ShapeDV, int *Status )
  {
8
  int iD;
9
  int *nValues;
10
11
12
13
14
  size_t len;
  
  CFI_index_t *lbounds, *ubounds;
  
  printf("=== Entering C_Allocate === \n");
Budiardja, Reuben's avatar
Budiardja, Reuben committed
15
  printf("A_DV.rank: %d\nShapeDV->dim[0].extent: %d\n", 
16
          A_DV->rank, (int) ShapeDV->dim[0].extent);
17
  // Error checking
18
  if ( A_DV->rank != ShapeDV->dim[0].extent )
19
    {
20
21
22
    printf("ERROR: Rank and Shape is not consistent\n");
    *Status = -1;
    return;
23
24
25
26
27
28
29
30
31
32
33
    }
  
  lbounds = (CFI_index_t *) malloc ( sizeof ( CFI_index_t ) * A_DV->rank );
  ubounds = (CFI_index_t *) malloc ( sizeof ( CFI_index_t ) * A_DV->rank );
  
  nValues = ( int * ) ShapeDV->base_addr;
  for ( iD = 0; iD < A_DV->rank; iD++ ) 
    {
    printf( "iD: %d - len: %d\n", iD, nValues [ iD ] );
    lbounds [ iD ] = 1;
    ubounds [ iD ] = nValues [ iD ];
34
    }
35
36
37
38
   
  printf( "Base addr before allocation: %p\n", A_DV->base_addr );
  CFI_allocate ( A_DV, lbounds, ubounds, len );
  printf( "Base addr after allocation: %p\n", A_DV->base_addr );
39
  
40
41
42
43
44
  if ( A_DV->base_addr )
    *Status = 0;
  else
    *Status = -1;
  printf("=== Exiting C_Allocate === \n");
45
  }