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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:15:26+00:00 2026-06-02T10:15:26+00:00

It is my understanding that Fortran, when reading data from file, will skip lines

  • 0

It is my understanding that Fortran, when reading data from file, will skip lines starting with and asterisk (*) assuming that they are a comment. Well, I seem to be having a problem with achieving this behavior with a very simple program I created. This is my simple Fortran program:

  1       program test
  2 
  3       integer dat1
  4 
  5       open(unit=1,file="file.inp")
  6 
  7       read(1,*) dat1
  8 
  9 
 10       end program test

This is “file.inp”:

  1 *Hello
  2 1

I built my simple program with

gfortran -g -o test test.f90

When I run, I get the error:

At line 7 of file test.f90 (unit = 1, file = 'file.inp')
Fortran runtime error: Bad integer for item 1 in list input

When I run the input file with the comment line deleted, i.e.:

1 1

The code runs fine. So it seems to be a problem with Fortran correctly interpreting that comment line. It must be something exceedingly simple I’m missing here, but I can’t turn up anything on google.

  • 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-02T10:15:27+00:00Added an answer on June 2, 2026 at 10:15 am

    Fortran doesn’t automatically skip comments lines in input files. You can do this easily enough by first reading the line into a string, checking the first character for your comment symbol or search the string for that symbol, then if the line is not a comment, doing an “internal read” of the string to obtain the numeric value.

    Something like:

    use, intrinsic :: iso_fortran_env
    
    character (len=200) :: line
    integer :: dat1, RetCode
    
    read_loop: do
       read (1, '(A)', isostat=RetCode)  line
        if ( RetCode == iostat_end)  exit ReadLoop
        if ( RetCode /= 0 ) then
          ... read error
          exit read_loop
        end if
        if ( index (line, "*") /= 0 )  cycle read_loop
        read (line, *) dat1
    end do read_loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the understanding that using /../ in a file location in bash will
It's my understanding that nulls are not indexable in DB2, so assuming we have
It is my understanding that I can test that a method call will occur
It is my understanding that System.Core.dll and System.Xml.Linq.dll are supported (or will be) in
I am coming to MySQL from MS SQL. It was my understanding that in
It's my understanding that py2exe can only dynamically link a python2x.dll file. Are there
I have the understanding that perm size is used to store meta data, that
I'm of the understanding that an unhandled exception in any appdomain will bring down
It was my understanding that when adding components to a BorderLayout they would take
Its my understanding that the questions in StackOverflow has the following format http://stackoverflow.com/questions/{question-id}/{slug-made-from-question-title} So

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.