BEGIN {
  epsilon = 0.01;
  nmin = 5;
  nmax = 500;
tlimit= 2;
 cmax = 0}

NF {
  for (i = 3; i <= NF; i += 2)
    {
      data[$i] = $ (i + 1);
      time = $1;
    date = $2}
  h2 = data["h2"]; o2=data["o2"]; air=data["air"];ch4=data["ch4"];
current = data["current"];
backup=data["backup"];

voltage = data["cell_voltage"]}

flag{
  if (current > cmax)    {
      cmax = current;
      ncmax = NR;
      vcmax=voltage;
      tmax=time;
      h2max = h2; o2max=o2; airmax=air;ch4max=ch4;
      backupmax=backup;
    };
}

(current > epsilon) && (!flag){
      cmax = current;
      ncmax = NR;
      vcmax=voltage;
  nstart = NR;
  tstart = time;
  dstart = date;
  flag = 1;

}

(current < epsilon) && (flag){
  nstop = NR;
  tstop = time;
  dstop = date;
  flag = 0;
  if (((nstop - nstart) > nmin) && (((nstop - nstart) < nmax)) &&
      (tstop - tstart) < tlimit)    print  "dstart",dstart,"dstop",dstop, "nstart",nstart,"ncmax",ncmax, "nstop",nstop, "tstart",tstart,"tstop", tstop,  "cmax",cmax, "Voltage_at_max_current",vcmax,       "H_2",h2max,"O_2",o2max, "Air",airmax,"CH_4",ch4max,"backup",backupmax;

#, -nstart + nstop, -tstart + tstop;
 cmax = 0;
}
