Routines (alphabetical) > Routines: C > CDF Routines > CDF_CREATE

# CDF_CREATE

The CDF_CREATE function creates a new Common Data Format file with the given filename and dimensions.

Note that when you create a CDF file, you may specify both encoding and decoding methods. Encoding specifies the method used to write data to the CDF file. Decoding specifies the method used to retrieve data from the CDF file and pass it to an application (IDL, for example). Encoding and decoding methods are specified by setting the XXX_ENCODING and XXX_DECODING keywords to CDF_CREATE. If no decoding method is specified, the decoding method is set to be the same as the encoding method.

All CDF encodings and decodings can be written or read on all platforms, but matching the encoding with the architecture used provides the best performance. Since most people work in a single-platform environment most of the time, the HOST_ENCODING method is used as the default encoding scheme. This provides maximum performance. If you know that the CDF file will be transported to a computer using another architecture, specify the encoding for the target architecture or specify NETWORK_ENCODING. Specifying the target architecture provides maximum performance on that architecture; specifying NETWORK_ENCODING provides maximum flexibility.

For more discussion on CDF encoding/decoding methods and combinations, see “Encoding” and “Decoding” in the CDF User’s Guide.

Note: Versions of IDL beginning with 6.3 support the CDF 3.1 library. If you need to create CDF files that can be read by earlier versions of IDL, or by CDF libraries earlier than version 3.0, use the CDF_SET_CDF27_BACKWARD_COMPATIBLE routine.

## Examples

Use the following command to create a 10-element by 20-element CDF using network encoding and Sun decoding:

id = CDF_CREATE('cdf_create.cdf', [10,20], /NETWORK_ENCODING, $

/SUN_DECODING)

; ... other cdf commands ...

CDF_CLOSE, id ; close the file.

Now suppose that we decide to use HP_DECODING instead. We can use the CLOBBER keyword to delete the existing file when creating the new file:

id = CDF_CREATE('cdf_create.cdf', [10,20], /NETWORK_ENCODING, $

/HP_DECODING, /CLOBBER)

; ... other cdf commands ...

CDF_CLOSE, id ; close the file.

The new file is written over the existing file. Use the following command to delete the file:

CDF_DELETE, id

## Syntax

Result = CDF_CREATE( Filename, [Dimensions] [, /CLOBBER] [, /MULTI_FILE | , /SINGLE_FILE] [, /COL_MAJOR | , /ROW_MAJOR] )

Encoding Keywords (pick one):
[, /ALPHAOSF1_ENCODING]
[, /ALPHAVMSD_ENCODING]
[, /ALPHAVMSG_ENCODING]
[, /DECSTATION_ENCODING]
[, /HOST_ENCODING]
[, /HP_ENCODING]
[, /IBMPC_ENCODING]
[, /IBMRS_ENCODING]
[, /MAC_ENCODING]
[, /NETWORK_ENCODING]
[, /NEXT_ENCODING]
[, /SGI_ENCODING]
[, /SUN_ENCODING]

Decoding Keywords (pick one):
[, /ALPHAOSF1_DECODING]
[, /ALPHAVMSD_DECODING]
[, /ALPHAVMSG_DECODING]
[, /DECSTATION_DECODING]
[, /HOST_DECODING]
[, /HP_DECODING]
[, /IBMPC_DECODING]
[, /IBMRS_DECODING]
[, /MAC_DECODING]
[, /NETWORK_DECODING]
[, /NEXT_DECODING]
[, /SGI_DECODING]
[, /SUN_DECODING]

## Return Value

Returns the CDF ID for the new file.

## Arguments

### Filename

A scalar string containing the name of the file to be created. Note that if the desired filename has a `.cdf` ending, you can omit the extension and specify just the first part of the filename. For example, specifying `“mydata”` would open the file `mydata.cdf`.

### Dimensions

A vector of values specifying size of each rVariable dimension. If no dimensions are specified, the file will contain a single scalar per record (i.e., a 0-dimensional CDF). This argument has no effect on zVariables.

## Keywords

### CLOBBER

Set this keyword to erase the existing file (if the file already exists) before creating the new version.

Note that if the existing file has been corrupted, the CLOBBER operation may fail, causing IDL to display an error message. In this case you must manually delete the existing file from outside IDL.

### COL_MAJOR

Set this keyword to use column major (IDL-like) array ordering for variable storage.

