cd $DATADIR/calcu
hdsort /IHD/calcu/calcu h00: d00
exit
 | awk -F: ' {
x[$1]=x[$1]""$2
}
END { for (i in x ) if (x[i]!="") print i":"x[i] } ' > $t3
awk -F: ' BEGIN { h=0;d=0
getline
}
FILENAME == ARGV[1] { 
	if ($1=="H")
	{
		x="h"
		if ($4+0==30) c[$7]=sprintf ("%s%.2d",x,h)
		v[$2]=sprintf ("%s%.2d",x,h)
		h++
	}
	if ($1=="D")
	{
		x="d"
		if ($4+0==30) c[$7]=sprintf ("%s%.2d",x,d)
		v[$2]=sprintf ("%s%.2d",x,d)
		d++
	}

	next
}

{
	for (j in c) if ( $1==j)
	{
		zz=$2
		l=length(zz)
		for (i in v)
		{
			
			while (x=index(zz,i))
			zz=substr(zz,1,x-1)""v[i]""substr(zz,x+length(i))
		}
		x=index(zz,"      ")
		if (x) zz=substr(zz,1,x-1)
		print c[j]""zz
	}
} ' $t $t3 >$file.c0
r1=$t.r1
r2=$t.r2
x1=$t.x1
x2=$t.x2
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\\r
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]
dd=0
z=rc
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
