#! /home/yanxu/bin/awk -f
BEGIN {
    printf("Instance & P &\tNode &\tRamp-up &\tIdle &\tRamp-down &\tWallclock &\t Efficiency\\\\ \\hline\n")
        node = 0
        count = 0
        RampUp = 0.0
        Idle = 0.0
        RampDown = 0.0
        wallclock = 0.0
        numP = 0
}

$1 == "Problem" {
  printf("%12s & ", $3)
  printon = 1
}

$3 == "Launched" {
  printf("%d &\t", $4)
}

#$2 == "Quality" {
#        printf(" %g &\t", $8)
#}

$5 == "processed" {
  printf(" %d &\t", $7)
  node += $7
}

#$5 == "left:" {
#        printf(" %d &\t", $6)
#}

$4 == "depth:" {
#       printf(" %d &\t", $4)
}

$2 == "Average" && $3 == "RampUp" {
  printf(" %.2f &\t", $5)
  RampUp += $5
}


$2 == "Average" && $3 == "Idle" {
  printf(" %.2f &\t", $5)
  Idle += $5
}

$2 == "Average" && $3 == "RampDown" {
  printf(" %.2f &\t", $5)
  RampDown += $5
}

$3 == "wallclock" {
  printf(" %.2f &  \\\\ \n", $5)
  wallclock += $5
}

$2 == "Fatal:" {
  if (printon == 1){
    printf(" Time \\\\ \n")
  }
  printon = 0;
}

$8 == "signal" && $9 == "9\""{
  if (printon == 1){
    printf(" Time \\\\ \n")
  }
  printon = 0;
}

$8 == "signal" && $9 == "15\""{
  if (printon == 1){
    printf(" Crash\\\\ \n")
  }
  printon = 0;
}

$2 == "Error" {
  if (printon == 1){
    printf(" Error \\\\ \n")
  }
  printon = 0;
}

END {
    printf("    & %d &\t %.2f &\t %.2f &\t %.2f &\t %.2f & \\\\ \n", 
             node , RampUp, Idle, RampDown, wallclock)
}
