Previous Scientific Data Formats: Common Data Format Next

Creating CDF Files

The following list details the basic IDL commands needed to create a new CDF file:

Reading CDF Files

The following commands are the basic commands needed to read data from a CDF file:

Type Conversion

Values are converted to the appropriate type before being written to a CDF file. For example, in the commands below, IDL converts the string "12" to a floating-point 12.0 before writing it:

varid=CDF_VARCREATE(fileid, 'VarName',['VARY','VARY'],$  
   DIM=[2,3+5],/CDF_FLOAT)  
CDF_VARPUT, fileid, 'VarName', '12' ; Reference by variable ID  

Example: Creating a CDF File

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'], $  
   /REC_VARY)  
att2_id = CDF_ATTCREATE(id, 'Time Standard', /VARIABLE_SCOPE)  
; times are every half hour starting a 8 am GMT.  
CDF_ATTPUT, id, att2_id, time_id, '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'], $  
   /REC_NOVARY)  
lat_id = CDF_VARCREATE(id, 'Latitude', ['VARY', 'VARY'], $  
   /REC_NOVARY)  
; write 10 temperature records:  
CDF_VARPUT, id, temp_id, FINDGEN(2, 3, 10)  
; create longitudes:  
CDF_VARPUT, id, long_id, [[10.0, 12.0], [8.0, 6.0], [3.0, 2.0]]  
; create latitudes:  
CDF_VARPUT, id, lat_id, [[40.0, 42.0], [38.0, 34.0],[30.0, 31.0]]  
CDF_CLOSE, id  

  IDL Online Help (March 06, 2007)