! This is max_conc.jnl
! Find the max surface concentration of total MP

def symbol inc = $1%1%

list ($itr)

let isfile = `test_opendap("test($itr)/tavg.01951.01.01.nc")`

if `isfile EQ 0` then

  use "test($itr)/tavg.01951.01.01.nc"

  let totmp=o_mp+o_mpa+o_mpp

  let npgmax=totmp[l=61,x=150e:120w@max,y=20n:40n@max,k=1] !max surface conc@NPG

  let nagmax=totmp[l=61,x=80w:10w@max,y=20n:40n@max,k=1] !max surface conc@NAG

  let spgmax=totmp[l=61,x=160w:80w@max,y=20s:40s@max,k=1] !max surface conc@SPG

  let sagmax=totmp[l=61,x=30w:10e@max,y=20s:40s@max,k=1] !max surface conc@SAG

  let iogmax=totmp[l=61,x=40e:110e@max,y=20s:40s@max,k=1] !max surface conc@IOG

list/format=(E9.3, " ",E9.3, " ",E9.3, " ",E9.3, " ",E9.3)/nohead/append/file=metric.txt npgmax, nagmax, spgmax, sagmax, iogmax

SPAWN grep -Po "pinp=\K[^,]*" control_($itr).in >> param1.txt
SPAWN grep -Po "prise=\K[^,]*" control_($itr).in >> param2.txt
SPAWN grep -Po "pbc=\K[^,]*" control_($itr).in >> param3.txt
SPAWN grep -Po "pagg=\K[^,]*" control_($itr).in >> param4.txt
SPAWN grep -Po "kp=\K[^,]*" control_($itr).in >> param5.txt
  canc data 1
endif

def symbol itr = `($itr)+($inc)`