| 1 | #! /bin/bash |
|---|
| 2 | |
|---|
| 3 | ### |
|---|
| 4 | ### fmcd_gfortran.sh |
|---|
| 5 | ### |
|---|
| 6 | ### ---> This should be used to make MCD fortran stuff directly accessible in python |
|---|
| 7 | ### ---> This script is for gfortran, but it is easy to adapt to your other compilers |
|---|
| 8 | ### ---> A file fmcd.so should be created |
|---|
| 9 | ### ---> See mcd.py for use in python. Very easy! |
|---|
| 10 | ### |
|---|
| 11 | ### AS. 17/04/2012. |
|---|
| 12 | ### |
|---|
| 13 | |
|---|
| 14 | ### LINKS |
|---|
| 15 | NETCDF=/home/marshttp/NETCDF/netcdf64-4.0.1_gfortran_fPIC/ |
|---|
| 16 | wheremcd=/home/marshttp/MCD_v5.1//mcd/ |
|---|
| 17 | num="5" |
|---|
| 18 | #num="5_dev" |
|---|
| 19 | |
|---|
| 20 | ### LOG FILE |
|---|
| 21 | touch fmcd$num.log |
|---|
| 22 | \rm fmcd$num.log |
|---|
| 23 | |
|---|
| 24 | ### COPY/PREPARE SOURCES |
|---|
| 25 | ### perform changes that makes f2py not to fail |
|---|
| 26 | sed s/"\!\!'"/"'"/g $wheremcd/call_mcd.F | sed s/"\!'"/"'"/g | sed s/"\!"/"\n\!"/g > tmp.call_mcd.F |
|---|
| 27 | sed s/"\!\!'"/"'"/g $wheremcd/julian.F | sed s/"\!'"/"'"/g | sed s/"\!"/"\n\!"/g > tmp.julian.F |
|---|
| 28 | sed s/"\!\!'"/"'"/g $wheremcd/heights.F | sed s/"\!'"/"'"/g | sed s/"\!"/"\n\!"/g > tmp.heights.F |
|---|
| 29 | sed s/"\!\!'"/"'"/g $wheremcd/constants_mcd.inc | sed s/"\!'"/"'"/g | sed s/"\!"/"\n\!"/g > constants_mcd.inc |
|---|
| 30 | |
|---|
| 31 | ### BUILD THROUGH f2py WHAT IS NECESSARY TO CREATE THE PYTHON FUNCTIONS |
|---|
| 32 | touch fmcd$num.pyf |
|---|
| 33 | \rm fmcd$num.pyf |
|---|
| 34 | f2py -h fmcd$num.pyf -m fmcd$num tmp.call_mcd.F tmp.julian.F tmp.heights.F > fmcd$num.log 2>&1 |
|---|
| 35 | |
|---|
| 36 | #### IMPORTANT: we teach f2py about variables in the call_mcd subroutines which are intended to be out |
|---|
| 37 | sed s/"real :: pres"/"real, intent(out) :: pres"/g fmcd$num.pyf | \ |
|---|
| 38 | sed s/"real :: dens"/"real, intent(out) :: dens"/g | \ |
|---|
| 39 | sed s/"real :: temp"/"real, intent(out) :: temp"/g | \ |
|---|
| 40 | sed s/"real :: zonwind"/"real, intent(out) :: zonwind"/g | \ |
|---|
| 41 | sed s/"real :: merwind"/"real, intent(out) :: merwind"/g | \ |
|---|
| 42 | sed s/"real dimension(5) :: meanvar"/"real dimension(5),intent(out) :: meanvar"/g | \ |
|---|
| 43 | sed s/"real dimension(100) :: extvar"/"real dimension(100),intent(out) :: extvar"/g | \ |
|---|
| 44 | sed s/"real :: seedout"/"real, intent(out) :: seedout"/g | \ |
|---|
| 45 | sed s/"integer :: ier"/"integer, intent(out) :: ier"/g > fmcd$num.pyf.modif |
|---|
| 46 | mv fmcd$num.pyf.modif fmcd$num.pyf |
|---|
| 47 | |
|---|
| 48 | ### BUILD |
|---|
| 49 | f2py -c fmcd$num.pyf tmp.call_mcd.F tmp.julian.F tmp.heights.F --fcompiler=gnu95 \ |
|---|
| 50 | -L$NETCDF/lib -lnetcdf \ |
|---|
| 51 | -lm -I$NETCDF/include \ |
|---|
| 52 | --f90flags="-fPIC" \ |
|---|
| 53 | --f77flags="-fPIC" \ |
|---|
| 54 | --verbose \ |
|---|
| 55 | > fmcd$num.log 2>&1 |
|---|
| 56 | # --include-paths $NETCDF/include:$NETCDF/lib \ ---> makes it fail |
|---|
| 57 | |
|---|
| 58 | ### CLEAN THE PLACE |
|---|
| 59 | \rm tmp.call_mcd.F tmp.julian.F tmp.heights.F constants_mcd.inc |
|---|