Fortran 95: formatting of output (ints and chars)

In summary, the physics student is having difficulty formatting data types in their FORTRAN 95 code and is looking for help.
  • #1
hetanquary
2
0
Hello. I am a physics student working on research project which involves Fortran 95 code. I am very new to Fortran but I do have an intermediate knowledge of Java. The task I am attempting seems like it should be very simple but there are many subtleties to learning a new language that are making it very time consuming, so after attempting different things all day with no luck I thought I would try here.

Here is what I need to do:
At the top of my pre-existing output file I need to write the following exactly in this format:

text month/day/year hours:minutes:seconds
text B=value1 G B=value1 G
text Te=value1 KeV Te=value1 Kev
text Tau=value3 Tau=value3

where: text is an arbitrary character string (it's just for filler); month, day, year, hours, minutes, and seconds are integers; value1, value2, and value3 are reals; the units and the B=, Te= etc... are just characters.

I am having many problems with this. Mainly working with trying to format combinations of data types and with how to tell it when to write on a new line and when not to.
 
Technology news on Phys.org
  • #2
hetanquary said:
Hello. I am a physics student working on research project which involves Fortran 95 code. I am very new to Fortran but I do have an intermediate knowledge of Java. The task I am attempting seems like it should be very simple but there are many subtleties to learning a new language that are making it very time consuming, so after attempting different things all day with no luck I thought I would try here.

Here is what I need to do:
At the top of my pre-existing output file I need to write the following exactly in this format:

text month/day/year hours:minutes:seconds
text B=value1 G B=value1 G
text Te=value1 KeV Te=value1 Kev
text Tau=value3 Tau=value3

where: text is an arbitrary character string (it's just for filler); month, day, year, hours, minutes, and seconds are integers; value1, value2, and value3 are reals; the units and the B=, Te= etc... are just characters.

I am having many problems with this. Mainly working with trying to format combinations of data types and with how to tell it when to write on a new line and when not to.

I always refer to this website http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html (WFS) when I am having issues with FORTRAN I/O. See if it helps.
 
  • #3
Thank you, that is actually the site that I found most helpful as well! I ended up figuring out how to do it after lots of time and much trial and error. I guess that's what it takes! Thank you again. :)
 

Related to Fortran 95: formatting of output (ints and chars)

What is the purpose of formatting output in Fortran 95?

The purpose of formatting output in Fortran 95 is to control the appearance and layout of data when it is displayed on the screen or written to a file. This allows for easier readability and presentation of data, which is important for both scientific and practical purposes.

How do you format integers in Fortran 95?

To format integers in Fortran 95, you can use the Iw format specifier, where w is the field width. This will display the integer with the specified number of digits, padding with leading spaces if necessary. You can also use other format specifiers, such as Zw to pad with leading zeros, or Fw.d to display the integer as a floating-point number with d decimal places.

Can you mix different format specifiers for different types of data in Fortran 95?

Yes, you can mix different format specifiers for different types of data in Fortran 95. For example, you can use Iw for integers, Fw.d for floating-point numbers, and Aw for characters. You can also use multiple format specifiers in the same WRITE statement to display data in different formats.

How do you align output in Fortran 95?

To align output in Fortran 95, you can use the TAB control specifier in your WRITE statement. This allows you to specify the number of spaces to skip before displaying the next item of data. You can also use the / control specifier to start a new line in your output.

Can you specify the number of digits to display after the decimal point for floating-point numbers in Fortran 95?

Yes, you can specify the number of digits to display after the decimal point for floating-point numbers in Fortran 95 by using the Fw.d format specifier, where w is the field width and d is the number of decimal places. You can also use the Ew.d format specifier to display numbers in scientific notation with d decimal places.

Similar threads

  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
29
Views
5K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
Back
Top