source: trunk/scripts/zg_zonal.sh @ 34

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/trunk/scripts/zg_zonal.sh@1252
Revision 34, 6.2 KB checked in by lalibert, 7 years ago (diff)

Initial import

Line 
1##################### HELP ####################################
2#
3#
4#THE CDB DEFINES THE FOLLOWING VARIABLES IN THE FILE cdb_header:
5#
6# PROGRAMS:
7#
8# CDB_CDO_PATH
9# CDB_NCO_PATH
10# CDB_PYTHON_PATH
11#
12# DIRECTORIES:
13#
14# CDB_TEMP_DIR
15# CDB_OUT_DIR
16# CDB_DIAG_DIR
17# CDB_SCRIPT_DIR
18# CDB_IN_DIR
19# CDB_SOURCE_DIR
20#
21#
22#THE DRIVER PASSES THE FOLLOWING INPUTS TO THIS SCRIPT:
23#
24# CDB_MODEL = MODEL NAME, E.G. CanESM2
25# CDB_RUN_ID = RUN_ID, E.G. r1i1p1
26# CDB_EXPT = EXPERIMENT NAME, E.G. rcp45
27# CDB_YEARS = COMMA-SEPARATED YEAR BOUNDS, E.G. 2050,2099
28#
29# CDB_DIAG_NAME
30#
31#THIS SCRIPT RECOVERS REQUESTED VARIABLES AS AN ARRAY OF PATHNAMES
32#
33# IT ALSO FORMATS A NATURAL OUTPUT FILENAME:
34# CDB_OUT_FILE with all run characteristics
35#
36################## END HELP ####################################
37
38################ MODELS USED IN THIS SCRIPT  ##############
39#
40CDB_MODEL_LIST="\
41"
42#
43################ END MODELS USED IN THIS SCRIPT  ##############
44
45################ EXPERIMENTS AND YEARS TO USE THIS SCRIPT ON  ##############
46#
47CDB_EXPT_LIST="\
48historical:1979,2004;\
49amip:1979,2004;\
50"
51#
52#
53################ END EXPERIMENTS AND YEARS TO USE THIS SCRIPT ON  ##############
54
55################ VARIABLES NEEDED IN THIS SCRIPT  ##############
56#
57# A space-separated list of variables names, frequencies, realm and MIP code must be
58# stored in the variable CDB_VAR_LIST. For example, to recover
59# daily surface temperature AND 3-hourly surface specific humidity:
60# CDB_VAR_LIST="tas,day,atmos,day huss,3hr,atmos,3hr"
61# To recover daily cloud area fraction AND monthly sea surface salinity:
62# CDB_VAR_LIST="cl,day,atmos,cfDay sos,mon,atmos,Omon"
63CDB_VAR_LIST="\
64zg,day,atmos,day;\
65zg,mon,atmos,Amon;\
66"
67#
68# For each element 'var_name,freq' in CDB_VAR_LIST, the driver will
69# create a bash variable 'CDB_VAR_var_name_freq' containing the
70# path to the data.
71#
72############# END VARIABLES NEEDED IN THIS SCRIPT  #############
73
74################ DO NOT ERASE BELOW  ##############
75#
76# SETUP THE QUERY
77while getopts :hvme opt; do
78  case $opt in
79    h)
80      echo "Help"
81      echo "h: help"
82      echo "v: prints the variables needed "
83      echo "m: prints the models needed"
84      echo "e: prints the experiments needed"
85      exit
86    ;;
87    v)
88        echo ${CDB_VAR_LIST}
89        exit
90    ;;
91    m)
92        echo ${CDB_MODEL_LIST}
93        exit
94    ;;
95    e)
96        echo ${CDB_EXPT_LIST}
97        exit
98    ;;
99    \?)
100      echo "Unknown option -$OPTARG use -h for help"
101    ;;
102  esac
103done
104#
105#
106#!START YEAR LOOP
107######DO NOT ERASE PREVIOUS LINE
108######It tells the driver to start a loop over the variable YEAR from
109######YEAR_START to YEAR_END, included. It also produces the appropriate
110######bash variables pointing towards the data file for each requested
111######variables
112
113############# END DO NOT ERASE  #############
114
115###################  INSERT YEARLY SCRIPT BELOW #################
116#This script computes:
117#
118#1) daily zonal-mean 250hPa geopotential height Z250_ZON
119#2) monthly 250hPa geopotential height Z250
120
121#Perform the computation month per month:
122for MONTH in 01 02 03 04 05 06 07 08 09 10 11 12
123do
124    CDB_TEMP_FILE=${CDB_OUT_FILE}_${CDB_YEAR}_${MONTH}
125
126    echo "Retrieving ${CDB_YEAR} month ${MONTH}"
127    #Retrieve the file from the archive:
128    cdo -s -f nc -setname,Z250_ZON -zonmean -sellevel,25000 -selname,zg -selyear,${CDB_YEAR} -selmon,${MONTH} ${CDB_VAR_zg_day}\
129                                          ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.z250_zon
130    cdo -s -f nc -setname,Z250 -sellevel,25000 -selname,zg -selyear,${CDB_YEAR} -selmon,${MONTH} ${CDB_VAR_zg_mon}\
131                                      ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.z250
132
133done #MONTH
134
135#Merge the monthly outputs. If one month was missing, output a data quality flag:
136MONTHLY_CAT_LIST="z250_zon z250"
137#Only the previous line should need to be changed if more than one file needs to be output.
138#Be careful if modifying the next few lines
139for VAR_ID in ${MONTHLY_CAT_LIST}; do
140    NUMBER_OF_FILES=$(ls ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID} | wc -l) 
141    if [ "$NUMBER_OF_FILES" -eq "12" ]; then
142        cdo -Q -s mergetime ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID} ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID}
143        mv ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID} ${CDB_OUT_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID}
144        rm ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID}
145    else
146        echo "QUALITY_ASSURANCE_FLAG: Some months are missing for ${VAR_ID} in year ${CDB_YEAR}."
147    fi
148done
149
150###############  END INSERT YEARLY SCRIPT #################
151
152#!END YEAR LOOP
153######DO NOT ERASE PREVIOUS LINE
154######It tells the driver to end the year loop
155
156###############  INSERT POSTPROCESSING SCRIPT BELOW ############
157#Note that bash variables defined in the yearly script will not carry over
158#
159#Merge the yearly files back together and we perform a MULTI-YEAR SEASONAL MEAN
160YEARLY_CAT_LIST="z250_zon z250"
161#Even if this list was defined previously, it still has to be defined here.
162#Only the previous line of code should need to be changed if more than one file needs to be output.
163#Be careful if modifying the next few lines.
164for VAR_ID in ${YEARLY_CAT_LIST}; do
165    NUMBER_OF_FILES=$(ls ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID} | wc -l) 
166    if [ "$NUMBER_OF_FILES" -eq "$((${CDB_YEAR_END}-${CDB_YEAR_START}+1))" ]; then
167        cdo -s mergetime ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID} ${CDB_OUT_DIR}/${CDB_OUT_FILE}.${VAR_ID}
168        rm ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID}
169    else
170        echo "QUALITY_ASSURANCE_FLAG: Some years are missing for ${VAR_ID}"
171    fi
172done
173
174#This script outputs the following file for each model:
175#${CDB_OUT_DIR}/${CDB_OUT_FILE}.psl_mask
176
177#Finally, we list the output files that we wish will be structured as in a typical ESG, essentially creating
178# new CMIP5 type variables. These will then be easily recoverable from another script.
179#This instruction will take the file ${CDB_OUT_DIR}/${CDB_OUT_FILE}.psl_mask and output each of the variables it contains to
180#a separate file, with a naming convention that assumes that the data it contains is at the daily frequency.
181#Do not forget to leave a blank space between entries.
182CDB_CMIP5_COMP_LIST="\
183${CDB_OUT_DIR}/${CDB_OUT_FILE}.z250_zon;day,atmos,day \
184${CDB_OUT_DIR}/${CDB_OUT_FILE}.z250;mon,atmos,Amon \
185"
Note: See TracBrowser for help on using the repository browser.