#!/bin/csh -f

#> This script is for setting up compilation and runtime environments
#> at EPA on Sol and Atmos.
 source /etc/profile.d/modules.csh 
 module purge
 module load modules 

#> Compiler settings
 switch ( $compiler )

    #> Intel fortran compiler......................................................
    case intel:
    
      switch ( $compilerVrsn )
        
         case 13.1:

            module load  intel/13.1  netcdf-4.3.1/intel-13.1  impi/4.1.0.024 ioapi-3.1/intel-13.1
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /usr/local/apps/ioapi-3.1/intel-13.1/Linux2_x86_64ifort #> I/O API precompiled modules
            setenv IOAPI_INCL_DIR  /usr/local/apps/ioapi-3.1/intel-13.1/ioapi/fixed_src    #> I/O API include header files
            setenv IOAPI_LIB_DIR   /usr/local/apps/ioapi-3.1/intel-13.1/lib                #> I/O API libraries
            setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.3.1/intel-13.1/lib             #> netCDF directory path
            setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.3.1/intel-13.1/include         #> netCDF directory path
            setenv MPI_LIB_DIR     /usr/local/apps/intel/impi/4.1.0.024/intel64            #> MPI directory path

            breaksw
       
         case 17.0:

            module load  intel/17.0.3  netcdf-4.4.1/intel-17.0  intelmpi/2017.2.191 pnetcdf-1.8.1/intel-17.0 #ioapi-3.1/intel-13.1
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/Linux2_x86_64ifort #> I/O API precompiled modules
            setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/ioapi/fixed_src    #> I/O API include header files
            setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/Linux2_x86_64ifort #> I/O API libraries
            setenv NETCDF_LIB_DIR  /home/wdx/lib_sol/x86_64/ifc-17.0.3/netcdf-4.4.1/lib             #> netCDF directory path
            setenv NETCDF_INCL_DIR /home/wdx/lib_sol/x86_64/ifc-17.0.3/netcdf-4.4.1/include         #> netCDF directory path
            setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/ifc-17.0.3/mpich                        #> MPI directory path

            breaksw
    
         default: 
            if ($CLUSTERNAME == "sol") then
              echo "No compiler version given. Sol system Detected. Assume Intel 13.1"
              setenv compilerVrsn 13.1
              module load  intel/13.1  netcdf-4.3.1/intel-13.1  impi/4.1.0.024 ioapi-3.1/intel-13.1
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /usr/local/apps/ioapi-3.1/intel-13.1/Linux2_x86_64ifort #> I/O API precompiled modules
              setenv IOAPI_INCL_DIR  /usr/local/apps/ioapi-3.1/intel-13.1/ioapi/fixed_src    #> I/O API include header files
              setenv IOAPI_LIB_DIR   /usr/local/apps/ioapi-3.1/intel-13.1/lib                #> I/O API libraries
              setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.3.1/intel-13.1/lib             #> netCDF directory path
              setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.3.1/intel-13.1/include         #> netCDF directory path
              setenv MPI_LIB_DIR     /usr/local/apps/intel/impi/4.1.0.024/intel64            #> MPI directory path
 
              breaksw
            else if ($CLUSTERNAME == "atmos") then
              echo "No compiler version given. Atmos system Detected. Assume Intel 17.0"
              setenv compilerVrsn 17.0
              module load  intel/17.0.3  netcdf-4.4.1/intel-17.0  intelmpi/2017.2.191 pnetcdf-1.8.1/intel-17.0 #ioapi-3.1/intel-13.1
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/Linux2_x86_64ifort #> I/O API precompiled modules
              setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/ioapi/fixed_src    #> I/O API include header files
              setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/ifc-17.0.3/ioapi_3.1/Linux2_x86_64ifort #> I/O API libraries
              setenv NETCDF_LIB_DIR  /home/wdx/lib_sol/x86_64/ifc-17.0.3/netcdf-4.4.1/lib             #> netCDF directory path
              setenv NETCDF_INCL_DIR /home/wdx/lib_sol/x86_64/ifc-17.0.3/netcdf-4.4.1/include         #> netCDF directory path
              setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/ifc-17.0.3/mpich                        #> MPI directory path

              breaksw
            endif
    
      endsw

      breaksw
    
