X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



2457 Rate this article:
No rating

Example how to use IDL to edit and existing attribute in a CDF file

Topic:

This help article provides a quick example of how a user can change the value of an existing attribute within a CDF file.

Discussion:

If you want to change the value of an existing attribute entry within a CDF file, you will need to complete the following steps:

- Open the CDF file
- Determine the number of entries within the attribute and the starting entry number
- Cycle through the entries in the file and use CDF_ATTEXISTS to test which entries exist
- Use CDF_ATTPUT to change the value

Since an attribute can have multiple entries, and the "entry number" associated with each entry is controlled by the creator of the file,  there is probably not great way to determine the entry number programmatically. However, if there are multiple entries in the attribute, you could assume that the entry number starts at 0 or 1 and increments by 1 to the maxgentry value. Then, you can use the "numgentries" and "maxgentry" values to determine the starting entry value.  With this information, you can cycle through the entries in the attribute and  use the CDF_ATTEXISTS procedure to test which entries exist.

Below is an example called "cdf_ex_test.pro". This program first creates a CDF file and closes it. Then, it is reopened and the value of an entry in an existing attribute is changed.

pro cdf_ex_test
  compile_opt idl2


  ;generate a cdf file with a global attribute
  id = cdf_create('temperature.cdf', [2,3], /clobber )
  att_id = cdf_attcreate(id, 'title', /global)
  att_id2 = cdf_attcreate(id, 'author', /global_scope)
  cdf_attput, id, att_id, 0, 'my fancy cdf'
  cdf_attput, id, att_id, 1, 'line 2 of file'


  cdf_close, id ;close the cdf file

  ;reopen the cdf file  read the current attribute
  ;value
  ocdf = cdf_open('temperature.cdf')

  ;get the number of attributes
  inq=cdf_inquire(ocdf)
  num_att = inq.natts
 
  ;get the max value starting value for the global entries
  cdf_control, ocdf, attribute='title', get_attr_info=att_info
  ngentry = att_info.numgentries ;2
  mgentry =  att_info.maxgentry ;1
  start_gentry = mgentry - ngentry + 1 ;0


  if (cdf_attexists(ocdf,'title',start_gentry)) then begin

    ;use cdf_attget to retrieve the value of the data
    cdf_attget, ocdf,'title',start_gentry,x
    print, "original value:"
    print, x
 
    ;use cdf_attput to change value of the attribute
    cdf_attput, ocdf,'title',start_gentry,"change my value"
    ;use cdf_attget to retrieve the value of the data
    cdf_attget, ocdf,'title',start_gentry,x
    print, "new value:"
    print, x
 
    cdf_close, ocdf ;close the cdf value
   
  endif

end

Written by DS Reviewed by JU (9/4/2014)

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »