source: branches/libIGCM_CESMEP/libIGCM_post/IGCM_Patch_20101208_nudge_interp.ksh

Last change on this file was 1059, checked in by sdipsl, 10 years ago
  • Attach the licence when it is not the case
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • 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.