Fortran Fortran help: Open and Write functions

  • Thread starter Thread starter Mustachio13
  • Start date Start date
  • Tags Tags
    Fortran Functions
AI Thread Summary
To achieve an open statement in Fortran that allows for later writing with a dynamic file name, use the OPEN statement with a CHARACTER variable for the file name and replace the '?' in the FORMAT statement with an A descriptor referencing that variable. When writing the statement, ensure the syntax is correct to avoid issues with formatting. The blue underlining and color changes observed when typing in the editor are likely features of the text editor being used, such as Microsoft Word, which highlights syntax for better readability. This highlighting is not part of Fortran's syntax and will not affect the program once saved. If the blue underlining is distracting, consider using a different programming editor that does not apply such formatting.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
5
Views
5K
Replies
12
Views
3K
Replies
8
Views
2K
Replies
8
Views
4K
Replies
6
Views
2K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
3
Views
3K
Back
Top