#! /bin/csh -f
# Last edited on 2001-11-02 11:35:25 by stolfi

set usage = "$0 FIRSTFRAG LASTFRAG FIRSTBAND LASTBAND"

set cmd = $0
echo "=== begin ${cmd:t} ===" 
echo "${cmd:t} $*"

if ( $#argv != 4 ) then
  echo "usage: ${usage}"; exit 1
endif

set firstFrag  = "$1"; shift;
set lastFrag   = "$1"; shift;
set firstBand  = "$1"; shift;
set lastBand   = "$1"; shift;

if ( $#argv != 0 ) then
  echo "usage: ${usage}"; exit 1
endif

set path = ( \
  ${STOLFIHOME}/programs/pm3-1.1.15/THESES/hcgl/1/bin/${PLATFORM} \
  ${cmd:h} \
  ${path} \
)

set curvedir = "data/multiscale"
if ( ! ( -d ${curvedir} ) ) then
  echo 'directory '"${curvedir}"'" does not exist"; exit 1
endif

set frags = ( `list-fragment-numbers` )
echo 'frags = '${frags}

set bands = ( 001 002 004 008 016 032 064 128 256 512 )
echo 'bands = '${bands}

foreach frag ( ${frags} )
  if ( ( ${frag} >= ${firstFrag} ) && ( ${frag} <= ${lastFrag} ) ) then
    foreach band ( ${bands} )
      if ( ( ${band} >= ${firstBand} ) && ( ${band} <= ${lastBand} ) ) then
        
        set fname  = "${curvedir}/${frag}/f${band}"
        echo '=== '"${fname}"'.flc -> '"${fname}"'.{flv,fla}'

        /bin/sh -c "/bin/rm -f ${fname}.{flv,fla}; exit 0"

        if ( -r ${fname}.flc ) then
          nice PZComputeVelAcc \
            -input ${fname} \
            -output ${fname} \
            -velUnit 0.0001 \
            -accUnit 0.000001 \
            -verbose 
        else
          echo "${fname}.flc does not exist, skipped"
        endif
      endif
    end
  endif
end

echo "=== end ${cmd:t} =========" 
