NetCDF  4.9.3
quickstart_env.md
1 Appendix G. Environment Variables and .RC files QuickStart {#nc_env_quickstart}
2 ==============================
3 
4 [TOC]
5 
6 The netCDF-c library provides several parameterization mechanisms to
7 control its behavior at run-time. The term _run-time_ means that the
8 library's behavior can be changed every time the library is initialized
9 
10 The most commonly used parameterization mechanisms are:
11 1. Environment Variables -- accessed by the getenv() function.
12 2. .RC files -- accessed from the file system.
13 
14 ## Environment Variables {#nc_env_vars}
15 
16 The following table describes (most of) the environment variables
17 used by the netcdf-c library. There are some not listed that are only
18 used for specialized debugging.
19 
20 <table>
21 <tr><th>Name<th>Description
22 <tr><td>ALLUSERSPROFILE<td>This is more-or-less the Windows equivalent of "HOME"
23 <tr><td>AWS_ACCESS_KEY_ID<td>Used by the aws access libraries; overrides ${HOME}/.aws/config entries.
24 <tr><td>AWS_CONFIG_FILE<td>Used by the aws access libraries; specifies absolute path to the config file.
25 <tr><td>AWS_DEFAULT_REGION<td>Used by the aws access libraries; specifies default S3 region.
26 <tr><td>AWS_PROFILE<td>Used by the aws access libraries; specifies default AWS profile.
27 <tr><td>AWS_REGION<td>Used by the aws access libraries; specifies specific region to use.
28 <tr><td>AWS_SECRET_ACCESS_KEY<td>Used by the aws access libraries; overrides ${HOME}/.aws/config entries.
29 <tr><td>CURLOPT_VERBOSE<td>Causes libcurl to produce verbose output.
30 <tr><td>HOME<td>The user's home directory.
31 <tr><td>MSYS2_PREFIX<td>If platform is MSYS2, then specify the root prefix.
32 <tr><td>NC_DEFAULT_CREATE_PERMS<td>For NCZarr, specify the default creation permissions for a file.
33 <tr><td>NC_DEFAULT_DIR_PERMS<td>For NCZarr, specify the default creation permissions for a directory.
34 <tr><td>NCLOGGING<td>Specify the log level: one of "OFF","ERR","WARN","NOTE","DEBUG".
35 <tr><td>NCPATHDEBUG<td>Causes path manager to output debugging information.
36 <tr><td>NCRCENV_HOME<td>Overrides ${HOME} as the location of the .rc file.
37 <tr><td>NCRCENV_IGNORE<td>Causes any .rc files to be ignored.
38 <tr><td>NCRCENV_RC<td>The absolute path to use for the .rc file.
39 <tr><td>NCTRACING<td>Specify the level of tracing detail.
40 <tr><td>NCZARRFORMAT<td>Force use of a specific Zarr format version: 2 or 3.
41 <tr><td>NETCDF_LOG_LEVEL<td>Specify the log level for HDF5 logging (separate from e.g. NCLOGGING).
42 <tr><td>TEMP<td>For Windows platform, specifies the location of a directory to store temporary files.
43 <tr><td>USERPROFILE<td>For Windows platform, overrides ${HOME}.
44 </table>
45 
46 ## Resource Control (.rc) Files {#nc_env_rc}
47 
48 In addition to using environment variables,
49 the netcdf-c library supports run-time configuration
50 of the library using the so-called ".rc" file mechanism.
51 This means that as part of its initialization, the netcdf-c
52 library will search for and process a set of files where
53 these files contain entries specifying (key,value) pairs.
54 These pairs are compiled into a single internal database
55 that can be queried by other parts of the netcdf-c library.
56 
57 ### Locating The _.rc_ Files
58 
59 For historical reasons, multiple .rc files are allowed.
60 
61 ### Search Order
62 
63 The netcdf-c library searches for, and loads from, the following files,
64 in this order:
65 1. $HOME/.ncrc
66 2. $HOME/.dodsrc
67 3. $CWD/.ncrc
68 4. $CWD/.dodsrc
69 
70 *$HOME* is the user's home directory and *$CWD* is the current working directory.
71 Entries in later files override any of the earlier files
72 
73 It is strongly suggested that you pick a uniform location and a uniform name
74 and use them always. Otherwise you may observe unexpected results
75 when the netcdf-c library loads an rc file you did not expect.
76 
77 ### RC File Format
78 
79 The rc file format is a series of lines of the general form:
80 ````
81  [<URL>]<key>=<value>
82 ````
83 where the bracket-enclosed URL is optional. Note that the brackets
84 are part of the line.
85 
86 ### URL Constrained RC File Entries
87 
88 Each line of the rc file can begin with a URL enclosed in
89 square brackets. The parts of the URL that are used for choosing
90 an entry are the host, the port, and the URL path.
91 Note that the host+port is the only part used when searching for
92 libcurl related entries. This is because libcurl's authorization grain is not
93 any finer than host+port level.
94 The URL path may be used for non-curl related entries.
95 Also note that the protocol is ignored.
96 
97 Here are some examples.
98 ````
99  [https://remotetest.unidata.ucar.edu/thredds]HTTP.VERBOSE=1
100 or
101  [https://fake.ucar.edu:9090]HTTP.VERBOSE=0
102 ````
103 
104 For selection purposes, the host+port+path is used when the path argument
105 for _nc_open()_ or _nc_create()_ takes the form of a URL.
106 If the url request from, say, the _netcdf_open_ method
107 has a host,port, and path matching one of the prefixes in the rc file, then
108 the corresponding entry will be used, otherwise ignored.
109 This means that an entry with a matching host+port+path will take
110 precedence over an entry without a host+port+path.
111 
112 For example, passing this URL to _nc_open_
113 ````
114  http://remotetest.unidata.ucar.edu/thredds/dodsC/testdata/testData.nc
115 ````
116 will have HTTP.VERBOSE set to 1 because its host and path match the example above.
117 
118 Similarly, using this path
119 ````
120  http://fake.ucar.edu:9090/dts/test.01
121 ````
122 will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
123 
124 ### Programmatic Access to .rc File
125 
126 It is possible for client programs to query and modify the internal .rc database
127 through the following API.
128 * ````char* nc_rc_get(const char* key);````
129  Get the value corresponding to key or return NULL if not defined. The caller must free the resulting value.
130 * ````int nc_rc_set(const char* key, const char* value);````
131  Set/overwrite the value corresponding to the specified key.
132 
133 Note that this API does not (currently) support URL prefixed keys, so the client will need to take this into account.
134 
135 ### Defined .rc file keys
136 
137 There a a number of keys used by the netcdf-c library. Most of them
138 are authorization-related. The file "auth.md" describes these keys.
139 
140 Other keys are as follows:
141 * libdap4/d4curlfunctions.c and oc2/ocinternal.c
142  - HTTP.READ.BUFFERSIZE -- set the read buffer size for DAP2/4 connection
143  - HTTP.KEEPALIVE -- turn on keep-alive for DAP2/4 connection
144 * libdispatch/ds3util.c
145  - AWS.PROFILE -- alternate way to specify the default AWS profile
146  - AWS.REGION -- alternate way to specify the default AWS region
147 * libnczarr/zinternal.c
148  - ZARR.DIMENSION_SEPARATOR -- alternate way to specify the Zarr dimension separator character
149 * oc2/occurlfunctions.c
150  - HTTP.NETRC -- alternate way to specify the path of the .netrc file
151 
152 ## History {#nc_env_history}
153 
154 __Author__: Dennis Heimbigner<br>
155 __Email__: dmh at ucar dot edu<br>
156 __Initial Version__: 01/09/2023<br>
157 __Last Revised__: 07/30/2024