Fortran How Can a Single READ Statement Handle Multiple Data Types in Programming?

  • Thread starter Thread starter cibui
  • Start date Start date
  • Tags Tags
    Programming
AI Thread Summary
To read both numbers and functions like "sin(x)" in a program, a single READ statement is insufficient. The READ statement can handle numbers or strings but cannot directly interpret functions. Instead, the input must be processed as a string, requiring additional logic to parse and identify function names and their arguments. For example, if a user inputs "sin2x," the program must distinguish between the function "sin" and the argument "2x." This parsing process can be complex, especially for those without programming experience, and may necessitate breaking down the input into manageable parts for effective processing.
cibui
Messages
8
Reaction score
0
Hi guys,

straight to the point, how do you make your READ statement to be able to read both numbers and letters(words) or functions at the same time? okay, for example, i want the user to input a continuous function. what if the function is, let say, sin(x)? do i need to break the READ statement into several READ statements or it can be done with only one statement? i was only taught to use "READ *, " but never told how does this really work.

I'm no programmer and have no programming background, so please help me :redface:
greatly appreciated
 
Last edited:
Technology news on Phys.org
This is a harder problem than you might realize, since your program has to parse the input text to recognize function names.

A READ statement can be set up to read numbers (either real or integer) or strings of characters. It can't be set up to read functions such as sqrt or sin. There must be logic in the program to match input strings to a list of functions. If you have no programming experience, this will probably be beyond your abilities.
 
Thanks for the reply Mark,
okay, so it is not possible afterall...
guess i will have to break the input structure into several steps then

anyway tyvm
 
I didn't say it wasn't possible. I said that with your lack of experience it would be very difficult.

In your first post you talked about "break(ing) the READ statement into several READ statements..." That's not what you need to do.

Your program needs to read the input as a string, and then it needs to parse the string to determine if the input string contains the name of a function, such as sin, or tan, or ln, or whatever.
 
i know that read statement can read strings of texts but the thing is what if it involves operable numbers? e.g. sin2x. i want it so that the inputted "2" by the user can be processed by the program as an operable number not as a part of a string of text. can READ actually do that?
thanks for your help
 
Everything will necessarily have to come into the program as a string of characters. In your example, if the user enters sin2x, your program will read this as a character string. Your program will then have to have logic so that it can separate out the function name (sin) from the argument (2x).
 
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...
Back
Top