Fortran90 help

  1. 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: Nov 6, 2011
  2. jcsd
  3. Mark44

    Staff: Mentor

    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.
  4. 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
  5. Mark44

    Staff: Mentor

    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.
  6. 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
  7. Mark44

    Staff: Mentor

    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).
Know someone interested in this topic? Share this thead via email, Google+, Twitter, or Facebook

Have something to add?