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

Re: 950201: netCDF NCVPT



> Keywords: 199502011956.AA15315 netCDF NCVPT

Hi Maureen,

> PROBLEM: My test program doesn't write data into a netCDF variable of
>          an open netCDF file.
> 
> ATTACHED: - the CDL file, T1.CDL
>           - the test program, T1.F
>           - output generated from the NCDUMP utility, OUTPUT
> 
> The following steps were followed:
> 
>            ncgen -o t1.nc t1.cdl
>            f77 -o t1 t1.f /local/lib/libnetcdf.a
>            t1
>            ncdump t1.nc > output
> 
> >From the contents of OUTPUT, it appears that nothing has been written into
> the variable var.  I'd appreciate your help with this problem ...
> 
> Maureen Cribb
> 
> (address@hidden)
> 
> X-Sun-Data-Name: t1.cdl
> 
> netcdf t1 {
> 
> dimensions:
>              index = 5 ;
> 
> variables:
> 
> float   var(index);
>         var:long_name = "Variable";
> 
> }
> 
> X-Sun-Data-Name: t1.f
> 
>       PROGRAM T1
> 
> C SunFORTRAN v1.3 - SunOS environment - SPARCstation 2
>   
>       INCLUDE '/local/include/netcdf.inc'
> 
>            REAL var(5)
>         INTEGER start(5),count(5),vdims(5),rcode
>       CHARACTER*31 dummy
> 
> C Assign values to VAR
> 
>        var(1) = 0.1
>        var(2) = 0.2
>        var(3) = 0.3
>        var(4) = 0.4
>        var(5) = 0.5  
>                          
> C open netcdf file for writing
> 
>       NCID=NCOPN('t1.nc',NCWRITE,RCODE)
> 
> C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> C obtain various parameters concerning the variable VAR
> C Note: this section taken from program GENNET.F by B.Schwartz
> C (http://www.unidata.ucar.edu/packages/netcdf/contrib.html)
> 
>       CALL NCVINQ(NCID, 1,DUMMY,NTP,NVDIM,VDIMS,NVS,RCODE)
>       LENSTR=1
>       DO  20 J=1,NVDIM
>          CALL NCDINQ(NCID,VDIMS(J),DUMMY,NDSIZE,RCODE)
>          LENSTR=LENSTR*NDSIZE
>          START(J)=1
>          COUNT(J)=NDSIZE
>   20  CONTINUE
>           
> C Write values of variable VAR to netcdf file
> 
>       CALL NCVPT(ncid, 1, start, count, var, rcode)
> 
> C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>       END
> 
> 
> X-Sun-Data-Name: output
> 
> netcdf t1 {
> dimensions:
>       index = 5 ;
> 
> variables:
>       float var(index) ;
>               var:long_name = "Variable" ;
> 
> data:
> 
>  var = FloatInf, FloatInf, FloatInf, FloatInf, FloatInf ;
> }

You need to close the netCDF file before the end of the program.  This makes
sure the internal buffers get flushed and all the data gets written to the
disk file.  Just add the statement

      CALL NCCLOS(ncid, rcode)

before your END statement and everything should work OK.

By the way, it's not necessary to use all that code from GENNET.F.  If you
only want to write 5 values into the var variable, you could do it this way:

      PROGRAM T1

C SunFORTRAN v1.3 - SunOS environment - SPARCstation 2
  
      INCLUDE '/local/include/netcdf.inc'

           REAL var(5)
        INTEGER start, count, rcode

C Assign values to VAR

       var(1) = 0.1
       var(2) = 0.2
       var(3) = 0.3
       var(4) = 0.4
       var(5) = 0.5  
                         
C open netcdf file for writing

      NCID=NCOPN('t1.nc',NCWRITE,RCODE)

C Write values of variable VAR to netcdf file

      idvar = ncvid(ncid, 'var', rcode)
      start = 1
      count = 5
      call ncvpt(ncid, idvar, start, count, var, rcode)
      call ncclos(ncid, rcode)

      END

>From address@hidden Thu Feb  2 06: 11:42 1995
 
Good morning Russ -
 
> Re: your response to my wee problem ...
>
> You need to close the netCDF file before the end of the program.  This makes
> sure the internal buffers get flushed and all the data gets written to the
> disk file.  Just add the statement
>
>      CALL NCCLOS(ncid, rcode)
 
> before your END statement and everything should work OK.
>
>By the way, ....... (etc.)
 
Yes, everything ended up working OK ... just wanted to thank you for your
quick response and helpful advice ...
 
Cheers!
 
Maureen Cribb