Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:08:33+00:00 2026-06-09T23:08:33+00:00

I am trying to create an array of arrays in Fortran. Something like the

  • 0

I am trying to create an array of arrays in Fortran.

Something like the following

TYPE :: array_of_arrays
   REAL, DIMENSION(:), POINTER :: p => NULL()
END TYPE

TYPE(array_of_arrays), DIMENSION(2) :: some_array

So that I can do:

REAL, DIMENSION(3), TARGET :: some_vector1 = (/1.0, 2.1, 4.3/)
REAL, DIMENSION(3), TARGET :: some_vector2 = (/3.0, 1.2, 9.6/)

some_array(1)%p => some_vector1
some_array(2)%p => some_vector2

WRITE(*,*) some_array(1)%p ! I see some_vector1
WRITE(*,*) some_array(2)%p ! I see some_vector2

Now it’s cumbersome for me to actually declare each of these some_vector arrays to correspond to each element in my array of arrays.

What I’d like to do is have in a separate subroutine where a temporary vector is set as a target, and that subroutine sets up my array of arrays to point to that temporary vector.

This way I can have anonymous arrays.

However, this doesn’t seem to be working and I wonder if first if I am doing something that Fortran doesn’t support.

So does Fortran support anonymous arrays, that is (in case I have the terms wrong), an array who can only be accessed through a reference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:08:34+00:00Added an answer on June 9, 2026 at 11:08 pm

    Sure; as IanH suggests, you can just have the pointer refer to allocated memory directly, rather than refer to a variable; this is one of the few cases where the allocated memory doesn’t automatically get deallocated once it goes out of scope.

    eg,

    module arrays
    
    
    TYPE :: array_of_arrays
       REAL, DIMENSION(:), POINTER :: p => NULL()
    END TYPE
    
    contains
    
    subroutine alloc(aa)
        type(array_of_arrays), intent(inout) :: aa(:)
        integer :: i
    
        allocate( aa(1)%p(1) )
        aa(1) % p = [1.]
    
        allocate( aa(2)%p(5) )
        aa(2) % p = [ (i, i=1,5) ]
    
    end subroutine alloc
    
    end module arrays
    
    
    
    program usearrays
        use arrays
    
        TYPE(array_of_arrays), DIMENSION(2) :: some_array
    
        call alloc(some_array)
    
        WRITE(*,*) some_array(1)%p ! I see some_vector1
        WRITE(*,*) some_array(2)%p ! I see some_vector2
    
        deallocate( some_array(1) )
        deallocate( some_array(2) )
    
    end program usearrays
    

    and running it gives

    $ gfortran -o arrays arrays.f90 
    $ ./arrays 
       1.0000000    
       1.0000000       2.0000000       3.0000000       4.0000000       5.0000000    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an array out of three arrays in the following
I am newbie for iOS programming. I'm trying to create an array of arrays
I'm trying to create an array (States) of arrays (Cities). Whenever I try to
I'm trying to create a cell array of cell arrays in Matlab. The code
I am trying to create a new array from two current arrays. Tried array_merge,
I would like to create a two dimensional numpy array of arrays that has
I'm trying to create a form that contains these multidimensional arrays: <input type=text name=cost[1][desc]>
I have done the following trying to create 2d and 3d arrays: Array1 =
Hi I am trying to use fortran structure like this type some u !
I'm trying to create an array of arrays that will be using repeated data,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.