Having some trouble with Fortran

  • Context: Fortran 
  • Thread starter Thread starter Bashkir
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a Fortran 90/95 program that fails to compile correctly. Participants explore potential causes for the errors encountered, including issues related to file formatting, compiler compatibility, and the use of specific text editors.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant reports an error stating "invalid character at (1)" when compiling a simple Hello World program, despite copying it directly from a book.
  • Another suggests that the issue might be related to UTF-8 with BOM, although this is not confirmed.
  • Some participants propose changing the program name to avoid using underscores, while others assert that underscores are valid in Fortran 90/95.
  • There is a discussion about the difference between free-format and fixed-format source code, with a recommendation to use free format for beginners.
  • A participant mentions the importance of consulting the specific reference manual for the version of Fortran being used to identify the problem.
  • One participant successfully compiles the program on their machine, prompting a request for details about the commands used and the operating system.
  • Another participant notes that gfortran may have bugs and provides a link to a resource discussing known issues.
  • There is a suggestion to check the version of gfortran being used, with one participant noting that their version is quite old.
  • After switching text editors to gedit, one participant reports success in compiling the program, but encounters issues running the resulting executable file.
  • Participants clarify how to execute the compiled program from the terminal.

Areas of Agreement / Disagreement

Participants express various hypotheses regarding the source of the compilation errors, with no consensus reached on a single cause. Some agree on the potential impact of text file formatting, while others focus on compiler issues or naming conventions.

Contextual Notes

Limitations include uncertainty about the specific compiler settings and the potential influence of different text editors on file formatting. The discussion also highlights the varying levels of familiarity with programming among participants.

Who May Find This Useful

Individuals learning Fortran, particularly beginners encountering compilation issues, may find the troubleshooting insights and suggestions beneficial.

Bashkir
Messages
31
Reaction score
1
I am sitting down and working my way through a Fortran 90/95 book for a research project I will be involved in at my university in a few weeks. However, I can't even seem to get the most basic program to work even when copying the template directly from the book. It always says invalid character at (1). For instance, my Hello World program was formatted as such:

PROGRAM Hello_world
WRITE(*,*) "Hello, World!"
END program Hello_world

Then, I saved it as hello.f90.

When I go to try to compile it, it keeps giving me an an invalid program statement at (1) and several other invalid character at (1) errors.

I am using the Terminal on Linux and VIM if that matters.
 
Technology news on Phys.org
For some reason it makes me think about UTF-8 with BOM. But I can be completely off.
 
You should be able to use "underscore" in Fortran 90 or 95 variable names etc - but there are some not-quite-standards-compliant compilers around (and some not-even-close-to-being-standards-compliant ones!)

Another possibility is the difference between free-format and fixed-format source code. If you and the compiler disagree about which format you are using, nothing will work and the error messages you get might look weird..

The two formats might be distinguished by different filename extensions like .f90 and .F90, or by using a compiler option on the command line. Check your compiler documentation. (If you are learning Fortran from scratch, use free format!)

As for standards, there's an old programming joke: scientific programmers are happy to write in any language, provided it's called FORTRAN. (And conversely, commercial programmers don't care what their programming language is called, so long as the syntax is identical to COBOL.)
 
Is there a copy of the reference manual on the web for the manufacturer's version of FORTRAN that you are using? I'm not asking for a generic FORTRAN book, but the manual for the exact version that you are using. With that it should be possible to track down exactly what the problem is and what is needed to fix this.
 
I tried saving the file as .F90 now, and it still gives me the same errors.

I will check the web for the reference manual.

@Jedi -- I copied that program directly and it is still giving me same error.

@Borek -- This is my first programming language, and I honestly have no idea what you just said haha.

Thank you everyone for the help.

Also, I am compiling with gfortran.
 
I copied your program directly and it compiled and ran just fine. Tell us exactly what commands you are using to compile and run the program, and what operating system you are using.
 
Well, I am running linux on one of my school's computers.

I open vim and type the program directly as it is show above. I then save it to my desktop as hello.f90

Then, in the terminal, I type compile it:

gfortran hello.f90

and also, at the advice of someone else, tried

gfortran -o hello hello.f90

but both of them gave me the same error.
 
  • #10
please post the output of the following command:
Code:
gfortran --version
 
  • #11
Bashkir said:
Well, I am running linux on one of my school's computers.

I open vim and type the program directly as it is show above. I then save it to my desktop as hello.f90
Then, in the terminal, I type compile it:
gfortran hello.f90
and also, at the advice of someone else, tried
gfortran -o hello hello.f90
but both of them gave me the same error.

That all looks OK. But you said...
Bashkir said:
This is my first programming language
... so your best option is find somebody who can sit down in front of you own computer and sort this out. We can keep guessing what the problem might be, but it you don't understand what the guesses mean, that might not help even if we guess right!

Yeah, this probably seems frustrating and ridiculous - but we've all been there, at some time in the past.
 
  • #12
Bashkir said:
Well, I am running linux on one of my school's computers.

I open vim and type the program directly as it is show above. I then save it to my desktop as hello.f90

Then, in the terminal, I type compile it:

gfortran hello.f90

and also, at the advice of someone else, tried

gfortran -o hello hello.f90

but both of them gave me the same error.

I'm not sure what the issue is. Like I said, I copied your program exactly and it compiled and ran fine on my Unix machine. My gfortran version is:

GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50)
Copyright (C) 2007 Free Software Foundation, Inc.
 
  • #13
phyzguy said:
I'm not sure what the issue is. Like I said, I copied your program exactly and it compiled and ran fine on my Unix machine. My gfortran version is:

GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50)
Copyright (C) 2007 Free Software Foundation, Inc.

That's pretty old. The current release is 4.9
 
  • #14
Bashkir said:
@Borek -- This is my first programming language, and I honestly have no idea what you just said haha.

It had nothing to do with programming, more with a format of the text file.

http://en.wikipedia.org/wiki/Utf-8#Byte_order_mark

I believe vim can be configured to add BOM to the files. I can be wrong though.
 
  • #15
Borek said:
It had nothing to do with programming, more with a format of the text file.

http://en.wikipedia.org/wiki/Utf-8#Byte_order_mark

I believe vim can be configured to add BOM to the files. I can be wrong though.

That's a good point. Why don't you try a different text editor - gedit or emacs and see if you have the same problem.
 
  • #16
Nevermind what this previously said.

I tried changing the text editor and that worked brilliantly. Thank you everyone so much for all of your help.
 
Last edited:
  • #17
Bashkir said:
I tried changing the text editor and used gedit instead. This seemed to work ok and when I compiled it it gave me an a.out file on my desktop. However, nothing seems to open that file.

It should also be noted that I specified an output name, I just don't know how to use this kind of file.

The .out file is the executable. Let's say the file is called a.out then to run it, just type:

$./a.out

To be clear, you don't type the $. This is the prompt supplied by the system.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 2 ·
Replies
2
Views
2K