APPLDIR=/ctn
DATADIR=/usr/ctn
t=/tmp/t
r1=$t.r1
r2=$t.r2
x1=$t.x1
x2=$t.x2
dir=artic
cat $APPLDIR/$dir/$dir.t[01] > $x1
cat $APPLDIR/$dir.x/$dir.t[01] > $x2
par=`awk -F: ' BEGIN {getline 
getline
printf "h%.2d",h++
j=0;
}
FILENAME == ARGV[1] && ($3+0<30 ||$3+0>49) {
printf ": h%.2d",h++
}
FILENAME == ARGV[2] && ($3+0<30 ||$3+0>49) {
printf ": d%.2d",d++
} ' $APPLDIR/$dir.x/*t[01] `
per=`awk -F: ' BEGIN {getline 
r=$1
}
FILENAME == ARGV[1] && ($3+0<30 ||$3+0>49) {h++}
FILENAME == ARGV[2] && ($3+0<30 ||$3+0>49) {d++}
END { printf "%.2d:%.2d:%.2d\n",h,r,d } ' $APPLDIR/$dir/*t[01] `
echo $par $per
cd $DATADIR/$dir
hdsort $APPLDIR/$dir.x/$dir $par >$r1
awk -F: ' BEGIN { j=0 
k=1
getline
}
FILENAME == ARGV[1] && ($3+0<30 ||$3+0>49) {
hact[j]=$1
frm[j]=sprintf ("%%-%d.%ds:",$2,$2)
j++
next
}
k==1 && FILENAME != ARGV[1] { getline }
FILENAME == ARGV[2] && ($3+0<30 ||$3+0>49) {
hold[$1]=k++
next
}
FILENAME == ARGV[3] {
	for (i=0;i<j;i++) if (hold[hact[i]]+0) printf frm[i],$hold[hact[i]]
		else  printf frm[i],""
	print ""
} ' $x1 $x2 $r1 >$r2
cd $DATADIR/$dir
echo Z | awk -F: ' BEGIN { split ("'"$per"'",p)
ant=" "
nh=p[1]+1
rd=nh+p[3]
rc=p[2]
print "nh="nh,"rd="rd,"rc="rc
dd=0
z=rc
hh=0
hh= -1
}
$1 != ant {
for (i=z;i<rc;i++) printf "-00001" >"HEAD"
	if (hh > -1) print"" >"HEAD"
	hh++
if ($1=="Z") exit

for (i=1;i<nh;i++) printf "%s",$i >"HEAD"
	z=0
}
{ ant=$1 }
rc != 0 {
	printf "%.6d",dd++ >"HEAD"
	for (i=nh;i<rd;i++)
		printf "%s",$i >"DOC"
	printf "%5d\n",hh >"DOC"
	z++
}
END {
	printf "%5d %6d",hh,dd >"INFO"
} ' $r2 -
#rm -r $APPLDIR/$dir.x
