NetCDF-Fortran  4.4.2
nf_misc.f90
1 !-- Routines for processing error messages, obtaining version numbers, etc. --
2 
3 ! Replacement for fort-misc.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 ! Version 2.: May 2006 - Updated to support g95
26 ! Version 3.: April 2009 - Updated for netCDF 4.0.1
27 ! Version 4.: April 2010 - Updated for netCDF 4.1.1
28 
29 !-------------------------------- nf_inq_libvers ---------------------------
30  Function nf_inq_libvers() RESULT(vermsg)
31 
32 ! Return string with current version of NetCDF library
33 
34  USE netcdf_nc_interfaces
35 
36  Implicit NONE
37 
38  Character(LEN=80) :: vermsg
39 
40  Character(LEN=81), Pointer :: fstrptr
41  TYPE(c_ptr) :: cstrptr
42  Integer :: inull, ilen
43 
44  vermsg = repeat(" ", len(vermsg)) !initialize vermsg to blanks
45 
46 ! Get C character pointer returned by nc_inq_vers and associate it
47 ! Fortran character pointer (fstrptr). Have to do this when the C
48 ! routine allocates space for the pointer and/or knows where it lives
49 ! not Fortran. This is also how you can pass character data back to
50 ! FORTRAN from C using a C function that returns a character pointer
51 ! instead using a void jacket function and passing the string as a hidden
52 ! argument. At least this is how cfortran.h appears to do it.
53 
54 
55  NULLIFY(fstrptr) ! Nullify fstrptr
56 
57  cstrptr = nc_inq_libvers() ! Get C pointer to version string and
58 
59  Call c_f_pointer(cstrptr, fstrptr) ! associate it with FORTRAN pointer
60 
61 ! Locate first C null character and then set it and remaining characters
62 ! in string to blanks
63 
64  ilen = len_trim(fstrptr)
65  inull = scan(fstrptr,c_null_char)
66  If (inull /= 0) ilen = inull-1
67  ilen = max(1, min(ilen,80)) ! Limit ilen to >=1 and <=80
68 
69 ! Load return value with trimmed fstrptr string
70 
71  vermsg(1:ilen) = fstrptr(1:ilen)
72 
73  End Function nf_inq_libvers
74 !-------------------------------- nf_stderror ------------------------------
75  Function nf_strerror(ncerr) RESULT(errmsg)
76 
77 ! Returns an error message string given static error code ncerr
78 
79  USE netcdf_nc_interfaces
80 
81  Implicit NONE
82 
83  Integer(KIND=C_INT), Intent(IN) :: ncerr
84 
85  Character(LEN=80) :: errmsg
86 
87  Character(LEN=81), Pointer :: fstrptr
88  TYPE(c_ptr) :: cstrptr
89  Integer :: inull, ilen
90  Integer(KIND=C_INT) :: cncerr
91 
92  errmsg = repeat(" ", len(errmsg)) !initialize errmsg to blanks
93 
94 ! Get C character pointer returned by nc_stderror and associate it
95 ! Fortran character pointer (fstrptr). Have to do this when the C
96 ! routine allocates space for the pointer and/or knows where it lives
97 ! not Fortran. This is also how you can pass character data back to
98 ! FORTRAN from C using a C function that returns a character pointer
99 ! instead using a void jacket function and passing the string as a hidden
100 ! argument. At least this is how cfortran.h appears to do it.
101 
102  NULLIFY(fstrptr) ! Nullify fstrptr
103 
104  cncerr = ncerr
105 
106  cstrptr = nc_strerror(cncerr) ! Return C character pointer and
107  Call c_f_pointer(cstrptr, fstrptr) ! associate C ptr with FORTRAN pointer
108 
109 ! Locate first C null character and then set it and remaining characters
110 ! in string to blanks
111 
112  ilen = len_trim(fstrptr)
113  inull = scan(fstrptr,c_null_char)
114  If (inull /= 0) ilen = inull-1
115  ilen = max(1, min(ilen,80)) ! Limit ilen to >=1 and <=80
116 
117 ! Load return value with trimmed fstrptr string
118 
119  errmsg(1:ilen) = fstrptr(1:ilen)
120 
121  End Function nf_strerror
122 !-------------------------------- nf_issyserr ------------------------------
123  Function nf_issyserr(nerr) RESULT(status)
124 
125 ! Check to see if nerr is > 0
126 
127  Integer, Intent(IN) :: nerr
128 
129  Logical :: status
130 
131  status = (nerr > 0)
132 
133  End Function nf_issyserr
Begin explicit interfaces for base nc_ functions.

Return to the Main Unidata NetCDF page.
Generated on Sun Dec 27 2015 13:19:49 for NetCDF-Fortran. NetCDF is a Unidata library.