#!/usr/bin/perl

 $proto = "hmm0/proto";
 $hmmdefs ="hmm0/hmmdefs";
 $mono = "monophones0";
 $proto2 = "proto2";
 $count = 0;
 unless (open(MONO, "$mono")) {
   die ("can't open mono");
 }

 open (HMMDEFS, ">$hmmdefs")   || die ("Unable to open hmmdefs file for writing");
 unless (open(PROTO, "$proto")) {
  die ("can't open proto");
 }
 open (PROTO2, ">$proto2")   || die ("Unable to open hmmdefs file for writing");

 while ($line = <PROTO>) {
   chop ($line);
   if ($count < 3) {
    print HMMDEFS "$line\n";
   }
   else {
    if ($count > 3) {
     print PROTO2 "$line\n";
    }
   }
   ++$count;
 }
 close(PROTO2);


 while ($line_phone = <MONO>) {
   chop ($line_phone);
   print HMMDEFS "~h \"";
   print HMMDEFS "$line_phone\"\n";
   unless (open(PROTO2, "$proto2")) {
    die ("can't open proto2");       
   }
   while ($line = <PROTO2>) {
    chop ($line);
    print HMMDEFS "$line\n";
   }
   close (PROTO2);
 }
 unlink ($proto2);
