Fortran Main Program Return Value 
Author Message
 Fortran Main Program Return Value

I would like to know how to return value from the main program in
fortran.  In C and Java, you can both return a value.  I searched in
many fortran books and none of the books talked about this.

My current situation is that our client is using an Oracle system (not
sure what programming language)  All they want from our Fortran
program is to do some computation and return a real number.  What is
the best way to do this?  Do I need to write a DLL?  Thanks.



Sat, 28 Apr 2007 05:51:26 GMT  
 Fortran Main Program Return Value

Quote:

> I would like to know how to return value from the main program in
> Fortran.

This concept is not defined by the standard.  *IF* there is any
answer (and there might not be), it would be specific to
particular compilers.

Quote:
> In C and Java, you can both return a value....
> All they want from our Fortran program is to do some computation and
> return a real number.

Ok.  My C proficiency is pretty weak (and my Java even weaker),
but I don't think you can do this in them either.  I could have
sworn that the C main (and presumably Java) could only return
an int (which tends to get used as a shell status).  Some
Fortran compilers can also do that (details are compiler specific,
as mentioned above), but I've never heard of returning a real
value.

Afraid that I don't know much about interfacing with Oracle,
but I think you need to start from that end, finding out what
the precise technical interface requirements are.  Just
"return a real number" isn't enough of a detailed technical
interface specification.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Sat, 28 Apr 2007 06:06:17 GMT  
 Fortran Main Program Return Value

Quote:
> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

It's not standard in Fortran.  Consider the following:

! File: error.f90
program error
   stop 11
end program error
! End of file: error.f90

! File: error_1.f90
program error_1
   call exit(13)
end program error_1
! End of file: error_1.f90

rem File: errorlevel.bat
df error
error
echo %errorlevel%
lf95 error
error
echo %errorlevel%
df error_1
error_1
echo %errorlevel%
lf95 error_1
error_1
echo %errorlevel%
rem End of file: errorlevel.bat

With output:

C:\LF9556\James\clf\errorlevel>errorlevel

C:\LF9556\James\clf\errorlevel>rem File: errorlevel.bat

C:\LF9556\James\clf\errorlevel>df error
Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update C)
Copyright 2003 Compaq Computer Corp. All rights reserved.

error
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/subsystem:console
/entry:mainCRTStartup
/debugtype:cv
/pdb:none
C:\DOCUME~1\James\LOCALS~1\Temp\obj2B.tmp
dfor.lib
libc.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:error.exe

C:\LF9556\James\clf\errorlevel>error
11

C:\LF9556\James\clf\errorlevel>echo 11
11

C:\LF9556\James\clf\errorlevel>lf95 error
Lahey/Fujitsu Fortran 95 Express Release 5.70f  S/N: XXXXXXXX
Copyright (C) 1994-2004 Lahey Computer Systems.  All rights reserved.
Copyright (C) 1998-2004 FUJITSU LIMITED. All rights reserved.
Registered to:  James Van Buskirk
                XXXXXXXXXXXXX
Options:
-nap           -nc            -nchk          -nchkglobal    -concc
-dal           -ndbl          -ndll          -nf95          -nfix
-ng            -nin           -ninfo         -li            -nlst
-nlong         -maxfatals 50  -o1            -npause        -nprefetch
-nprivate      -npca          -nquad         -nsav          -staticlib
-nstaticlink   -stchk         -tp            -trace         -ntrap
-w             -nwide         -winconsole    -nwo           -nxref
-zero

Compiling file error.f90.
Compiling program unit error at line 1:
Encountered 0 errors, 0 warnings in file error.f90.
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

C:\LF9556\James\clf\errorlevel>error
11

C:\LF9556\James\clf\errorlevel>echo 0
0

C:\LF9556\James\clf\errorlevel>df error_1
Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update C)
Copyright 2003 Compaq Computer Corp. All rights reserved.

error_1
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/subsystem:console
/entry:mainCRTStartup
/debugtype:cv
/pdb:none
C:\DOCUME~1\James\LOCALS~1\Temp\obj2F.tmp
dfor.lib
libc.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:error_1.exe

C:\LF9556\James\clf\errorlevel>error_1

C:\LF9556\James\clf\errorlevel>echo 13
13

C:\LF9556\James\clf\errorlevel>lf95 error_1
Lahey/Fujitsu Fortran 95 Express Release 5.70f  S/N: XXXXXXXX
Copyright (C) 1994-2004 Lahey Computer Systems.  All rights reserved.
Copyright (C) 1998-2004 FUJITSU LIMITED. All rights reserved.
Registered to:  James Van Buskirk
                XXXXXXXXXXXXX
Options:
-nap           -nc            -nchk          -nchkglobal    -concc
-dal           -ndbl          -ndll          -nf95          -nfix
-ng            -nin           -ninfo         -li            -nlst
-nlong         -maxfatals 50  -o1            -npause        -nprefetch
-nprivate      -npca          -nquad         -nsav          -staticlib
-nstaticlink   -stchk         -tp            -trace         -ntrap
-w             -nwide         -winconsole    -nwo           -nxref
-zero

Compiling file error_1.f90.
Compiling program unit error_1 at line 1:
Encountered 0 errors, 0 warnings in file error_1.f90.
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

C:\LF9556\James\clf\errorlevel>error_1

C:\LF9556\James\clf\errorlevel>echo 13
13

C:\LF9556\James\clf\errorlevel>rem End of file: errorlevel.bat

C:\LF9556\James\clf\errorlevel>

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end



Sat, 28 Apr 2007 06:39:56 GMT  
 Fortran Main Program Return Value

(snip)

Quote:
> Ok.  My C proficiency is pretty weak (and my Java even weaker),
> but I don't think you can do this in them either.  I could have
> sworn that the C main (and presumably Java) could only return
> an int (which tends to get used as a shell status).  Some
> Fortran compilers can also do that (details are compiler specific,
> as mentioned above), but I've never heard of returning a real
> value.

C main returns an int, but unix only uses eight bits of it
as the system return code.

The java main method has return type void, but
System.exit() can return an int.  I don't know how many
bits are available.  One could use floatToIntBits to convert
the bits to an int and return that.

-- glen



Sat, 28 Apr 2007 06:44:20 GMT  
 Fortran Main Program Return Value
On Mon, 08 Nov 2004 at 21:51 GMT, Sam (aka Bruce)
  was almost, but not quite, entirely unlike tea:

Quote:
> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

In C, you can return an int.

In most cases, returning an int from main() just gives an exit code to
your program. In unix, and exit code can be less than 128. Exit codes
above 128 arise from the program getting a signal.

In fortran, I have had luck with using "call exit(i)", where i is the
int you want to return as an exit code.

It may work for you, but it is not going to be extremely portable. If
all you care about is unix, then it should work. No idea whether it
will work on inferior systems :)

Quote:
> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  What is
> the best way to do this?  Do I need to write a DLL?  Thanks.

What is it with people's fascinations with DLLs on this froup,
lately?

Is it because of all this .NET crap^Wcraze?

--
TimC -- http://astronomy.swin.edu.au/staff/tconnors/
We would be called technicians, not researchers, if we knew
what we were doing



Sat, 28 Apr 2007 11:15:15 GMT  
 Fortran Main Program Return Value
On 8 Nov 2004 13:51:26 -0800

Quote:

> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  What is
> the best way to do this?  Do I need to write a DLL?  Thanks.

How about just writing the number out to * and telling the surrounding
code to capture the stdout of your program?

David



Sat, 28 Apr 2007 17:32:15 GMT  
 Fortran Main Program Return Value


Quote:
> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  What is
> the best way to do this?  Do I need to write a DLL?  Thanks.

A DLL or an inprocess COM would work best. DLL's don't have a 'program
main', they have a DllMain (which you can write yourself if you have
special needs to do so or the compiler supplies a hidden default one) but
it's not used to pass results. Any of the DLL's functions/subroutines with
an exported entry point can pass data to the Oracle client. Change 'program
main' to 'function/subroutine main(...)', export its entry point, and have
it return whatever you want.

--
You're Welcome,
Gerry T.
______
"Some of those writing letters to this program are slightly fictitious but
others definitely are not." --{*filter*} Cavett, host of The Detroit Symphony
Orchestra, PBS Radio.



Sat, 28 Apr 2007 20:30:53 GMT  
 Fortran Main Program Return Value

Quote:

> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

Correct. The "standard" for Fortran does not allow it.

Quote:
> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  
> What is the best way to do this?  

Use Fortran to write the value to a file,
and get the calling program to read the value from the file.


Sun, 29 Apr 2007 00:41:08 GMT  
 Fortran Main Program Return Value

Quote:

> On Mon, 08 Nov 2004 at 21:51 GMT, Sam (aka Bruce)
>   was almost, but not quite, entirely unlike tea:
>> I would like to know how to return value from the main program in
>> Fortran.  In C and Java, you can both return a value.  I searched in
>> many fortran books and none of the books talked about this.

> In C, you can return an int.

> In most cases, returning an int from main() just gives an exit code to
> your program. In unix, and exit code can be less than 128. Exit codes
> above 128 arise from the program getting a signal.

> In fortran, I have had luck with using "call exit(i)", where i is the
> int you want to return as an exit code.

> It may work for you, but it is not going to be extremely portable. If
> all you care about is unix, then it should work. No idea whether it
> will work on inferior systems :)

Of what I know *all* Fortran compilers provide this extension on both
Windows and Unix/Linux platforms. I have tested it with MS Fortran Station
4.0 (should be dead by now), Salfords FTN95 (on win), Lahey and Intel (on
Linux), Vast f90 (it's dead), g77 (both win+cygwin but 7 years ago, and
Linux). So I suppose using CALL EXIT(I) is quite *portable* after all.
Else, just wrap it in a module and modify it appropriately when moving to a
new environment (or use a preprocessor).

/Sakis



Sun, 29 Apr 2007 07:05:35 GMT  
 Fortran Main Program Return Value

  [about call exit]

Quote:
> Of what I know *all* Fortran compilers provide this extension on both
> Windows and Unix/Linux platforms....

I'm afraid that this just illustrates that you aren't familliar with
all Fortran compilers.  I have worked on many Fortran compilers that
did not support a call exit.  That includes current ones.  I just now
checked to see if support for it had been slipped in sometime when
I didn't notice.  Nope.  The current version of the compiler that
I most often use on Unix/Linux systems doesn't support it.  I didn't
bother to look further.

Quote:
> Else, just wrap it in a module and modify it appropriately when moving to a
> new environment (or use a preprocessor).

Agree.  That's the kind of approach I typically recommend for
nonstandard functionality.  Isolate the system dependence and then
document it.  For some functionalities, the isolation isn't practical,
but it is very much practicall for this one.  A wrapper procedure
is just the thing here.

Except that I specifically would *NOT* name it exit.  When
I wrap non-portable functionality like that, I make sure to not use
names that are commonly used for it by some systems.  The problem is
that if some system happens to implement it slightly differently,
I'm then stuck.

And I'm still not sure that it would actually solve the OP's problem
because I'm not convinced that the program status code is actually
what his interface is expected to be through; the mention of real
values certainly doesn't match thatvery well.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Sun, 29 Apr 2007 08:02:55 GMT  
 Fortran Main Program Return Value

Quote:

> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  What is
> the best way to do this?  Do I need to write a DLL?  Thanks.

As others have explained, the concept of a program returning a
number is mostly if not always limited to the exit code that a
shell script or batch file can use to check the, well, exit
status of the program.

