@@ -75,7 +75,7 @@ module DisNCStructuredModule
7575 procedure :: define_dim
7676 procedure :: define_dependent
7777 procedure :: define_gridmap
78- procedure :: define_projection
78+ procedure :: define_geocoords
7979 procedure :: add_proj_data
8080 procedure :: add_grid_data
8181 end type DisNCStructuredType
@@ -153,11 +153,24 @@ subroutine dis_export_init(this, modelname, modeltype, modelfname, nc_fname, &
153153
154154 if (latsz > 0 .and. lonsz > 0 ) then
155155 this% latlon = .true.
156+ if (this% wkt /= ' ' ) then
157+ write (warnmsg, ' (a)' ) ' Ignoring user provided NetCDF wkt parameter &
158+ &as longitude and latitude arrays have been provided.'
159+ call store_warning(warnmsg)
160+ this% wkt = ' '
161+ this% gridmap_name = ' '
162+ end if
156163 call mem_setptr(this% latitude, ' LATITUDE' , this% ncf_mempath)
157164 call mem_setptr(this% longitude, ' LONGITUDE' , this% ncf_mempath)
158165 end if
159166 end if
160167
168+ if (this% dis% lenuni == 1 ) then
169+ this% lenunits = ' ft'
170+ else
171+ this% lenunits = ' m'
172+ end if
173+
161174 ! create the netcdf file
162175 call nf_verify(nf90_create(this% nc_fname, &
163176 IOR (NF90_CLOBBER, NF90_NETCDF4), this% ncid), &
@@ -191,7 +204,7 @@ subroutine df(this)
191204 ! define root group dimensions and coordinate variables
192205 call this% define_dim()
193206 ! define grid projection variables
194- call this% define_projection ()
207+ call this% define_geocoords ()
195208 if (isim_mode /= MVALIDATE) then
196209 ! define the dependent variable
197210 call this% define_dependent()
@@ -707,8 +720,8 @@ subroutine define_dim(this)
707720 this% nc_fname)
708721 call nf_verify(nf90_def_var(this% ncid, ' y' , NF90_DOUBLE, this% dim_ids% y, &
709722 this% var_ids% y), this% nc_fname)
710- call nf_verify(nf90_put_att(this% ncid, this% var_ids% y, ' units' , ' m ' ), &
711- this% nc_fname)
723+ call nf_verify(nf90_put_att(this% ncid, this% var_ids% y, ' units' , &
724+ this % lenunits), this% nc_fname)
712725 call nf_verify(nf90_put_att(this% ncid, this% var_ids% y, ' axis' , ' Y' ), &
713726 this% nc_fname)
714727 call nf_verify(nf90_put_att(this% ncid, this% var_ids% y, ' standard_name' , &
@@ -730,8 +743,8 @@ subroutine define_dim(this)
730743 this% nc_fname)
731744 call nf_verify(nf90_def_var(this% ncid, ' x' , NF90_DOUBLE, this% dim_ids% x, &
732745 this% var_ids% x), this% nc_fname)
733- call nf_verify(nf90_put_att(this% ncid, this% var_ids% x, ' units' , ' m ' ), &
734- this% nc_fname)
746+ call nf_verify(nf90_put_att(this% ncid, this% var_ids% x, ' units' , &
747+ this % lenunits), this% nc_fname)
735748 call nf_verify(nf90_put_att(this% ncid, this% var_ids% x, ' axis' , ' X' ), &
736749 this% nc_fname)
737750 call nf_verify(nf90_put_att(this% ncid, this% var_ids% x, ' standard_name' , &
@@ -782,7 +795,7 @@ subroutine define_dependent(this)
782795
783796 ! put attr
784797 call nf_verify(nf90_put_att(this% ncid, this% var_ids% dependent, &
785- ' units' , ' m ' ), this% nc_fname)
798+ ' units' , this % lenunits ), this% nc_fname)
786799 call nf_verify(nf90_put_att(this% ncid, this% var_ids% dependent, &
787800 ' standard_name' , this% annotation% stdname), &
788801 this% nc_fname)
@@ -816,9 +829,9 @@ end subroutine define_gridmap
816829
817830 ! > @brief define grid projection variables
818831 ! <
819- subroutine define_projection (this )
832+ subroutine define_geocoords (this )
820833 class(DisNCStructuredType), intent (inout ) :: this
821- if (this% latlon .and. this % wkt /= ' ' ) then
834+ if (this% latlon) then
822835 ! lat
823836 call nf_verify(nf90_def_var(this% ncid, ' lat' , NF90_DOUBLE, &
824837 (/ this% dim_ids% x, this% dim_ids% y/ ), &
@@ -841,13 +854,13 @@ subroutine define_projection(this)
841854 call nf_verify(nf90_put_att(this% ncid, this% var_ids% longitude, &
842855 ' long_name' , ' longitude' ), this% nc_fname)
843856 end if
844- end subroutine define_projection
857+ end subroutine define_geocoords
845858
846859 ! > @brief add grid projection data
847860 ! <
848861 subroutine add_proj_data (this )
849862 class(DisNCStructuredType), intent (inout ) :: this
850- if (this% latlon .and. this % wkt /= ' ' ) then
863+ if (this% latlon) then
851864 ! lat
852865 call nf_verify(nf90_put_var(this% ncid, this% var_ids% latitude, &
853866 this% latitude, start= (/ 1 , 1 / ), &
@@ -865,20 +878,30 @@ end subroutine add_proj_data
865878 ! > @brief add grid coordinates
866879 ! <
867880 subroutine add_grid_data (this )
881+ use ConstantsModule, only: DZERO
868882 class(DisNCStructuredType), intent (inout ) :: this
869883 integer (I4B) :: ibnd, n ! , k, i, j
870884 real (DP), dimension (:, :), pointer , contiguous :: dbl2d
871885 real (DP), dimension (:), allocatable :: x, y
886+ real (DP) :: xoff, yoff
887+
888+ if (this% dis% angrot /= DZERO) then
889+ xoff = DZERO
890+ yoff = DZERO
891+ else
892+ xoff = this% dis% xorigin
893+ yoff = this% dis% yorigin
894+ end if
872895
873896 allocate (x(size (this% dis% cellx)))
874897 allocate (y(size (this% dis% celly)))
875898
876899 do n = 1 , size (this% dis% cellx)
877- x(n) = this% dis% cellx(n) + this % dis % xorigin
900+ x(n) = this% dis% cellx(n) + xoff
878901 end do
879902
880903 do n = 1 , size (this% dis% celly)
881- y(n) = this% dis% celly(n) + this % dis % yorigin
904+ y(n) = this% dis% celly(n) + yoff
882905 end do
883906
884907 call nf_verify(nf90_put_var(this% ncid, this% var_ids% x, x), &
@@ -897,8 +920,8 @@ subroutine add_grid_data(this)
897920 ibnd = 1
898921 do n = 1 , size (this% dis% cellx)
899922 if (ibnd == 1 ) then
900- dbl2d(1 , ibnd) = this % dis % xorigin
901- dbl2d(2 , ibnd) = this % dis % xorigin + this% dis% delr(ibnd)
923+ dbl2d(1 , ibnd) = xoff
924+ dbl2d(2 , ibnd) = xoff + this% dis% delr(ibnd)
902925 else
903926 dbl2d(1 , ibnd) = dbl2d(1 , ibnd - 1 ) + this% dis% delr(ibnd)
904927 dbl2d(2 , ibnd) = dbl2d(2 , ibnd - 1 ) + this% dis% delr(ibnd)
@@ -914,8 +937,8 @@ subroutine add_grid_data(this)
914937 ibnd = 1
915938 do n = size (this% dis% celly), 1 , - 1
916939 if (ibnd == 1 ) then
917- dbl2d(1 , ibnd) = this % dis % yorigin + sum (this% dis% delc) - this% dis% delc(n)
918- dbl2d(2 , ibnd) = this % dis % yorigin + sum (this% dis% delc)
940+ dbl2d(1 , ibnd) = yoff + sum (this% dis% delc) - this% dis% delc(n)
941+ dbl2d(2 , ibnd) = yoff + sum (this% dis% delc)
919942 else
920943 dbl2d(1 , ibnd) = dbl2d(1 , ibnd - 1 ) - this% dis% delc(n)
921944 dbl2d(2 , ibnd) = dbl2d(2 , ibnd - 1 ) - this% dis% delc(n)
@@ -982,15 +1005,13 @@ subroutine ncvar_gridmap(ncid, varid, gridmap_name, latlon, nc_fname)
9821005 logical (LGP), intent (in ) :: latlon
9831006 character (len=* ), intent (in ) :: nc_fname
9841007 if (gridmap_name /= ' ' ) then
985- if (latlon) then
986- call nf_verify(nf90_put_att(ncid, varid, ' coordinates' , ' lon lat' ), &
987- nc_fname)
988- else
989- call nf_verify(nf90_put_att(ncid, varid, ' coordinates' , ' x y' ), &
990- nc_fname)
991- end if
1008+ call nf_verify(nf90_put_att(ncid, varid, ' coordinates' , ' x y' ), &
1009+ nc_fname)
9921010 call nf_verify(nf90_put_att(ncid, varid, ' grid_mapping' , gridmap_name), &
9931011 nc_fname)
1012+ else if (latlon) then
1013+ call nf_verify(nf90_put_att(ncid, varid, ' coordinates' , ' lon lat' ), &
1014+ nc_fname)
9941015 end if
9951016 end subroutine ncvar_gridmap
9961017
0 commit comments