Skip to content

Instantly share code, notes, and snippets.

@adamabernathy
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save adamabernathy/7b7b3842ebebabc0c6ab to your computer and use it in GitHub Desktop.

Select an option

Save adamabernathy/7b7b3842ebebabc0c6ab to your computer and use it in GitHub Desktop.
How to write NetCDF files in IDL.
; Set up the file & handler
n_profiles = n_elements(lat) ; just pick any of your data arrays
fid=ncdf_create('FILENAME-GOES-HERE'+'.nc',/CLOBBER)
d=indgen(2,/LONG) ; number of dimensions that will be created
; Set Dimensions
d[0]=ncdf_dimdef(fid,'n_profiles',n_profiles) ; length 'j'
d[1]=ncdf_dimdef(fid,'n_bins',n_bins) ; length 'i'
; Define variables to be stored
var_id=ncdf_vardef(fid,'Longitude',d[0],/DOUBLE)
var_id=ncdf_vardef(fid,'Latitude',d[0],/DOUBLE)
var_id=ncdf_vardef(fid,'Temp',[d[1],d[0]],/double)
var_id=ncdf_vardef(fid,'Pressure',[d[1],d[0]],/double)
; Change modes
ncdf_control,fid,/ENDEF
; Write the data
ncdf_varput,fid,'Longitude',rg_lon
ncdf_varput,fid,'Latitude',rg_lat
ncdf_varput,fid,'Temp',temp
ncdf_varput,fid,'Pressure',pressure
ncdf_varput,fid,'SH',sh
; Close the file & release the handler
ncdf_close,fid
print,' > Writing complete... Closing...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment