source: trunk/tools/netCDF_scripts/make_1mm @ 43

Last change on this file since 43 was 43, checked in by ericg, 16 years ago

Added directory with nco shell script utilities for post-it - make_1mm for now

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/bin/sh
2# -*- Mode: sh -*-
3#
4#  Script to build 1mm and annual mean from time serie
5#
6#  Uses nco tools
7#
8usage() {
9echo
10echo "usage : make_1mm [-d] [-g] [-v <field1>,<field2>...] [-t <record name>] [-g <grid>] [-m] <file> <nyears>"
11echo
12}
13#
14#
15# --------------------------------------------------------------
16#  E. Guilyardi - LODYC -  July 1999 - Nov 2007
17#
18#
19# Inits
20#
21
22while getopts g:dhv:t:m name
23do
24    case $name in
25        d) set -x ;;
26        g) type="$OPTARG";;
27        v) fields="$OPTARG" ;;
28        t) timef="$OPTARG" ;;
29        m) nomean=1;;
30        h) usage
31           echo
32           exit 1
33           ;;
34    esac
35done
36
37#
38# so that $1 is root
39#
40shift `expr $OPTIND - 1`
41file=$1
42
43enam=`echo $file | awk -F\_ '{print $1}'`
44ave=`echo $file | awk -F\_ '{print $2}'`
45date1=`echo $file | awk -F\_ '{print $3}'`
46year1=`echo $date1 | sed 's/\(.*\)../\1/'`
47date2=`echo $file | awk -F\_ '{print $4}'`
48year2=`echo $date2 | sed 's/\(.*\)../\1/'`
49ndates=$2
50
51root=${enam}_${ave}_${date1}_${date2}
52
53type=`echo $file | awk -F\_ '{print $5}'`
54type2=`echo $file | awk -F\_ '{print $6}'`
55type3=`echo $file | awk -F\_ '{print $7}'`
56type4=`echo $file | awk -F\_ '{print $8}'`
57type=${type}_${type2}_${type3}_${type4}
58type=`echo $type | sed 's/\(.*\)\.nc.*/\1/'`
59
60
61type=${type:-"auto"}
62nomean=${nomean:-0}
63
64echo ""
65echo "Processing: $enam $ave $year1 $year2 $ndates $type"
66
67case $type in
68    t30) long="nav_lon" 
69            lati="nav_lat" 
70           time="time_counter" ;;
71    lmdz*) long="lon" 
72            lati="lat" 
73            time="time_counter" ;;
74    reg1) long="lon" 
75            lati="lat" 
76            time="time" ;;
77    t42) long="lon" 
78            lati="lat" 
79            time="time" ;;
80    t62) long="lon" 
81           lati="lat" 
82           time="time" ;;
83    umat) long="longitude" 
84            lati="latitude" 
85            time="t" ;;
86    umau) long="longitude" 
87            lati="latitude" 
88            time="t" ;;
89    reg1mtrop) long="longitude" 
90            lati="latitude" 
91            time="t" ;;
92    *) long="nav_lon" 
93       lati="nav_lat" 
94       time=`ncdump -h ${file} | grep UNLIMITED | awk '{print $1}'` ;;
95esac
96time=${timef:-$time}
97fields=${fields:-"-x -v $long,$lati"}
98         
99#
100case $ave in
101    1m) # output file name
102        month1=`echo $date1 | sed 's/.*\(..\)/\1/'`
103        month2=`echo $date2 | sed 's/.*\(..\)/\1/'`
104
105        aveoum=1mm
106        ;;
107
108    *) echo " ERROR : case ave=$ave not relevant "
109       exit 1
110       ;;
111esac
112
113#
114PATH=$PATH:/usr/local/netcdf/bin:/u/rech/eee/reee217/bin
115#
116out1m=${enam}_${aveoum}_01_12_${year1}-${year2}_$type.nc
117outmean=${enam}_${ndates}y_${year1}_${year2}_$type.nc
118#
119optg="-O"
120grid=0
121if [ $grid -eq 1 ] ; then
122# get grid
123    ncks -O -v $lati,$long ${file} $out1m || echo 'no grid'
124    optg="-A"
125fi
126
127m_list="00 01 02 03 04 05 06 07 08 09 10 11"
128
129# average every month
130
131for m in ${m_list}
132    do
133        m1=`expr $m + 1`
134#       echo "   averaging month $m1 "
135        ncks -O -d $time,$m,,12 ${file} ${root}_${type}_mean_month.nc || exit
136        ncra -O -F -d $time,1,$ndates ${root}_${type}_mean_month.nc ${root}_${type}_mean_month_${m}.nc || exit
137        rm ${root}_${type}_mean_month.nc
138done
139   
140# build monthly means
141   
142echo " Building ${enam}_${aveoum}_01_12_${year1}-${year2}_$type.nc"
143   
144ncrcat ${optg} ${root}_${type}_mean_month_??.nc $out1m
145
146if [ $nomean -eq 0 ] ; then
147
148    echo " Building ${outmean}"
149   
150    ncra ${optg} $out1m $outmean
151
152fi
153
154rm -f ${root}_${type}_mean_*.nc
Note: See TracBrowser for help on using the repository browser.