Re: How to pass a string to/from a function in 77



Gary L. Scott wrote:

jane.sync@xxxxxxxxx wrote:

I'm trying to pass strings between functions in Fortran 77, but I can't
find any reference for this... Can anyone help with explaining how to
send a string to a function and have the function return a string? So
far I have this:

      PROGRAM HELLOWORLD
      IMPLICIT NONE
      Character*256 MyFunc

      PRINT *, 'Hello '
      FunctionString()

      END PROGRAM

      FUNCTION FunctionString() RESULT(String)
      Implicit None
      Character(*) String
      String = "World"
      Return
      End


The below is a little closer and works with a particular F95 compiler (not F77). I would probably write the function more generically than this.


      PROGRAM HELLOWORLD

      IMPLICIT NONE

      character(10) functionstring

      PRINT *, 'Hello ',FunctionString()

      END PROGRAM

      FUNCTION FunctionString() RESULT(String)

      Implicit None

      Character(10) String

      String = "World"

      Return

      End

Sorry, probably should have been declared with length 5 rather than 10 in this example.

--

Gary Scott
mailto:garyscott@xxxxxxx

Fortran Library:  http://www.fortranlib.com

Support the Original G95 Project:  http://www.g95.org
-OR-
Support the GNU GFortran Project:  http://gcc.gnu.org/fortran/index.html

Why are there two?  God only knows.


If you want to do the impossible, don't hire an expert because he knows it can't be done.


-- Henry Ford
.



Relevant Pages

  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)
  • Re: String Reference Type
    ... All unary and binary operators have predefined implementations that are ... Therefore its always allocated in the heap and a variable of string ... As with all classes in this case y and x both reference the same String ... language depandant matter as below. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Abstract class variables question
    ... But as I think you've seen elsewhere in this thread, a value type can exist inside a class and in that case the value type is stored in the heap with the rest of the class instance. ... But as far as the "faster" goes, yes...to some extent value types have less overhead than reference types, and so can perform better in certain cases. ... Well, that would be true for a string object too, if there was any way to actually change a string. ... Seriously though, it is practically always the case that when you are writing an assignment to a reference, you're replacing the reference held by the variable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Measurement of pitch
    ... as the method used by the Pythagoreans. ... of these reference units in the quantity to be measured. ... vibrating string seems as good as anything. ... The string or pendulum in question could no doubt be specified exactly, ...
    (sci.physics)
  • Re: Abstract class variables question
    ... I think I understand boxing a little better now. ... the object that is on the heap. ... value types are copied to the heap and made into an object and reference ... String types are already reference types and all we are doing when we do ...
    (microsoft.public.dotnet.languages.csharp)