-
Notifications
You must be signed in to change notification settings - Fork 1
/
hdsTune.c
262 lines (224 loc) · 9.28 KB
/
hdsTune.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include "ems.h" /* EMS error reporting routines */
#include "hds1.h" /* Global definitions for HDS */
#include "rec.h" /* Public rec_ definitions */
#include "rec1.h" /* Private rec_ definitions */
#include "str.h" /* Character string import/export macros */
#include "dat1.h" /* Internal dat_ definitions */
#include "dat_err.h" /* DAT__ error code definitions */
#include "hds.h"
int
hdsTune(const char *param_str,
int value,
int *status)
{
/*
*+
* Name:
* HDS_TUNE
* Purpose:
* Set tuning parameter value.
* Language:
* ANSI C
* Description:
* The routine sets a new value for an HDS tuning parameter.
* Arguments:
* PARAM = CHARACTER * ( * ) (Given)
* Name of the tuning parameter whose value is to be set (case
* insensitive).
* VALUE = INTEGER (Given)
* New value for the parameter.
* STATUS = INTEGER (Given and Returned)
* The global status.
* Notes:
* Tuning parameter names may be abbreviated, to no less than four
* characters.
* Copyright:
* Copyright (C) 1992 Science & Engineering Research Council
* Copyright (C) 2005 Particle Physics & Astronomy Research Council.
* All Rights Reserved.
* Authors:
* RFWS: R.F. Warren-Smith (STARLINK, RAL)
* BKM: B.K. McIlwrath (STARLINK, RAL)
* TIMJ: Tim Jenness (JAC, Hawaii)
* {enter_new_authors_here}
* History:
* 26-FEB-1992 (RFWS):
* Re-written.
* 10-SEP-1992 (RFWS):
* Added special values -1, -2 and -3 for the MAP tuning
* parameter.
* 30-NOV-1992 (RFWS):
* Added support for the SHELL tuning parameter.
* 27-NOV-2000 (BKM):
* Changing file mapping mode on Linux found to be causing data
* corruption due to file system caching. Make this routine flush
* all buffers on a change.
* 06-DEC-2001 (BKM)
* Convert to a C function with FORTRAN wrapper.
* 06-MAY-2004 (BKM)
* Add 64BIT tuning parameter.
* 04-DEC-2005 (TIMJ):
* No reason for input arg to be a pointer.
* {enter_further_changes_here}
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA
* Bugs:
* {note_any_bugs_here}
*-
*/
/* Local variables: */
char name[ DAT__SZNAM + 1 ]; /* Upper case version of parameter name */
struct DSC param; /* Parameter name descriptor */
int i; /* Loop counter */
/*. */
/* Check the inherited global status. */
if ( !_ok( *status ) ) return *status;
hds_gl_status = *status;
/* Import the tuning parameter name. */
_strcsimp( ¶m, param_str );
/* Convert the name to upper case, and perform initial validation. */
dau_check_name( ¶m, name );
/* Ensure that the default tuning parameter values have been initialised. */
dat1_intune( &hds_gl_status );
/* Test for each valid tuning parameter name in turn and assign the new */
/* value, applying appropriate constraints (note that these constraints */
/* should match those imposed by dat1_intune). Where a parameter has a */
/* "one-shot" value, then assign the new value to it (i.e. modify */
/* hds_gl_inalq, rather than hds_gl_inalq0). */
if ( _ok( hds_gl_status ) )
{
/* Initial file allocation quantity: constrain this to be at least 2 */
/* blocks. */
if ( strncmp( name, "INAL", 4 ) == 0 )
{
hds_gl_inalq = value;
if ( hds_gl_inalq < 2 ) hds_gl_inalq = 2;
}
/* Use file mapping if available? */
else if ( strncmp( name, "MAP", 3 ) == 0 )
{
/* Flush all open files if mapping is changed */
if ( value != hds_gl_map )
for( i=0; i<rec_gl_endslot; i++ )
if( rec_ga_fcv[i].open )
if ( rec_ga_fcv[i].write != REC__NOIOCHAN )
fflush(rec_ga_fcv[i].write);
switch ( value )
{
/* If -1 was specified, set file mapping if it is the best mode for */
/* sequential file access. */
case -1:
hds_gl_map = HDS__MAPSEQ;
break;
/* If -2 was specified, set file mapping if it is the best mode for sparse */
/* file access. */
case -2:
hds_gl_map = HDS__MAPSPARSE;
break;
/* If -3 was specified, set file mapping if it is the best mode for */
/* minimising memory usage. */
case -3:
hds_gl_map = HDS__MAPMEM;
break;
/* Convert all other non-zero values to 1. */
default:
hds_gl_map = ( value != 0 );
break;
}
/* Turn mapping off if it is not implemented. */
hds_gl_map = ( hds_gl_map && HDS__CANMAP );
}
/* Maximum size of the "working page list": constrain this to be at least */
/* the default value (HDS__MAXWPL). */
else if ( strncmp( name, "MAXW", 4 ) == 0 )
{
hds_gl_maxwpl = value;
if ( hds_gl_maxwpl < HDS__MAXWPL ) hds_gl_maxwpl = HDS__MAXWPL;
}
/* Size of the internal "transfer buffer": constrain this to be at least */
/* the default value (HDS__NBLOCKS). */
else if ( strncmp( name, "NBLO", 4 ) == 0 )
{
hds_gl_nblocks = value;
if ( hds_gl_nblocks < HDS__NBLOCKS ) hds_gl_nblocks = HDS__NBLOCKS;
}
/* Optimum number of structure components: constrain this to be at least */
/* one. */
else if ( strncmp( name, "NCOM", 4 ) == 0 )
{
hds_gl_ncomp = value;
if ( hds_gl_ncomp < 1 ) hds_gl_ncomp = 1;
}
/* Shell used for file name expansion (UNIX & POSIX systems only): if the */
/* supplied value lies outside the supported range, then use the default */
/* shell. */
else if ( strncmp( name, "SHEL", 4 ) == 0 )
{
hds_gl_shell = value;
if ( ( hds_gl_shell < HDS__NOSHELL ) ||
( hds_gl_shell > HDS__MXSHELL ) )
{
hds_gl_shell = HDS__SHELL;
}
}
/* System wide lock flag: zero implies no system wide locking, everything */
/* else implies system wide locking. */
else if ( strncmp( name, "SYSL", 4 ) == 0 )
{
hds_gl_syslck = value;
hds_gl_syslck = ( hds_gl_syslck != 0 );
}
/* Wait for locked files? Zero implies don't wait, everything else implies */
/* wait. */
else if ( strncmp( name, "WAIT", 4 ) == 0 )
{
hds_gl_wait = value;
hds_gl_wait = ( hds_gl_wait != 0 );
}
/* Create 64-bit (HDS V4) files? Zero implies no (create HDS3 compatible */
/* files. anything else implies yes. */
else if ( strncmp( name, "64BIT", 5 ) == 0 )
{
hds_gl_c64bit = value;
hds_gl_c64bit = ( hds_gl_c64bit != 0 );
}
/* If the tuning parameter name was not recognised, then report an error. */
else
{
hds_gl_status = DAT__NAMIN;
emsSetnc( "PARAM", (char *) param.body, param.length );
emsRep( "HDS_TUNE_1",
"Unknown tuning parameter name \'^PARAM\' specified \
(possible programming error).",
&hds_gl_status );
}
}
/* If an error occurred, then report contextual information. */
if ( !_ok( hds_gl_status ) )
{
emsRep( "HDS_TUNE_ERR",
"HDS_TUNE: Error setting a new value for an HDS tuning \
parameter.",
&hds_gl_status );
}
/* Return the current global status value. */
*status = hds_gl_status;
return *status;
}