Commit 5bd66714 authored by kbk's avatar kbk
Browse files

test and use real axis before using axis offset+increment method

parent e6c8aa26
!$Id: ncdf_topo.F90,v 1.6 2005-04-25 09:32:34 kbk Exp $
!$Id: ncdf_topo.F90,v 1.7 2005-06-10 16:01:22 kbk Exp $
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
......@@ -81,7 +81,10 @@ module ncdf_topo
! Karsten Bolding and Hans Burchard)
!
! $Log: ncdf_topo.F90,v $
! Revision 1.6 2005-04-25 09:32:34 kbk
! Revision 1.7 2005-06-10 16:01:22 kbk
! test and use real axis before using axis offset+increment method
!
! Revision 1.6 2005/04/25 09:32:34 kbk
! added NetCDF IO rewrite + de-stag of velocities - Umlauf
!
!
......@@ -94,6 +97,8 @@ module ncdf_topo
integer, private :: proj_lon_id,proj_lat_id,proj_rot_id
integer, private :: rearth_id
integer, private :: bathymetry_id
integer, private :: xcord_id=missing_id
integer, private :: ycord_id=missing_id
integer, private :: dx_id,dy_id,x0_id,y0_id
integer, private :: dlon_id, dlat_id,lon0_id,lat0_id
integer, private :: convx_id,convc_id
......@@ -102,6 +107,7 @@ module ncdf_topo
integer, private, dimension(2) :: dimidsT(2)
integer, private, dimension(2) :: dimidsX(2)
logical, private :: have_axis = .false.
logical, private :: latlonx_exists = .true.
logical, private :: latlonc_exists = .true.
logical, private :: xyx_exists = .true.
......@@ -153,12 +159,12 @@ contains
!EOP
!
! !LOCAL VARIABLES:
#include"netcdf.inc"
integer :: status
integer :: ndims
integer :: dimlen
!
character*(NF_MAX_NAME) :: ncname
!-------------------------------------------------------------------------
#include"netcdf.inc"
! Look for things in the bathymetry file that should be there
! for all grid types.
......@@ -242,6 +248,39 @@ contains
jextr = dimlen
#endif
! Does the bathymetry have proper axis defined?
! We will obtain the names of the two dimensions and
! then inquire if there are variables with the same names - if
! that is the case they are by NetCDF definition cordinate
! axis.
! If we have proper cordinate axis we will not ask for and
! read x0, dx, y0, dy (equidistant cartesian) or lon0, dlon,
! lat0, dlat further down. Instead we will get the information
! from the axis directly.
status = nf_inq_dimname(ncbathy,dimidsT(1),ncname)
if (status .ne. NF_NOERR) then
call netcdf_error(status,"ncdf_check_grid()", &
"Could not get name associated with dimidsT(1) in "//trim(filename)//".")
endif
status = nf_inq_varid(ncbathy,ncname,xcord_id)
if (status .ne. NF_NOERR) then
call netcdf_warning(status,"ncdf_check_grid()", &
"Could not get first cordinate name in "//trim(filename)//".")
endif
status = nf_inq_dimname(ncbathy,dimidsT(2),ncname)
if (status .ne. NF_NOERR) then
call netcdf_error(status,"ncdf_check_grid()", &
"Could not get name associated with dimidsT(2) in "//trim(filename)//".")
endif
status = nf_inq_varid(ncbathy,ncname,ycord_id)
if (status .ne. NF_NOERR) then
call netcdf_warning(status,"ncdf_check_grid()", &
"Could not get second cordinate name in "//trim(filename)//".")
endif
have_axis = (xcord_id .ne. missing_id) .and. (ycord_id .ne. missing_id)
! Set grid rotation to zero
! (may be updated below)
......@@ -390,6 +429,7 @@ contains
"Cannot use Cartesian grid with SPHERICAL or CURVILINEAR #defined.")
#endif
if( .not. have_axis) then
! Look for grid spacing
status = nf_inq_varid(ncbathy,"dx",dx_id)
if (status .ne. NF_NOERR) then
......@@ -419,7 +459,7 @@ contains
y0_id = missing_id
y0 = _ZERO_
endif
end if
! Try if you can find something more on the T-points
......@@ -458,7 +498,6 @@ contains
endif
LEVEL3 'Using Cartesian grid.'
case(2)
......@@ -468,6 +507,7 @@ contains
"Cannot use spherical grid with SPHERICAL not #defined.")
#endif
if( .not. have_axis) then
! Look for grid spacing
status = nf_inq_varid(ncbathy,"dlon",dlon_id)
if (status .ne. NF_NOERR) then
......@@ -497,6 +537,7 @@ contains
lat0_id = missing_id
lat0 = _ZERO_
endif
end if
! Try if you can find something on T-points
......@@ -607,6 +648,7 @@ contains
integer :: status
integer :: il,ih,jl,jh,iloc,jloc,i,j
integer :: ilocl,iloch,jlocl,jloch
integer :: indx(1)
!
!-------------------------------------------------------------------------
#include"netcdf.inc"
......@@ -741,6 +783,23 @@ contains
select case (grid_type)
case(1)
if(have_axis) then
! This seems a bit complicated - but instead of reading in
! x0, dx, y0, dy we calculate them based on the cordinates
! for the T-points. Remember (x0,y0) are relative to X-points).
! The procedure below only works for equidistant grids.
! Necessary to compy with .../domain/domain.F90.
indx(1) = 1
status = nf_get_var1_double(ncbathy,xcord_id,indx,x0)
status = nf_get_var1_double(ncbathy,ycord_id,indx,y0)
indx(1) = 2
status = nf_get_var1_double(ncbathy,xcord_id,indx,dx)
status = nf_get_var1_double(ncbathy,ycord_id,indx,dy)
dx=dx-x0
dy=dy-y0
x0=x0-0.5*dx
y0=y0-0.5*dy
else
! Get grid spacing
status = nf_get_var_double(ncbathy,dx_id,dx)
if (status .ne. NF_NOERR) then
......@@ -766,10 +825,27 @@ contains
call netcdf_error(status,"ncdf_get_grid()","Could not read 'y0'.")
endif
endif
endif
case(2)
if(have_axis) then
! This seems a bit complicated - but instead of reading in
! lon0, dlon, lat0, dlat we calculate them based on the cordinates
! for the T-points. Remember (lon0,lat0) are relative to X-points).
! The procedure below only works for equidistant grids.
! Necessary to compy with .../domain/domain.F90.
indx(1) = 1
status = nf_get_var1_double(ncbathy,xcord_id,indx,lon0)
status = nf_get_var1_double(ncbathy,ycord_id,indx,lat0)
indx(1) = 2
status = nf_get_var1_double(ncbathy,xcord_id,indx,dlon)
status = nf_get_var1_double(ncbathy,ycord_id,indx,dlat)
dlon=dlon-lon0
dlat=dlat-lat0
lon0=lon0-0.5*dlon
lat0=lat0-0.5*dlat
else
! Get grid spacing
status = nf_get_var_double(ncbathy,dlon_id,dlon)
if (status .ne. NF_NOERR) then
......@@ -796,6 +872,7 @@ contains
call netcdf_error(status,"ncdf_get_grid()","Could not read 'lat0'.")
endif
endif
end if
if (rearth_id.ne.missing_id) then
status = nf_get_var_double(ncbathy,rearth_id,rearth)
......@@ -812,6 +889,10 @@ contains
call getm_error("ncdf_get_grid()","Invalid grid type.")
end select
STDERR lon0,dlon
STDERR lat0,dlat
stop
return
end subroutine ncdf_get_grid
!EOC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment