#!/bin/bash


f90=f90
replay_comment="replay automatic include"
if [ $# = 0 ] ; then
   \rm -f dump_replay*.h dump_param.h dump_ini.h  input tmp_get_subroutine_arg  tmp_include_line  tmp_include_line*  tmp_include_line*_cpp  tmp_include_line*

   for file in `grep "$replay_comment" *f90 *F90 | cut -d: -f1` ; do
      sed -i"" -e "/$replay_comment/d" $file
   done
   cat > call_param_replay.${f90} <<...eod
   subroutine call_param_replay(ngrid,nlay)
   integer,intent(in) :: ngrid,nlay
   stop 'In call_param_replay : You should run replay_equip.sh before runing replay[13]d'
   return
   end
...eod
   cat > call_ini_replay.${f90} <<...eod
   subroutine call_ini_replay
   stop 'In call_ini_replay : You should run replay_equip.sh before runing replay[13]d'
   return
   end
...eod

else
   for file in $* ; do
       list_include=`grep $replay_comment $file | grep include | cut -d\" -f2`
       echo removing $list_include
       \rm -f $list_include
       \rm -f dump_replay_`basename $file .${f90}`_*h
       sed -i'' -e "/$replay_comment/d" $file
   done
fi
