source: trunk/scripts/psl_daily.sh @ 34

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/trunk/scripts/psl_daily.sh@1252
Revision 34, 5.6 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#
40#Use find_optimset.sh to generate a list of models to be used
41CDB_MODEL_LIST="\
42"
43#
44############# END MODELS USED IN THIS SCRIPT  #############
45 
46################ EXPERIMENTS AND YEARS TO USE THIS SCRIPT ON  ##############
47#
48CDB_EXPT_LIST="\
49historical:1965,2004;\
50rcp45:2060,2099;\
51"
52#
53#
54############# END EXPERIMENTS USED IN THIS SCRIPT  #############
55
56################ VARIABLES NEEDED IN THIS SCRIPT  ##############
57#
58# A space-separated list of variables names, frequencies, realm and MIP code must be
59# stored in the variable CDB_VAR_LIST. For example, to recover
60# daily surface temperature AND 3-hourly surface specific humidity:
61# CDB_VAR_LIST="tas,day,atmos,day huss,3hr,atmos,3hr"
62# To recover daily cloud area fraction AND monthly sea surface salinity:
63# CDB_VAR_LIST="cl,day,atmos,cfDay sos,mon,atmos,Omon"
64#CDB_VAR_LIST="tas,mon,atmos,Amon"
65CDB_VAR_LIST="\
66psl,day,atmos,day;\
67"
68#
69# For each element 'var_name,freq' in CDB_VAR_LIST, the driver will
70# create a bash variable 'CDB_VAR_var_name_freq' containing the
71# path to the data.
72#
73############# END VARIABLES NEEDED IN THIS SCRIPT  #############
74
75################ DO NOT ERASE BELOW  ##############
76#
77# SETUP THE QUERY
78while getopts :hvme opt; do
79  case $opt in
80    h)
81      echo "Help"
82      echo "h: help"
83      echo "v: prints the variables needed "
84      echo "m: prints the models needed"
85      echo "e: prints the experiments needed"
86      exit
87    ;;
88    v)
89        echo ${CDB_VAR_LIST}
90        exit
91    ;;
92    m)
93        echo ${CDB_MODEL_LIST}
94        exit
95    ;;
96    e)
97        echo ${CDB_EXPT_LIST}
98        exit
99    ;;
100    \?)
101      echo "Unknown option -$OPTARG use -h for help"
102    ;;
103  esac
104done
105#
106#
107#!START YEAR LOOP
108######DO NOT ERASE PREVIOUS LINE
109######It tells the driver to start a loop over the variable YEAR from
110######YEAR_START to YEAR_END, included. It also produces the appropriate
111######bash variables pointing towards the data file for each requested
112######variables
113
114############# END DO NOT ERASE  #############
115
116###################  INSERT YEARLY SCRIPT BELOW #################
117#THIS SCRIPT COMPUTES THE DAILY CYCLONE MASK IN PSL USING WERNLI AND SCHWIERZ.
118for MONTH in 01 02 03 04 05 06 07 08 09 10 11 12
119do
120CDB_TEMP_FILE=${CDB_OUT_FILE}_${CDB_YEAR}_${MONTH}
121
122echo "Retrieving ${CDB_YEAR} month ${MONTH}"
123cdo -s -f nc -selyear,${CDB_YEAR} -selmon,${MONTH} ${CDB_VAR_psl_day}\
124                                  ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.retrieve
125
126#First compute the cyclone mask
127cdo -s -selzaxis,surface ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.retrieve ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.surf
128rm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.retrieve
129
130done #MONTH
131
132#Merge the monthly outputs. If one month was missing, output a data quality flag:
133MONTHLY_CAT_LIST="surf"
134#Only the previous line should need to be changed if more than one file needs to be output.
135#Be careful if modifying the next few lines
136for VAR_ID in ${MONTHLY_CAT_LIST}; do
137    NUMBER_OF_FILES=$(ls ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID} | wc -l) 
138    if [ "$NUMBER_OF_FILES" -eq "12" ]; then
139        cdo -Q -s mergetime ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID} ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID}
140        mv ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID} ${CDB_OUT_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}.${VAR_ID}
141        rm ${CDB_TEMP_DIR}/${CDB_OUT_FILE}_${CDB_YEAR}_??.${VAR_ID}
142    else
143        echo "QUALITY_ASSURANCE_FLAG: Some months are missing for ${VAR_ID} in year ${CDB_YEAR}."
144    fi
145done
146
147###############  END INSERT YEARLY SCRIPT #################
148
149#!END YEAR LOOP
150######DO NOT ERASE PREVIOUS LINE
151######It tells the driver to end the year loop
152
153###############  INSERT POSTPROCESSING SCRIPT BELOW ############
154#Note that bash variables defined in the yearly script will not carry over
155#
156#Merge the yearly files back together and we perform a MULTI-YEAR SEASONAL MEAN
157YEARLY_CAT_LIST="surf"
158#Even if this list was defined previously, it still has to be defined here.
159#Only the previous line of code should need to be changed if more than one file needs to be output.
160#Be careful if modifying the next few lines.
161for VAR_ID in ${YEARLY_CAT_LIST}; do
162    NUMBER_OF_FILES=$(ls ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID} | wc -l) 
163    if [ "$NUMBER_OF_FILES" -eq "$((${CDB_YEAR_END}-${CDB_YEAR_START}+1))" ]; then
164        cdo -s mergetime ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID} ${CDB_OUT_DIR}/${CDB_OUT_FILE}.${VAR_ID}
165        rm ${CDB_OUT_DIR}/${CDB_OUT_FILE}_????.${VAR_ID}
166    else
167        echo "QUALITY_ASSURANCE_FLAG: Some years are missing for ${VAR_ID}"
168    fi
169done
170
171#Finally, we list the output files that we wish will be structured as in a typical ESG, essentially creating
172# new CMIP5 type variables. These will then be easily recoverable from another script.
173CDB_CMIP5_COMP_LIST="\
174${CDB_OUT_DIR}/${CDB_OUT_FILE}.surf;day,atmos,day\
175"
Note: See TracBrowser for help on using the repository browser.