#>  Portland Group fortran compiler.............................................
    case pgi:
 
      switch ( $compilerVrsn )
        
         case 15.3:

            module load pgi/15.3  openmpi-1.8.6/pgi-15.3  netcdf-4.3.3/pgi-15.3 ioapi-3.1_150122/pgi-15.3
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
            setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/ioapi/fixed_src  #> I/O API directory path
            setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
            setenv NETCDF_LIB_DIR  /home/wdx/lib_sol/x86_64/pgi-15.3/netcdf/lib                 #> netCDF directory path
            setenv NETCDF_INCL_DIR /home/wdx/lib_sol/x86_64/pgi-15.3/netcdf/include             #> netCDF directory path
            setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/pgi-15.3/mpich                      #> MPI directory path

            breaksw
         
         case 17.4:

            module load pgi/17.4  openmpi-2.1.0/pgi-17.4  netcdf-4.4.1/pgi-17.4 #ioapi-3.1_150122/pgi-15.3
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
            setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/ioapi/fixed_src  #> I/O API directory path
            setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
            setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.4.1/pgi-17.4/lib                    #> netCDF directory path
            setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.4.1/pgi-17.4/include                #> netCDF directory path
            setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/pgi-17.4/mpich                      #> MPI directory path

            breaksw
    
         default: 
            if ($CLUSTERNAME == "sol") then
              echo "No compiler version given. Assume PGI 15.3"
              setenv compilerVrsn 15.3
              module load pgi/15.3  openmpi-1.8.6/pgi-15.3  netcdf-4.3.3/pgi-15.3 ioapi-3.1_150122/pgi-15.3
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
              setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/ioapi/fixed_src  #> I/O API directory path
              setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/pgi-15.3/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
              setenv NETCDF_LIB_DIR  /home/wdx/lib_sol/x86_64/pgi-15.3/netcdf/lib                 #> netCDF directory path
              setenv NETCDF_INCL_DIR /home/wdx/lib_sol/x86_64/pgi-15.3/netcdf/include             #> netCDF directory path
              setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/pgi-15.3/mpich                      #> MPI directory path

              breaksw
            else if ($CLUSTERNAME == "atmos") then
              echo "No compiler version given. Atmos system Detected. Assume PGI 17.4"
              setenv compilerVrsn 17.4
              module load pgi/17.4  openmpi-2.1.0/pgi-17.4  netcdf-4.4.1/pgi-17.4 #ioapi-3.1_150122/pgi-15.3
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
              setenv IOAPI_INCL_DIR  /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/ioapi/fixed_src  #> I/O API directory path
              setenv IOAPI_LIB_DIR   /home/wdx/lib_sol/x86_64/pgi-17.4/ioapi_3.1/Linux2_x86_64pg  #> I/O API directory path
              setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.4.1/pgi-17.4/lib                 #> netCDF directory path
              setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.4.1/pgi-17.4/include                #> netCDF directory path
              setenv MPI_LIB_DIR     /home/wdx/lib_sol/x86_64/pgi-17.4/mpich                      #> MPI directory path

              breaksw
    
            endif
      endsw
 
      breaksw
    
