aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-03-05 10:45:38 +0000
committertradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-03-05 10:45:38 +0000
commit6117ad9cc8057bdaa08240348e305e8bb58df1c8 (patch)
tree95c3638b2bd7bec4d5b0679bab93a4f99548c6df
parent158f087573b84e501cc55ec313a8d60191faa468 (diff)
IOUtil_GetAllParameters() takes another argument now to indicate whether to
save all parameters or just the ones which have been set before. This change fixes a bug that occured during recovery when you actually could change non-steerable parameters. Please also update the I/O thorns in AlphaThorns/IOHDF5, BetaThorns/IOHDf5Util, and CactusPUGHIO now. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@152 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r--src/CheckpointRecovery.c47
-rw-r--r--src/ioutil_CheckpointRecovery.h2
2 files changed, 26 insertions, 23 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c
index d35e551..7904d73 100644
--- a/src/CheckpointRecovery.c
+++ b/src/CheckpointRecovery.c
@@ -691,25 +691,33 @@ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH,
@vtype const cGH *
@vio in
@endvar
+ @var all
+ @vdesc flag indicating whether to save all parameters or just the ones
+ which have been set before
+ @vtype int
+ @vio in
+ @endvar
@returntype char *
@returndesc the allocated string or NULL
@endreturndesc
@@*/
-char *IOUtil_GetAllParameters (const cGH *GH)
+char *IOUtil_GetAllParameters (const cGH *GH, int all)
{
- int i, first;
- char *param;
+ int i, first, add_len, current_len, max_len;
+ char *param, *value, *tmp, *retval;
const char *thorn;
const cParamData *pdata;
#define BUFFER_INCREMENT 1024
- int currentLen = 0, maxLen = 0;
- char *parameters = NULL;
+ DECLARE_CCTK_PARAMETERS
/* avoid compiler warning about unused parameter */
GH = GH;
+ retval = NULL;
+ current_len = max_len = 0;
+
/* loop over all thorns */
for (i = CCTK_NumCompiledThorns () - 1; i >= 0; i--)
{
@@ -725,12 +733,10 @@ char *IOUtil_GetAllParameters (const cGH *GH)
first = 1;
while (CCTK_ParameterWalk (first, thorn, &param, &pdata) == 0)
{
- char *value;
-
first = 0;
- /* skip the parameters which weren't explicitely set */
- if (pdata->n_set > 0)
+ /* if 'all' is false get only parameters which have been set */
+ if (all || pdata->n_set > 0)
{
value = CCTK_ParameterValString (pdata->name, pdata->thorn);
if (value == NULL)
@@ -740,23 +746,20 @@ char *IOUtil_GetAllParameters (const cGH *GH)
}
else
{
- int addLen = strlen (param) + strlen (value) + 5;
-
- if (currentLen + addLen >= maxLen)
+ add_len = strlen (param) + strlen (value) + 5;
+ if (current_len + add_len >= max_len)
{
- char *newBuffer;
-
- newBuffer = (char*) realloc(parameters, maxLen+=BUFFER_INCREMENT);
- if (! newBuffer)
+ tmp = (char *) realloc (retval, max_len += BUFFER_INCREMENT);
+ if (! tmp)
{
CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Failed to allocate buffer of %d bytes", maxLen);
+ "Failed to allocate buffer of %d bytes", max_len);
}
-
- parameters = newBuffer;
+ retval = tmp;
}
- sprintf (parameters + currentLen, "%s = %s\n", param, value);
- currentLen += addLen - 1;
+
+ sprintf (retval + current_len, "%s = %s\n", param, value);
+ current_len += add_len - 1;
free (value);
}
@@ -767,7 +770,7 @@ char *IOUtil_GetAllParameters (const cGH *GH)
} /* end of loop walking over all parameters of given thorn */
} /* end of looping over all thorns */
- return (parameters);
+ return (retval);
}
diff --git a/src/ioutil_CheckpointRecovery.h b/src/ioutil_CheckpointRecovery.h
index 8f9cde5..3944b2a 100644
--- a/src/ioutil_CheckpointRecovery.h
+++ b/src/ioutil_CheckpointRecovery.h
@@ -55,7 +55,7 @@ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH,
const char *fileType);
/* return the parameter database as one single string */
-char *IOUtil_GetAllParameters (const cGH *GH);
+char *IOUtil_GetAllParameters (const cGH *GH, int all);
/* set all parameters contained in the given string */
void IOUtil_SetAllParameters (const char *parameters);