Start by checking the status return of each command. They usually give a
hint ;)
Den ons. 6. maj 2020 kl. 20.06 skrev SANJIV R <sanjiv@xxxxxxxx>:
> 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
>
> _______________________________________________
> NOTE: All exchanges posted to Unidata maintained email lists are
> recorded in the Unidata inquiry tracking system and made publicly
> available through the web. Users who post to any of the lists we
> maintain are reminded to remove any personal information that they
> do not want to be made public.
>
>
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit:
> https://www.unidata.ucar.edu/mailing_lists/
>
--
Kind regards Nick