Re: I want to change the sort of attributes for a netCDF file

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon, 02 Mar 2009 13:20:38 -0700

Hi Dave,

You're right, the efficient ncl writing method (as shown in the link you
forwarded) does write them in forward order. Thus, it writes them in the
same order as would be shown in printVarSummary.

I only use the efficient method to write out larger files, or files with
many variables. Otherwise I stick with the easier/quicker to code
inefficient method, as the method doesn't seem to make much of a
difference in file-writing speed for smaller files.

Thanks for the clarification!
Adam

Dave Allured wrote:
> Adam,
>
> I am curious about an alternate method of creating attributes. Does
> the filevarattdef routine add attributes in *forward* order to a
> file variable? This is a more complicated method to write a Netcdf
> file than what you showed, but it may be worth noting for some
> applications that use file predefinition.
>
> http://www.ncl.ucar.edu/Applications/method_2.shtml
>
> Dave Allured
> CU/CIRES Climate Diagnostics Center (CDC)
> http://cires.colorado.edu/science/centers/cdc/
> NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
> http://www.cdc.noaa.gov/psd1/
>
> Adam Phillips wrote:
>> Hi Ehsan,
>> The order that the attributes are written is opposite to how they are
>> shown in the netCDF file (or in the output of printVarSummary). For example:
>>
>> ncl 1> a = addfile("example.nc","c")
>> ncl 2> var = (/1,2,3,4/)
>> ncl 3> var!0 = "var"
>> ncl 4> var&var = var
>> ncl 5> var_at_att1 = "Attribute 1"
>> ncl 6> var_at_att2 = "Attribute 2"
>> ncl 7> var_at_att3 = "Attribute 3"
>> ncl 8> a->var = var
>> ncl 9> exit
>>
>> -/home/>ncdump -h example.nc | less
>> netcdf what {
>> dimensions:
>> var = 4 ;
>> variables:
>> int var(var) ;
>> var:att3 = "Attribute 3" ;
>> var:att2 = "Attribute 2" ;
>> var:att1 = "Attribute 1" ;
>>
>> I know of no quick way to alter the order of attributes in a netCDF
>> file. The only ways I can think of are: by either editing it by hand in
>> NCL (by using the "w" option of addfiles), or by using the ncatted
>> netCDF operator and deleting and then recreating the attributes in the
>> proper order.
>> Adam
>>
>>
>> Ehsan Khorsandi wrote:
>>> Dear all,
>>>
>>> I maked a netCDF file and the attribute are in sort that I don't need,
>>> they are like this:
>>>
>>> float ALD2(TSTEP, LAY, ROW, COL) ;
>>> ALD2:var_desc = "Model species ALD2
>>> " ;
>>> ALD2:units = "moles/s " ;
>>> ALD2:long_name = "ALD2 " ;
>>>
>>>
>>> and want the attributes in this way:
>>>
>>>
>>> float ALD2(TSTEP, LAY, ROW, COL) ;
>>> ALD2:units = "moles/s " ;
>>> ALD2:long_name = "ALD2 " ;
>>> ALD2:var_desc = "Model species ALD2
>>> " ;
>>>
>>>
>>> I checked all way but there were no chance please see if you can help me to make attributes sorted as I need.
>>>
>>> Thanks,
>>> Ehsan
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 02 2009 - 13:20:38 MST

This archive was generated by hypermail 2.2.0 : Mon Mar 02 2009 - 16:45:42 MST