0

In my simple code I extract one variable named bet from the NETCDF file and then I write it out of the NETCDF file as here:

import os, glob 
print(filenamels)
for fn in filenamels:
outputFile = fn[:len(fn)-3]+'_ull_st.dat'
os.system( gdalcmd)

There are other variables feg,dis,lam, named ,in these NETCDF files and I do not want to run the code for each variable.I wonder how we can write a loop to extract these variables at once.

1 Answer 1

1

ncks from the NCO package (http://nco.sourceforge.net/nco.html) is the way to go here. For example, extracting variables bet, feg, dis, lam from a file called myfile.nc and outputting them into a file called myfileout.nc would be:

ncks -v bet,feg,dis,lam myfile.nc -O myfileout.nc 
Sign up to request clarification or add additional context in comments.

1 Comment

You can extract data from the netcdf file and store it in a .dat file with ncks -v bet -s '%f\n' file.nc > output.dat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.