View Full Version : Does anyone know Fortran?

2006-Oct-05, 05:56 PM
Specifically Fortran 90/95?
I've been working on an assignment for class and I've pretty much got it done but the statements that print out all look rather hideous, for instance:

The time interal is (big gap) 1 hours, (big gap) 6 minutes and (big gap) 40

They all have these giant gaps between the numbers that I'm getting out of the program and the sentence that I'm trying to print. Does anyone know how to get rid of the spaces?

This part isn't really necessary for my assignment, but I'm being nitpicky and would like to make it look nice.

edit: apparantly when I type it in on here it looks fine, but I assure you that in my window it looks funny.

2006-Oct-05, 06:07 PM
They all have these giant gaps between the numbers that I'm getting out of the program and the sentence that I'm trying to print. Does anyone know how to get rid of the spaces?

I haven't done Fortran since college, and I haven't seen your code, so I can't help you on the details. Maybe I can help you understand what's happening though. The numbers are being converted to print with understood leading zeros (or blanks). This may be because you're using long integers or float type variables.

You may wish to convert your numbers to a character string, and possibly trimming out the blanks yourself before printing. I've no clue how you would do that. The rare times I've used fortran outside of assigned classwork (linpack), I've used a linker to connect it to a C interface. This was far less inconvenient than building the interface out of fortran (77).

2006-Oct-05, 06:17 PM
Apparantly emacs won't let me cut and paste to here, all my variables are just integers, I can't really convert them to characters because I need to do some math with them first (my program converts a time interval in seconds to hours, minutes and seconds) and my print statement for that line looks like this:

Print *, "The time interval is",h," hours,",m," minutes and",s," seconds."

Where h,m and s are the integers I'm working with.

2006-Oct-05, 06:20 PM
I meant to convert/copy them to characters _after_ you're done with the math but immediately before you print them.

You can keep doing math on the integers.

2006-Oct-05, 06:35 PM
How do I convert them at the end?

character (len=1) :: h,m,s ! after I'm done with the math?

2006-Oct-05, 06:48 PM
As I said, no idea. You'll need someone with current Fortran knowledge to help you with the specifics.

2006-Oct-05, 07:58 PM
Checking the way-back memory...

you can use a formating satement such as:

Print 100, HR, MIN, SEC
100 FORMAT ('the tiime interval is ', I4, ' Hours', 3X, I4, ' Minutes', 3X, I4,' Seconds')

this should print out: the time interval is, a four digit integer, Hours, ...

the time interval is 1234 Hours 1234 Minutes 1234 Seconds

2006-Oct-05, 08:44 PM
My Fortran was 66 (Watfiv) and then 77.

Looking around at 90/95 online, maybe try inserting formating code after the variables to be printed. From the internet:

print *, ‘Hello, world: the time is ‘, T(1:2), “:”, & T(3:4)

from another site:

Another form of the i descriptor is iw.m, where w defines the field width, and m specifies the minimum number of digits to be displayed, if necessary preceded by zeros.

Hope this helps. The examples I saw didn't seem to have your problem.

Good luck.

2006-Oct-05, 11:36 PM
BioSci is leading you in the right direction. Look up how to use the FORMAT statement, it (well, duh) formats the output so that you don't get the ugliness that * gives.