Fortran help: Open and Write functions

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

Discussion Overview

The discussion revolves around the use of OPEN and WRITE statements in Fortran, specifically focusing on how to dynamically include a filename in a formatted output and addressing formatting issues encountered in code editors.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant inquires about how to include a variable filename in a WRITE statement's format, suggesting the use of a CHARACTER variable and an A descriptor.
  • Another participant expresses confusion about the appearance of blue, underlined text when typing a colon after 'file' in their WRITE statement, indicating they are new to Fortran.
  • Responses clarify that the color coding and underlining are features of the text editor being used, not part of Fortran syntax, and that these visual cues are meant to aid readability.
  • It is noted that the highlighting does not affect the actual Fortran code and will not persist after saving the file.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the text editor's behavior, but there is no consensus on the best way to format the WRITE statement with a variable filename.

Contextual Notes

Participants mention that the behavior of the text editor may vary, and the specific features available could depend on the software being used. There is also an implicit understanding that the use of a CHARACTER variable for the filename is a common practice, though not universally agreed upon in this thread.

Who May Find This Useful

Individuals learning Fortran, particularly those interested in file handling and output formatting, as well as users seeking to understand text editor features related to coding.

Mustachio13
Messages
2
Reaction score
0
How can I have an open statement:

OPEN(Unit=1,File='data.txt',...)

and be able to later have a write statement:

WRITE(*,15)
15 FORMAT('Data was collected from ',?,'file:')

where the ? would call in the file name. Also, when I type 'file:', it creates a link to something. How do I stop that or do I need to just do something else instead?
 
Technology news on Phys.org
'data.txt' can be the value of a variable of type CHARACTER. You would replace the ? in yourFORMAT statement with an A descriptor and use the name of the CHARACTER variable on the corresponding WRITE statement.

For your last question, could you clarify what you are asking?
 
Thank you, I should have realized that sooner. With my second question, when I went to type my write statement, once I had the ':' after file, it became blue and underlined. I am still new to fortran and I have never seen or had to use a feature that did that. Is it something that can be suppressed or do I have to use a different character instead of ':' after the word 'file'?
 
Mustachio13 said:
With my second question, when I went to type my write statement, once I had the ':' after file, it became blue and underlined.

What are you using for writing your code? That sounds like something Microsoft Word would do.
 
Some programming editors use different colors to display statements according to their use in the program. For instance, declaration statements may be one color, comments another, executable statements another, etc. The final color sometimes cannot be determined until the statement is completely entered.
 
Needless to say, this highlighting of characters or entire words has nothing to with the Fortran program per se and are not part of the syntax, nor persist once you save the file to disk and quit whatever editor you are using...it is simply a convenience offered by some text editors to make it easier to the human eye to tell things apart...just wanted to mention this since nobody seemed to have said it and it seems that you could benefit from such commentary, too.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K