1

I would like to extract CRU precipitation data in netcdf format into separate GeoTIFF files. Usually if the netcdf file only have variables: lon, lat, time and pre I can manage to extract it using below script:

for t in `cdo showdate input.nc`; do
  cdo seldate,$t input.nc dummy.nc
  gdal_translate -of GTiff -a_ullr <top_left_lon> <top_left_lat> <bottom_right_lon> <bottom_right_lat> -a_srs EPSG:4326 dummy.nc $t.tif
done

The CRU precipitation data have variables: lon, lat, time, pre and stn

I can't use above script because it contains 2 subdataset, got message from CDO: Input file contains subdatasets. Please, select one of them for reading.

How to select pre variables in CDO and applying into above script?

user97103
  • 235
  • 1
  • 7

1 Answers1

1

If you mean that the files have more than one variable then you can select the variable "pre" using the command selvar, which you can then pipe to seldate:

cdo seldate,$t -selvar,pre input.nc dummy.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Thank you! It's worked. I will use your suggestion for next analysis. While ago before finding your way, I used ```cdo delname,stn input.nc output.nc```, deleting variable ```stn``` then execute using my script above, worked but not efficient :) – user97103 Sep 16 '20 at 16:36