diff --git a/check_commit_mesonh.sh b/check_commit_mesonh.sh index 00cd074e3e554d95f00d82b584480509c001c2f7..3a392d1bb9b644964055db66c36138782b872a5f 100755 --- a/check_commit_mesonh.sh +++ b/check_commit_mesonh.sh @@ -186,14 +186,19 @@ if [ $run -ge 1 ]; then fi if [ $check -eq 1 ]; then + allt=0 echo "### Check commit $commit against commit $reference" echo "Compare with python..." # Compare variable of both Synchronous and Diachronic files with printing difference + set +e if [ "$reference" == "" ]; then - python3 $PHYEXTOOLSDIR/compare.py $commit ref + $PHYEXTOOLSDIR/compare.py $commit ref else - python3 $PHYEXTOOLSDIR/compare.py $commit $reference + $PHYEXTOOLSDIR/compare.py $commit $reference fi + t=$? + set -e + allt=$(($allt+$t)) #Check bit-repro after date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks) file1=$REFDIR/MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_$commit/16JAN.1.12B18.001.nc @@ -203,9 +208,17 @@ if [ $check -eq 1 ]; then file2=$REFDIR/MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_$reference/16JAN.1.12B18.001.nc fi echo "Compare with ncdump..." - ncdump $file1 > dump_$commit - ncdump $file2 > dump_$reference - cmp -n 62000 dump_$commit dump_$reference - rm -f dump_$commit dump_$reference - echo "...comparison done" + set +e + diff <(ncdump $file1 | head -c 62889) <(ncdump $file2 | head -c 62889) + t=$? + set -e + allt=$(($allt+$t)) + #rm -f dump_$commit dump_$reference + + if [ $allt -eq 0 ]; then + status="OK" + else + status="Files are different" + fi + echo "...comparison done: $status" fi diff --git a/compare.py b/compare.py old mode 100644 new mode 100755 index 55effd003dd99fda823d04d8f215adf02bb0cf4f..5cff23f31a12cf8535c5c8d59ebeed769248e10e --- a/compare.py +++ b/compare.py @@ -1,51 +1,57 @@ -import xarray as xr -import os - -#REFDIR a renseigner -#REFDIR="/home/rodierq/" -REFDIR = os.environ['REFDIR'] - -def compareFiles(file1,file2): - path_user=REFDIR+'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_'+file1 - if file2 == "ref": - path_ref=REFDIR+'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2' - else: - path_ref=REFDIR+'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_'+file2 - - filen='16JAN.1.12B18.001.nc' - da = xr.open_dataset(path_user+'/'+filen) - da2 = xr.open_dataset(path_ref+'/'+filen) - variables=list(da.keys()) - for var in variables: - try: - ecart_min=float(da2[var].min())-float(da[var].min()) - ecart_moy=float(da2[var].mean())-float(da[var].mean()) - ecart_max=float(da2[var].max())-float(da[var].max()) - if (ecart_min !=0 or ecart_moy !=0 or ecart_max !=0): - print(var,ecart_min,ecart_moy,ecart_max) - except: - pass - - filen='16JAN.1.12B18.000.nc' - da = xr.open_dataset(path_user+'/'+filen) - da2 = xr.open_dataset(path_ref+'/'+filen) - variables=list(da.keys()) - for var in variables: - try: - ecart_min=float(da2[var].min())-float(da[var].min()) - ecart_moy=float(da2[var].mean())-float(da[var].mean()) - ecart_max=float(da2[var].max())-float(da[var].max()) - if (ecart_min !=0 or ecart_moy !=0 or ecart_max !=0): - print(var,ecart_min,ecart_moy,ecart_max) - except: - pass - -if __name__ == "__main__": - import argparse - parser = argparse.ArgumentParser(description='Compare toutes les variables si trouvées dans les deux fichiers') - value = argparse.ArgumentParser() - parser.add_argument('file1', metavar='file1', type=str, help="file1 user ") - parser.add_argument('file2', metavar='file2', type=str, help="file2 reference; ref for MNH-V5-5-0 reference") - args = parser.parse_args() - compareFiles(args.file1,args.file2) - +#!/usr/bin/env python3 + +import xarray as xr +import os + +REFDIR = os.environ['REFDIR'] + +def compareFiles(file1, file2): + status = 0 + path_user = REFDIR + 'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_' + file1 + if file2 == "ref": + path_ref = REFDIR + 'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2' + else: + path_ref = REFDIR + 'MNH-V5-5-0/MY_RUN/KTEST/007_16janvier/008_run2_' + file2 + + filen = '16JAN.1.12B18.001.nc' + da = xr.open_dataset(path_user + '/' + filen) + da2 = xr.open_dataset(path_ref + '/' + filen) + variables = list(da.keys()) + for var in variables: + try: + ecart_min = float(da2[var].min())-float(da[var].min()) + ecart_moy = float(da2[var].mean())-float(da[var].mean()) + ecart_max = float(da2[var].max())-float(da[var].max()) + if (ecart_min !=0 or ecart_moy !=0 or ecart_max !=0): + status += 1 + print(var, ecart_min, ecart_moy, ecart_max) + except: + pass + + filen = '16JAN.1.12B18.000.nc' + da = xr.open_dataset(path_user + '/' + filen) + da2 = xr.open_dataset(path_ref + '/' + filen) + variables = list(da.keys()) + for var in variables: + try: + ecart_min = float(da2[var].min())-float(da[var].min()) + ecart_moy = float(da2[var].mean())-float(da[var].mean()) + ecart_max = float(da2[var].max())-float(da[var].max()) + if (ecart_min !=0 or ecart_moy !=0 or ecart_max !=0): + status += 1 + print(var, ecart_min, ecart_moy, ecart_max) + except: + pass + + return status + +if __name__ == "__main__": + import argparse + import sys + parser = argparse.ArgumentParser(description='Compare toutes les variables si trouvées dans les deux fichiers') + value = argparse.ArgumentParser() + parser.add_argument('file1', metavar='file1', type=str, help="file1 user ") + parser.add_argument('file2', metavar='file2', type=str, help="file2 reference; ref for MNH-V5-5-0 reference") + args = parser.parse_args() + sys.exit(compareFiles(args.file1, args.file2)) +