source: trunk/tools/netCDF_scripts/make_1mm @ 68

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

Clean up of make_1mm

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/bin/sh
2# -*- Mode: sh -*-
3#
4#  Script to build 1mm and full record annual mean from monthly time serie
5#
6#  Uses nco tools
7#
8usage() {
9echo
10echo "usage : make_1mm [-d] [-v <field1>,<field2>...] [-t <record name>] [-m] <file> <nyears>"
11echo "        -d : toggle debug mode"
12echo "        -v : specify fields to work on"
13echo "        -t : specify time record name (should be detected automatically)"
14echo "        -m : do not make full record time mean"
15echo "        <file>   : netcdf post-it format file"
16echo "        <nyears> : number of years in file"
17echo
18}
19#
20#
21# --------------------------------------------------------------
22#  E. Guilyardi - LODYC -  July 1999 - Nov 2007
23#
24#
25# Inits
26#
27
28while getopts dhv:t:m name
29do
30    case $name in
31        d) set -x ;;
32        v) fields="$OPTARG" ;;
33        t) timef="$OPTARG" ;;
34        m) nomean=1;;
35        h) usage
36           echo
37           exit 1
38           ;;
39    esac
40done
41
42#
43# decode file name
44#
45shift `expr $OPTIND - 1`
46file=$1
47
48enam=`echo $file | awk -F\_ '{print $1}'`
49ave=`echo $file | awk -F\_ '{print $2}'`
50date1=`echo $file | awk -F\_ '{print $3}'`
51year1=`echo $date1 | sed 's/\(.*\)../\1/'`
52date2=`echo $file | awk -F\_ '{print $4}'`
53year2=`echo $date2 | sed 's/\(.*\)../\1/'`
54ndates=$2
55
56root=${enam}_${ave}_${date1}_${date2}
57
58type=`echo $file | awk -F\_ '{print $5}'`
59type2=`echo $file | awk -F\_ '{print $6}'`
60type3=`echo $file | awk -F\_ '{print $7}'`
61type4=`echo $file | awk -F\_ '{print $8}'`
62type=${type}_${type2}_${type3}_${type4}
63type=`echo $type | sed 's/\(.*\)\.nc.*/\1/'`
64
65
66type=${type:-"auto"}
67nomean=${nomean:-0}
68
69echo ""
70echo "Processing: $enam $ave $year1 $year2 $ndates $type"
71
72# detect time dimension
73
74time=`ncdump -h ${file} | grep UNLIMITED | awk '{print $1}'`
75time=${timef:-$time}
76fields=${fields:-"-x -v $long,$lati"}
77         
78#
79case $ave in
80    1m) # output file name
81        month1=`echo $date1 | sed 's/.*\(..\)/\1/'`
82        month2=`echo $date2 | sed 's/.*\(..\)/\1/'`
83
84        aveoum=1mm
85        ;;
86
87    *) echo " ERROR : case ave=$ave not relevant "
88       exit 1
89       ;;
90esac
91
92#
93out1m=${enam}_${aveoum}_01_12_${year1}-${year2}_$type.nc
94outmean=${enam}_${ndates}y_${year1}_${year2}_$type.nc
95#
96optg="-O"
97
98m_list="00 01 02 03 04 05 06 07 08 09 10 11"
99
100# average every month
101
102for m in ${m_list}
103    do
104        m1=`expr $m + 1`
105#       echo "   averaging month $m1 "
106        ncks -O -d $time,$m,,12 ${file} ${root}_${type}_mean_month.nc || exit
107        ncra -O -F -d $time,1,$ndates ${root}_${type}_mean_month.nc ${root}_${type}_mean_month_${m}.nc || exit
108        rm ${root}_${type}_mean_month.nc
109done
110   
111# build monthly means
112   
113echo " Building ${enam}_${aveoum}_01_12_${year1}-${year2}_$type.nc"
114   
115ncrcat ${optg} ${root}_${type}_mean_month_??.nc $out1m
116
117if [ $nomean -eq 0 ] ; then
118
119    echo " Building ${outmean}"
120   
121    ncra ${optg} $out1m $outmean
122
123fi
124
125rm -f ${root}_${type}_mean_*.nc
Note: See TracBrowser for help on using the repository browser.