Project

General

Profile

chain operators div & mergetime

Added by Kostas S over 5 years ago

Hi to all,

I have a question about how to chain operators like mergetime and div in a bash script.

1st part of my question have to do with mergetime operator in a bash script.
I have multiple precipitation datasets and i want to do the following task

cdo yearsum -mulc,86400 -div landmask.nc -mergetime '$path/pr*.nc' outfile

while in bash this command works fine in bash script single quotes ' ' gives this error:
expandWildCards: wordexp() returns an error.

So i had to replace them with double quotes " "

but when using double quotes in a bash script " " the mergetime operator gives wrong values. So how i have to chain mergetime with wildcard * in bash script to work as usual?

The 2nd part of my question have to do with div in chain. When i use a static file like landmask.nc, is it used as numerator or denominator? for example:
cdo div landmask.nc -mergetime 'pr*.nc' outfile
Generally, in chaining operators with 2 inputs, the static file comes 1st or second?

In bash prompt, the chain works fine, but in bash script gives wrong values.

This is my cdo configuration:

Climate Data Operators version 1.9.5rc3 (http://mpimet.mpg.de/cdo)
System: x86_64-pc-linux-gnu
CXX Compiler: mpicxx -std=gnu++11 -g -O2 -fopenmp
CXX version : unknown
C Compiler: mpicc -std=gnu99 -O2 -fPIC -fopenmp
C version : unknown
F77 Compiler: mpif77 -g -O2
F77 version : unknown
Features: 15GB 4threads C++11 Fortran DATA PTHREADS OpenMP3 HDF5 NC4/HDF5 OPeNDAP SZ UDUNITS2 PROJ.4 XML2 MAGICS CURL FFTW3 CMOR SSE2
Libraries: HDF5/1.10.2 proj/5.1 CMOR/3.3.2 xml2/2.9.1 curl/7.29.0
Filetypes: srv ext ieg grb1 grb2 nc1 nc2 nc4 nc4c nc5
CDI library version : 1.9.5
CGRIBEX library version : 1.9.1
GRIB_API library version : 2.8.0
NetCDF library version : 4.6.1 of Jul 27 2018 12:54:12 $
HDF5 library version : 1.10.2
EXSE library version : 1.4.0
FILE library version : 1.8.3


Replies (5)

RE: chain operators div & mergetime - Added by Uwe Schulzweida over 5 years ago

Sorry the error message

expandWildCards: wordexp() returns an error.
is not very precise. The correct error message is:
expandWildCards: Undefined shell variable in '$path/pr*.nc'
which means $path is unknown. In bash you have to add the export keyword to the variable path to export this variable:
export path=/...

RE: chain operators div & mergetime - Added by Uwe Schulzweida over 5 years ago

For the CDO operator div the first input file is always the numerator and the second is the denominator.

RE: chain operators div & mergetime - Added by Kostas S over 5 years ago

Uwe Schulzweida wrote:

Sorry the error message
[...]is not very precise. The correct error message is:
[...]which means $path is unknown. In bash you have to add the export keyword to the variable path to export this variable:
[...]

echo $path gives the right value. but apart from this, if i don't use a variable for the path , but the absolute path, i got the same error if i use double quotes " " for mergetime operator in chain in bash script. I cann't use signle quotes ''. If i use single i got the error "expandWildCards: wordexp() returns an error." Just test it.

RE: chain operators div & mergetime - Added by Kostas S over 5 years ago

Uwe Schulzweida wrote:

For the CDO operator div the first input file is always the numerator and the second is the denominator.

The question was not for div stand alone. But for div (and also for other operators wchich need 2 inputs) in chain.
For example:
div landmask.nc --mergetime pr*.nc

Which is the numerator? the static landmask.nc or the stream which comes from mergetime?

RE: chain operators div & mergetime - Added by Uwe Schulzweida over 5 years ago

You have to take care when using CDO chaining with operators which have more than one input file.
If you can express your input files with wildcards as one argument you can add single quotes around it:

cdo add mask.nc -mergetime 'data*' outfile
or
cdo add -mergetime 'data*' mask.nc outfile
It will not work without the singlequotes:
cdo add -mergetime data* mask.nc outfile  <--- wrong !!

    (1-5/5)