Intel® Fortran Compiler 18.0 Developer Guide and Reference

FOR_DESCRIPTOR_ASSIGN (W*S)

Run-Time Subroutine: Creates an array descriptor in memory.

Module

USE IFCORE

CALL FOR_DESCRIPTOR_ASSIGN (dp,base,size,reserved,rank,dims_info)

dp

(Input) A Fortran pointer to an array; the array can be of any data type.

base

(Input) INTEGER(4) or INTEGER(8). The base address of the data being described by dp.

Note that a Fortran pointer describes both the location and type of the data item.

size

(Input) INTEGER(4). The size of the data type; for example, 4 for INTEGER(4).

reserved

(Input) INTEGER(4). A logical bitwise OR combination of the following constants, which are defined in IFCORE.F90:

  • FOR_DESCRIPTOR_ARRAY_DEFINED - Specifies whether the array pointed to has been allocated or associated. If the bit is set, the array has been allocated or associated.

  • FOR_DESCRIPTOR_ARRAY_NODEALLOC - Specifies whether the array points to something that can be deallocated by a call to DEALLOCATE, or whether it points to something that cannot be deallocated. For example:

      integer, pointer :: p(:)
      integer, target :: t
      p => t   ! t cannot be deallocated
      allocate(p(10)) ! t can be deallocated

    If the bit is set, the array cannot be deallocated.

  • FOR_DESCRIPTOR_ARRAY_CONTIGUOUS - Specifies whether the array pointed to is completely contiguous in memory or whether it is a slice that is not contiguous. If the bit is set, the array is contiguous.

rank

(Input) INTEGER(4). The rank of the array pointed to.

dims_info

(Input) An array of derived type FOR_DIMS_INFO; you must specify a rank for this array. The derived type FOR_DIMS_INFO is defined in IFCORE.F90 as follows:

TYPE FOR_DIMS_INFO
  INTEGER(4) LOWERBOUND  !Lower bound for the dimension
  INTEGER(4) UPPERBOUND  !Upper bound for the dimension
  INTEGER(4) STRIDE      !Stride for the dimension
END TYPE FOR_DIMS_INFO 

The FOR_DESCRIPTOR_ASSIGN routine is similar to a Fortran pointer assignment, but gives you more control over the assignment, allowing, for example, assignment to any location in memory.

You can also use this routine to create an array that can be used from both Fortran or C.

Example


use IFCORE
common/c_array/ array
real(8) array(5,5)
external  init_array
external  c_print_array
real(8),pointer :: p_array(:,:)
type(FOR_DIMS_INFO) dims_info(2)
 call init_array()

 do i=1,5
   do j=1,5
      print *,i,j, array(i,j)
   end do
 end do

 dims_info(1)%LOWERBOUND = 11
 dims_info(1)%UPPERBOUND = 15
 dims_info(1)%STRIDE = 1

 dims_info(2)%LOWERBOUND = -5
 dims_info(2)%UPPERBOUND = -1
 dims_info(2)%STRIDE = 1

 call FOR_DESCRIPTOR_ASSIGN(p_array, &
   LOC(array), &
   SIZEOF(array(1,1)), &
   FOR_DESCRIPTOR_ARRAY_DEFINED .or. &
   FOR_DESCRIPTOR_ARRAY_NODEALLOC .or. &
   FOR_DESCRIPTOR_ARRAY_CONTIGUOUS,  &
   2, &
   dims_info )
                
p_array = p_array + 1
call c_print_array()
end

The following shows the C program containing init_array and c_print_array:


#include <stdio.h>
#if !defined(_WIN32) && !defined(_WIN64)
#define C_ARRAY c_array_
#define INIT_ARRAY init_array_
#define C_PRINT_ARRAY c_print_array_
#endif
double C_ARRAY[5][5];
void INIT_ARRAY(void);
void C_PRINT_ARRAY(void);
void INIT_ARRAY(void)
{
  int i,j;
  for(i=0;i<5;i++)
     for(j=0;j<5;j++)
       C_ARRAY[i][j] = j + 10*i; 
}
void C_PRINT_ARRAY(void)
{
   int i,j;
   for(i=0;i<5;i++){
     for(j=0;j<5;j++)
         printf("%f ", C_ARRAY[i][j]);
     printf("\n");
   }
}

See Also