Re: [netcdfgroup] [EXTERNAL] Reading in netcdf files using fortran 90

  • To: SANJIV R <sanjiv@xxxxxxxx>, "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdfgroup] [EXTERNAL] Reading in netcdf files using fortran 90
  • From: "Warner, John C" <jcwarner@xxxxxxxx>
  • Date: Wed, 6 May 2020 18:13:03 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=usgs.gov; dmarc=pass action=none header.from=usgs.gov; dkim=pass header.d=usgs.gov; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0UhrWEloy3mIpZRZv17pHUSHwlZ5lRq6eXsnpnyf6kw=; b=KJsQW2QLqYl4Gtg8xNCywh3p40CvQyhx18RhEGh8yg/wO2ssYNlrM7K44YOFuuSwv0IQ3Ph+Pwjrngzdm3hZe5cTXKckO/Sm4QqrM711mLJWwo1twbJF0naJKQKs3MhfODTuDMGkRu+ym0OoLF8CBFu45b23DuP1rKdjnGp3QIvBz6bzRVwVgajK16Ja8NBYX14jbCTx2ALjtUajAMC2RRI8IS2k4/NO/CrgllVy6hv4Lp11R6LlgW5xDAMTHlLD5+Hl9LQj45ZJkszyyx6MYi0ePx4N8HZm+hWQJWG2sOgF+jokUXNETg3JWKEKNivxcbpPC7ezCY/LoM+rv6hoag==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ECvLfPbCL4cuPTBCwHZ1xDiq8QouNP/oZ0unRI2r762c8NjtmYOgmqu1r2p0A8gRagOalr3KtyTsBnGXHY8b/ajpj1pwTqlEZGg3R9tc2HLhmM2cW7YKke7wbIwlgZoFaSS1roYXIyMODr3+gXQOhiqbzowD83rVG4NBLc+g+lT4H9CBwvYjYAmEv4+u0NC33D246GInK+znBxLm2ZWL3bGSerBQboltDv377OiS/OfvJYhtL5BXUDEvGE/72s+zel6Wuk42ta4yaPIT4sTEf/fcXEV+rm21WKkCfoH87PHxIYMhc3mlYPKtlqDaMxKuRec8DoqEXW3WitXlf8IXvA==
  • Authentication-results: tamu.edu; dkim=none (message not signed) header.d=none;tamu.edu; dmarc=none action=none header.from=usgs.gov;
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

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