source: branches/nemo_v3_3_beta/NEMOGCM/TOOLS/WEIGHTS/SCRIP1.4/grids/convert_old.f @ 2352

Last change on this file since 2352 was 2352, checked in by sga, 11 years ago

NEMO branch nemo_v3_3_beta
Add NOCS tools based on SCRIP package for creating weights for interpolation on the fly
These now should build with the maketools script in the TOOLS directory using the same
architecture configuration file as the model (hopefully)

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