/src/netcdf-c/libsrc4/nc4dispatch.c
Line | Count | Source |
1 | | /* Copyright 2005-2018 University Corporation for Atmospheric |
2 | | Research/Unidata. */ |
3 | | /** |
4 | | * @file |
5 | | * @internal This header file contains libsrc4 dispatch |
6 | | * initialization, user-defined format, and logging prototypes and |
7 | | * macros. |
8 | | * |
9 | | * @author Dennis Heimbigner, Ed Hartnett |
10 | | */ |
11 | | |
12 | | #include "config.h" |
13 | | #include <stdlib.h> |
14 | | #include "netcdf.h" |
15 | | #include "nc4internal.h" |
16 | | #include "nc4dispatch.h" |
17 | | #include "nc.h" |
18 | | #include "ncudfplugins.h" |
19 | | |
20 | | /* If user-defined formats are in use, we need to declare their |
21 | | * dispatch tables. */ |
22 | | #ifdef USE_UDF0 |
23 | | extern NC_Dispatch UDF0_DISPATCH; |
24 | | #endif /* USE_UDF0 */ |
25 | | #ifdef USE_UDF1 |
26 | | extern NC_Dispatch UDF1_DISPATCH; |
27 | | #endif /* USE_UDF1 */ |
28 | | |
29 | | extern int nc_plugin_path_initialize(void); |
30 | | extern int nc_plugin_path_finalize(void); |
31 | | |
32 | | /** |
33 | | * @internal Initialize netCDF-4. If user-defined format(s) have been |
34 | | * specified in configure, load their dispatch table(s). |
35 | | * |
36 | | * @return ::NC_NOERR No error. |
37 | | * @author Dennis Heimbigner |
38 | | */ |
39 | | int |
40 | | NC4_initialize(void) |
41 | 1 | { |
42 | 1 | int ret = NC_NOERR; |
43 | | |
44 | | #ifdef USE_UDF0 |
45 | | /* If user-defined format 0 was specified during configure, set up |
46 | | * it's dispatch table. */ |
47 | | if ((ret = nc_def_user_format(NC_UDF0, UDF0_DISPATCH_FUNC, NULL))) |
48 | | return ret; |
49 | | #endif /* USE_UDF0 */ |
50 | | |
51 | | #ifdef USE_UDF1 |
52 | | /* If user-defined format 0 was specified during configure, set up |
53 | | * it's dispatch table. */ |
54 | | if ((ret = nc_def_user_format(NC_UDF1F, &UDF1_DISPATCH_FUNC, NULL))) |
55 | | return ret; |
56 | | #endif /* USE_UDF0 */ |
57 | | |
58 | | #ifdef LOGGING |
59 | | if(getenv(NCLOGLEVELENV) != NULL) { |
60 | | char* slevel = getenv(NCLOGLEVELENV); |
61 | | long level = atol(slevel); |
62 | | #ifdef USE_NETCDF4 |
63 | | if(level >= 0) { |
64 | | nc_set_log_level((int)level); |
65 | | } |
66 | | } |
67 | | #endif |
68 | | #endif |
69 | | |
70 | 1 | #if defined(USE_HDF5) || defined(NETCDF_ENABLE_NCZARR) |
71 | 1 | nc_plugin_path_initialize(); |
72 | 1 | #endif |
73 | | |
74 | | /* Load UDF plugins from RC file configuration */ |
75 | 1 | if ((ret = NC_udf_load_plugins())) |
76 | 0 | return ret; |
77 | | |
78 | 1 | NC_initialize_reserved(); |
79 | 1 | return ret; |
80 | 1 | } |
81 | | |
82 | | /** |
83 | | * @internal Finalize netCDF-4. |
84 | | * |
85 | | * @return ::NC_NOERR No error. |
86 | | * @author Dennis Heimbigner |
87 | | */ |
88 | | int |
89 | | NC4_finalize(void) |
90 | 1 | { |
91 | 1 | #if defined(USE_HDF5) || defined(NETCDF_ENABLE_NCZARR) |
92 | 1 | nc_plugin_path_finalize(); |
93 | 1 | #endif |
94 | 1 | return NC_NOERR; |
95 | 1 | } |