### MULTI_FILE

Set this keyword to cause all CDF control information and attribute entry data to be placed in one `.cdf` file, with a separate file created for each defined variable. If the variable is an rVariable, then the variable files will have extensions of `.v0`, `.v1`, etc.; zVariables will be stored in files with extensions of `.z0`, `.z1`, etc. See “Format” in the CDF User’s Guide for more information. If both SINGLE_FILE and MULTI_FILE are set the file will be created in the SINGLE_FILE format.

Note: In versions of IDL prior to 6.3, MULTI_FILE was the default.

MULTI_FILE Example:

id=CDF_CREATE('multi', /MULTI_FILE)

CDF_CONTROL, id, GET_FORMAT=cdf_format

HELP, cdf_format

IDL prints:

CDF_FORMAT STRING = 'MULTI_FILE'

### ROW_MAJOR

Set this keyword to specify row major (C-like) array ordering for variable storage. This is the default.

### SINGLE_FILE

Set this keyword to cause all CDF information (control information, attribute entry data, variable data, etc.) to be written to a single `.cdf` file. This is the default. See “Format” in the CDF User’s Guide for more information. If both SINGLE_FILE and MULTI_FILE are set the file will be created in the SINGLE_FILE format.

Note: In versions of IDL prior to 6.3, MULTI_FILE was the default.

### Encoding Keywords

Select one of the following keywords to specify the type of encoding:

### ALPHAOSF1_ENCODING

Set this keyword to indicate DEC ALPHA/OSF1 data encoding.

### ALPHAVMSD_ENCODING

Set this keyword to indicate DEC ALPHA/VMS data encoding using Digital’s D_FLOAT representation.

### ALPHAVMSG_ENCODING

Set this keyword to indicate DEC ALPHA/VMS data encoding using Digital’s G_FLOAT representation.

### DECSTATION_ENCODING

Set this keyword to select Decstation (MIPSEL) data encoding.

### HOST_ENCODING

Set this keyword to select that the file will use native data encoding. This is the default method.

### HP_ENCODING

Set this keyword to select HP 9000 data encoding.

### IBMPC_ENCODING

Set this keyword to select IBM PC data encoding.

### IBMRS_ENCODING

Set this keyword to select IBM RS/6000 series data encoding.

### MAC_ENCODING

Set this keyword to select Macintosh data encoding.

### NETWORK_ENCODING

Set this keyword to select network-transportable data encoding (XDR).

### NEXT_ENCODING

Set this keyword to select NeXT data encoding.

### SGI_ENCODING

Set this keyword to select SGI (MIPSEB) data encoding (Silicon Graphics Iris and Power series).

### SUN_ENCODING

Set this keyword to select SUN data encoding.

### Decoding Keywords

Select one of the following keywords to specify the type of decoding:

### ALPHAOSF1_DECODING

Set this keyword to indicate DEC ALPHA/OSF1 data decoding.

### ALPHAVMSD_DECODING

Set this keyword to indicate DEC ALPHA/VMS data decoding using Digital’s D_FLOAT representation.

### ALPHAVMSG_DECODING

Set this keyword to indicate DEC ALPHA/VMS data decoding using Digital’s G_FLOAT representation.

### DECSTATION_DECODING

Set this keyword to select Decstation (MIPSEL) data decoding.

### HOST_DECODING

Set this keyword to select that the file will use native data decoding. This is the default method.

### HP_DECODING

Set this keyword to select HP 9000 data decoding.

### IBMPC_DECODING

Set this keyword to select IBM PC data decoding.

### IBMRS_DECODING

Set this keyword to select IBM RS/6000 series data decoding.

### MAC_DECODING

Set this keyword to select Macintosh data decoding.

### NETWORK_DECODING

Set this keyword to select network-transportable data decoding (XDR).

### NEXT_DECODING

Set this keyword to select NeXT data decoding.

### SGI_DECODING

Set this keyword to select SGI (MIPSEB) data decoding (Silicon Graphics Iris and Power series).

### SUN_DECODING

Set this keyword to select SUN data decoding.

## Version History

Pre 4.0 | Introduced
6.3 | Changed default behavior to create a single file rather than multiple files (see SINGLE_FILE and MULTI_FILE) Changed default behavior to use HOST_ENCODING rather than NETWORK_ENCODING Changed default behavior to use HOST_DECODING rather than NETWORK_DECODING