New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
create_latlon.f in branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/TOOLS/WEIGHTS/SCRIP1.4/grids – NEMO

source: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/TOOLS/WEIGHTS/SCRIP1.4/grids/create_latlon.f @ 5985

Last change on this file since 5985 was 5985, checked in by timgraham, 8 years ago

Reinstate keywords before upgrading to head of trunk

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2!
3!     This program creates a remapping grid file for a lat/lon grid.
4!
5!-----------------------------------------------------------------------
6!
7!     CVS:$Id$
8!
9!     Copyright (c) 1997, 1998 the Regents of the University of
10!       California.
11!
12!     Unless otherwise indicated, this software has been authored
13!     by an employee or employees of the University of California,
14!     operator of the Los Alamos National Laboratory under Contract
15!     No. W-7405-ENG-36 with the U.S. Department of Energy.  The U.S.
16!     Government has rights to use, reproduce, and distribute this
17!     software.  The public may copy and use this software without
18!     charge, provided that this Notice and any statement of authorship
19!     are reproduced on all copies.  Neither the Government nor the
20!     University makes any warranty, express or implied, or assumes
21!     any liability or responsibility for the use of this software.
22!
23!***********************************************************************
24
25      program create_latlon
26
27!-----------------------------------------------------------------------
28!
29!     This file creates a remapping grid file for a Gaussian grid
30!
31!-----------------------------------------------------------------------
32
33      use kinds_mod
34      use constants
35      use iounits
36      use netcdf_mod
37
38      implicit none
39
40!-----------------------------------------------------------------------
41!
42!     variables that describe the grid
43!
44!-----------------------------------------------------------------------
45
46      integer (kind=int_kind), parameter ::
47     &             nx = 360, ny = 180,
48     &             grid_size = nx*ny,
49     &             grid_rank = 2,
50     &             grid_corners = 4
51
52      character(char_len), parameter :: 
53     &             grid_name = 'Lat/lon 1 degree Grid',
54     &             grid_file_out = 'll1deg_grid.nc'
55
56      integer (kind=int_kind), dimension(grid_rank) ::
57     &             grid_dims
58
59!-----------------------------------------------------------------------
60!
61!     grid coordinates and masks
62!
63!-----------------------------------------------------------------------
64
65      integer (kind=int_kind), dimension(grid_size) ::
66     &             grid_imask
67
68      real (kind=dbl_kind), dimension(grid_size) ::
69     &             grid_center_lat,  ! lat/lon coordinates for
70     &             grid_center_lon   ! each grid center in degrees
71
72      real (kind=dbl_kind), dimension(grid_corners,grid_size) ::
73     &             grid_corner_lat,  ! lat/lon coordinates for
74     &             grid_corner_lon   ! each grid corner in degrees
75
76!-----------------------------------------------------------------------
77!
78!     other local variables
79!
80!-----------------------------------------------------------------------
81
82      integer (kind=int_kind) :: i, j, iunit, atm_add
83
84      integer (kind=int_kind) ::
85     &        ncstat,            ! general netCDF status variable
86     &        nc_grid_id,        ! netCDF grid dataset id
87     &        nc_gridsize_id,    ! netCDF grid size dim id
88     &        nc_gridcorn_id,    ! netCDF grid corner dim id
89     &        nc_gridrank_id,    ! netCDF grid rank dim id
90     &        nc_griddims_id,    ! netCDF grid dimension size id
91     &        nc_grdcntrlat_id,  ! netCDF grid center lat id
92     &        nc_grdcntrlon_id,  ! netCDF grid center lon id
93     &        nc_grdimask_id,    ! netCDF grid mask id
94     &        nc_grdcrnrlat_id,  ! netCDF grid corner lat id
95     &        nc_grdcrnrlon_id   ! netCDF grid corner lon id
96
97      integer (kind=int_kind), dimension(2) ::
98     &        nc_dims2_id        ! netCDF dim id array for 2-d arrays
99
100      real (kind=dbl_kind) :: dlon, minlon, maxlon, centerlon,
101     &                        dlat, minlat, maxlat, centerlat
102
103!-----------------------------------------------------------------------
104!
105!     compute longitudes and latitudes of cell centers and corners.
106!
107!-----------------------------------------------------------------------
108
109      grid_dims(1) = nx
110      grid_dims(2) = ny
111
112      dlon = 360./nx
113      dlat = 180./ny
114
115      do j=1,ny
116
117        minlat = -90._dbl_kind + (j-1)*dlat
118        maxlat = -90._dbl_kind +  j   *dlat
119        centerlat = minlat + half*dlat
120
121        do i=1,nx
122          centerlon = (i-1)*dlon
123          minlon = centerlon - half*dlon
124          maxlon = centerlon + half*dlon
125
126          atm_add = (j-1)*nx + i
127
128          grid_center_lat(atm_add  ) = centerlat
129          grid_corner_lat(1,atm_add) = minlat
130          grid_corner_lat(2,atm_add) = minlat
131          grid_corner_lat(3,atm_add) = maxlat
132          grid_corner_lat(4,atm_add) = maxlat
133
134          grid_center_lon(atm_add  ) = centerlon
135          grid_corner_lon(1,atm_add) = minlon
136          grid_corner_lon(2,atm_add) = maxlon
137          grid_corner_lon(3,atm_add) = maxlon
138          grid_corner_lon(4,atm_add) = minlon
139        end do
140      end do
141
142!-----------------------------------------------------------------------
143!
144!     define mask
145!
146!-----------------------------------------------------------------------
147
148      grid_imask = 1
149
150!-----------------------------------------------------------------------
151!
152!     set up attributes for netCDF file
153!
154!-----------------------------------------------------------------------
155
156      !***
157      !*** create netCDF dataset for this grid
158      !***
159
160      ncstat = nf_create (grid_file_out, NF_CLOBBER,
161     &                    nc_grid_id)
162      call netcdf_error_handler(ncstat)
163
164      ncstat = nf_put_att_text (nc_grid_id, NF_GLOBAL, 'title',
165     &                          len_trim(grid_name), grid_name)
166      call netcdf_error_handler(ncstat)
167
168      !***
169      !*** define grid size dimension
170      !***
171
172      ncstat = nf_def_dim (nc_grid_id, 'grid_size', grid_size, 
173     &                     nc_gridsize_id)
174      call netcdf_error_handler(ncstat)
175
176      !***
177      !*** define grid corner dimension
178      !***
179
180      ncstat = nf_def_dim (nc_grid_id, 'grid_corners', grid_corners, 
181     &                     nc_gridcorn_id)
182      call netcdf_error_handler(ncstat)
183
184      !***
185      !*** define grid rank dimension
186      !***
187
188      ncstat = nf_def_dim (nc_grid_id, 'grid_rank', grid_rank, 
189     &                     nc_gridrank_id)
190      call netcdf_error_handler(ncstat)
191
192      !***
193      !*** define grid dimension size array
194      !***
195
196      ncstat = nf_def_var (nc_grid_id, 'grid_dims', NF_INT,
197     &                     1, nc_gridrank_id, nc_griddims_id)
198      call netcdf_error_handler(ncstat)
199
200      !***
201      !*** define grid center latitude array
202      !***
203
204      ncstat = nf_def_var (nc_grid_id, 'grid_center_lat', NF_DOUBLE,
205     &                     1, nc_gridsize_id, nc_grdcntrlat_id)
206      call netcdf_error_handler(ncstat)
207
208      ncstat = nf_put_att_text (nc_grid_id, nc_grdcntrlat_id, 'units',
209     &                          7, 'degrees')
210      call netcdf_error_handler(ncstat)
211
212      !***
213      !*** define grid center longitude array
214      !***
215
216      ncstat = nf_def_var (nc_grid_id, 'grid_center_lon', NF_DOUBLE,
217     &                     1, nc_gridsize_id, nc_grdcntrlon_id)
218      call netcdf_error_handler(ncstat)
219
220      ncstat = nf_put_att_text (nc_grid_id, nc_grdcntrlon_id, 'units',
221     &                          7, 'degrees')
222      call netcdf_error_handler(ncstat)
223
224      !***
225      !*** define grid mask
226      !***
227
228      ncstat = nf_def_var (nc_grid_id, 'grid_imask', NF_INT,
229     &                     1, nc_gridsize_id, nc_grdimask_id)
230      call netcdf_error_handler(ncstat)
231
232      ncstat = nf_put_att_text (nc_grid_id, nc_grdimask_id, 'units',
233     &                          8, 'unitless')
234      call netcdf_error_handler(ncstat)
235
236      !***
237      !*** define grid corner latitude array
238      !***
239
240      nc_dims2_id(1) = nc_gridcorn_id
241      nc_dims2_id(2) = nc_gridsize_id
242
243      ncstat = nf_def_var (nc_grid_id, 'grid_corner_lat', NF_DOUBLE,
244     &                     2, nc_dims2_id, nc_grdcrnrlat_id)
245      call netcdf_error_handler(ncstat)
246
247      ncstat = nf_put_att_text (nc_grid_id, nc_grdcrnrlat_id, 'units',
248     &                          7, 'degrees')
249      call netcdf_error_handler(ncstat)
250
251      !***
252      !*** define grid corner longitude array
253      !***
254
255      ncstat = nf_def_var (nc_grid_id, 'grid_corner_lon', NF_DOUBLE,
256     &                     2, nc_dims2_id, nc_grdcrnrlon_id)
257      call netcdf_error_handler(ncstat)
258
259      ncstat = nf_put_att_text (nc_grid_id, nc_grdcrnrlon_id, 'units',
260     &                          7, 'degrees')
261      call netcdf_error_handler(ncstat)
262
263      !***
264      !*** end definition stage
265      !***
266
267      ncstat = nf_enddef(nc_grid_id)
268      call netcdf_error_handler(ncstat)
269
270!-----------------------------------------------------------------------
271!
272!     write grid data
273!
274!-----------------------------------------------------------------------
275
276      ncstat = nf_put_var_int(nc_grid_id, nc_griddims_id, grid_dims)
277      call netcdf_error_handler(ncstat)
278
279      ncstat = nf_put_var_int(nc_grid_id, nc_grdimask_id, grid_imask)
280      call netcdf_error_handler(ncstat)
281
282      ncstat = nf_put_var_double(nc_grid_id, nc_grdcntrlat_id, 
283     &                           grid_center_lat)
284      call netcdf_error_handler(ncstat)
285
286      ncstat = nf_put_var_double(nc_grid_id, nc_grdcntrlon_id, 
287     &                           grid_center_lon)
288      call netcdf_error_handler(ncstat)
289
290      ncstat = nf_put_var_double(nc_grid_id, nc_grdcrnrlat_id, 
291     &                           grid_corner_lat)
292      call netcdf_error_handler(ncstat)
293
294      ncstat = nf_put_var_double(nc_grid_id, nc_grdcrnrlon_id, 
295     &                           grid_corner_lon)
296      call netcdf_error_handler(ncstat)
297
298      ncstat = nf_close(nc_grid_id)
299      call netcdf_error_handler(ncstat)
300
301!-----------------------------------------------------------------------
302
303      end program create_latlon
304
305!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Note: See TracBrowser for help on using the repository browser.