Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Not sure if my compiler can handle format statements

Not sure if my compiler can handle format statements

Not sure if my compiler can handle format statements

Okay, so Im working through some basic stuff with learning fortran, but Im running up against an issue with format statements.

Using gfortran, I try to compile this example program from a tutorial pdf Im reading:


      implicit none
      integer:: i, j
      real:: x
      character(len=10):: mychars
      write(*,*)' Enter digits 0 to 9 twice in succession '
      100 FORMAT(1x, a5, i5, f6.2, i3)      
      read(*,100)mychars, i, x, j
      write(*,*)mychars, i, j, x
      end program FORMAT 

when I try to compile, I get

Quote (gfortran)

bruce@bruceblushingdevelopment/fortran$ gfortran -o format format.f

100 format(1x, a5, i5, f6.2, i3)
Error: Invalid character in name at (1)

read(*,100)mychars, i, x, j
Error: FORMAT label 100 at (1) not defined

The issue only pops up when trying to use format statements. Are format statements not supported by gfortran, or am I writing them in an outdated syntax version?

RE: Not sure if my compiler can handle format statements

If your file extension is .f or .for, then it assumes that you are programming in F77 i.e. fixed format. Columns 1-5 for labels (your 100 you be in here), Column 6 for continuation and Column 7-72 for code.

RE: Not sure if my compiler can handle format statements

Please change thread title to "I am not sure if I can handle format statements" bigsmile

Yes, Fortran 77 is a bit weird in that some blank spaces are significant (firs 6 columns).

Yes, Fortran 90 is a bit weird in that all blank spaces (outside quoted text) are ignored.


A few pointers:
  • You should make sure that you are learning Fortran 90 or later.
  • Give your Fortran source files an extension of ".f90"
  • Please do not learn from very old code where all text is left justified.
  • Please do not use ALL UPPERCASE like they used to (great...you are already doing that).
  • Practice good indentation (4 blank spaces per level).
  • Do not use hard tabs, use emulated tabs...make sure your editor replaces tabs with blank spaces, look into settings.
  • Stop using numeric labels altogether to refer to FORMATs and use strings instead.
I see what you are practicing but, personally, I steer away from column-oriented reading; instead, you should stick to list-oriented read. Use format only for writing. Here is your program, for example, no using labels.


program format
    implicit none
    integer:: i, j
    real:: x
    character(len=10):: mychars
    character(len=80):: fmt
    fmt = '(1x, a5, i5, f6.2, i3)'
    write(*,*)' Enter digits 0 to 9 twice in succession '
    read(*,fmt) mychars, i, x, j
    write(*,*)mychars, i, j, x
end program format 

Keep it up, Fortran is nice, easy to program and easy to read (no unnecessary ornaments and the like). Make sure you have an editor with syntax highlighting and can handle Fortran 90 and beyond (Notepad++, for example).

RE: Not sure if my compiler can handle format statements

I cant seem to find where I can change the thread title. I will change that if I can find out how to change it

Changing the extension to .f90 fixed the problem, thank you.

I am learning Fortran 90, my main resource being this pdf


(which I have found to be quite easy to understand, for what its worth)

no worries about the uppercase thing, that was just the way the example was written. I was trying the FORMAT keyword in uppercase to see if that would fix the problem. I will refrain from talking in capital letters in the future ;)

I will try to indent a bit more clearly, but I was having problems with lines extending too many spaces. I suspect that should be fixed now that gfortran knows it should be compiling fortran 90 instead of fortran 77

I tried that example program you posted and it works fine, but I dont understand how passing through a character string to the read statement does that.

Funny that you should mention Fortran as being easy. It does actually seem a lot more like a scripting language than C and C++ do. (C++ was the first language I learned)

Somewhat off topic, but is Fortran really used all that much anymore? I mostly decided to learn it just for the heck of it, but it doesnt seem to be all that common anymore.

RE: Not sure if my compiler can handle format statements

I was kidding about the title change, of course...are you too?

Fortran is case-insensitive.

Fortran 77 was limited to 72 columns wide; I think Fortran 90 may by default allow up to 132, if not, a simple compiler flag should do.

What is there to not understand in passing a string to the 'format' statement? That is the same thing you were passing before...an explicit quoted string, but nevertheless a string...I just simply chose to pass a string variable, instead.

First...lingo...Fortran, C/C++ are not called scripting languages. Typically, it is understood that a scripting language is one that does not require explicit user compilation ahead of execution; what's more, with a scripting language, one can be in the corresponding shell and execute commands interactively...think DOS terminal in Windows, cshell/bash on Linux...think tcl, python, etc.

Other than that, sorry you had to learn C++ first winky smile

Fortran is easy enough to have been the language of choice for many non-computer-scientists, i.e., engineers and scientists. And there is a reason why, after 57 years, is still around. Also, so much code was developed with it and debugged over the years to such perfection, that nobody dares to rewrite it. Anyway, here is one recent article I run into not long ago.

Universities choice of first programming language to teach is not necessarily based on technical merit, often times is a matter of phad...switching away from Fortran to C, from C to C++, from C++ to Java and I hear they are now switching away from Java to Python...going back almost full circle to another language that is easy to learn, write and read.

Finally, to address each of your statements/questions, depending which field you go to...sure, you will find yourself with some Fortran code. Not in Business, though; but then you will need to watch out for another dinosaur, there...COBOL bigsmile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close