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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:49:43+00:00 2026-06-13T06:49:43+00:00

okay i have a file that looks like this: 2 3 6 6 22

  • 0

okay i have a file that looks like this:

2 3
6 6 22
-1 3 0

the integers in the first row are the dimensions of the matrix (not to be included in the matrix)
the rows below the dimensions are the actual matrix
i am trying to write a program that stores this matrix into a 2D array but i keep getting a runtime error when i try to read in the matrix with the nested do loop. It keeps saying “fortran runtime error: end of file” here is my code

PROGRAM addsub
IMPLICIT NONE

CHARACTER(30)::file1
INTEGER:: i,j,err1
INTEGER, DIMENSION(1)::dim1r,dim1c
REAL, ALLOCATABLE:: array1(:,:)


WRITE(*,101) "What is the first filename?"
READ(*,*) file1

OPEN (UNIT=11, FILE=file1, STATUS="OLD", ACTION="READ", IOSTAT=err1)
IF (err1 .NE. 0) THEN
    WRITE(*,'(2A)')"There was an error opening ", file1
    STOP
END IF

DO i=1,1,1
    READ(11,*)dim1r(1),dim1c(1)
END DO

ALLOCATE(array1(dim1r(1),dim1c(1)))

REWIND(11)
DO i=1,dim1r(1),1
    DO j=1,dim1c(1),1
        READ(11,*) array1(i,j)
    END DO
END DO

END PROGRAM addsub
  • 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-13T06:49:44+00:00Added an answer on June 13, 2026 at 6:49 am

    The main problem is that each of your READ statements are trying to read a separate line; so you’re trying to read 6 lines, and your file doesn’t have that many.

    There’s a few ways around this:

    You can try to read each number one at a time using advance='no', but that means you can’t use list-directed input and need to use formatting explicitly:

    DO i=1,dim1r
        DO j=1,dim1c-1
            READ(11,FMT='(F2.0)',advance='no') array1(i,j)
            PRINT *, array1(i,j)
        END DO
        READ(11,FMT='(F2.0)') array1(i,dim1c)
    END DO
    

    You can use implied do loops to read an entire row at once:

    DO i=1,dim1r
        READ(11,*) (array1(i,j),j=1,dim1c)
    END DO
    

    Or just have read deal with it by giving it the array slice:

    DO i=1,dim1r
        READ(11,*) array1(i,1:dim1c)
    END DO
    

    Note another couple of things — dim1c and dim1r don’t have to be arrays; and you shouldn’t REWIND after reading the header, or else you’ll read the header in as data.

    So a complete working version looks like this:

    PROGRAM addsub
    IMPLICIT NONE
    
    CHARACTER(30)::file1
    INTEGER:: i,err1
    INTEGER ::dim1r,dim1c
    REAL, ALLOCATABLE:: array1(:,:)
    
    
    PRINT *, "What is the first filename?"
    READ(*,*) file1
    
    OPEN (UNIT=11, FILE=file1, STATUS="OLD", ACTION="READ", IOSTAT=err1)
    IF (err1 .NE. 0) THEN
        WRITE(*,'(2A)')"There was an error opening ", file1
        STOP
    END IF
    
    DO i=1,1,1
        READ(11,*)dim1r, dim1c
    END DO
    
    ALLOCATE(array1(dim1r,dim1c))
    
    DO i=1,dim1r
        READ(11,*) array1(i,1:dim1c)
    END DO
    
    DO i=1,dim1r
        PRINT *, array1(i,:)
    END DO
    
    DEALLOCATE(array1)
    
    END PROGRAM addsub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that looks like this: namespace myName { typedef HRESULT (*PFN_HANDLE)(myName::myStruct);
We have a java project with dependencies that looks something like this. A ->
Okay, to clarify, I have an XML/RDF file that describes data with a natural
Okay, so I have this CSV file of products and all the products have
I have a UITableView with custom cells in it. This custom cell looks like
Okay I have a JSON file and it has a set of objects that
Let's say we have a comma separated file (csv) like this: name of movie,starring,director,release
okay, so i have a text file with example content below line1with some random
Okay, basically, I have a large list of phone numbers in a text file
okay i have been trying to understand this for hours i am learning VB

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.