Creating CDF Files
The following list details the basic IDL commands needed to create a new CDF file:
- CDF_CREATE: Call this procedure to begin creating a new file. CDF_CREATE contains a number of keywords which affect the internal format of the new CDF file.
- CDF_VARCREATE: Define the variables to be used in the file.
- CDF_ATTPUT: Optionally, use attributes to describe the data.
- CDF_VARPUT: Write the appropriate data to the CDF file.
- CDF_CLOSE: Close the file.
Note
On Windows, CDF routines can save and retrieve data sets greater than 64 KB in size.
Reading CDF Files
The following commands are the basic commands needed to read data from a CDF file:
- CDF_OPEN: Open an existing CDF file.
- CDF_INQUIRE: Call this function to find the general information about the contents of the CDF file.
- CDF_CONTROL: Call this function to obtain further information about the CDF file
- CDF_VARINQ: Retrieve the names, types, sizes, and other information about the variables in the CDF file.
- CDF_VARGET: Retrieve the variable values.
- CDF_ATTINQ: Optionally, retrieve the names, scope and other information about the CDFs attributes.
- CDF_ATTGET: Optionally, retrieve the attributes.
- CDF_CLOSE: Close the file.
- If the structure of the CDF file is already known, the inquiry routines do not need to be called—only CDF_OPEN, CDF_ATTGET, CDF_VARGET, and CDF_CLOSE would be needed.
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