Re: Problems writing NetCDF4 file

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 09 2012 - 14:10:24 MST

Hi Bridget,
The fix for the NetCDF4 error will be in the next release.
The reason "if (isatt(new_t,"bounds")) then delete(new_t@bounds) end if"
does not get rid of the bounds attribute in the output file is that it is not an attribute of new_t. It is an attribute of the original 'time' coordinate variable that is read as part of the
'agggcm' variable. To eliminate it you should do:
delete(agggcm&time@bounds)
Notice that assigning a new time coordinate does not eliminate attributes that were already part of the original time coordinate. Instead, new attributes are merged into the list of existing attributes.
Also probably the simplest workaround for the NetCDF4 error in your version of NCL is just to eliminate the _FillValue from the the time coordinate attached to the variable you are writing. As in:

new_agggcm&time = new_t
delete(new_agggcm&time@_FillValue)
fout = addfile("regridded_tasmax_1950-1959.nc","c")
fout->tasmax = new_agggcm

It's usually an error to have any missing values in a coordinate variable anyway, so the _FillValue attribute is not needed.
 -dave

On Mar 7, 2012, at 2:54 PM, Bridget Thrasher wrote:

> Thanks, Dave. Adding "fout->time = new_t" before writing the variable to the file worked, though I'm getting "warning:Right hand side has no coordinate variable can not delete coordinate variable of a file, use (/ .. /) to avoid this message." Also, the "delete(new_t@bounds)" call does not appear to be working since the attribute is still writing to the file. Not sure what's going on there...
>
> -Bridget
>
> On Wed, Mar 7, 2012 at 1:31 PM, David Brown <dbrown@ucar.edu> wrote:
> Hi Bridget,
>
> Unlike NetCDF3, NetCDF4 requires that the _FillValue attribute be written prior to any data for any particular variable and also it cannot be changed after it is created. This created a problem for NCL's simple style of writing variables because originally when a variable was assigned to a file using the simple method (f->var = var), the data was written before the attributes. So in 2009 I modified the code so that the attributes were written first. However, it is possible something is written in the wrong order in your case. It looks like you are not explicitly writing the 'time' variable to the file, but that, because it is a coordinate of your data variable, it is being implicitly written. I didn't think this would be a problem, but perhaps there is a pathway that I have not considered.
>
> As a work-around you could try explicitly assigning the 'time' variable to the file (fout->time = time) before writing the 'new_agggcm' variable. Let us know whether or not this works.
> In any case, it would be good if you can send us enough code and data to duplicate the problem. See the 'report bugs' page if you need a refresher on uploading to the ftp site.
> -dave
>
>
>
>
> On Mar 7, 2012, at 2:03 PM, Bridget Thrasher wrote:
>
>> I am getting an error that I don't understand and cannot seem to get around when trying to write out a file with a NetCDF4 format. Can anyone explain this to me? Here is my output with the error followed by the pertinent code snippets:
>>
>> Copyright (C) 1995-2011 - All Rights Reserved
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 6.0.0
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>>
>> Variable: new_t
>> Type: double
>> Total Size: 29216 bytes
>> 3652 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [time | 3652]
>> Coordinates:
>> Number Of Attributes: 6
>> standard_name : time
>> long_name : time
>> axis : T
>> calendar : gregorian
>> units : days since 1850-01-01
>> _FillValue : 9.969209968386869e+36
>>
>> (0) writing file
>> ncattput: ncid 131072: NetCDF: Attempt to define fill value when data already exists.
>> fatal:Attempt to delete undefined attribute from variable
>> warning:FileWriteVarVar: Could not write attribute (_FillValue) to variable (time) in file (regridded_2deg_tasmin_day_bcc-csm1-1_historical_r1i1p1_19500101-19591231), continuing anyway
>> ncendef: ncid 131072: NetCDF: Can't open HDF5 attribute
>> ncendef: ncid 131072: NetCDF: Can't open HDF5 attribute
>> (0) file written
>>
>>
>>
>> setfileoption("nc","Format","NetCDF4Classic")
>> setfileoption("nc","CompressionLevel",5) ; 0 through 9 possible
>>
>> t = fin->time
>> ut = ut_calendar(t,-5)
>> ii = ind(isleapyear(ut(:,0)).and.ut(:,1).eq.2.and.ut(:,2).eq.28)
>> n = dimsizes(ii)
>> dims = dimsizes(agggcm)
>> new_agggcm = new((/dims(0)+n,dims(1),dims(2)/),float,fill)
>> new_ut = new((/dimsizes(t)+n,6/),typeof(ut))
>> new_t = new((/dimsizes(t)+n/),typeof(t))
>>
>> new_agggcm(:ii(0),:,:) = agggcm(:ii(0),:,:)
>> new_ut(:ii(0),:) = ut(:ii(0),:)
>>
>> do i = 0,n-1
>> new_agggcm(ii(i)+1+i,:,:) = (agggcm(ii(i),:,:) + agggcm(ii(i)+1,:,:))/2.
>> new_ut(ii(i)+1+i,:) = (/ut(ii(i)+i,0),2,29,ut(ii(i)+i,3),ut(ii(i)+i,4),ut(ii(i)+i,5)/)
>> if (i.lt.n-1) then
>> new_agggcm(ii(i)+2+i:ii(i+1)+1+i,:,:) = agggcm(ii(i)+1:ii(i+1),:,:)
>> new_ut(ii(i)+2+i:ii(i+1)+1+i,:) = ut(ii(i)+1:ii(i+1),:)
>> end if
>> end do
>>
>> new_agggcm((ii(n-1)+n+1):,:,:) = agggcm(ii(n-1)+1:,:,:)
>> new_ut((ii(n-1)+n+1):,:) = ut(ii(n-1)+1:,:)
>> new_t = ut_inv_calendar(new_ut(:,0),new_ut(:,1),new_ut(:,2),new_ut(:,3),new_ut(:,4),new_ut(:,5),t@units,0)
>>
>> new_agggcm!0 = "time"
>> new_agggcm!1 = "lat"
>> new_agggcm!2 = "lon"
>> new_t!0 = "time"
>> copy_VarAtts(t,new_t)
>> new_t@calendar = "gregorian"
>> if (isatt(new_t,"bounds")) then delete(new_t@bounds) end if
>> printVarSummary(new_t)
>> copy_VarAtts(agggcm,new_agggcm)
>> new_agggcm&time = new_t
>> print("writing file")
>> fout->$var$ = new_agggcm
>> print("file written")
>>
>>
>>
>>
>> --
>> Bridget Thrasher, PhD
>> Independent Contractor, Research Scientist
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> --
> Bridget Thrasher, PhD
> Independent Contractor, Research Scientist
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Mar 9 11:10:33 2012

This archive was generated by hypermail 2.1.8 : Tue Mar 13 2012 - 14:00:14 MDT