The CDF_ATTPUT procedure writes an attribute entry to a Common Data Format file, or attaches an attribute to a CDF variable. If the specified entry already exists, it is overwritten.

Examples


Id= CDF_CREATE('foo', /SUN_ENCODING, /HOST_DECODING, $
   /ROW_MAJOR)   ; no dimensions.
dummy= CDF_VARCREATE(id, 'Var1', /CDF_INT4, /REC_VARY)
v2= CDF_VARCREATE(id, 'Var2', /CDF_FLOAT, /REC_NOVARY)
dummy= CDF_ATTCREATE(id, 'Title', /VARIABLE)
global_dummy = CDF_ATTCREATE(id,'Date',/GLOBAL)
dummy= CDF_ATTCREATE(id, 'Att2', /VARIABLE)
CDF_ATTPUT, id, 'Title', 'Var1', 'Temperature at surface'
CDF_ATTPUT, id, 'Title', v2, 'Time of recording'
CDF_ATTPUT, id, 'Date',1,'July 4, 1996'
CDF_ATTPUT, id, 'Att2', 'Var2', FINDGEN(10)
 
; Rename the "Att2" attribute to "Attribute2":
CDF_ATTRENAME, Id, 'Att2', 'Attribute2'
 
; Verify the attribute number (zero-based) of Attribute2
PRINT, CDF_ATTNUM(id, 'Attribute2')
 
; Close the CDF file. This file is used in the CDF_ATTGET example.
CDF_CLOSE, id

Also see Additional Examples below.

Syntax


CDF_ATTPUT, Id, Attribute, EntryNum, Value [, /CDF_BYTE] [, /CDF_CHAR] [, /CDF_DOUBLE] [, /CDF_EPOCH] [, /CDF_FLOAT] [, /CDF_INT1] [, /CDF_INT2] [, /CDF_INT4] [, /CDF_INT8] [, /CDF_LONG_EPOCH] [, /CDF_REAL4] [, /CDF_REAL8] [, /CDF_TIME_TT2000] [, /CDF_UCHAR] [, /CDF_UINT1] [, /CDF_UINT2] [, /CDF_UINT4] [, /ZVARIABLE]

Arguments


Id

The CDF ID, returned from a previous call to CDF_OPEN or CDF_CREATE.

Attribute

A string containing either the name or number of the attribute to be written.

EntryNum

The entry number. If the attribute is variable in scope, this is either the name or number of the variable the attribute is to be associated with. If the attribute is global in scope, this is the actual gEntry. It is the user’s responsibility to keep track of valid gEntry numbers. Normally gEntry numbers will begin with 0 or 1 and will increase up to MAXGENTRY (as reported in the GET_ATTR_INFO structure returned by CDF_CONTROL), but this is not required.

Value

The value(s) to be written.

Keywords


CDF_BYTE

Set this keyword if your Value is IDL type byte or type int and you want to force the CDF datatype to this type. The default for IDL type byte is CDF_UINT1.

Note: If this keyword is set and Value is type int then the value must be in the range -128 to +127.

CDF_CHAR

Set this keyword if your Value is IDL type string and you want to force the CDF datatype to this type. This is the default for IDL type string.

CDF_DOUBLE

Set this keyword if your Value is IDL type double and you want to force the CDF datatype to this type. This is the default for IDL type double.

CDF_EPOCH

Set this keyword if your Value is IDL type long64 or double and you want to force the CDF datatype to this type. The default for IDL type long64 is CDF_INT8 while for IDL type double the default is CDF_DOUBLE.

Note: If CDF_EPOCH is set and Value is IDL type int64, then the CDF datatype will actually be CDF_TIME_TT2000.

Note: If CDF_EPOCH is set and Value is IDL type dcomplex, then the CDF datatype will actually be CDF_EPOCH16.

CDF_FLOAT

Set this keyword if your Value is IDL type float and you want to force the CDF datatype to this type. This is the default for IDL type float.

CDF_INT1

Set this keyword if your Value is IDL type byte or type int and you want to force the CDF datatype to this type. The default for IDL type byte is CDF_UINT1.

Note: If this keyword is set and Value is type int then the value must be in the range -128 to +127.

CDF_INT2

Set this keyword if your Value is IDL type int and you want to force the CDF datatype to this type. This is the default for IDL type int.

CDF_INT4

Set this keyword if your Value is IDL type long and you want to force the CDF datatype to this type. This is the default for IDL type long.

CDF_INT8

Set this keyword if your Value is IDL type long64 and you want to force the CDF datatype to this type. This is the default for IDL type long64.

CDF_LONG_EPOCH

Set this keyword if your Value is IDL type dcomplex and you want to force the CDF datatype to CDF_EPOCH16. This is the default for IDL type dcomplex.

CDF_REAL4

Set this keyword if your Value is IDL type float and you want to force the CDF datatype to this type. The default for IDL type float is CDF_FLOAT.

CDF_REAL8

