The number of vertical levels is not stored in that ocean model grid netcdf
file. Maybe first do an ncdump -h to get the dimensions that are in that grid
file, then try to read one of them, such as a horizontal dimension, like xi_rho.
-j
John C. Warner, Ph.D.
U.S. Geological Survey
384 Woods Hole Road
Woods Hole, MA 02543
508-457-2237<tel:508-457-2237> ph. 508-457-2310<tel:508-457-2310> fax
jcwarner@xxxxxxxx<mailto:jcwarner@xxxxxxxx>
https://www.usgs.gov/staff-profiles/john-warner
________________________________
From: netcdfgroup <netcdfgroup-bounces@xxxxxxxxxxxxxxxx> on behalf of SANJIV R
<sanjiv@xxxxxxxx>
Sent: Wednesday, May 6, 2020 2:06 PM
To: netcdfgroup@xxxxxxxxxxxxxxxx <netcdfgroup@xxxxxxxxxxxxxxxx>
Subject: [EXTERNAL] [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<http://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