source: TOOLS/INTERP_NUDGE/interp_from_era.ksh @ 2592

Last change on this file since 2592 was 2172, checked in by jgipsl, 9 years ago

Updated with correct path at storedir.

  • Property svn:executable set to *
File size: 4.2 KB
Line 
1#!/bin/ksh
2set verbose echo
3#
4# This script will interpolate horizontaly ERA-I
5# output to the desired model grid
6#
7# Contact Josefine Ghattas
8###############################################################################
9###############################################################################
10###############################################################################
11# BEGIN USER DEFINITION
12###############################################################################
13
14# gridfile : file grilles_gcm.nc containing longitudes and latitudes of the destination grid
15gridfile=/ccc/store/cont003/dsm/p86ghatt/IGCM_OUT/LMDZ/ELC-128x118x39/ATM/Output/Grid/ELC-128x118x39_grilles_gcm.nc
16
17# indir : path for directory containing the files to interpolate
18#indir=/u/rech/psl/rpsl376/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_PL
19indir=/ccc/store/cont003/subipsl/subipsl/dmf_import/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_PL
20# insuffix : suffix in input files
21insuffix=.aphei.GLOBAL_075.nc
22
23# varlist : list of variables to interpolate
24varlist="u v ta r"
25
26# Variables for output :
27# outdir : directory to store output files
28outdir=$WORKDIR/NUDGEFILES/ERAI-128x118x39
29# outsuffix : suffix to output files
30outsuffix=_erai.nc
31
32# Time variables :
33# first_year : first year to interpolate
34first_year=2000
35# last_year : last year to interpolate
36last_year=2000
37
38# rundir : temporary run directory
39rundir=`pwd`/rundir
40echo rundir=$rundir
41
42###############################################################################
43# END USER DEFINITION
44###############################################################################
45###############################################################################
46###############################################################################
47if [ ! -d ${rundir} ] ; then
48    mkdir -p ${rundir}
49fi
50cp -f era2gcm.ksh $rundir/.
51cd $rundir
52
53###############################################################################
54# For all variables do :
55#   1) Interpolate all month and years for each variable
56#   2) Add a time step last in each file coming from next month
57###############################################################################
58# Loop over all variables
59for var in $varlist ; do
60    year=$first_year
61    month=01
62
63    # 1 - Loop over all files and interpolate the variable
64    while [[ ${year} -le ${last_year} ]] ; do
65        # Create output directory if it does not exist
66        if [ ! -d $outdir/${year} ] ; then
67            mkdir -p $outdir/${year}
68        fi
69
70        # Define source and target file
71        filein=${indir}/${year}/${var}.${year}${month}${insuffix}
72        fileout=${outdir}/${year}/${var}_${year}${month}${outsuffix}
73
74        # Interpolate filein and save in fileout
75        echo Interpolate file $filein and save in file $fileout
76        ./era2gcm.ksh $gridfile $filein tmp.nc $var
77        mv tmp.nc $fileout
78        echo
79
80
81        # Find next month and year
82        case $month in
83            12)
84                nextyear=`expr $year + 1`
85                nextmonth=01
86                ;;
87            *)
88                nextyear=$year
89                nextmonth=`expr $month + 1`
90                if [[ $nextmonth -le 9 ]] ; then
91                    nextmonth=0$nextmonth
92                fi
93                ;;
94        esac
95        # Update month and year
96        year=$nextyear
97        month=$nextmonth
98    done
99
100
101    # 2 - Loop over all files and add a time step :
102    #     take the first time step from next coming month and add last in current month
103    echo Before add step
104
105    year=$first_year
106    month=01
107    while [[ ${year} -le ${last_year} ]] ; do
108        # Find next month and year
109        case $month in
110            12)
111                nextyear=`expr $year + 1`
112                nextmonth=01
113                ;;
114            *)
115                nextyear=$year
116                nextmonth=`expr $month + 1`
117                if [[ $nextmonth -le 9 ]] ; then
118                    nextmonth=0$nextmonth
119                fi
120                ;;
121        esac
122       
123        file=${outdir}/${year}/${var}_${year}${month}${outsuffix}
124        nextfile=${outdir}/${year}/${var}_${nextyear}${nextmonth}${outsuffix}
125        if [ -f ${nextfile} ] ; then
126            echo First time step from file ${nextfile} will be added last in file ${file}
127            cp -f $file file.nc
128            cp -f $nextfile next.nc
129            ncks -O -d TIME,0,0 next.nc tmp.nc
130            ncrcat -O file.nc tmp.nc tmptot.nc
131            mv tmptot.nc $file
132        else
133            echo Next file ${nextfile} does not exist. Nothing will be done for ${file}
134        fi
135
136        # Update month and year
137        year=$nextyear
138        month=$nextmonth
139    done
140
141
142   
143# End of loop variable list
144done
145
146### Copy gridfile in output dir
147cp -f $gridfile $outdir/grilles_gcm.nc
148   
149exit
Note: See TracBrowser for help on using the repository browser.