if condition with "expr"
Added by Ivana Cvijanovic 3 months ago
Hi,
I have a file containing t2m and rh (tarh_era5.nc). I would like to select rh only for those time steps when t2m is >30.
I use the following command:
cdo -expr,'rhsample=(t2m>30) ? rh : -999.9' tarh_era5.nc rhsample_era5.nc
Can someone confirm if this command is doing what I was hoping it would ? My files dont look right, there are missing values at locations that should satisfy this condition, so I suspect not.
Thank you,
Ivana
Replies (1)
RE: if condition with "expr" - Added by Estanislao Gavilan 3 months ago
Hi Ivana,
to mask a variable using a different variable your need to follow this formula
cdo -expr,'x_mask=((y > c) ? x : mask_c)' infile outfile
So you have to add two missing brackets
cdo -expr,'rhsample=((t2m>30) ? rh : -999.9)' tarh_era5.nc rhsample_era5.nc
Best regards,
Estanislao