#! /bin/csh -f

@ i = 5325

while ($i <= 5385)
  set magdir = /mag/fd_M_96m_01d.00$i/
  @ six = `time_index -6 day=$i`
  @ last_six = $six + 3
  @ j = $six
  while ( $j <= $last_six )
    mkdir fd_Mag_remap_small_01d.00$j
    if ( $j == $six ) then
      foreach file ( $magdir/fd_M_96m_01d.$i.0000.fits $magdir/fd_M_96m_01d.$i.0001.fits $magdir/fd_M_96m_01d.$i.0002.fits $magdir/fd_M_96m_01d.$i.0003.fits )
        cp $file fd_Mag_remap_small_01d.00$j/
      end
    else if ( $j == $six + 1 ) then
      foreach file ( $magdir/fd_M_96m_01d.$i.0004.fits $magdir/fd_M_96m_01d.$i.0005.fits $magdir/fd_M_96m_01d.$i.0006.fits $magdir/fd_M_96m_01d.$i.0007.fits )
        cp $file fd_Mag_remap_small_01d.00$j/
      end
    else if ( $j == $six + 2 ) then
      foreach file ( $magdir/fd_M_96m_01d.$i.0008.fits $magdir/fd_M_96m_01d.$i.0009.fits $magdir/fd_M_96m_01d.$i.0010.fits $magdir/fd_M_96m_01d.$i.0011.fits )
        cp $file fd_Mag_remap_small_01d.00$j/
      end
    else if ( $j == $six + 3 ) then
      foreach file ( $magdir/fd_M_96m_01d.$i.0012.fits $magdir/fd_M_96m_01d.$i.0013.fits $magdir/fd_M_96m_01d.$i.0014.fits )
        cp $file fd_Mag_remap_small_01d.00$j/
      end
    endif 
    @ j++
  end
  @ i++
end  
    
