Fortran: Pointer to array section with vector subscripts

In summary, the conversation discusses the process of making a pointer point to specific columns of a rank-2 array, creating a "filtered" table. The method being attempted involves using a target array and a pointer to point to the desired columns and rows. However, it has been noted that this procedure is not allowed according to a constraint in the F2008 standard. The person is seeking alternative methods for achieving the same result. The use of a scalar triplet on the second index is not viable due to selecting multiple columns without a regular stride.
  • #1
seneika
4
0
Hi. I'm trying to make a pointer point to sections of a rank-2 array given by specific values of
it's second index. I other words: given a table I wan't a pointer to point to specific columns, making of it a "filtered" table.

The method I was trying was like

Code:
DOUBLE PRECISION, DIMENSION(M,N), TARGET :: arrA  
DOUBLE PRECISION, DIMENSION(:,:), POINTER :: ptr1  
  ...
ptr1 => arrA(1:k,(/col1,col3/))

to point to columns col1 and col3, rows 1 to k.

However, I've been told in the Intel forum that this procedure would consist in targeting an array
subsection with a vector subscript, which is forbiden in the standard by the constraint C724 of
F2008.

Is there any other way of doing this?

I'm not using a scalar triplet on the second index because, in practice, I'll select more columns without a regular stride, so a rule like col1:colN:stride doesn't seem to be of use.

Thanks.
 
Technology news on Phys.org
  • #2
I would like to resurrect this thread, I am interested in the answer. :-)
 

1. What is a pointer to array section in Fortran?

A pointer to array section in Fortran is a variable that holds the address of a specific section of an array. It allows for efficient manipulation and access of data within the array without the need to constantly pass the entire array as a parameter.

2. How do you declare a pointer to array section in Fortran?

To declare a pointer to array section in Fortran, you must first declare a pointer variable using the POINTER attribute. Then, you can use the POINTER statement to associate the pointer variable with a specific array section. For example:
REAL, DIMENSION(10) :: array
REAL, POINTER :: ptr
ptr => array(3:5)

3. Can you have multiple pointers to different sections of the same array in Fortran?

Yes, it is possible to have multiple pointers to different sections of the same array in Fortran. This allows for even more efficient manipulation and access of data within the array, as different sections can be accessed simultaneously without the need for extra memory allocation.

4. How do you use vector subscripts with a pointer to array section in Fortran?

In order to use vector subscripts with a pointer to array section in Fortran, you must first declare the pointer variable with the TARGET attribute. This allows the pointer to point to a specific array section based on the vector subscripts provided. For example:
REAL, DIMENSION(10,10) :: array
REAL, POINTER, TARGET :: ptr
ptr => array(1:3, 4:6)

5. Can you deallocate a pointer to array section in Fortran?

Yes, you can deallocate a pointer to array section in Fortran by using the NULLIFY statement. This will disassociate the pointer from the array section and free up any allocated memory. It is important to deallocate pointers when they are no longer needed to avoid memory leaks.

Similar threads

  • Programming and Computer Science
Replies
20
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Programming and Computer Science
Replies
2
Views
8K
  • Programming and Computer Science
Replies
1
Views
932
  • Special and General Relativity
5
Replies
146
Views
6K
  • Programming and Computer Science
Replies
10
Views
25K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
15K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top