#!/bin/csh -f

# create the links needed to expose a specific catalog to the distribution server

# general locations
set wwwroot = /data/ippc11.0/dvodist/www-root
set catroot = /data/ipp064.0/eugene/refcat.20120202/catdir.syn.test.v1

set catdir = catdir.syn.test
set cattgt = $wwwroot/$catdir

set nlist = (n0000 n0730 n1500 n2230 n3000 n3730 n4500 n5230 n6000 n6730 n7500 n8230)
set slist = (s0000 s0730 s1500 s2230 s3000 s3730 s4500 s5230 s6000 s6730 s7500 s8230)

# top-level files
mkdir -p $cattgt
foreach file (HostTable.dat Images.dat Photcodes.dat SkyTable.fits flatcorr.fits)
  ln -s $catroot/$file $cattgt
end

# make DEC directories
foreach dir ($nlist $slist)
  mkdir $cattgt/$dir
end

# link all files from all hostdirs into all DEC dirs
if (-e $cattgt/HostTable.dat) then
  foreach hostdir (`grep -v \# $cattgt/HostTable.dat | awk '{print $3}'`)
    echo $hostdir
    foreach dir ($nlist $slist)
      ln -s $hostdir/$dir/*.cpt $cattgt/$dir
      ln -s $hostdir/$dir/*.cpm $cattgt/$dir
      ln -s $hostdir/$dir/*.cps $cattgt/$dir
      ln -s $hostdir/$dir/*.cpn $cattgt/$dir
    end
  end
else
  set hostdir = $catroot
  echo $hostdir
  foreach dir ($nlist $slist)
    ln -s $hostdir/$dir/*.cpt $cattgt/$dir
    ln -s $hostdir/$dir/*.cpm $cattgt/$dir
    ln -s $hostdir/$dir/*.cps $cattgt/$dir
    ln -s $hostdir/$dir/*.cpn $cattgt/$dir
  end
endif
