Coverage Report

Created: 2025-10-28 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/netcdf-c/liblib/nc_initialize.c
Line
Count
Source
1
/*********************************************************************
2
 *   Copyright 2018, UCAR/Unidata
3
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
4
 *********************************************************************/
5
6
#include "config.h"
7
8
#ifdef USE_PARALLEL
9
#include <mpi.h>
10
#endif
11
12
#include "ncdispatch.h"
13
14
#ifdef USE_NETCDF4
15
#include "nc4internal.h"
16
#endif
17
18
#ifdef USE_HDF5
19
#include "hdf5internal.h"
20
extern int NC_HDF5_initialize(void);
21
extern int NC_HDF5_finalize(void);
22
#endif
23
24
#ifdef NETCDF_ENABLE_DAP2
25
extern int NCD2_initialize(void);
26
extern int NCD2_finalize(void);
27
#endif
28
29
#ifdef NETCDF_ENABLE_DAP4
30
extern int NCD4_initialize(void);
31
extern int NCD4_finalize(void);
32
#endif
33
34
35
#ifdef USE_PNETCDF
36
extern int NCP_initialize(void);
37
extern int NCP_finalize(void);
38
#endif
39
40
#ifdef USE_HDF4
41
extern int NC_HDF4_initialize(void);
42
extern int NC_HDF4_finalize(void);
43
#endif
44
45
#ifdef NETCDF_ENABLE_S3
46
EXTERNL int NC_s3sdkinitialize(void);
47
EXTERNL int NC_s3sdkfinalize(void);
48
#endif
49
50
#ifdef _MSC_VER
51
#include <io.h>
52
#include <fcntl.h>
53
#endif
54
55
int NC_initialized = 0;
56
int NC_finalized = 1;
57
58
#ifdef NETCDF_ENABLE_ATEXIT_FINALIZE
59
/* Provide the void function to give to atexit() */
60
static void
61
finalize_atexit(void)
62
1
{
63
1
    (void)nc_finalize();
64
1
}
65
#endif
66
67
/**
68
This procedure invokes all defined
69
initializers, and there is an initializer
70
for every known dispatch table.
71
So if you modify the format of NC_Dispatch,
72
then you need to fix it everywhere.
73
It also initializes appropriate external libraries.
74
*/
75
76
int
77
nc_initialize()
78
1
{
79
1
    int stat = NC_NOERR;
80
81
1
    if(NC_initialized) return NC_NOERR;
82
1
    NC_initialized = 1;
83
1
    NC_finalized = 0;
84
85
    /* Do general initialization */
86
1
    if((stat = NCDISPATCH_initialize())) goto done;
87
88
    /* Initialize each active protocol */
89
1
    if((stat = NC3_initialize())) goto done;
90
#ifdef NETCDF_ENABLE_DAP
91
    if((stat = NCD2_initialize())) goto done;
92
#endif
93
#ifdef NETCDF_ENABLE_DAP4
94
    if((stat = NCD4_initialize())) goto done;
95
#endif
96
#ifdef USE_PNETCDF
97
    if((stat = NCP_initialize())) goto done;
98
#endif
99
1
#ifdef USE_NETCDF4
100
1
    if((stat = NC4_initialize())) goto done;
101
1
#endif /* USE_NETCDF4 */
102
#ifdef USE_HDF5
103
    if((stat = NC_HDF5_initialize())) goto done;
104
#endif
105
#ifdef USE_HDF4
106
    if((stat = NC_HDF4_initialize())) goto done;
107
#endif
108
#ifdef NETCDF_ENABLE_S3
109
    if((stat = NC_s3sdkinitialize())) goto done;
110
#endif
111
1
#ifdef NETCDF_ENABLE_NCZARR
112
1
    if((stat = NCZ_initialize())) goto done;
113
1
#endif
114
115
1
#ifdef NETCDF_ENABLE_ATEXIT_FINALIZE
116
    /* Use atexit() to invoke nc_finalize */
117
1
    if(atexit(finalize_atexit))
118
0
  fprintf(stderr,"atexit failed\n");
119
1
#endif
120
121
1
done:
122
1
    return stat;
123
1
}
124
125
/**
126
This procedure invokes all defined
127
finalizers, and there should be one
128
for every known dispatch table.
129
So if you modify the format of NC_Dispatch,
130
then you need to fix it everywhere.
131
It also finalizes appropriate external libraries.
132
*/
133
134
int
135
nc_finalize(void)
136
1
{
137
1
    int stat = NC_NOERR;
138
1
    int failed = stat;
139
140
1
    if(NC_finalized) goto done;
141
1
    NC_initialized = 0;
142
1
    NC_finalized = 1;
143
144
    /* Finalize each active protocol */
145
146
#ifdef NETCDF_ENABLE_DAP2
147
    if((stat = NCD2_finalize())) failed = stat;
148
#endif
149
#ifdef NETCDF_ENABLE_DAP4
150
    if((stat = NCD4_finalize())) failed = stat;
151
#endif
152
153
#ifdef USE_PNETCDF
154
    if((stat = NCP_finalize())) failed = stat;
155
#endif
156
157
#ifdef USE_HDF4
158
    if((stat = NC_HDF4_finalize())) failed = stat;
159
#endif /* USE_HDF4 */
160
161
1
#ifdef USE_NETCDF4
162
1
    if((stat = NC4_finalize())) failed = stat;
163
1
#endif /* USE_NETCDF4 */
164
165
#ifdef USE_HDF5
166
    if((stat = NC_HDF5_finalize())) failed = stat;
167
#endif
168
169
1
#ifdef NETCDF_ENABLE_NCZARR
170
1
    if((stat = NCZ_finalize())) failed = stat;
171
1
#endif
172
173
#ifdef NETCDF_ENABLE_S3
174
    if((stat = NC_s3sdkfinalize())) failed = stat;
175
#endif
176
177
1
    if((stat = NC3_finalize())) failed = stat;
178
179
    /* Do general finalization */
180
1
    if((stat = NCDISPATCH_finalize())) failed = stat;
181
182
1
done:
183
1
    if(failed) fprintf(stderr,"nc_finalize failed: %d\n",failed);
184
1
    return failed;
185
1
}