#csh -x
#
#  script for putting buiding an external function or
#  procedure for linking into NCL
#

#set verbose

if ($#argv == 0) then
     echo "Usage:  make_ncl_fortran "
     exit 1
endif

echo " build for COMPAQ alpha, DIG 5. "

echo " construct C wrapper for fortran code... "
wrapit77 <  $argv[1].f > $argv[1]_W.c

if ($status == 0) then
     echo " wrapper generated "
else
     echo " return status non-zero for wrapper generation, error exit "
     exit 1
endif

echo " compile C wrapper... "
nhlcc -c $argv[1]_W.c

if ($status == 0) then
     echo " C wrapper compiled "
else
     echo " return status non-zero for C wrapper compile, error exit "
     exit 1
endif


echo " compile fortran routine... "

nhlf77 -c $argv[1].f
if ($status == 0) then
     echo " fortran routine compiled "
else
     echo " return status non-zero for fortran compile, error exit "
     exit 1
endif

echo " create shared library... "

ld -shared -o $argv[1].so $argv[1].o $argv[1]_W.o -lc -lfor -lm

if ($status == 0) then
     echo " shared library created "
     echo " library is " $argv[1].so 
     exit 0
else
     echo " error in load, error exit "
     exit 1
endif

