Our program demonstrates how to work with environment variables in Co-array Fortran. Environment variables are a universal mechanism for conveying configuration information to programs. Let’s look at how to set, get, and list environment variables.
To compile and run the program:
The list of keys in the environment will depend on your particular machine.
If we set BAR in the environment first, the running program picks that value up:
Note that Co-array Fortran doesn’t have a direct equivalent to Go’s os.Environ() function. Instead, we’ve used a loop with get_environment_variable to retrieve all environment variables. Also, string handling in Fortran is different from Go, so we’ve had to use allocatable character variables and handle string lengths explicitly.