Fortran How can I search for a specific phrase in a sentence using FORTRAN?

  • Thread starter Thread starter manjurul
  • Start date Start date
  • Tags Tags
    Beginners Fortran
AI Thread Summary
The discussion primarily revolves around the usage of the READ and WRITE commands in Fortran, as outlined in Michael Kupferschmid's "Classical Fortran: Programming for Engineering and Scientific Applications." The generalized form of the READ command is explained, highlighting that the 'unit' can range from 0-99 or be represented by an asterisk, with both 5 and * indicating standard input. The format can either be a default or specified through a FORMAT statement, which dictates how input/output is structured. Participants discuss how to ensure output values are written on the same line using the WRITE command, emphasizing the importance of the FORMAT statement for achieving this. A sample code snippet is provided to illustrate how to format output correctly. Additionally, there is a request for assistance in writing a Fortran code that reads a specific sentence from a text file and searches for the phrase "good boy," including its position in the sentence. The discussion remains focused on practical coding solutions and formatting techniques within Fortran.
manjurul
Messages
4
Reaction score
0
Most of the examples here are given from the following book,

Michael Kupferschmid, "Classical Fortran: Programming for Engineering and Scientific Applications", Taylor & Francis Group, 2009

The generalized form of READ command is as follows,

READ (unit, format) list

where, the value of 'unit' could be any value ranging from 0-99 or star symbol '*'. Both 5 or * means standard-in (usually keyboards). If the 'format' is *, then the format will be according to the compiler default. However if 'format' is not * , then it will refer the label of the FORMAT statement. Note that the FORMAT statement is used to specify exactly how the input/output will be. The 'list' is the list of variables to be read.

Any of the commands are used to read an input for variable A,

PHP:
READ (*,*) A

and

PHP:
READ *,A

are same commands. It means the program will take an input from standard-in (usually keyboard).
 
Last edited:
Technology news on Phys.org
For output the general forms are as follows,

WRITE (unit, format) listfor the details of 'unit', 'format' and 'list' see above.
 
Last edited:
HI,
I want to write some results in my fortran code. The way i want to get it written is the values should be written on the same line and NOT on the next line and so on...How can i achieve it bu using the write command?
 
Hi Nisha,

You need to use FORMAT statement and it is not difficult to do that.. you can see the following link to do that,

http://fortranmanjurul.blogspot.com/

also test the following code and see how FORMAT statement works

PHP:
         PROGRAM readonce
         REAL*8 X/1.23D0/, Y/53.0D0/
         J=37
         WRITE(6,10) J,X,Y
 10      FORMAT(1X,I3,T7,'X=',T9,F5.2,3X,T17,D8.2)
         STOP
         END PROGRAM readonce

Hope this solves your problem
 
Last edited:
I need to write a code which can read the following sentence from a text file,

"I know that he is a good boy!".

After reading it, the code has to search if the word "good boy" is there or not. Also the position number of "good boy" in the sentence (i.e. after how many character)

Kindly anyone help me
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

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