The following is a simple example demonstrates the basic procedure used in creating a CDF file. See Variables and Attributes for a discussion of the variances used in this example. See the documentation for individual CDF routines for more specific examples.
id = CDF_CREATE('Temperature.cdf', [2,3], /CLOBBER )
att_id = CDF_ATTCREATE(id, 'Title', /GLOBAL)
CDF_ATTPUT, id, att_id, 0, 'My Fancy CDF'
att1_id = CDF_ATTCREATE(id, 'Planet', /GLOBAL)
CDF_ATTPUT, id, 'Planet', 0, 'Mars'
time_id = CDF_VARCREATE(id, 'Time', ['NOVARY', 'NOVARY'], $
att2_id = CDF_ATTCREATE(id, 'Time Standard', /VARIABLE_SCOPE)
CDF_ATTPUT, id, att2_id, time_id, 'GMT' ; times are every half hour starting a 8 am GMT.
FOR I=0,9 DO CDF_VARPUT, id, time_id, 8.+ 0.5 * I, rec_start=I
temp_id = CDF_VARCREATE(id, 'Temp', ['VARY', 'VARY'], $
/REC_VARY, /ZVAR, DIMENSIONS=[2,3])
long_id = CDF_VARCREATE(id, 'Longitude', ['VARY', 'VARY'], $
lat_id = CDF_VARCREATE(id, 'Latitude', ['VARY', 'VARY'], $
CDF_VARPUT, id, temp_id, FINDGEN(2, 3, 10)
;
write 10 temperature records.
CDF_VARPUT, id, long_id, [[10.0, 12.0], [8.0, 6.0], [3.0, 2.0]]
;
create longitudes.
CDF_VARPUT, id, lat_id, [[40.0, 42.0], [38.0, 34.0],[30.0, 31.0]]
create latitudes.