If I understand your question correctly, then:
- I assume that your program gets input from the Oracle system
- It is supposed to compute a result from that input (possibly
  using other input as well from outside the Oracle system,
  like:
  - Oracle tells it what input file to use
  - Your program then reads that input file
- This result must be transferred to the Oracle system

You will have to inspect the documentation on this kind
of communication to and from the Oracle system to make
clear what mechanism is to be used, for instance:
- Your program may simply write a number to "standard output"
  (like: write(*,*) result)
- Your program is supposed to write to a particular file
- Your program is called as a DLL or a shared object/library,
  then the result of the function/subroutine that is the
  starting point for the computation/communication would
  be the way to get the number into the Oracle system.

All this is based on my experience with inter-process
communication and it is quite possible that there are
other mechanisms available.

To conclude, the question to be answered is:
What mechanism is to be used? And the answer must
be somewhere in the Oracle documentation.

Regards,

Arjen



Sun, 29 Apr 2007 16:00:48 GMT  
 Fortran Main Program Return Value

Quote:

> I would like to know how to return value from the main program in
> Fortran.  In C and Java, you can both return a value.  I searched in
> many fortran books and none of the books talked about this.

> My current situation is that our client is using an Oracle system (not
> sure what programming language)  All they want from our Fortran
> program is to do some computation and return a real number.  What is
> the best way to do this?  Do I need to write a DLL?  Thanks.

Standard Fortran does not provide any mechanism to do this, however
many vendor/implementors provide extensions to do so.

You can wrap the exit function in a subroutine (Dont call it exit) and
use that, if your compilier supports it (for future compatibility)

Or you can write the info to a file and have whatever is invoking your
program read the file.



Sun, 29 Apr 2007 22:10:55 GMT  
 Fortran Main Program Return Value

Quote:


>   [about call exit]
>> Of what I know *all* Fortran compilers provide this extension on both
>> Windows and Unix/Linux platforms....

> I'm afraid that this just illustrates that you aren't familliar with
> all Fortran compilers.  I have worked on many Fortran compilers that
> did not support a call exit.  That includes current ones.  I just now
> checked to see if support for it had been slipped in sometime when
> I didn't notice.  Nope.  The current version of the compiler that
> I most often use on Unix/Linux systems doesn't support it.  I didn't
> bother to look further.

Which compiler is that? I also work on Unix/Linux and I would like to avoid
it ;-) I any case the next sentense I think is a vaible solution.

Quote:
>> Else, just wrap it in a module and modify it appropriately when moving to
>> a new environment (or use a preprocessor).

> Agree.  That's the kind of approach I typically recommend for
> nonstandard functionality.  Isolate the system dependence and then
> document it.  For some functionalities, the isolation isn't practical,
> but it is very much practicall for this one.  A wrapper procedure
> is just the thing here.

> Except that I specifically would *NOT* name it exit.  When
I agree with that.
> I wrap non-portable functionality like that, I make sure to not use
> names that are commonly used for it by some systems.  The problem is
> that if some system happens to implement it slightly differently,
> I'm then stuck.

I have created a Unix_SystemCalls.f90 module (actually two: one for
the Fortran compilers I possess for Windows) so that my programs
unchanged compile in both environments.

Quote:
> .............

/Sakis


Tue, 01 May 2007 19:16:25 GMT  
 Fortran Main Program Return Value

Quote:


>   [about call exit]

>>Of what I know *all* Fortran compilers provide this extension on both
>>Windows and Unix/Linux platforms....
> I'm afraid that this just illustrates that you aren't familliar with
> all Fortran compilers.  I have worked on many Fortran compilers that
> did not support a call exit.  That includes current ones.  I just now
> checked to see if support for it had been slipped in sometime when
> I didn't notice.  

At some point in Fortran history was there a zero argument
CALL EXIT?  I have known systems to support it, but I don't
know where it came from.  In some cases it gets around a message
that would be printed by STOP.

-- glen



Tue, 01 May 2007 19:04:37 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Returning Values in Fortran 77

2. reading return-value of C-function in Fortran

3. returning values from FORTRAN with f2py

4. Q: Reading Return Value from AWK Program

5. Help !! RUN external program return value

6. Getting return values from REXX-called C programs

7. Returning values to assembly language program

8. C call, in a Fortran subroutine, within a C main program

9. (Linux ELF) dynamic libf2c.so and non-Fortran main programs

10. How to get the return value for a Spawned program

11. Programs return value from exec

12. return value from Tcl to calling C program

 

 
Powered by phpBB® Forum Software