#!/usr/bin/awk -f # lmdz_analyse_stomate_out - filter ORCHIDEE node output : # command : # lmdz_analyse_stomate_out.awk [-d] out_orchidee[_0000] #************************************************************** # Author: Martial.Mancip # Contact: Martial.Mancip__at__ipsl.jussieu.fr # $Revision:: 373 $ Revision of last commit # $Author:: sdipsl $ Author of last commit # $Date:: 2010-10-29 12:37:36 +0200 (Fri, 29 Oct 2010) $ Date of last commit # IPSL (2006) # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC # #************************************************************** #========================== function myprint(str) { if (debug) { print str } } #========================== BEGIN { # print "traitement de " ARGV[1] nbarg=ARGC if (ARGV[1] == "-d") { debug=1 file=ARGV[2] delete ARGV[1] nbarg-- } else { debug=0 file=ARGV[1] } exit_value=0 if (nbarg != 2) { print "Usage: lmdz_analyse_stomate_out.awk [-d] file" exit_value=-1 exit } line=0 fluxCarbon_found=0 counterCO2=0 fluxLU_found=0 counterLU=0 fluxNBP_found=0 counterNBP=0 CO2file[1]="" LUfile[1]="" NBPfile[1]="" } #========================== { # myprint($0) line=line+1 if (match($0, ".*GLOBAL net_co2_flux_monthly.*")) { myprint("fluxCarbon_found = 1") fluxCarbon_found=1 counterCO2=counterCO2+1 nb=split($0,felts, "=") myprint("nb :" nb) for (elt in felts) { myprint(elt "- elt :" felts[elt]) } myprint("elts_co2 :" felts[2]) CO2file[counterCO2]=felts[2] } else if (match($0, ".*GLOBAL net_cflux_prod_monthly.*")) { myprint("fluxLU_found = 1") fluxLU_found=1 counterLU=counterLU+1 nb=split($0,felts, "=") myprint("nb :" nb) for (elt in felts) { myprint(elt "- elt :" felts[elt]) } myprint("elts_co2 :" felts[2]) LUfile[counterLU]=felts[2] } else if (match($0, ".*GLOBAL net_biosp_prod_monthly.*")) { myprint("fluxNBP_found = 1") fluxNBP_found=1 counterNBP=counterNBP+1 nb=split($0,felts, "=") myprint("nb :" nb) for (elt in felts) { myprint(elt "- elt :" felts[elt]) } myprint("elts_nbp :" felts[2]) NBPfile[counterNBP]=felts[2] } } #========================== END { if ( exit_value != -1 ) { if ( fluxCarbon_found == 1 ) { myprint("CO2 value for " file) myprint("counterCO2 :" counterCO2) for (i=1; i<=counterCO2; i++) { print CO2file[i] myprint("value :" CO2file[i]) } if ( fluxLU_found == 1 ) { myprint("LU value for " file) myprint("counterLU :" counterLU) for (i=1; i<=counterLU; i++) { print LUfile[i] myprint("value :" LUfile[i]) } if ( fluxNBP_found == 1 ) { myprint("NBP value for " file) myprint("counterNBP :" counterNBP) for (i=1; i<=counterNBP; i++) { print NBPfile[i] myprint("value :" NBPfile[i]) } exit_value=0 exit 0 } else { myprint("ERROR : NO NBP value for " file) print "0003" exit 1 } exit_value=0 exit 0 } else { myprint("ERROR : NO LU value for " file) print "0002" print "0003" exit 1 } } else { myprint("ERROR : NO CO2 value for " file) print "0001" print "0002" print "0003" exit 1 } } else { print "0000" exit 1 } }