#>  gfortran compiler............................................................
    case gcc:
 
      switch ( $compilerVrsn )
        
         case 4.9:

            module load  gcc/4.9.1  openmpi-1.8.1/gcc-4.9.1  netcdf-4.4.1/gcc-4.4.7  ioapi-3.1/gcc-4.4.7
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /home/wdx/lib/x86_64/gcc/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
            setenv IOAPI_INCL_DIR  /home/wdx/lib/x86_64/gcc/ioapi_3.1/ioapi/fixed_src     #> I/O API directory path
            setenv IOAPI_LIB_DIR   /home/wdx/lib/x86_64/gcc/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
            setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.4.1/gcc-4.4.7/lib             #> netCDF directory path
            setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.4.1/gcc-4.4.7/include         #> netCDF directory path
            setenv MPI_LIB_DIR     /usr/local/apps/openmpi-1.8.1/gcc-4.9.1                #> MPI directory path

            breaksw
         
         case 6.1:

            # gcc/4.8.5 is available by default
            module load  gcc/6.1.0 openmpi-2.1.0/gcc-4.8.5  netcdf-4.4.1/gcc-4.8.5  #ioapi-3.1/gcc-4.4.7
    
            #> I/O API, netCDF, and MPI library locations
            setenv IOAPI_MOD_DIR   /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
            setenv IOAPI_INCL_DIR  /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/ioapi/fixed_src     #> I/O API directory path
            setenv IOAPI_LIB_DIR   /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
            setenv NETCDF_LIB_DIR  /home/wdx/lib/x86_64/gcc-6.1/netcdf/lib                    #> netCDF directory path
            setenv NETCDF_INCL_DIR /home/wdx/lib/x86_64/gcc-6.1/netcdf/include                #> netCDF directory path
            setenv MPI_LIB_DIR     /home/wdx/lib/x86_64/gcc-6.1/mpich                         #> MPI directory path

            breaksw
    
         default: 
            if ($CLUSTERNAME == "sol") then
              echo "No compiler version given. Assume GCC 4.9"
              setenv compilerVrsn 4.9
              module load  gcc/4.9.1  openmpi-1.8.1/gcc-4.9.1  netcdf-4.4.1/gcc-4.4.7  ioapi-3.1/gcc-4.4.7
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /home/wdx/lib/x86_64/gcc/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
              setenv IOAPI_INCL_DIR  /home/wdx/lib/x86_64/gcc/ioapi_3.1/ioapi/fixed_src     #> I/O API directory path
              setenv IOAPI_LIB_DIR   /home/wdx/lib/x86_64/gcc/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
              setenv NETCDF_LIB_DIR  /usr/local/apps/netcdf-4.4.1/gcc-4.4.7/lib             #> netCDF directory path
              setenv NETCDF_INCL_DIR /usr/local/apps/netcdf-4.4.1/gcc-4.4.7/include         #> netCDF directory path
              setenv MPI_LIB_DIR     /usr/local/apps/openmpi-1.8.1/gcc-4.9.1                #> MPI directory path

              breaksw
            else if ($CLUSTERNAME == "atmos") then
              echo "No compiler version given. Atmos system Detected. Assume GCC 6.1"
              setenv compilerVrsn 6.1

              # gcc/4.8.5 is available by default
              module load  gcc/6.1.0 openmpi-2.1.0/gcc-4.8.5  netcdf-4.4.1/gcc-4.8.5  #ioapi-3.1/gcc-4.4.7
    
              #> I/O API, netCDF, and MPI library locations
              setenv IOAPI_MOD_DIR   /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
              setenv IOAPI_INCL_DIR  /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/ioapi/fixed_src     #> I/O API directory path
              setenv IOAPI_LIB_DIR   /home/wdx/lib/x86_64/gcc-6.1/ioapi_3.1/Linux2_x86_64gfort  #> I/O API directory path
              setenv NETCDF_LIB_DIR  /home/wdx/lib/x86_64/gcc-6.1/netcdf/lib                    #> netCDF directory path
              setenv NETCDF_INCL_DIR /home/wdx/lib/x86_64/gcc-6.1/netcdf/include                #> netCDF directory path
              setenv MPI_LIB_DIR     /home/wdx/lib/x86_64/gcc-6.1/mpich                         #> MPI directory path

              breaksw
    
            endif
      endsw
  
      breaksw

    default:
        echo "*** Compiler $compiler not found"
        exit(2)
        breaksw

 endsw

#> Load Allinea Modules for Debugging and Profiling
 module load allinea
