I want to apply the CDO (Climate Data Operator) "remapnn" command in order to extract time series for a set of points that are stored in the "coords.txt" file. The stucture of the coords.txt file is the following:

station , lat , lon 
ABTR2100 ,39.13,34.52
GRMR0100 ,20.18,49.00
DDDD0100 ,23.22,46.81
SLPT0100 ,26.91,32.23
NDRT0100 ,29.55,48.97

For this reason, I have tried to write the following bash shell that will allow me to run the remapnn command for all stations in a loop:

while read p; do
  echo $p
   cdo remapnn,lon=$lon_lat=$lat, temperature.nc $output.nc
done <coords.txt

More specifically, where "lon" the longitude of the station is supposed to be assigned, and where "lat" the latitude of the station is supposed to be assigned. The "temperature.nc" file is my NetCDF file from which I want to extract the time series, "out.nc" is the output. The command works perfectly for a single location, for instance:

cdo remapnn,lon=34.52_lat=39.13, temperature.nc output.nc

but unfortunately, doesn't work in a loop. This is the error message I get:

cdo remapnn (Abort): Open failed on lon==!

This is a guess, as I have no idea what this cdo command does or how it works.

 # arrange the input to come from a fixed place
 exec < coords.txt
 # Copy the header line, which looks like "station , lat, lon"
 read -r header
 echo -- "$header"
 while IFS=", " read -r st la lo
    cdo "remapnn,lon=${lo}_lat=${la}," temperature.nc "${st}_out.nc"

I don't know if cdo appends to the output.nc file or you will only get the results for the last station.

|improve this answer|||||
  • Icarus, thank you for your reply! I want to save the output for each run to the "output.nc" with a different name. Preferably, I would want to save the output using the id in the "Station" column of my .txt that contains the coordinates. So I would have "ABTR2100_out.nc", "GRMR0100_out.nc" etc. – Maria Karypidou Dec 3 '16 at 10:30
  • Edited to save the output as requested – icarus Dec 3 '16 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.