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).
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top