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

[netCDF #NUC-119714]: struggling with writing data to nc file



Laurens,

In order to understand what your code is intended to do, we will need 
for you to send the output from running the following command:

  ncdump -h /data/ganzevl/inputdata/emissions/EDGARV3.2/co_2000.nc

I suspect there might be a confusion of Fortran array order (first
index varying fastest) with C and CDL array order (last index varying
fastest).

Also, since you are only using the netCDF-3 F77 functions, it might be
easier and less confusing for you to look at the older documentation for 
that version of the F77 library, which is here (in HTML, or PDF, or 
ASCII):

  
http://www.unidata.ucar.edu/software/netcdf/old_docs/docs_3_6_3/netcdf-f77.html
  http://www.unidata.ucar.edu/software/netcdf/old_docs/docs_3_6_3/netcdf-f77.pdf
  http://www.unidata.ucar.edu/software/netcdf/old_docs/docs_3_6_3/netcdf-f77.txt

That's the documentation I'll refer to in discussing how to use nf_get_vara_real
from:

  
http://www.unidata.ucar.edu/netcdf/old_docs/docs_3_6_3/netcdf-f77.html#NF_005fGET_005fVARA_005f-type

for example.

--Russ

> Dear Unidata employees,
> 
> I hope that you are actually working at the moment and not affected by
> the government shutdown; I am already struggling now for some weeks with
> a simple script to read and write data to netcdf in a F77 model code. I
> am able to read-in and then write some manipulated data in F90 version
> but the F77 version gives problems with the writing; I have copied below
> the F90 version of the write_nc routine I used and that works with my
> installation of the netcdf software (3.6.2) on my Suse11.2 linux system. I
> have also copied a version of the F77 subroutine that doesn't work;
> I am basically looking for the F77 equivalent of some of the calls of
> the various nc functions where the help page has helped a lot but not to
> solve this remaining problem. Your feedback would be highly appreciated,
> 
> Thanks, Laurens Ganzeveld
> 
> F90:
> 
> The subroutine is called in a timeloop over 12 months writing out the
> global emission field (emis3D), at a resolution of 1x1 degree for each
> month to a new netcdf file:
> 
> SUBROUTINE write_nc_file
> 
> ! write timestep
> CALL nf(nf90_inquire_dimension(ncid, tid, len=timestep))
> timestep = timestep + 1
> 
> print *,'write_nc: timestepping ',timestep
> read (*,*)
> 
> CALL nf(nf90_put_var(ncid, tid, time, (/timestep/) ))
> 
> ! syntax: nf90_put_var(ncid, varid, values, start, cnt)
> ! start:  start in netcdf variable
> ! cnt:    number of netcdf variable points
> ! values: starting point of the fortran variable
> start1d = (/ 1,               timestep /)
> start2d = (/ 1,    1,         timestep /)
> start3d = (/ 1,    1,   1,    timestep /)
> 
> CALL nf(nf90_put_var(ncid, emis3Did,      emis3D,   start3d, cnt3d)) ! emis.
> 
> END SUBROUTINE write_nc_file
> 
> 
> F77:
> Ncid, tid, emisid are all properly defined as well as the parameter emis
> 
> SUBROUTINE write_nc_file(ii,time,ncid,tid,emisid,emis)
> 
> integer :: ii,timestep,status,ncid,tid,dimtid,timelen,nrecs,
> &             emisid,start2d(3),cnt2d(3),j,k
> real    :: time,emis(180,360)
> 
> character*(20) recnam
> 
> ! write timestep
> timestep = ii
> print *,'timestep',timestep,time
> 
> CALL nf(nf_put_var_double(ncid, tid, time, (/timestep/) ))
> read (*,*)
> 
> ! syntax: nf90_put_var(ncid, varid, values, start, cnt)
> ! start:  start in netcdf variable
> ! cnt:    number of netcdf variable points
> ! values: starting point of the fortran variable
> start2d = (/ 1,    1,         timestep /)
> cnt2d   = (/ 180,  360,              1 /)
> 
> ! write 2d data
> 
> CALL nf(nf_put_var_real(ncid, emisid, emis, start2d, cnt2d)) ! emis .
> 
> END SUBROUTINE write_nc_file
> 
> =======================================================================
> Dr. ir. Laurens Ganzeveld
> Assistant professor
> Department of Environmental Sciences, Chair group Earth System Sciences
> Wageningen University and Research Centre
> Lumen, room D.001, Droevendaalsesteeg 4, 6708 PB, Wageningen, Netherlands
> Phone: (+31) 317-486651 / 613066079, Fax: (+31) 317-419000,
> Being in in Colombia: +57 310 2979313
> E-mail: address@hidden<mailto:address@hidden>
> 
> Affiliate of Universidad de Los Andes, Depart de Biología, Bogota, Colombia
> Affiliate of Max Planck Institute for Chemistry, Depart. of Atmospheric 
> Chemistry, Mainz, Germany,
> =======================================================================
> 
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: NUC-119714
Department: Support netCDF
Priority: Normal
Status: Closed