#! /bin/bash
# Last edited on 2005-09-24 18:13:28 by stolfi


funcs=( \
  f0 f1 f2 f3 f4 \
  f5 f6 f7 f8 \
  fadd \
  fdiv \
  fiamany \
  fmax \
  fmax2 \
  fmul \
  fmul2 \
)

for f in ${funcs[@]}; do 
  cin="junk/${f}-old.c"
  cot="z2f_${f}.c"
  hot="z2f_${f}.h"
  
  # Header file
  /bin/rm -f ${hot}
  
  echo "/* A function to test bivariate zero-finders. */" >> ${hot} 
  echo "/* Last edited on DATE TIME by USER */" >> ${hot}
  echo " " >> ${hot}
  echo "#ifndef z2f_${f}_H" >> ${hot}
  echo "#define z2f_${f}_H" >> ${hot}
  echo " " >> ${hot}
  echo "#include <aa.h>" >> ${hot}
  echo "#include <ia.h>" >> ${hot}
  echo "#include <flt.h>" >> ${hot}
  echo "#include <zeros2fns.h>" >> ${hot}
  echo " " >> ${hot}
  echo "z2f_data_t z2f_${f}_get_data(void);" >> ${hot}
  echo " " >> ${hot}
  echo "#endif" >> ${hot}
  
  # Implementation file: 

  /bin/rm -f ${cot}
  echo "/* See {${hot}}. */" >> ${cot} 
  echo "/* Last edited on DATE TIME by USER */" >> ${cot}
  echo " " >> ${cot}
  echo "#include <${hot}>" >> ${cot}
  echo "#include <aa.h>" >> ${cot}
  echo "#include <ia.h>" >> ${cot}
  echo "#include <flt.h>" >> ${cot}
  echo "#include <zeros2fns.h>" >> ${cot}
  echo " " >> ${cot}
  echo "Float z2f_${f}_eval_flt (Float x, Float y);" >> ${cot}
  echo "Interval z2f_${f}_eval_ia (Interval x, Interval y);" >> ${cot}
  echo "AAP z2f_${f}_eval_aa (AAP x, AAP y);" >> ${cot}
  echo " " >> ${cot}
  cat ${cin} \
    | sed \
        -e 's/aat_ftag/z2f_'"${f}"'_tag/g' \
        -e 's/aat_fname/z2f_'"${f}"'_descr/g' \
        -e 's/aat_fxd/z2f_'"${f}"'_xd/g' \
        -e 's/aat_fyd/z2f_'"${f}"'_yd/g' \
        -e 's/aat_f_/z2f_'"${f}"'_eval_/g' \
        -e 's/aat_/z2f_'"${f}"'_/g' \
    >> ${cot}
  echo " " >> ${cot}
  echo "z2f_data_t z2f_${f}_get_data(void)" >> ${cot}
  echo "  { " >> ${cot}
  echo "    z2f_data_t f;" >> ${cot}
  echo "    f.tag = z2f_${f}_tag;" >> ${cot}
  echo "    f.descr = z2f_${f}_descr;" >> ${cot}
  echo "    f.eval_flt = &z2f_${f}_eval_flt;" >> ${cot}
  echo "    f.eval_ia = &z2f_${f}_eval_ia;" >> ${cot}
  echo "    f.eval_aa = &z2f_${f}_eval_aa;" >> ${cot}
  echo "    f.xd = z2f_${f}_xd;" >> ${cot}
  echo "    f.yd = z2f_${f}_yd;" >> ${cot}
  echo "    return f;" >> ${cot}
  echo "  }" >> ${cot}
  echo " " >> ${cot}
  
  ls -l ${hot} ${cot}
done
