1!------- Routines for obtaining info on dimensions, varible sizes, etc ------- 2 3! Replacement for fort-geninq.c 4 5! Written by: Richard Weed, Ph.D. 6! Center for Advanced Vehicular Systems 7! Mississippi State University 8! rweed@cavs.msstate.edu 9 10 11! License (and other Lawyer Language) 12 13! This software is released under the Apache 2.0 Open Source License. The 14! full text of the License can be viewed at : 15! 16! http:www.apache.org/licenses/LICENSE-2.0.html 17! 18! The author grants to the University Corporation for Atmospheric Research 19! (UCAR), Boulder, CO, USA the right to revise and extend the software 20! without restriction. However, the author retains all copyrights and 21! intellectual property rights explicitly stated in or implied by the 22! Apache license 23 24! Version 1.: Sept. 2005 - Initial Cray X1 version 25! April 2006 - Updated to include 3.6.1 function nf_inq_format 26! Version 2.: May 2006 - Updated to support g95 27! Version 3.: April 2009 - Updated to Netcdf 4.0.1 28! Version 4.: April 2010 - Updated to Netcdf 4.1.1 29! Version 5.: May 2014 - Ensure return error status checked from C API calls 30! Version 6.: Jan. 2016 - General code cleanup. 31! 32!-------------------------------- nf_inq ---------------------------------- 33 Function nf_inq(ncid, ndims, nvars, ngatts, unlimdimid) RESULT(status) 34 35! Inquire about number of dimensions, number of varibles, number of 36! global attributes, and the id of the ulimited dimension for NetCDF file 37! id ncid 38 39 USE netcdf_nc_interfaces 40 41 Implicit NONE 42 43 Integer, Intent(IN) :: ncid 44 Integer, Intent(OUT) :: ndims, nvars, ngatts, unlimdimid 45 46 Integer :: status 47 48 Integer(C_INT) :: cncid, cndims, cnvars, cngatts, cunlimdimid, cstatus 49 50 cncid = ncid 51 52 cstatus = nc_inq(cncid, cndims, cnvars, cngatts, cunlimdimid) 53 54 If (cstatus == NC_NOERR) Then 55 ndims = cndims 56 nvars = cnvars 57 ngatts = cngatts 58 59! Shift C id by plus one to Fortran id if unlimdimid is not -1 60 61 If (cunlimdimid == - 1) Then 62 unlimdimid = -1 63 Else 64 unlimdimid = cunlimdimid + 1 65 EndIf 66 EndIf 67 status = cstatus 68 69 End Function nf_inq 70!-------------------------------- nf_inq_ndims ----------------------------- 71 Function nf_inq_ndims(ncid, ndims) RESULT(status) 72 73! Inquire about number of dimensions for NetCDF file id ncid 74 75 USE netcdf_nc_interfaces 76 77 Implicit NONE 78 79 Integer, Intent(IN) :: ncid 80 Integer, Intent(OUT) :: ndims 81 82 Integer :: status 83 84 Integer(C_INT) :: cncid, cndims, cstatus 85 86 cncid = ncid 87 88 cstatus = nc_inq_ndims(cncid, cndims) 89 90 If (cstatus == NC_NOERR) Then 91 ndims = cndims 92 EndIf 93 status = cstatus 94 95 End Function nf_inq_ndims 96!-------------------------------- nf_inq_nvars ----------------------------- 97 Function nf_inq_nvars(ncid, nvars) RESULT(status) 98 99! Inquire about number of variables for NetCDF file id ncid 100 101 USE netcdf_nc_interfaces 102 103 Implicit NONE 104 105 Integer, Intent(IN) :: ncid 106 Integer, Intent(OUT) :: nvars 107 108 Integer :: status 109 110 Integer(C_INT) :: cncid, cnvars, cstatus 111 112 cncid = ncid 113 114 cstatus = nc_inq_nvars(cncid, cnvars) 115 116 If (cstatus == NC_NOERR) Then 117 nvars = cnvars 118 EndIf 119 status = cstatus 120 121 End Function nf_inq_nvars 122!-------------------------------- nf_inq_natts ----------------------------- 123 Function nf_inq_natts(ncid, ngatts) RESULT(status) 124 125! Inquire about number of global attributes for NetCDF file id ncid 126 127 USE netcdf_nc_interfaces 128 129 Implicit NONE 130 131 Integer, Intent(IN) :: ncid 132 Integer, Intent(OUT) :: ngatts 133 134 Integer :: status 135 136 Integer(C_INT) :: cncid, cngatts, cstatus 137 138 cncid = ncid 139 140 cstatus = nc_inq_natts(cncid, cngatts) 141 142 If (cstatus == NC_NOERR) Then 143 ngatts = cngatts 144 EndIf 145 status = cstatus 146 147 End Function nf_inq_natts 148!-------------------------------- nf_inq_unlimdim -------------------------- 149 Function nf_inq_unlimdim(ncid, unlimdimid) RESULT(status) 150 151! Inquire about id of unlimited dimension for NetCDF file id ncid 152 153 USE netcdf_nc_interfaces 154 155 Implicit NONE 156 157 Integer, Intent(IN) :: ncid 158 Integer, Intent(OUT) :: unlimdimid 159 160 Integer :: status 161 162 Integer(C_INT) :: cncid, cunlimdimid, cstatus 163 164 cncid = ncid 165 166 cstatus = nc_inq_unlimdim(cncid, cunlimdimid) 167 168! Shift C id by plus one to Fortran id if unlimdimid is not -1 169 170 If (cstatus == NC_NOERR) Then 171 If (cunlimdimid == -1) Then 172 unlimdimid = -1 173 Else 174 unlimdimid = cunlimdimid + 1 175 EndIf 176 EndIf 177 status = cstatus 178 179 End Function nf_inq_unlimdim 180!-------------------------------- nf_inq_format ------------------------------- 181 Function nf_inq_format(ncid, format_type) RESULT(status) 182 183! Inquire about internal file format for NetCDF file id ncid 184 185 USE netcdf_nc_interfaces 186 187 Implicit NONE 188 189 Integer, Intent(IN) :: ncid 190 Integer, Intent(OUT) :: format_type 191 192 Integer :: status 193 194 Integer(C_INT) :: cncid, cformatp, cstatus 195 196 cncid = ncid 197 198 cstatus = nc_inq_format(cncid, cformatp) 199 200 If (cstatus == NC_NOERR) Then 201! Return format_type 202 203 format_type = cformatp 204 EndIf 205 status = cstatus 206 207 End Function nf_inq_format 208