cpld_gridgen  1.7.0
 All Data Structures Files Functions Variables
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,mastertask
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  if(mastertask) then
50  logmsg = '==> writing CICE grid to '//trim(fname)
51  print '(a)', trim(logmsg)
52  if(rc .ne. 0)print '(a)', 'nf90_create = '//trim(nf90_strerror(rc))
53  end if
54 
55  rc = nf90_def_dim(ncid, 'ni', ni, idimid)
56  rc = nf90_def_dim(ncid, 'nj', nj, jdimid)
57 
58  do ii = 1,maxvars
59  if(len_trim(cicevars(ii)%var_name) .gt. 0)then
60  vname = trim(cicevars(ii)%var_name)
61  vlong = trim(cicevars(ii)%long_name)
62  vunit = trim(cicevars(ii)%unit_name)
63  vtype = trim(cicevars(ii)%var_type)
64 
65  dim2(:) = (/idimid, jdimid/)
66  if(vtype .eq. 'r8')rc = nf90_def_var(ncid, vname, nf90_double, dim2, id)
67  if(vtype .eq. 'r4')rc = nf90_def_var(ncid, vname, nf90_float, dim2, id)
68  if(vtype .eq. 'i4')rc = nf90_def_var(ncid, vname, nf90_int, dim2, id)
69  rc = nf90_put_att(ncid, id, 'units', vunit)
70  rc = nf90_put_att(ncid, id, 'long_name', vlong)
71  end if
72  enddo
73  rc = nf90_put_att(ncid, nf90_global, 'history', trim(history))
74  rc = nf90_enddef(ncid)
75 
76  rc = nf90_inq_varid(ncid, 'ulon', id)
77  rc = nf90_put_var(ncid, id, ulon)
78 
79  rc = nf90_inq_varid(ncid, 'ulat', id)
80  rc = nf90_put_var(ncid, id, ulat)
81 
82  rc = nf90_inq_varid(ncid, 'htn', id)
83  rc = nf90_put_var(ncid, id, htn)
84 
85  rc = nf90_inq_varid(ncid, 'hte', id)
86  rc = nf90_put_var(ncid, id, hte)
87 
88  rc = nf90_inq_varid(ncid, 'angle', id)
89  rc = nf90_put_var(ncid, id, angle)
90 
91  rc = nf90_inq_varid(ncid, 'kmt', id)
92  rc = nf90_put_var(ncid, id, int(wet4))
93 
94  rc = nf90_close(ncid)
95 
96  end subroutine write_cicegrid
97 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