Set this keyword if your Value is IDL type double and you want to force the CDF datatype to this type. The default for IDL type double is CDF_DOUBLE.

CDF_TIME_TT2000

Set this keyword if your Value is IDL type long64 and you want to force the CDF datatype to this type. The default for IDL type long64 is CDF_INT8.

CDF_UCHAR

Set this keyword if your Value is IDL type string and you want to force the CDF datatype to this type. The default for IDL type string is CDF_CHAR.

CDF_UINT1

Set this keyword if your Value is IDL type byte and you want to force the CDF datatype to this type. This is the default for IDL type byte.

CDF_UINT2

Set this keyword if your Value is IDL type unsigned int and you want to force the CDF datatype to this type. This is the default for IDL type unsigned int.

CDF_UINT4

Set this keyword if your Value is IDL type unsigned long and you want to force the CDF datatype to this type. This is the default for IDL type unsigned long.

ZVARIABLE

If EntryNum is a variable ID (as opposed to a variable name) and the variable is a zVariable, set this flag to indicate that the variable ID is a zVariable ID. The default is to assume that EntryNum is an rVariable ID. Note: the Attribute must have a scope of VARIABLE_SCOPE.

CDF Type and IDL Type Keywords


CDF Type

IDL Type and Keyword

CDF_BYTE Byte with /CDF_BYTE

CDF_CHAR

String (default)

CDF_DOUBLE

Double (default)

CDF_EPOCH

Double with /CDF_EPOCH

CDF_EPOCH16

Dcomplex (default), or dcomplex with /CDF_EPOCH

CDF_FLOAT Float (default)
CDF_INT1 Byte with /CDF_INT1

CDF_INT4

Long (default)
CDF_INT8 Long64 (default)
CDF_REAL4 Float with /CDF_REAL4
CDF_REAL8

Double with /CDF_REAL8

CDF_TIME_TT2000

Long64 with /CDF_EPOCH or /CDF_TIME_TT2000

CDF_UCHAR String with /CDF_UCHAR
CDF_UINT1

Byte (default)

CDF_UINT2 Unsigned int (default)
CDF_UINT4

Unsigned long (default)

Additional Example


The following example uses the Global attribute “MODS” to keep track of the modification history of a CDF file named mods.cdf.

id = CDF_CREATE('mods.cdf', /CLOBBER)
cid = CDF_ATTCREATE(id, 'MODS', /GLOBAL_SCOPE)
CDF_ATTPUT, id, cid, 0, 'Original Version'
CDF_CLOSE, id
 
; Next, reopen the CDF file and make modifications:
id = CDF_OPEN('mods.cdf')
CDF_CONTROL, id, ATTRIBUTE='MODS', GET_ATTR_INFO=ginfo
 
;Use CDF_CONTROL to get the MAXGENTRY used.
CDF_ATTPUT, id, cid, ginfo.maxgentry+1,'Second Version'
 
;Insert the new gEntry at MAXGENTRY+1.
CDF_CLOSE, id
 
; Reopen the CDF file again and make more modifications:
id = CDF_OPEN('mods.cdf')
CDF_CONTROL, id, ATTRIBUTE='MODS', GET_ATTR_INFO=ginfo
CDF_ATTPUT, id, cid, ginfo.maxgentry+1, 'Third Version'
CDF_CLOSE, id
 
;Reopen the CDF file again and make a modification in the
;MAXGENTRY + 2 spot (skipping an entry number).
id = CDF_OPEN('mods.cdf')
CDF_CONTROL, id, ATTRIBUTE='MODS', GET_ATTR_INFO=ginfo
CDF_ATTPUT, id, cid, ginfo.maxgentry+2, 'Fourth Version'
 
; Now, examine the CDF file to review its modification history.
; Since the gENTRY numbers have a gap in them, we can check each
; attribute with the CDF_ATTEXISTS function. This is a good idea 
; if you do not know for certain that the attribute entries are
; serially numbered.
 
CDF_CONTROL, id, ATTRIBUTE='MODS', GET_ATTR_INFO=ginfo
  FOR I=0, ginfo.maxgentry DO BEGIN
   IF CDF_ATTEXISTS(id, cid, I) THEN BEGIN
     CDF_ATTGET, id, cid, I, gatt
     PRINT, I, gatt, FORMAT='("Attribute: MODS (gENTRY #",i1,") = ",A)'
   ENDIF ELSE BEGIN
     PRINT, I, FORMAT='("Attribute: MODS (gENTRY #",i1,") $
       Does not exist")'
   ENDELSE
  ENDFOR
CDF_CLOSE, id

IDL prints:

Attribute: MODS (gENTRY #0) = Original Version
Attribute: MODS (gENTRY #1) = Second Version
Attribute: MODS (gENTRY #2) = Third Version
Attribute: MODS (gENTRY #3) Does not exist
Attribute: MODS (gENTRY #4) = Fourth Version

Version History


Pre 4.0

Introduced

8.6.1

Added type keywords.