#!/usr/bin/perl -w
#
# Zsolt's magical feedback merging script (6 Feb 2006)
#
# Merge experiment header files with allsession.hdr,
# end get rid of the 'give feedback' related line
#

print "\n\nRun this program in the directory where the experiment feedback\n";
print "files are (*.hdr). The all session feedback will be added to these,\n";
print "and the *.hdr files will be copied to the mergehdr directory.\n\n"; 
print "Archive these newly created station feedback files.\n\n";

unless (-e "mergehdr")
  {mkdir("mergehdr",0777) || die "\n\nCannot create mergehdr directory: $!"};
my @hdrfiles = glob("*.hdr");
foreach (@hdrfiles){
  unless ($_ =~ /allsession/){
    $hdr = $_;
    print "$hdr \n";
    open(NEWHDR, ">mergehdr/$hdr");
    open(OLDHDR, "$hdr");
    while (<OLDHDR>){
# Taking out the line containing HREF 
      unless ($_ =~ /HREF/){print NEWHDR "$_"}
    }
    close(OLDHDR);
    print NEWHDR "<P>\n";
    open(SESS, "allsession.hdr");
    while(<SESS>){
# Taking out line containing HREF  
      unless ($_ =~ /HREF/){print NEWHDR "$_"}
    }
    close(SESS);
    close(NEWHDR);
  }
}

