source: CONFIG/LMDZOR/branches/LMDZOR_v4/CREATE/SCRIPT/interp_from_era.ksh

Last change on this file was 1366, checked in by jgipsl, 13 years ago
  • era2gcm.ksh : new simplified version of era2gcm.x
  • interp_from_era.ksh : new version of get_era.x including interpolation and adding next time step.
  • Property svn:executable set to *
File size: 4.1 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=/work/cont003/p86ghatt/GUIDAGE/INTERP_FROM_TS/LMD96x95_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=/dmnfs/cont003/p24data/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=/dmnfs/cont003/p86ghatt/IGCM_OUT/LMDZOR/NUDGEFILES/LMD9695/ERAI
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=$CSCRATCHDIR/RUNDIR/interprun
40###############################################################################
41# END USER DEFINITION
42###############################################################################
43###############################################################################
44###############################################################################
45if [ ! -d ${rundir} ] ; then
46    mkdir -p ${rundir}
47fi
48cp -f era2gcm.ksh $rundir/.
49cd $rundir
50
51###############################################################################
52# For all variables do :
53#   1) Interpolate all month and years for each variable
54#   2) Add a time step last in each file coming from next month
55###############################################################################
56# Loop over all variables
57for var in $varlist ; do
58    year=$first_year
59    month=01
60
61    # 1 - Loop over all files and interpolate the variable
62    while [[ ${year} -le ${last_year} ]] ; do
63        # Create output directory if it does not exist
64        if [ ! -d $outdir/${year} ] ; then
65            mkdir -p $outdir/${year}
66        fi
67
68        # Define source and target file
69        filein=${indir}/${year}/${var}.${year}${month}${insuffix}
70        fileout=${outdir}/${year}/${var}_${year}${month}${outsuffix}
71
72        # Interpolate filein and save in fileout
73        echo Interpolate file $filein and save in file $fileout
74        ./era2gcm.ksh $gridfile $filein tmp.nc $var
75        mv tmp.nc $fileout
76        echo
77
78
79        # Find next month and year
80        case $month in
81            12)
82                nextyear=`expr $year + 1`
83                nextmonth=01
84                ;;
85            *)
86                nextyear=$year
87                nextmonth=`expr $month + 1`
88                if [[ $nextmonth -le 9 ]] ; then
89                    nextmonth=0$nextmonth
90                fi
91                ;;
92        esac
93        # Update month and year
94        year=$nextyear
95        month=$nextmonth
96    done
97
98
99    # 2 - Loop over all files and add a time step :
100    #     take the first time step from next coming month and add last in current month
101    echo Before add step
102
103    year=$first_year
104    month=01
105    while [[ ${year} -le ${last_year} ]] ; do
106        # Find next month and year
107        case $month in
108            12)
109                nextyear=`expr $year + 1`
110                nextmonth=01
111                ;;
112            *)
113                nextyear=$year
114                nextmonth=`expr $month + 1`
115                if [[ $nextmonth -le 9 ]] ; then
116                    nextmonth=0$nextmonth
117                fi
118                ;;
119        esac
120       
121        file=${outdir}/${year}/${var}_${year}${month}${outsuffix}
122        nextfile=${outdir}/${year}/${var}_${nextyear}${nextmonth}${outsuffix}
123        if [ -f ${nextfile} ] ; then
124            echo First time step from file ${nextfile} will be added last in file ${file}
125            cp -f $file file.nc
126            cp -f $nextfile next.nc
127            ncks -O -d TIME,0,0 next.nc tmp.nc
128            ncrcat -O file.nc tmp.nc tmptot.nc
129            mv tmptot.nc $file
130        else
131            echo Next file ${nextfile} does not exist. Nothing will be done for ${file}
132        fi
133
134        # Update month and year
135        year=$nextyear
136        month=$nextmonth
137    done
138
139
140   
141# End of loop variable list
142done
143
144### Copy gridfile in output dir
145cp -f $gridfile $outdir/grilles_gcm.nc
146   
147exit
Note: See TracBrowser for help on using the repository browser.