added source code
[unres.git] / source / wham / src / mygetenv.F
1       subroutine mygetenv(string,var)
2 C
3 C Version 1.0
4 C
5 C This subroutine passes the environmental variables to FORTRAN program.
6 C If the flags -DMYGETENV and -DMPI are not for compilation, it calls the
7 C standard FORTRAN GETENV subroutine. If both flags are set, the subroutine
8 C reads the environmental variables from $HOME/.env
9 C
10 C Usage: As for the standard FORTRAN GETENV subroutine.
11
12 C Purpose: some versions/installations of MPI do not transfer the environmental
13 C variables to slave processors, if these variables are set in the shell script
14 C from which mpirun is called.
15 C
16 C A.Liwo, 7/29/01
17 C
18       implicit none
19       character*(*) string,var
20 #if defined(MYGETENV) && defined(MPI) 
21       include "DIMENSIONS.ZSCOPT"
22       include "mpif.h"
23       include "COMMON.MPI"
24       character*360 ucase
25       external ucase
26       character*360 string1(360),karta
27       character*240 home
28       integer i,n,ilen
29       external ilen
30       call getenv("HOME",home)
31       open(99,file=home(:ilen(home))//"/.env",status="OLD",err=112)
32       do while (.true.)
33         read (99,end=111,err=111,'(a)') karta
34         do i=1,80
35           string1(i)=" "
36         enddo
37         call split_string(karta,string1,80,n)
38         if (ucase(string1(1)(:ilen(string1(1)))).eq."SETENV" .and.
39      &   string1(2)(:ilen(string1(2))).eq.string(:ilen(string)) ) then
40            var=string1(3)
41            print *,"Processor",me,": ",var(:ilen(var)),
42      &      " assigned to ",string(:ilen(string))
43            close(99)
44            return
45         endif  
46       enddo    
47  111  print *,"Environment variable ",string(:ilen(string))," not set."
48       close(99)
49       return
50  112  print *,"Error opening environment file!"
51 #else
52       call getenv(string,var)
53 #endif
54       return
55       end