source: BOL/Multi_atlas/cmor.sh @ 4340

Last change on this file since 4340 was 4340, checked in by musat, 19 months ago

Inclut environnement spirit et dernieres corrections (1/3)
IonelaMusat?

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1#!/bin/bash
2
3#set -vx
4
5source ~/env_Multi_atlas.sh
6
7local=`pwd -P`
8cd $local
9
10####################################################################
11# Frederic Hourdin. 2015/09/07
12# Script de pseudo Cmorisation (passage au format CMIP des sorties
13# du modele.
14####################################################################
15
16####################################################################
17# Defaults :
18####################################################################
19
20runstxt=${local}/runs.txt
21while test -n "${1}"; do
22   case $1 in
23      "-runsfile") runstxt=$2 ; shift ;;
24      *) comp=$1 ;;
25   esac
26   shift
27done
28
29MainDIR=$DODSDIR/$login/lmdz/SE
30INDIR=$DODSDIR/$login/lmdz/SE/ORIG
31COMP_D=$DODSDIR/$login/lmdz/MultiSimu/$comp
32
33if [ ! -f $COMP_D/def.txt ] ; then
34    echo comparaison multi modele $COMP_D non prevue
35    exit
36fi
37if [ ! -f $runstxt ] ; then
38    echo Fichier listant les simulations inexistants
39    exit
40fi
41
42WRK=$MainDIR/WORK/CMOR
43
44i=1
45while [ "`ps -ux | grep cmor.sh | grep bin | wc -l`" != "2" ] ; do
46   echo Mise en attente de cmor.sh deja en cours d execution $i
47   sleep 2 ; (( i = $i + 1 ))
48   if [ "$i" = "3600" ] ; then exit ; fi
49done
50
51
52####################################################################
53# Interactive options
54####################################################################
55force_create=0 # if = 0/1, the existing files are not / are reprocessed
56listevar="sfcWind,hfls,hfss,huss,hurs,pr,rldscs,rlds,rlus,rsdscs,rsds,rsuscs,rsus,rsutcs,rsut,rlut,rlutcs,rsdt,sfcWind,tas,ts,sst,tauu,tauv,psl,hfns,ta,ua,va,wap,hus,hur,clcalipso,cllcalipso,clmcalipso,clhcalipso,cltcalipso,clt,prw,cll,clm,clh,tasmax,tasmin,uas,vas"
57listevar="sfcWind,hfls,hfss,huss,hurs,pr,rldscs,rlds,rlus,rsdscs,rsds,rsuscs,rsus,rsutcs,rsut,rlut,rlutcs,rsdt,sfcWind,tas,ts,sst,tauu,tauv,psl,zg500,hfns,ta,ua,va,wap,hus,hur,clcalipso,cllcalipso,clmcalipso,clhcalipso,cltcalipso,clt,prw,cll,clm,clh,tasmax,tasmin,uas,vas"
58#listevar="psl"
59
60ulimit -s unlimited
61\rm -rf $WRK ; mkdir -p $WRK ; touch out$$
62
63################################################################################
64# Loop on avaliable simulations
65################################################################################
66
67cd $INDIR
68#for file in *_histmth.nc ; do
69
70for SE in `awk ' { print $1"_SE_"$2 } ' $COMP_D/def.txt` ; do
71  sim=`echo $SE | sed -e 's/_SE_/ /' | awk ' { print $1 } '`
72  years=`echo $SE | sed -e 's/_SE_/ /' | awk ' { print $2 } '`
73  echo SEsim $SE $sim
74  simdir=`grep -w "^$sim " $runstxt | awk ' { print $2 } '`
75  simorig=`basename $simdir`
76  echo SEsim simorig $simorig
77  echo SEsim basename $simdir
78  file=$simdir/ATM/Analyse/SE/${simorig}_SE_${years}_1M_histmth.nc
79  if [ ! -f $file ] ; then
80      echo PB fichier $file inexistant
81    file=$INDIR/${simorig}_SE_${years}_1M_histmth.nc
82    echo $file
83  fi
84  if [ -f $file ] ; then
85   file=$INDIR/${simorig}_SE_${years}_1M_histmth.nc
86   echo $file
87   echo FILE $file
88   cd $WRK
89   dirout=$MainDIR/CMOR/${sim}_${years}/$cas
90   echo $sim $years $dirout
91
92   echo SEsim $dirout
93   mkdir -p  $dirout
94
95   for var in `echo $listevar | sed -e 's/,/ /g'` ; do
96
97     case $var in
98        clcalipso|cltcalipso|clhcalipso|clmcalipso|cllcalipso) filei=`echo $file | sed -e 's/histmth/histmthCOSP/'` ;;
99        *) filei=$file
100     esac
101
102     if [ -f "$filei" ] ; then
103
104       fact=1.
105       case $var in
106          hfls)    varo=flat ; fact=-1. ;;
107          hfss)    varo=sens ; fact=-1. ;;
108          pr)      varo=precip ;;
109          sfcWind) varo=wind10m ;;
110          rldscs)  varo=LWdnSFCclr ;;
111          rlds)    varo=LWdnSFC ;;
112          rlus)    varo=LWupSFC ;;
113          rsdscs)  varo=SWdnSFCclr ;;
114          rsds)    varo=SWdnSFC ;;
115          rsuscs)  varo=SWupSFCclr ;;
116          rsus)    varo=SWupSFC ;;
117          rsutcs)  varo=SWupTOAclr ;;
118          rsut)    varo=SWupTOA ;;
119          rsdt)    varo=SWdnTOA ;;
120          rlut)    varo=topl ;;
121          rlutcs)  varo=topl0 ;;
122          sfcWind) varo=wind10m ;;
123          tas)     varo=t2m ;;
124          uas)     varo=u10m ;;
125          vas)     varo=v10m ;;
126          tasmax)     varo=ave_t2m_daily_max ;;
127          tasmin)     varo=ave_t2m_daily_min ;;
128          ts)      varo=tsol ;;
129          sst)     varo=tsol_oce ;;
130          huss)    varo=q2m ;;
131          hurs)    varo=rh2m ;;
132          tauu)    varo=taux_oce ;;
133          tauv)    varo=tauy_oce ;;
134          psl)     varo=slp ; fact=0.01 ;;
135          zg500)   varo=z500 ;;
136          hfns)    varo=bils ;;
137          prw)     varo=prw ;;
138          ta)      varo=temp ;;
139          ua)      varo=vitu ;;
140          va)      varo=vitv ;;
141          wap)     varo=vitw ;;
142          hus)     varo=ovap ;;
143          hur)     varo=rhum ; fact=100. ;;
144          clcalipso)    varo=clcalipso ; fact=100. ;;
145          cltcalipso)    varo=cltcalipso ; fact=100. ;;
146          clhcalipso)    varo=clhcalipso ; fact=100. ;;
147          clmcalipso)    varo=clmcalipso ; fact=100. ;;
148          cllcalipso)    varo=cllcalipso ; fact=100. ;;
149          cll)     varo=cldl ; fact=100. ;;
150          clm)     varo=cldm ; fact=100. ;;
151          clh)     varo=cldh ; fact=100. ;;
152          clt)     varo=cldt ; fact=100. ;;
153          *) echo "var $var non prevu" ; exit
154       esac
155
156       outfile=$dirout/$var.nc
157       #echo `pwd`/$outfile
158       if [ $force_create = 1 ] ; then rm -f $outfile ; fi
159       if [ ! -f $outfile ] ; then
160          \rm -f tmp.nc tmp1.nc
161          if [ $fact = 1. ]; then
162            opt="selvar,$varo"
163          else
164            opt="mulc,$fact -selvar,$varo"
165          fi
166          echo cdo $opt $filei tmp.nc
167          cdo $opt $filei tmp.nc >> out$$
168          if [ $var != $varo ]; then
169            echo ncrename -v $varo,$var tmp.nc -O tmp1.nc
170            ncrename -v $varo,$var tmp.nc -O tmp1.nc  >> out$$
171          else
172            mv tmp.nc tmp1.nc
173          fi
174          if [ ! -f tmp1.nc ] ; then
175              echo echec $years $var
176          else
177              \mv -f tmp1.nc $outfile
178          fi
179       fi
180     fi # -f $filei
181  done
182 fi
183done
Note: See TracBrowser for help on using the repository browser.