cpld_gridgen  1.13.0
 All Data Structures Files Functions Variables Pages
cicegrid.F90
Go to the documentation of this file.
1 
7 
8 module cicegrid
9 
10  use grdvars, only: ni,nj,ulat,ulon,htn,hte,angle,wet4
11  use charstrings, only: history, logmsg
12  use vartypedefs, only: maxvars, cicevars, cicevars_typedefine
13  use gengrid_kinds, only: cm
14  use netcdf
15 
16  implicit none
17  private
18 
19  public write_cicegrid
20 
21 contains
27 
28  subroutine write_cicegrid(fname)
29 
30  character(len=*), intent(in) :: fname
31 
32  ! local variables
33  integer :: ii,id,rc, ncid, dim2(2)
34  integer :: idimid,jdimid
35 
36  character(len=2) :: vtype
37  character(len=CM) :: vname
38  character(len=CM) :: vlong
39  character(len=CM) :: vunit
40 
41  !---------------------------------------------------------------------
42  ! create the netcdf file
43  !---------------------------------------------------------------------
44 
45  ! define the output variables and file name
47 
48  rc = nf90_create(fname, nf90_write, ncid)
49  logmsg = '==> writing CICE grid to '//trim(fname)
50  print '(a)', trim(logmsg)
51  if(rc .ne. 0)print '(a)', 'nf90_create = '//trim(nf90_strerror(rc))
52 
53  rc = nf90_def_dim(ncid, 'ni', ni, idimid)
54  rc = nf90_def_dim(ncid, 'nj', nj, jdimid)
55 
56  do ii = 1,maxvars
57  if(len_trim(cicevars(ii)%var_name) .gt. 0)then
58  vname = trim(cicevars(ii)%var_name)
59  vlong = trim(cicevars(ii)%long_name)
60  vunit = trim(cicevars(ii)%unit_name)
61  vtype = trim(cicevars(ii)%var_type)
62 
63  dim2(:) = (/idimid, jdimid/)
64  if(vtype .eq. 'r8')rc = nf90_def_var(ncid, vname, nf90_double, dim2, id)
65  if(vtype .eq. 'r4')rc = nf90_def_var(ncid, vname, nf90_float, dim2, id)
66  if(vtype .eq. 'i4')rc = nf90_def_var(ncid, vname, nf90_int, dim2, id)
67  rc = nf90_put_att(ncid, id, 'units', vunit)
68  rc = nf90_put_att(ncid, id, 'long_name', vlong)
69  end if
70  enddo
71  rc = nf90_put_att(ncid, nf90_global, 'history', trim(history))
72  rc = nf90_enddef(ncid)
73 
74  rc = nf90_inq_varid(ncid, 'ulon', id)
75  rc = nf90_put_var(ncid, id, ulon)
76 
77  rc = nf90_inq_varid(ncid, 'ulat', id)
78  rc = nf90_put_var(ncid, id, ulat)
79 
80  rc = nf90_inq_varid(ncid, 'htn', id)
81  rc = nf90_put_var(ncid, id, htn)
82 
83  rc = nf90_inq_varid(ncid, 'hte', id)
84  rc = nf90_put_var(ncid, id, hte)
85 
86  rc = nf90_inq_varid(ncid, 'angle', id)
87  rc = nf90_put_var(ncid, id, angle)
88 
89  rc = nf90_inq_varid(ncid, 'kmt', id)
90  rc = nf90_put_var(ncid, id, int(wet4))
91 
92  rc = nf90_close(ncid)
93 
94  end subroutine write_cicegrid
95 end module cicegrid
subroutine cicevars_typedefine
Define the variables written to the CICE grid file.
subroutine, public write_cicegrid(fname)
Write the CICE6 grid file.
Definition: cicegrid.F90:28