#!/bin/csh
#++++++++++++++++
#.IDENTIFICATION make_par
#.LANGUAGE       C-shell
#.AUTHOR         Daniel Egret [IPAC/CDS]
#.ENVIRONMENT    
#.KEYWORDS       
#.VERSION  1.0   26-May-2002
#.PURPOSE        Generate the files for UCDs
#.COMMENTS       
#----------------
#  newcats: re-writes the html files of catalogues and tables

######################################################################
#	Create the table Catid Tabid name unit UCD Explanation
######################################################################
sqsh -Uasu -Pasu4VizieR << ====getTSV
\set bcp_colsep='	'
\go
\set colsep='	'
\go
Select METAfam.name, METAfam.explain, usage=count(*) 
  from METAfam, METAcol
 Where METAcol.famid = METAfam.famid
 group by METAfam.name
\go -m bcp | sed 's/\|\$//' > metafam.tsv
Select tab=METAtab.name, col=METAcol.name, unit, 
  ucd=METAfam.name, METAcol.explain
  into #u
  From METAcol, METAfam, METAtab
 Where METAcol.famid = METAfam.famid
   and METAcol.catid = METAtab.catid
   and METAcol.tabid = METAtab.tabid
go
Update #u set unit = "---" where unit = ""
go
Select * from #u
\go -m bcp | sed 's/\|\$//' > metacol.tsv
====getTSV

### Generate the Indexes
echo "....Generating the Indexes..."
parfile -d -i1 -i- -lw 8 metacol.tsv
parfile -d -i1 -i- -lw 8 metafam.tsv

### Generate the UCD counts
rm -f metacol.ucd
acut -d -f4,1 metacol.tsv | rev | acut -d/ -f2- | rev \
| sort | acut -d -f1 | uniq -c > metacol.ucd
