#!/bin/csh -v

set reg_factor =  1
set sigma_tresh = 3
set min_value = 0
set scale = 0
set min_scale = 0
set max_scale = 0

    set filt_list = `'ls' list_*out | awk '{print substr($1,6,5)}' | sort -u`
    foreach filt ($filt_list)
      set list_$filt =
      set list_temp =
      set filt_old =
    end
    set crlist = 0
    set list_cr =
    set nimage = 0
    set ncr = 0
    foreach fich (list_*out)
      set filt = `echo $fich | awk '{print substr($1,6,5)}'`
      if ("$filt_old" != "$filt" || $nimage > 1) then
       if ( $crlist > 0 ) then
        if ($ncr <= 2 ) then
         set num = 1
        else if ($ncr > 2 ) then
         set num = 2
        else if ($ncr > 4) then
         set num = 3
        endif
  #set reg_factor = 3
        while ($num > 0)
          echo "crmask $reg_factor $sigma_tresh $min_value $list_tmp\n"  \
               |& tee -a test.out

#          nice crmask $reg_factor $sigma_tresh \
#               $min_value $list_tmp|& tee -a $filecsh_out

          @ num = $num - 1
        end
       endif
       set list_tmp =
       set ncr = 0
       @ crlist = $crlist + 1
      endif
      set nb_img = `cat $fich | awk '{print $1}'`
      set nimage = $#nb_img
      @ ncr = $ncr + $nimage
      foreach img (`cat $fich | awk '{print $1}'`)
         set dx = `grep $img $fich|awk '{print ($2)}'`
         set dy = `grep $img $fich|awk '{print ($3)}'`
         set list_tmp = "$list_tmp $img $scale $min_scale $max_scale $dx $dy"
      end
      set list_cr$crlist = "$list_tmp"
      set list_cr = "$list_cr list_cr$crlist"

      set list_$filt = "$list_tmp"
      set filt_old = $filt
      echo $list_temp
    end

