Fortran 95: formatting of output (ints and chars)

  • Context: Fortran 
  • Thread starter Thread starter hetanquary
  • Start date Start date
  • Tags Tags
    Fortran Output
Click For Summary
SUMMARY

The discussion focuses on formatting output in Fortran 95, specifically for a physics research project. The user needed to write a specific format to a pre-existing output file, including date and time, along with various values. Key challenges included managing data type combinations and controlling line breaks. The user ultimately found success after consulting resources like the provided website on Fortran I/O formatting.

PREREQUISITES
  • Understanding of Fortran 95 syntax and I/O operations
  • Familiarity with data types in Fortran (integers and reals)
  • Basic knowledge of string manipulation in programming
  • Experience with debugging and trial-and-error coding techniques
NEXT STEPS
  • Research Fortran 95 formatted I/O statements
  • Learn about the WRITE statement in Fortran for output formatting
  • Explore the use of character strings and concatenation in Fortran
  • Study examples of date and time formatting in Fortran 95
USEFUL FOR

Physics students, Fortran developers, and anyone involved in scientific computing who needs to format output data effectively in Fortran 95.

hetanquary
Messages
2
Reaction score
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
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.
 
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. :)
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 29 ·
Replies
29
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K