

if test $# -lt 1 ; then

echo "usage: `basename $0` file1 <file2 ...>"
cat <<BLOCK

### example of input python file ( G : gain, P: phase, nu:tune )
#
# turnL = [ 1,2,3,4,5,6,7,8,9,10,11,12 ] # previous turn number of input (this case, 1 to 12-th previous turns are input )
# tune0 = {"nu":0,    "gain":0,              "order":0 } # constraint: dG/dnu = 0  
# tune1 = {"nu":0.15, "gain":1, "phase":-90, "order":2 } # constraint: dG/dnu=d^2 G/dnu^2=0 and dP/dnu=d^2P/dnu^2=0  
# tuneL = [ tune0, tune1 ]                               # list of tune data
#
###--- examples of definition of tune parameters
#   tune1 = {"nu":0.15,"gain":1,"phase":-90,"order_phase":2,"order_gain":0 }
#     with the constraints d(phase)/dnu = d^2(phase)/dnu^2 = 0
#
#   tune1 = {"nu":0.15, "gain":1, "phase":-90, "order_phase":2, "order_gain":[1,2]} 
#   tune1 = {"nu":0.15, "gain":1, "phase":-90, "order_phase":2, "order_gain":2 } 
#     with the constraints d(phase)/dnu = d^2(phase)/dnu^2 = d(gain)/dnu = d^2(gain)/dnu^2=0
#
# Three are the same input parameters with constraint ( For backward compatibility )
#   tune1 = {"nu":0.15, "gain":1, "phase":-90, "order":2 }
#     is the same as
#   tune1 = {"nu":0.15, "gain":1, "phase":-90, "order_phase":2, "order_gain":2 }    
#     with the constraints d(gain)/dnu = d^2 (gain)/dnu^2 = 0 = d(phase)/dnu = d^2(phase)/dnu^2 = 0
#  
#################
# parameters of each dictionary are
#  "nu"     : target tune
#  "gain"   : gain at target tune 
#  "phase"  : phase at target tune in degree 
#  "order_phase", "order" : order of Tylor expansion for tune shift around target tune for phase response
#  "order_gain",  "order" : order of Tylor expansion for tune shift around target tune for gain response 
# for "order, " 
#   "order":0 , just a band pass filter 
#          :1 , flat region around target tune 
#          :2 , wider flat region around target tune 
#            ...
#  for nu=0, no phase constraint is necessary 
##################################
BLOCK

fi

EXE=FIR_coef.py

for FILE in $* ; do
    echo $FILE
    FILE_OK=`grep -v "^#" $FILE | grep '{' | wc -l`
    if test $FILE_OK -eq 0 ; then
       echo "$FILE is not input file"
       continue 
    fi
    NAME=`echo $FILE | sed 's/.in$//g' | sed 's/.py$//g'`
    COEF=${NAME}.coef
    FIR=${NAME}.fir
    POW=${NAME}.power
    echo "$EXE   $FILE >  $COEF"
          $EXE   $FILE >  $COEF
    grep -v "#" $COEF  >  $FIR       
    grep power_pass $COEF | grep '=' > $POW
done

