#!/bin/csh -f

@ nmax = $#argv

set HISTORYRC = $argv[1]
set     COLLS = ''
@ n = 1
while( $n < $nmax )
      @ m = $n + 1
set     COLLS = `echo $COLLS $argv[$m]`
      @ n = $n + 1
end

if( .$COLLS[1] == . ) then
     set collections = `$GEOSUTIL/post/get_streams $HISTORYRC`
else
     set collections = `echo $COLLS`
endif

# Find Archive Template
# ---------------------
set archives = ''

if( .$COLLS[1] == . ) then
   foreach collection ($collections)
                             set archive  = `grep $collection.archive: $HISTORYRC | cut -d "'" -f2`
      if( ."$archive" == . ) set archive  =       $collection
                             set archives = `echo $archives $archive`
   end
else
   foreach COLL ($COLLS)
   foreach collection ($collections)
      if( .$COLL == . | .$COLL == .$collection ) then
                             set archive  = `grep $collection.archive: $HISTORYRC | cut -d "'" -f2`
      if( ."$archive" == . ) set archive  =       $collection
                             set archives = `echo $archives $archive`
      endif
   end
   end
endif

#set  ncolls  = $#collections
#echo NCOLLS: $ncolls
#if( $ncolls != 0 ) then
#  @ n = 1
#    while( $n <= $ncolls ) 
#    echo $collections[$n] $archives[$n]
#  @ n = $n + 1
#    end
#endif

echo $archives
