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

Last change on this file was 1367, checked in by jgipsl, 13 years ago

Added script to interpolate nudge files from model output format (TS).

  • Property svn:executable set to *
File size: 6.1 KB
Line 
1#!/bin/ksh
2set -xv
3set verbose echo
4#
5# This script will interpolate horizontaly time series from IPSLCM5 model
6# output to the desired model grid
7#
8# Contact Josefine Ghattas
9###############################################################################
10###############################################################################
11###############################################################################
12# BEGIN USER DEFINITION
13###############################################################################
14
15# gridfile : file grilles_gcm.nc containing longitudes and latitudes of the destination grid
16gridfile=/work/cont003/p86ghatt/GUIDAGE/INTERP_FROM_TS/LMD96x95_grilles_gcm.nc
17
18
19# indir : path for directory containing the files to interpolate
20indir=/dmnfs/cont003/p86denv/IGCM_OUT/IPSLCM5A/PROD/rcp45/v3.rcp45.1/ATM/Analyse/TS_HF
21
22# varlist : list of variables to interpolate
23#varlist="vitu vitv temp hur"
24varlist="vitu"
25
26# filelist_var : list of files to interpolate for variable var
27filelist_vitu="v3.rcp45.1_20060101_20151231_HF_vitu.nc  v3.rcp45.1_20360101_20451231_HF_vitu.nc  v3.rcp45.1_20660101_20751231_HF_vitu.nc v3.rcp45.1_20160101_20251231_HF_vitu.nc  v3.rcp45.1_20460101_20551231_HF_vitu.nc  v3.rcp45.1_20760101_20851231_HF_vitu.nc v3.rcp45.1_20260101_20351231_HF_vitu.nc  v3.rcp45.1_20560101_20651231_HF_vitu.nc  v3.rcp45.1_20860101_20951231_HF_vitu.nc"
28
29filelist_vitv="v3.rcp45.1_20060101_20151231_HF_vitv.nc  v3.rcp45.1_20360101_20451231_HF_vitv.nc  v3.rcp45.1_20660101_20751231_HF_vitv.nc v3.rcp45.1_20160101_20251231_HF_vitv.nc  v3.rcp45.1_20460101_20551231_HF_vitv.nc  v3.rcp45.1_20760101_20851231_HF_vitv.nc v3.rcp45.1_20260101_20351231_HF_vitv.nc  v3.rcp45.1_20560101_20651231_HF_vitv.nc  v3.rcp45.1_20860101_20951231_HF_vitv.nc"
30
31filelist_temp="v3.rcp45.1_20060101_20151231_HF_temp.nc  v3.rcp45.1_20360101_20451231_HF_temp.nc  v3.rcp45.1_20660101_20751231_HF_temp.nc v3.rcp45.1_20160101_20251231_HF_temp.nc  v3.rcp45.1_20460101_20551231_HF_temp.nc  v3.rcp45.1_20760101_20851231_HF_temp.nc v3.rcp45.1_20260101_20351231_HF_temp.nc  v3.rcp45.1_20560101_20651231_HF_temp.nc  v3.rcp45.1_20860101_20951231_HF_temp.nc"
32
33filelist_hur="v3.rcp45.1_20060101_20151231_HF_hur.nc  v3.rcp45.1_20360101_20451231_HF_hur.nc  v3.rcp45.1_20660101_20751231_HF_hur.nc v3.rcp45.1_20160101_20251231_HF_hur.nc  v3.rcp45.1_20460101_20551231_HF_hur.nc  v3.rcp45.1_20760101_20851231_HF_hur.nc v3.rcp45.1_20260101_20351231_HF_hur.nc  v3.rcp45.1_20560101_20651231_HF_hur.nc  v3.rcp45.1_20860101_20951231_HF_hur.nc"
34
35# Define variables for output
36# Complet file name for output : $outdir/$year/$outprefix_$var_$year_$month.nc
37# outdir : directory to store output files
38outdir=$DMFDIR/IGCM_OUT/LMDZOR/NUDGEFILES/LMD9695/RCP45
39
40# outprefix : prefix to output files
41outprefix=v3.rcp45.1_HF_
42# outsuffix : suffix to output files
43outsuffix=.nc
44
45# Time variables
46# first_year : first year to interpolate
47first_year=2006
48# last_year : last year to interpolate
49last_year=2095
50
51# rundir : temporary run directory
52rundir=$CSCRATCHDIR/RUNDIR/interprun
53###############################################################################
54# END USER DEFINITION
55###############################################################################
56###############################################################################
57###############################################################################
58# Create and move to run directory
59if [ ! -d ${rundir} ] ; then
60    mkdir -p ${rundir}
61fi
62cp -f era2gcm.ksh $rundir/.
63cd $rundir
64
65# Create output directory if it does not exist
66if [ ! -d $outdir ] ; then
67    mkdir -p $outdir
68fi
69
70
71###############################################################################
72# Loop over variable list
73#   * Loop over corresponding file list
74#     1 - Interpolate the whole time-serie to destination grid
75#     2 - Devide files into monthly files
76#   * Loop over all years for each variable
77#     3 - Add a time step last in each file coming from next month
78###############################################################################
79for var in $varlist ; do
80    case $var in
81        vitu)
82            filelist=$filelist_vitu ;;
83        vitv)
84            filelist=$filelist_vitv ;;
85        temp)
86            filelist=$fileslist_temp ;;
87        hur)
88            filelist=$filelist_hur ;;
89    esac
90   
91    echo $var : $filelist; echo
92 
93    for file in $filelist ; do
94# 1 - Interpolate time serie to destiation grid
95        filein=$indir/$file
96        file2=$outdir/$file
97        cp -f $filein file1.nc
98        echo Interpolate file $filein and save in file $file2
99        ./era2gcm.ksh $gridfile file1.nc file2.nc $var
100       
101# 2 - Devide files into monthly files
102        cdo splityear file2.nc outyear_
103    done
104    ls -lrt
105
106    year=$first_year
107    while [[ ${year} -le ${last_year} ]] ; do
108        # split in month
109        cdo splitmon outyear_$year.nc outmonth_
110
111        # move monthly files to output directory
112        mkdir -p $outdir/$year
113        month=01
114        for month in 01 02 03 04 05 06 07 08 09 10 11 12 ; do
115            mv outmonth_$month.nc $outdir/$year/${outprefix}${var}_${year}_${month}${outsuffix}
116        done
117       
118        # update year
119        year=`expr $year + 1`
120    done
121   
122# Loop over all years for one variables
123# 3 - Add first time step last in file
124    echo Before add step
125    ls -lrt $outdir
126    ls -lrt $outdir/*
127
128    year=$first_year
129    month=01
130    while [[ ${year} -le ${last_year} ]] ; do
131        case $month in
132            12)
133                nextyear=`expr $year + 1`
134                nextmonth=01
135                ;;
136            *)
137                nextyear=$year
138                nextmonth=`expr $month + 1`
139                if [[ $nextmonth -le 9 ]] ; then
140                    nextmonth=0$nextmonth
141                fi
142                ;;
143        esac
144       
145        file=$outdir/$year/${outprefix}${var}_${year}_${month}${outsuffix}
146        nextfile=$outdir/$year/${outprefix}${var}_${nextyear}_${nextmonth}${outsuffix}
147        if [ -f ${nextfile} ] ; then
148            echo First time step from file ${nextfile} will be added last in file ${file}
149            cp -f $file file.nc
150            cp -f $nextfile next.nc
151            ncks -O -d time,0,0 next.nc tmp.nc
152            ncrcat -O file.nc tmp.nc tmptot.nc
153            mv tmptot.nc $file
154        else
155            echo Next file ${nextfile} does not exist. Nothing will be done for ${file}
156        fi
157       
158        # Update month and year
159        year=$nextyear
160        month=$nextmonth
161   
162    done
163       
164# End of loop variable list
165done
166
167### Copy gridfile in output dir
168cp -f $gridfile $outdir/grilles_gcm.nc
169           
170exit
Note: See TracBrowser for help on using the repository browser.