Line data Source code
1 : !------------------------------------------------------------------------------
2 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
3 : ! and NASA/GSFC, SIVO, Code 610.3 !
4 : !------------------------------------------------------------------------------
5 : !BOP
6 : !
7 : ! !MODULE: HCO_m_netcdf_io_get_dimlen
8 : !
9 : ! !INTERFACE:
10 : !
11 : module HCO_m_netcdf_io_get_dimlen
12 : !
13 : implicit none
14 : !
15 : ! !PUBLIC MEMBER FUNCTIONS:
16 : !
17 : public Ncget_Dimlen
18 : public Ncget_Unlim_Dimlen
19 : !
20 : ! !DESCRIPTION: Provides routines to obtain the length of a given dimension.
21 : !\\
22 : !\\
23 : ! !AUTHOR:
24 : ! Jules Kouatchou
25 : !
26 : ! !REVISION HISTORY:
27 : ! See https://github.com/geoschem/ncdfutil for complete history
28 : !EOP
29 : !------------------------------------------------------------------------------
30 : !BOC
31 : CONTAINS
32 : !EOC
33 : !------------------------------------------------------------------------------
34 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
35 : ! and NASA/GSFC, SIVO, Code 610.3 !
36 : !------------------------------------------------------------------------------
37 : !BOP
38 : !
39 : ! !IROUTINE: Ncget_Dimlen
40 : !
41 : ! !INTERFACE:
42 : !
43 0 : subroutine Ncget_Dimlen (ncid, dim_name, dim_len )
44 : !
45 : ! !USES:
46 : !
47 : use m_do_err_out
48 : !
49 : implicit none
50 : !
51 : include 'netcdf.inc'
52 : !
53 : ! !INPUT PARAMETERS:
54 : !! dim_name : netCDF dimension name
55 : !! ncid : netCDF file id
56 : character (len=*), intent(in) :: dim_name
57 : integer, intent(in) :: ncid
58 : !
59 : ! !OUTPUT PARAMETERS:
60 : !! dim_len: netCDF dimension length
61 : integer, intent(out) :: dim_len
62 : !
63 : ! !DESCRIPTION: Returns the length of a given netCDF dimension.
64 : ! If err\_stop is set to FALSE, -1 is returned if
65 : ! the given dimension cannot be found. Otherwise,
66 : ! an error is prompted and the program stops.
67 : !\\
68 : !\\
69 : ! !AUTHOR:
70 : ! John Tannahill (LLNL) and Jules Kouatchou
71 : !
72 : ! !REVISION HISTORY:
73 : ! See https://github.com/geoschem/ncdfutil for complete history
74 : !EOP
75 : !------------------------------------------------------------------------------
76 : !BOC
77 : !
78 : ! !LOCAL VARIABLES:
79 : character (len=512) :: err_msg
80 : integer :: dimid
81 : integer :: ierr
82 :
83 0 : ierr = Nf_Inq_Dimid (ncid, dim_name, dimid)
84 :
85 0 : if (ierr /= NF_NOERR ) then
86 : err_msg = 'In Ncget_Dimlen #1: ' // Trim (dim_name) // &
87 0 : ', ' // Nf_Strerror (ierr)
88 0 : call Do_Err_Out (err_msg, .true., 1, ncid, 0, 0, 0.0d0, 0.0d0)
89 : end if
90 :
91 0 : ierr = Nf_Inq_Dimlen (ncid, dimid, dim_len)
92 :
93 0 : if (ierr /= NF_NOERR) then
94 0 : err_msg = 'In Ncget_Dimlen #2: ' // Nf_Strerror (ierr)
95 0 : call Do_Err_Out (err_msg, .true., 2, ncid, dimid, 0, 0.0d0, 0.0d0)
96 : end if
97 :
98 0 : return
99 : end subroutine Ncget_Dimlen
100 : !EOC
101 : !------------------------------------------------------------------------------
102 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
103 : ! and NASA/GSFC, SIVO, Code 610.3 !
104 : !------------------------------------------------------------------------------
105 : !BOP
106 : !
107 : ! !IROUTINE: Ncget_Unlim_Dimlen
108 : !
109 : ! !INTERFACE:
110 : !
111 0 : subroutine Ncget_Unlim_Dimlen (ncid, udim_len)
112 : !
113 : ! !USES:
114 : !
115 : use m_do_err_out
116 : !
117 : implicit none
118 : !
119 : include 'netcdf.inc'
120 : !
121 : ! !INPUT PARAMETERS:
122 : !! ncid : netCDF file id
123 : integer, intent(in) :: ncid
124 : !
125 : ! !OUTPUT PARAMETERS:
126 : !! udim_len : netCDF unlimited dimension length
127 : integer, intent(out) :: udim_len
128 : !
129 : ! !DESCRIPTION: Returns the length of the unlimited netCDF dimension.
130 : !\\
131 : !\\
132 : ! !AUTHOR:
133 : ! John Tannahill (LLNL) and Jules Kouatchou
134 : !
135 : ! !REVISION HISTORY:
136 : ! See https://github.com/geoschem/ncdfutil for complete history
137 : !EOP
138 : !------------------------------------------------------------------------------
139 : !BOC
140 : !
141 : ! !LOCAL VARIABLES:
142 : character (len=512) :: err_msg
143 : integer :: ierr
144 : integer :: udimid
145 : !
146 0 : ierr = Nf_Inq_Unlimdim (ncid, udimid)
147 :
148 0 : if (ierr /= NF_NOERR) then
149 0 : err_msg = 'In Ncget_Unlim_Dimlen #1: ' // Nf_Strerror (ierr)
150 0 : call Do_Err_Out (err_msg, .true., 1, ncid, 0, 0, 0.0d0, 0.0d0)
151 : end if
152 :
153 0 : ierr = Nf_Inq_Dimlen (ncid, udimid, udim_len)
154 :
155 0 : if (ierr /= NF_NOERR) then
156 0 : err_msg = 'In Ncget_Unlim_Dimlen #2: ' // Nf_Strerror (ierr)
157 0 : call Do_Err_Out (err_msg, .true., 2, ncid, udimid, 0, 0.0d0, 0.0d0)
158 : end if
159 :
160 0 : return
161 :
162 : end subroutine Ncget_Unlim_Dimlen
163 : !EOC
164 : end module HCO_m_netcdf_io_get_dimlen
|