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

Return to the Main Unidata NetCDF page.
Generated on Mon Dec 19 2016 16:43:43 for NetCDF-Fortran. NetCDF is a Unidata library.