Re: problem writing netCDF file using filevardef

From: Saji Njarackalazhikam Hameed <saji_at_nyahnyahspammersnyahnyah>
Date: Fri, 05 May 2006 11:36:00 -1000

Hi,

Maybe this is the right occasion to ask this question. How can I keep
adding data to the unlimited dimension? A small code sniplet would be
helpful : say I want to keep writing data along the time dimension to
the same output netcdf file.

Thanks,

saji

* David Ian Brown <dbrown_at_ucar.edu> [2006-05-05 12:49:49 -0600]:

> Hi Will,
> The NetCDF library requires that only the left-most (slowest moving)
> dimension
> can be unlimited. In your script you define time as an unlimited
> dimension and then
> define the variable "slp_mn" with time as the right-most dimension.
> That is not
> allowed by NetCDF and that is what the message is telling you.

> FYI, NetCDF 4, which is due to be released this fall, will allow
> multiple
> unlimited dimensions. We intend to support NetCDF 4 at the time of its
> release.
> -dave

> On May 5, 2006, at 12:28 PM, Will Hobbs wrote:

> >Hi

> >I have a script that writes data to a netCDF, but I get the following
> >error message

> >ncvardef: ncid 10: NC_UNLIMITED in the wrong index
> >fatal:FileAddVar: an error occurred while adding a variable to a file,
> >check to make sure data type is supported by the output format
> >fatal:Execute: Error occurred at or near line 162 in file
> >station_daytomonth.ncl

> >The command at line 162 is ' filevardef(fout, "slp_mn", typeof(slp_mn),
> >(/"region","time"/))'

> >The data type of slp_mn is float, as are 'region' and 'time', so I
> >really
> >can't see where the problem is. The full script is pasted below, and
> >I've
> >moved the datafile to my ptmp directory (i.e. /ptmp/whobbs/) on
> >'tempest', should you wish to try and run it.

> >Many thanks

> >Will

> >============================
> >Room 3221C
> >UCLA Department of Geography
> >1255 Bunche Hall
> >Los Angeles CA 90095-1524

> >;=====================================================================;
> >load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> >load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> >load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> >load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> >;======================================================================
> >;Reads in sea_level_pressure for a number of station critical to SH
> >ZW1,
> >averages into regions of interest and into monthly means, then writes
> >to file

> >begin

> > yrstrt = 1994
> > yrend = 1999

> >;***********************************************
> >;read in data
> >;*************************************************

> > FIL0 = "zw1_station_slp.nc"
> > diri0 = "/whobbs/ptmp/"

> > f0 = addfile(diri0+FIL0, "r")

> > x = f0->pressure
> > jul = f0->T

> > p = short2flt(x(T|:,IWMO|:))
> > delete(x)

> >;*******************************************
> >;Create new p-data array
> >;*********************************************

> > dimz = dimsizes(p)
> > days = dimz(0)

> > stat = new((/3, days/), float)

> > delete(dimz)

> >;first dim of stat is area of interest

> >;0 = subpolar trough (stns 619970, 619980, 689940)
> >;1 = subtrop trough (stns 919580, 939940, 939970, 919600)
> >;2 = subtrop ridge (stns 689020, 689060)

> >;get regional statn averages

> > stat(0,:) = dim_avg(p(:,0:2))
> > stat(1,:) = dim_avg(p(:,3:6))
> > stat(2,:) = dim_avg(p(:,7:8))

> > delete(p)

> >;assign attributes to time dimension

> > stat!0 = "region"
> > stat!1 = "time"

> > stat&time = jul

> >;create new time array in format mmyyyy

> > nmon = 12*(yrend-yrstrt+1) ; total number of months in data
> > X = new((/nmon/), string) ; new time coord array

> > mn = 0

> > do yy = yrstrt, yrend ; concatenate month and years
> > do mm = 1,12
> > X(mn) = mm+""+yy
> > mn = mn+1
> > end do
> > end do

> > time = stringtofloat(X) ; need to convert for use as netCDF
> >dimension

> > delete(X)

> >;*******************************************
> >;convert daily data to monthly means
> >;*********************************************

> > slp_mn = new((/3,nmon/), float)

> > monlength = (/31,28,31,30,31,30,31,31,30,31,30,31/)

> > mn = 0

> > do yy = yrstrt, yrend
> > do mm = 1, 12

> > STR = doubletoint(greg2jul(yy, mm, 1, 0)) ; determine julian
> >start
> >day of month
> > ll = monlength(mm-1)

> > if (mm.eq.2) then ; for Feb in
> >leapyear.....
> > if (isleapyear(yy).eq."True") then
> > ll = 29 ;....use ll = 29
> >days...
> > end if
> > end if

> > FIN = doubletoint(STR+ll)

> > slp_mn(:,mn) = dim_avg(stat(:, {STR:FIN}))

> > mn = mn+1
> > end do
> > end do

> > printVarSummary(slp_mn)

> >; print(slp_mn(:,0:3))

> > delete(stat)
> > delete(jul)
> > delete(monlength)

> >;****************************************************
> >;Write data to file
> >;****************************************************

> > diri1 = "/u/whobbs/fourier/data/"
> > FIL1 = "zw1_stn_slp.nc"

> > system("rm "+diri1+FIL1)

> > fout = addfile(diri1+FIL1, "c")

> > ;create file attributes

> > fAtt = True ; assign file attributes
> > fAtt_at_title = "Station slp for SH ZW1-critical regions"
> > fAtt_at_source_file = "station_daytomonth.ncl"
> > fAtt_at_Conventions = "Region 0=subpolar_trough, 1=subtrop_trough,
> >2=subtrop_ridge"
> > fAtt_at_creation_date = systemfunc ("date")

> > fileattdef( fout, fAtt )

> >;set dimensions

> > dimNames = (/"region","time"/)
> > dimSizes = (/3, -1/)
> > dimUnlim = (/False,True/)
> > filedimdef(fout,dimNames,dimSizes,dimUnlim)

> >;set file variables

> > region = fspan(1,3,1)

> > filevardef(fout, "time" ,typeof(time),"time")
> > filevardef(fout, "region", typeof(region), "region")
> > filevardef(fout, "slp_mn", typeof(slp_mn), (/"region","time"/))

> >;set other attributes

> > time_at_long_name = "month+year"
> > slp_mn_at_long_name = "Monthly mean slp for each ZW1-critical region"
> > slp_mn_at_units = "hPa"
> > region_at_long_name = "ZW1-critical region"

> > filevarattdef(fout,"slp_mn", slp_mn)
> > filevarattdef(fout,"time",slp_mn&time)
> > filevarattdef(fout,"region",slp_mn&region)

> >;populate file

> > fout->time = (/time/)
> > fout->region = (/region/)
> > fout->slp_mn = (/slp_mn/)

> >end

> >_______________________________________________
> >ncl-talk mailing list
> >ncl-talk_at_ucar.edu
> >http://mailman.ucar.edu/mailman/listinfo/ncl-talk

> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
Saji N. Hameed,
Assistant Researcher,			Tel:808 9569534
International Pacific Research Center,	email:saji_at_hawaii.edu
2525 Correa Rd, Honolulu, HI 96822	http://iprc.soest.hawaii.edu/~saji
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri May 05 2006 - 15:36:00 MDT

This archive was generated by hypermail 2.2.0 : Fri May 05 2006 - 15:37:41 MDT