2

Is it possible to get system environment information on Fortran 90 (OpenVMS operating system)? I use compiler VSI Fortran V8.3-104957-50Q83. I won't realize the next C-code on Fortran

char *bind_addr= getenv("MYSQL_TEST_BINDADDR");
Anton Golovenko
  • 634
  • 4
  • 19
  • 1
    Did you try whether `getenv` exists in your compiler? There is nothing standard in Fortran 90, everything is compiler specif, just like your previous question about command line arguments. – Vladimir F Героям слава Oct 07 '20 at 07:30
  • 1
    After checking the documentation of vmssoftware, I'm unable to find any compiler extension that allows you to extract environment variables. It also only supports Fortran 90/95 and not 2003. The latter has the subroutine `GET_ENVIRONMENT_VARIABLE`. However, your compiler does not support Fortran 2003. The only suggestion I might make is an attempt to call the C-function `getenv` directly into Fortran, but that is again a compiler dependent hack. – kvantour Oct 07 '20 at 09:36
  • 2
    Have a look at _Section 10.10_ of the [VSI Fortran for OpenVMS User Manual](https://vmssoftware.com/docs/VSI_FORTRAN_USER.pdf). It explains how you can link a Fortran program with a self written C-library. So you could quickly write a wrapper for `getenv` in C and link it with Fortran according to the procedure defined that document. – kvantour Oct 07 '20 at 13:50

1 Answers1

3

This topic is one in a series of questions on what appears to be a porting effort for an "C" application to Fortran on OpenVMS. In order to provide the best possible answers it may help to know a bit more background - WHY the effort is taking place, WHAT is the source platform?

That said, Environment Variables as most of us know them do NOT exist as such on OpenVMS. OpenVMS DCL SYMBOLS and User/group/system LOGICAL NAMES which can and will be treated as environment variables by support libraries such as available through the C-RTL, Perl and Python.

To define them, one expects a shell (DCL) action selecting either symbols or logical names as the vehicle. Knowing that mechanism the application to be ported may just want to call the native OpenVMS functions to get or set the values (SYS$TRNLNM, LIB$GET_SYMBOL, LIB$SET_SYMBOL).

Writing your own 'my_getenv' wrapper to call the C-RTL provided getenv may be a good solution if you have access to a C compiler.

Another workaround could be to reverse engineer and call the actual C support function (likely called DECC$GETENV - not verified!) this may require some initialization to be called first (again, not verified)

Surely there are more articles on this out there. Google? For some background on symbols and logicals the documentation and FAQ should help. For example - http://www.hoffmanlabs.org/vmsfaq/vmsfaq_012.html

Good luck, Hein.

Hein
  • 1,453
  • 8
  • 8