[netcdfgroup] Reading in netcdf files using fortran 90

Hi,
   I am trying to get the dimension sizes from the gridfile for an ocean
model (ROMS). I am pasting below a short script that is trying to retrieve
the dimension id, dimension name and the dimension size for the vertical
coordinate. The script is returning junk values for all three variables. It
always prints out zero for the dimension id, a blank string for the
variable name and random numbers (e.g., -1067735120) for the dimension
size. Also, each time I run the code I get a different junk number for the
dimension size.

I am using netcdf-fortran version 4.4.4 on an intel machine. The libraries
have been compiled on my campus cluster.

I am compiling using:
ifort prog.f90 -I$NETCDF_HOME/include -L$NETCDF_HOME/lib -lnetcdff  -o
a.out,

where $NETCDF_HOME

Here is the script:
********************************************************************
program main

  use netcdf
  implicit none

  integer(kind=4) nz
  integer(kind=4) ncid,nzid,status

  character(len=200) gridfile, varname
!--------------------------------
  gridfile='grid.nc'

! Get the file id for the netcdf file being read
  status=  nf90_open(gridfile,nf90_nowrite,ncid)

! 's_rho' is the vertical coordinate
! Return the dimension id for s_rho in nzid
  status = nf90_inq_dimid(ncid, "s_rho", nzid)
! Using the dimension id to return the variable name (varname) no. of
vertical levels (nz)
  status = nf90_inquire_dimension(ncid, nzid, varname, nz)

! All three commands below are printing out junk!
  write(6,*) nzid
  write(6,*)' variable: ',varname
  write(6,*)'No. of vertical levels (should be 50)= ', nz

  status=nf90_close(ncid)

end program main
*************************************************************************

Does anybody know where am I making a mistake?

Thanks for your help.

Sanjiv,
Texas A & M University
  • 2020 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: