Newbie to Fortran: Simplistic questions (I think)

Newbie to Fortran: Simplistic questions (I think)

I just installed ifort version 8.0 on my Debian GNU/Linux (kernel 2.4.25) system.

I wrote a test program:

PROGRAM hello_world
real :: num
print *, "Input a number: "
read *, num
print *, "You typed ", num, ". Ain't that special?"
END PROGRAM hello_world

I compiled the program with:

$ ifort test.f90

And ran the program:

$ ./a.out
Input a number:
42
You typed 42.00000 . Ain't that special?

Question 1:
If you look closely, there are spaces in front of each line of output. A space in front of " Input" and a space in front of " You", even though I didn't have that space in the string I wanted to print. What are those spaces doing there?

Question 2:
Why are those newlines being generated? I didn't specify a '
'. Do I need to surpress automatic newlines? I assume there HAS to be a way to do something like:

Input a number: 42

instead of what happens with automatic newlines:

Input a number:
42

Question 3:
Besides the strange whitespace in front of each line, there's a strange space around the real number 42:

You typed 42.00000 . Ain't that special?

Four spaces in front of "42.00000" and 5 spaces after it. Why are those spaces there?

Question 4:
When I control C when the program expects input, I get some very strange output:

$ ./a.out
Input a number:
forrtl: info: Fortran error message number is 69.
forrtl: warning: Could not open message catalog: ifcore_msg.cat.
forrtl: info: Check environment variable NLSPATH and protection of /usr/lib/ifcore_msg.cat.

I assume "rtl" stands for the Fortran run-time library. Does this mean something's not installed correctly? Installation was a bit of a bear since I'm on a non-rpm system, but I thought everything went OK. Maybe not.

Any hints/advice/suggestions on this strange info and warning message?

Thanks!
Pete

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Ack. Sorry to reply to my own message, but web forums stink, and it ate up the multiple spaces in my post. Let me see if I can try to post what I was talking about.

Here is the output of the program, ignore the double quotes. I'm using them to try to preserve the initial spaces:

"$ ./a.out"
" Input a number:"
"42"
" You typed 42.00000 . Ain't that special?"

Hopefully that will preserve the wierd spacing problems I mentioned in the previous post.

Welcome to the forum! I hope you find it a helpful resource.

1. You are using list-directed formatting (the * format). The language definition specifies that the record written with list-directed formatting have a leading blank. This is connected with the notion of "Fortran carriage control" in which the first character of the record is interpreted as a carriage control specification. By default in Intel Fortran, the first character is treated as ordinary data, but the language requires the leading blank. If you want to avoid that, then you will have to use explicit formatting.

2. Fortran, by default, starts every new output record on a new line. Fortran does not have the concept of
. There is a way in standard Fortran to get the effect you want, as follows:

write (*,"(A)",advance="no") "Input a number: "
read (*,*) num

3. List-directed output again - it applies default formatting with fixed-width fields that vary depending on the datatype. Avoiding the extra blanks with integers is easy, as you would use an I0 format in an explicit format. Doing so with real values is trickier.

4. The compiler install is supposed to set the path to the message catalog, but we have found sometimes it doesn't. try this:

SETENV NLSPATH opt/intel/compiler80/lib/ifcore_msg.cat/%N (note the /%N at the end)

You may want to pick up a good book on the Fortran 95 language to help with understanding Fortran I/O.

Steve - Intel Developer Support

Hi Steve,

Thanks for the awesome reply. I really appreciate your excellent response.

I'm using bash, and it appears that my installation is under a slightly different directory. If anybody reads this in the future, here's what I used:

export NLSPATH='/opt/intel_fc_80/lib/ifcore_msg.cat'

As for my Fortran questions, I've been reading "Fortran 90 Programming" by Ellis, Philips and Lahey, and it seems like an excellent book.

I guess my problem is that Fortran 90 looks so much like C (compared to the Fortran 77 code I've seen out there which looks like it belongs in the Smithsonian Museum of history) that I've been skimming rather than reading.

Fortran 90 looks like a _really_ user friendly language. As a C programmer, I can really appreciate some of the conveniences that you don't normally see in non-OOP compiled languages.

I mean, string handling is a breeze (not to mention memory boundary safe). The "implied DO" looks like it belongs more in a language like perl or Tcl rather than a compiled language.

So far, Fortran 90 seems like a really awesome language. I'm really enjoying it. I've looked at my book's TOC, and it looks like I'll learn more about PRINT and READ formats in chapter 8 (which again reminds me of Perl).

Again, thanks!
Pete

Leave a Comment

Please sign in to add a comment. Not a member? Join today