#! /usr/bin/awk -f
# 
# Extract data from an "Excitations" run of ADF.
# read excitation energies etc. from output 
# of ADF and print the data blocks to output.
# The data blocks are created in the 
# developers version of ADF in case a CD spectrum
# is requested.
#

# print header to be used by the "plot-spectrum.f90" program:

/Nr of excitation energies per irrep to be calculated/{
  x = 0;
  getline ; 
  getline ;
  while ($0 !~ "STARTING CALCULATION"  ){
    if ($9 ~ "column"){
      x++ ;
      array[x] = $2 ;
      symlab[x] = $8
    }
    getline } ;
  printf ("&plot nsyme(1)=");
  y = 0 ;
  for (i=1; i <= x; i++) {y+= array[i]; printf ("%s,",array[i]) } ;
  printf (" ndegen(1)=");
  for (i=1; i <= x; i++) {
#    y+= array[i]; 
    deg = 1
    if (substr(symlab[i],1,1) ~ "E"){deg = 2}
    if (substr(symlab[i],1,1) ~ "T"){deg = 3}
    if (substr(symlab[i],1,1) ~ "G"){deg = 4}
    if (substr(symlab[i],1,1) ~ "H"){deg = 5}
    printf ("%d,", deg)
  } ;  
  printf (" sigma=0, sharpen=1, npoints=300, \n nexcit=%s, lorentz=.f., invert=.f. /\n", y) ;
  print " "; 
} ; 

# find and print the data blocks

/Symmetry /{ lala=$0;getline;
 getline var
   if (var ~ "Excitation") {
     print lala  ; 
     print var ; 
     getline ; print $0; getline; getline; print " ";
#
#    read data until "Major MO-MO contribs" or second occurence
#    of "Excitations" due to dipole-velocity data
#
     while ( ($1 != "Excitation") && ($1 != "Major") ){ 
#
#      cut out possible transition dipole moment datablocks
#
       if ($1 ==  "Transition") {
	 getline; getline; getline;
	 while (NF != 0){getline}; getline;
       }
#
#      print data
#
       if ($0 ~ "Major"){
         print "Achtung!",$0}
       else {
       print $0 };
       getline;
     }
     print " " ;
   }
} 

