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 6207307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:36:25+00:00 2026-05-24T05:36:25+00:00

In my Fortran 90 code, I have created the following array (called array )

  • 0

In my Fortran 90 code, I have created the following array (called array) of integers:

 1     2     3     4     5     6     7     8     9    10
11    12    13    14    15    16    17    18    19    20
21    22    23    24    25    26    27    28    29    30
31    32    33    34    35    36    37    38    39    40

I wish to extract the first column, and save it in a four-element vector called time. I have the following code:

PROGRAM test
  IMPLICIT NONE
  INTEGER, PARAMETER :: numrows=4, numcols=10
  INTEGER :: i, j, k
  INTEGER, DIMENSION(:,:), ALLOCATABLE :: array, time

  ALLOCATE(array(numrows,numcols))
  ALLOCATE(time(numrows))

  k=1
  DO i=1,numrows
    DO j=1,numcols
      array(i,j)=k
      k=k+1
    END DO
  END DO

  DO i=1,numrows
    WRITE(*,"(100(3X,I3))") (array(i,j), j=1,numcols)
  END DO

  time=array(:,1)
END PROGRAM test

But, I get the following error message (when compiling in gfortran):

test.f90:8.15:

  ALLOCATE(time(numrows))
               1
Error: Rank mismatch in array reference at (1) (1/2)
test.f90:22.2:

  time=array(:,1)
  1
Error: Incompatible ranks 2 and 1 in assignment at (1)

Why is this the case? The error message seems to suggest that the array array(:,1) is of rank 2, not rank 1. Is there any way that I can convert array(:,1) to an array of rank 1? Do I need to use RESHAPE to somehow squeeze the array? Or is the problem that by using array(:,1), I am specifying a column vector rather than a row vector? Thank you very much for your time.

  • 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-24T05:36:26+00:00Added an answer on May 24, 2026 at 5:36 am

    You are specifying a rank-2 allocatable array called time:

    INTEGER, DIMENSION(:,:), ALLOCATABLE :: array, time
    

    and then attempting to allocate it as a rank-1 array:

      ALLOCATE(time(numrows))
    

    — don’t do that. This works perfectly fine:

    PROGRAM test
      IMPLICIT NONE
      INTEGER, PARAMETER :: numrows=4, numcols=10
      INTEGER :: i, j, k
      INTEGER, DIMENSION(:,:), ALLOCATABLE :: array
      INTEGER, DIMENSION(:), ALLOCATABLE :: time
    
      ALLOCATE(array(numrows,numcols))
      ALLOCATE(time(numrows))
    
      k=1
      DO i=1,numrows
        DO j=1,numcols
          array(i,j)=k
          k=k+1
        END DO
      END DO
    
      DO i=1,numrows
        WRITE(*,"(100(3X,I3))") (array(i,j), j=1,numcols)
      END DO
    
      time=array(:,1)
    END PROGRAM test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following FORTRAN code which I need to convert to C or
I have a line of Fortran code, which includes some text. I'm changing the
I have a piece of fortran code, and I am not sure which standard
I have a fortran (unmanaged code) dll as the calculation engine, and a C#
In my Fortran code I made the following call to the dnrm2 routine: d
I have a C code created in Plato3. I want to create an exe
I very rarely use fortran, however I have been tasked with taking legacy code
I have a module in Fortran called QFoo. It defines a type QFooType. I
A have a lot of code written in FORTRAN 77. I want start developing
I have a library that contains a significant amount of fortran code in it,

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.