source: tags/libIGCM_v2.2/libIGCM_post/IGCM_Patch_20101208_nudge_interp.ksh

Last change on this file was 401, checked in by sdipsl, 13 years ago
  • Cesium changes his behaviour this week end. Usually only environment variable poitned by list_var_env are passed to a child job. Suddenly cesium passes all environement variables to the child jobs. Add a workaround.
  • Upgrade IGCM_Patch_20101208_nudge_interp.ksh (jg)
  • Cosmetics
  • tag v1_10 will be updated as well
  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 5.8 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Josefine Ghattas
5# Contact: Josefine.Ghattas__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13#
14# Interpolation of monthly input ERAI files to the actual model grid.
15#
16# The patch should be applied once for each variable to interpolate. The file start.nc must be present in lmdz.car OutputFiles.
17# In lmdz.card all monthly ERAI files for the actual year to be interpolated must be present at format var_month_year.nc, where var=[u,v],
18# month=[1,13]. The file var_13_year.nc correspond to january the following year.
19# Partial year can be interpolated.
20#
21#
22function IGCM_Patch_20101208_nudge_interp {
23    IGCM_debug_PushStack "IGCM_Patch_nudge_interp" $@
24
25###################################################################################################
26# 1 - Define variables
27# Filein is the first month to interpolate for a variable.
28# Filein name should be at format X_Y_ZZZZ.nc, where X=varaiable name [u,v,ta], Y=[1,13] and ZZZZ=year.
29# To do one year complete for one variable X, 13 month must be present.
30###################################################################################################
31    filein=${1}
32
33# Define startfile containg the destination grid. This file must exist in the OutputFiles list in lmdz.card.
34    startfile=start.nc
35
36# Determine which variable and year concerned by this patch
37    var=$( echo ${filein} | awk '-F_' '{print $1}' )
38    year=$( echo ${filein} | awk '-F_' '{print $3}' | awk '-F.nc' '{print $1}' )
39    echo var=$var year=$year
40
41###################################################################################################
42# 2 - Interpolate all files for the actual varaiable.
43#     Original files will be overritten.
44###################################################################################################
45    filelist=${var}_*.nc
46    echo 'filelist 1 = ' ${filelist}
47    for file in ${filelist}; do
48        month=$( echo ${file} | awk '-F_' '{print $2}' | awk '-F_' '{print $1}' )
49        echo 'era2gcm for file = ' ${file} 
50        IGCM_era2gcm ${file} tmp_${file} ${var} ${year}
51        IGCM_sys_Mv tmp_${file} ${file}
52    done
53
54###################################################################################################
55# 3 - Add a final time step in each file, coming from the first time step in following month
56###################################################################################################
57    filelist=${var}_*.nc
58    echo 'filelist 2 = ' ${filelist}
59    for file in ${filelist}; do
60        month=$( echo ${file} | awk '-F_' '{print $2}' | awk '-F_' '{print $1}' )
61        month_next=`expr $month + 1`
62        file_next=${var}_${month_next}_${year}.nc
63        if [ -f ${file_next} ] ; then
64            echo First time step from file ${file_next} will be added last in file ${file}
65            ncks -O -d THOUR,0,0 ${file_next} tmp.nc
66            ncrcat -O $file tmp.nc tmptot.nc
67            IGCM_sys_Mv tmptot.nc $file
68        else
69            echo Next file ${file_next} does not exist. Nothing will be done for ${file}
70        fi
71    done
72
73###################################################################################################
74# 4 - Remove 13'th month
75###################################################################################################
76    if [ -f ${var}_13_${year}.nc ] ; then
77        echo Remove file ${var}_13_${year}.nc
78        IGCM_sys_Rm ${var}_13_${year}.nc
79    fi
80
81    IGCM_debug_PopStack "IGCM_Patch_nudge_interp"
82}
83
84
85function IGCM_era2gcm {
86#set -xv
87# Function that does a linear interpolation of the variable in
88# filein towards the destionation grid in gridfile. Results in are
89# stored in fileout.
90    IGCM_debug_PushStack "IGCM_era2gcm" $@
91
92###################################################################
93# 1 - Define variables
94###################################################################
95    filein=$1
96    fileout=$2
97    varin=$3
98    year=$4
99
100# Define file with destination grid
101    gridfile=start.nc
102   
103# Find time boundaries
104    tmin=1
105    tmax=`ncdump -h ${filein} | grep time | head -1 | awk ' { print $6 } '`
106    tmax=$( echo ${tmax} | awk '-F(' '{print $2}' )
107   
108# Choose grid and output variable name
109    if [ ${varin} = 'u' ] ; then
110        varout=uwnd
111        grille='grille_u'
112    elif [ ${varin} = 'v' ] ; then
113        varout=vwnd
114        grille='grille_v'
115    elif [ ${varin} = 'ta' ] ; then
116        varout=air
117        grille='grille_t'
118    elif [ ${varin} = 'r' ] ; then
119        varout=rh
120        grille='grille_t'
121    elif [ ${varin} = 'msl' ] ; then
122        varout=sp
123        grille='grille_t'
124    else
125        echo Error : ${varin} unknown!!!!
126        exit
127    fi 
128
129###################################################################
130# 2 - Create ferret script for interpolation
131###################################################################
132    cat << eod >  ${varin}.jnl
133set memory/size=50
134
135use ${gridfile}
136use ${filein}
137let ${varout}=${varin}
138
139define axis/t=01-JAN-${year}:31-DEC-${year}:6/units=hours thour
140
141define grid/like=${varout}[d=2]/x=cu[d=1]/y=cu[d=1] grille_u
142define grid/like=${varout}[d=2]/x=cv[d=1]/y=cv[d=1] grille_v
143define grid/like=${varout}[d=2]/x=cv[d=1]/y=cu[d=1] grille_t
144
145save/clobber/file=${fileout} ${varout}[d=2,g=${grille},l=1,gt=thour@asn]
146repeat/l=1:${tmax} save/file="${fileout}"/append ${varout}[d=2,g=${grille},gt=thour@asn]
147
148exit
149eod
150   
151###################################################################
152# 3 - Launch interpolation with ferret
153###################################################################
154    ferret -nojnl <<eod >  /dev/null
155go ${varin}.jnl
156quit
157eod
158
159    IGCM_debug_PopStack "IGCM_era2gcm"   
160}
Note: See TracBrowser for help on using the repository browser.