[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #ZMF-465105]: can not append data to an exist NETCDF file on cygwin platform



> But it looks like that I have to just provide 'start=...' when I write a
> record value (not a array or vector), such as
> 
> ierr=nf90_put_var(ncid,varid,dnum,start=(/ m /))
> 
> Once I provided the 'count=...' argument, such as
> 
> ierr=nf90_put_var(ncid,varid,dnum,start=(/ m /)*, count=(/1/)*)
>
> I can not compile it successfully. Can you tell me why?

I think the syntax of the above statement is wrong.  Try leaving out
the "*" characters, as in:

  ierr=nf90_put_var(ncid,varid,dnum,start=(/ m /), count=(/ 1 /))

Also, Fortran-2003 compilers now accept using "count=[ 1 ]" instead of 
"count=(/ 1 /)" notation for array initialization, which might also
work.

--Russ

> Regards.
> Yours sincerely,
> Xueming Zhu
> 
> 2013/8/23 1:28, Unidata netCDF Support ?:
> > Xueming Zhu,
> >
> >> Thanks for your replying. But if in that case, I have a question why
> >> I can not find any introduction of the nf90_put_vara from your link or
> >> the help file of netcdf interface( attached by this e-mail)? I just can
> >> find the interface nf90_put_var, and it looks like can be used to wroten
> >> an array to the netcdf variable. I know that there are an interface
> >> nf_put_vara for nf77. But never heard about the nf90_put_vara.
> > Oops, sorry, I forgot that the nf90_put_var interface already includes the
> > put_vara behavior if you provide the optional keyword arguments "start=..."
> > and "count=...". You're right, that there is no separate function for using
> > those optional arguments, as there is in C, which didn't have optional
> > keyword arguments.
> >
> > A Fortran-90 example using those arguments to write a record variable is 
> > here:
> >
> >    
> > http://www.unidata.ucar.edu/software/netcdf/examples/programs/pres_temp_4D_wr.f90
> >
> > --Russ
> >
> >> 2013/8/23 0:34, Unidata netCDF Support ?:
> >>> Hi Xueming Zhu,
> >>>
> >>>> I tried to write data to an exist netCDF file with record variables
> >>>> on cygwin platform. My fortran codes as follow,
> >>>>
> >>>> clm  =trim(direc)//trim(casename)//'_monthly_'//year//'.nc'
> >>>> ierr=nf90_open(trim(clm),nf90_write,ncid)
> >>>> CALL HANDLE_ERR(ierr)
> >>>> do m=1,12
> >>>> ierr=nf90_inq_varid(ncid,'ocean_time',varid)
> >>>> CALL HANDLE_ERR(ierr)
> >>>> ierr=nf90_put_var(ncid,varid,dnum,start=(/ m /))
> >>>> CALL HANDLE_ERR(ierr)
> >>>> enddo
> >>>>
> >>>> the variable ocean_time's dimension is ocean_time, which is an
> >>>> unlimited dimension. At beginning, ocean_time's dimension is 1. But
> >>>> after the loop, it is 1 still. Some ncdump results as follow,
> >>>>
> >>>> $ ncdump.exe -v ocean_time np8_monthly_2002.nc
> >>>> netcdf np8_monthly_2002 {
> >>>> dimensions:
> >>>> tracer = 2 ;
> >>>> boundary = 4 ;
> >>>> s_rho = 22 ;
> >>>> s_w = 23 ;
> >>>> ocean_time = UNLIMITED ; // (1 currently)
> >>>> eta_rho = 633 ;
> >>>> xi_rho = 1545 ;
> >>>> eta_u = 633 ;
> >>>> xi_u = 1544 ;
> >>>> eta_v = 632 ;
> >>>> xi_v = 1545 ;
> >>>> variables:
> >>>>
> >>>> double ocean_time(ocean_time) ;
> >>>> ocean_time:long_name = "averaged time since
> >>>> initialization" ;
> >>>> ocean_time:units = "seconds since 1990-01-01 00:00:00" ;
> >>>> ocean_time:calendar = "gregorian" ;
> >>>> ocean_time:field = "time, scalar, series" ;
> >>>>
> >>>> I found the file size changed, but had not got any error when run the
> >>>> fortran code. It is weird for me.
> >>>>
> >>>> Can you give me any suggestions to fix the problem? Thanks a lot.
> >>> I think the problem is that you should be using nf90_put_vara
> >>> instead of nf90_put_var.  For an explanation why, see this section
> >>> of the nf90_put_var documentation:
> >>>
> >>>     
> >>> http://www.unidata.ucar.edu/netcdf/docs/netcdf-f90.html#NF90_005fPUT_005fVAR
> >>>
> >>> where it says:
> >>>
> >>>     Take care when using the simplest forms of this interface with
> >>>     record variables (variables that use the NF90_UNLIMITED dimension)
> >>>     when you don't specify how many records are to be written. If you
> >>>     try to write all the values of a record variable into a netCDF file
> >>>     that has no record data yet (hence has 0 records), nothing will be
> >>>     written. Similarly, if you try to write all the values of a record
> >>>     variable from an array but there are more records in the file than
> >>>     you assume, more in-memory data will be accessed than you expect,
> >>>     which may cause a segmentation violation. To avoid such problems, it
> >>>     is better to specify start and count arguments for variables that
> >>>     use the NF90_UNLIMITED dimension.
> >>>
> >>> --Russ
> >>>
> >>> Russ Rew                                         UCAR Unidata Program
> >>> address@hidden                      http://www.unidata.ucar.edu
> >>>
> >>>
> >>>
> >>> Ticket Details
> >>> ===================
> >>> Ticket ID: ZMF-465105
> >>> Department: Support netCDF
> >>> Priority: Normal
> >>> Status: Closed
> >>>
> >>>
> >>
> >>
> > Russ Rew                                         UCAR Unidata Program
> > address@hidden                      http://www.unidata.ucar.edu
> >
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: ZMF-465105
> > Department: Support netCDF
> > Priority: Normal
> > Status: Closed
> >
> >
> 
> 
> 

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: ZMF-465105
Department: Support netCDF
Priority: Normal
Status: Closed