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

  • SEARCH
  • Home
  • 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 6609531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:43:44+00:00 2026-05-25T19:43:44+00:00

I have written a program which reads a file containing multidimensional data (most commonly

  • 0

I have written a program which reads a file containing multidimensional data (most commonly 3D, but 2D could occur as well). To heighten simplicity I would like to store the data in an array of the same rank (or something pretending to be one), i.e. using a three-dimensional array for 3D data, etc.; the trouble is that the program only learns about the dimensionality on reading the data file.

Currently I store all data in an array of rank one and calculate each element’s index in that array from the element’s coordinates (this was also suggested here). However, I have also read about pointer rank remapping, which seems very elegant and just what I have been looking for, as it would allow me to scrap my procedures for array index determination (which are probably far less efficient than what goes on behind the scenes). Now, however, it looks like I’m facing the same problem as with directly declaring a multidimensional array – how to do the declaration? Again, it requires information about the rank.

How could I use pointer rank remapping or some other, more suitable technique for setting an array’s rank at runtime – in case this can be done at all. Or am I best off sticking to the rank one-array that I am currently using?

  • 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-05-25T19:43:45+00:00Added an answer on May 25, 2026 at 7:43 pm

    I once asked something similar, i.e. how to treat a two-dimensional array as one dimension, see here: changing array dimensions in fortran.

    The answers were about the RESHAPE instrinsic of pointers, however there seems to be no way to use the same array name unless you use subroutine wrappers, but then you need callbacks to have the eventual subroutine with only one name, so the problems get larger.

    program test
        real, allocatable :: data(:)
        allocate(data(n_data))
        ! read stuff, set is_2d and sizes
        if (is_2d) then
            call my_sub2(data, nX, nY)
        else
            call my_sub3(data, nX, nY, nZ)
        end if
    end program test
    
    subroutine my_sub2(data, nX, nY)
        real :: data(nx,nY)
        ! ...
    end subroutine my_sub2
    
    subroutine my_sub3(data, nX, nY, nZ)
        real :: data(nx,nY,nZ)
        ! ...
    end subroutine my_sub3
    

    EDIT: as an alternative, set the third rank to 1:

    program test
        real, allocatable, target:: data(:)
        real, pointer:: my_array(:,:,:)
        logical is_2d
        n_data = 100
        allocate(data(n_data))
        ! read stuff, determine is_2d and n
        if (is_2d) then
            i=n
            j=n
            k=1
        else
            i=n
            j=n
            k=n
        end if
        my_array(1:i,1:j,1:k) => data
        write(*,*) my_array
    end program test
    

    Then you handle the 2D case as a special 3D case with third dimension 1.

    EDIT2: also, beware when passing non-contiguous arrays to subroutines with explicit-shape arrays: http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/optaps/fortran/optaps_prg_arrs_f.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program which reads input from csv file and its working
I have a program (written in C#) that reads/writes its data directly (direct file
I have a program which i have myself written in java, but I want
I have a program which reads data from 2 text files and then save
I have a program written in VB.NET which stops a service that uses file
I have written a C++ program that reads in a file and outputs the
I have a program written in Fortran by someone else which consequently reads a
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I am beginning to port a program which is written in C and have
Let say I have written a small program that reads file_A and file_B as

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.