1

I used Climate data operator (CDO) to extract time series in CSV format with the following code
cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc> output.csv
Here, CSV file comes with variables date, lon, lat and value in a single column as shown below.

date lat lon value
1950-01-01 31.57 -85.25 0.05
1950-01-01 31.57 -85.25 0.06
1950-01-01 31.57 -85.25 0.07
.......
.......
2000-01-01 31.57 -85.25 3.01

How can I create a column for each variable?
If possible, I want to change in the given code.

b_takhel
  • 55
  • 7
  • 1
    Please show how the output of `cdo` looks as you've invoked it — I don't have the program and can't see for myself. Probably want to use a preformatted block for it. Is it just a single output set, or a series (time-series as you say) of date,lon,lat,value entries? – Stephen P Jun 23 '20 at 20:38
  • 1
    @StephenP I have edited the question as I could not provide the output table in this section. – b_takhel Jun 23 '20 at 20:54
  • 1
    Also include your required output from your sample input. Verbal descriptions are often confusing, whereas showing what you need will be easy to understand. Good luck. – shellter Jun 23 '20 at 22:59

2 Answers2

1

I am not sure whether it's a good way to answer myself as I don't want to delete my question.I want to attached my answer as I am able to solve by using the following code

cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc | awk 'FNR==1{ row=$2","$3","$4","$5;print row } FNR!=1{ row=$1","$2","$3","$4; print row}' > output.csv

b_takhel
  • 55
  • 7
1

Use sed to turn the spaces into commas?

Something like

cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc |
  sed 's/[[:space:]]/,/g' > output.csv

(This will also work if cdo uses tabs instead of spaces to separate values).

Shawn
  • 47,241
  • 3
  • 26
  • 60