#!/usr/bin/perl

# Script to read a bunch of .plot files from
# molpop and produce an ASCII table including
# Temperature and Frequency. This table can then
# be easily imported in a number crunching
# software (e.g Matlab).
#
# usage:
# perl molplot.pl *.plot > outfile
#
# (c) Rodrigo Parra - 2005 --------------------------------- 
#
# NOTE: it uses a modified molpop.f file which
#       adds a '*' marking the headers in the plot files.


# Loops through all the input files
foreach $filename ( @ARGV ){

   open(FILE,$filename);

   # Loop to go through the header
   # to get relevant parameter (Temperature in this case)
   for($i=0 ; $i<21 ; $i++){
     $row = <FILE>;
     if($row =~ m/      Tgas = (\d{4})/){$T_gas = $1};
   }

   # Main loop.
   # Reads the frequency from table's header
   # and then prints a row with two new columns appended
   while($row){

      if($row =~ m/\*.+\( (\d{2}.\d{3}).+GHz\)/){$f = $1};
      if($row !~ m/^\*/ && $row !~ m/Tau/){print("$T_gas $f $row");}

      $row = <FILE>;
   }

}
