diff options
author | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2001-04-23 22:48:39 +0000 |
---|---|---|
committer | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2001-04-23 22:48:39 +0000 |
commit | 744608582b87ea33f1c726e30cc1d6ee98c08b32 (patch) | |
tree | 0fe7e54bdc6394c7ba5bc0d08eb7ccf3828b0d31 | |
parent | 52f7d1f0f9a0d91167fa9b0e8a5a8eb6f056a69b (diff) |
Files from "IO::recover_ID_files" list are now searched in "IO::recovery_dir".
This closes PR CactusBase-622.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@116 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r-- | src/CheckpointRecovery.c | 487 |
1 files changed, 283 insertions, 204 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c index 7c048d2..f1df055 100644 --- a/src/CheckpointRecovery.c +++ b/src/CheckpointRecovery.c @@ -1,44 +1,66 @@ - /*@@ +/*@@ @file CheckpointRecovery.c @date Jun 04 1999 @author Thomas Radke - @desc - Utility routines for checkpointing/recovery and the filereader - The actual work is done by the IO thorns. + @desc + Utility routines for checkpointing/recovery and the filereader + The actual work is done by the IO thorns. + @enddesc + @version $Id$ @@*/ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - #include "cctk.h" #include "cctk_Parameters.h" #include "StoreHandledData.h" + #include "ioGH.h" #include "ioutil_CheckpointRecovery.h" -/* check for scandir(3) which is used to evaluate IO::recover = "auto" */ -#ifdef HAVE_SCANDIR +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#ifdef HAVE_SCANDIR #include <ctype.h> #include <dirent.h> +#endif -/* prefix and extension of potential recovery files */ -static char *recoverFilePrefix; -static const char *recoverFileExtension; +static char *rcsid = "$Header$"; +CCTK_FILEVERSION(CactusBase_IOUtil_CheckpointRecovery_c) -/* prototypes of the select and sort routine used by scandir(3) */ -static int IOUtil_RecoverFileSelect (struct dirent *entry); -static int IOUtil_RecoverFileCompare (struct dirent **a, struct dirent **b); -#endif /* HAVE_SCANDIR */ +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +void IOUtil_RecoverGH (cGH *GH); +void IOUtil_RecoverIDFromDatafiles (cGH *GH); -static void SetInputFlag (int vindex, const char *optstring, void *arg); +/******************************************************************** + ******************** Static Variables ************************* + ********************************************************************/ /* Local data holding info on Recover Functions */ static cHandledData *RecoverFunctions = NULL; static int num_functions = 0; +#ifdef HAVE_SCANDIR +/* prefix and extension of potential recovery files */ +static char *recoverFilePrefix; +static const char *recoverFileExtension; +#endif + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static void SetInputFlag (int vindex, const char *optstring, void *arg); + +#ifdef HAVE_SCANDIR +/* prototypes of the select and sort routine used by scandir(3) */ +static int IOUtil_RecoverFileSelect (struct dirent *entry); +static int IOUtil_RecoverFileCompare (struct dirent **a, struct dirent **b); +#endif + /************************************************************************ * @@ -50,81 +72,81 @@ static int num_functions = 0; @routine IOUtil_RegisterRecover @date Monday 21 June 1999 @author Gabrielle Allen - @desc + @desc Registers a new recovery method - @enddesc + @enddesc @calls Util_GetHandle Util_NewHandle - @history - @endhistory - + @var name @vdesc The name of the function for recovery @vtype const char * @vio in - @vcomment - @endvar + @vcomment + @endvar @returntype int @returndesc - -2 = memory allocation failed - -1 = method with this name already registered - i>0 = handle for function + -1 method with this name already registered, or + return code of @seeroutine Util_NewHandle @endreturndesc - - @version $Header$ - @@*/ - -int IOUtil_RegisterRecover(const char *name, int (*func)(cGH *, const char *, int)) +int IOUtil_RegisterRecover (const char *name, + int (*func) (cGH *, const char *, int)) { - int handle; - /* Check that the method hasn't already been registered */ - handle = Util_GetHandle(RecoverFunctions, name, NULL); - if(handle < 0) + /* Check that the method hasn't already been registered */ + handle = Util_GetHandle (RecoverFunctions, name, NULL); + if (handle < 0) { - /* New function */ - - /* Get a handle for it. */ - handle = Util_NewHandle(&RecoverFunctions, name, func); + /* New function - get a handle for it. */ + handle = Util_NewHandle (&RecoverFunctions, name, func); /* Remember how many methods there are */ num_functions++; } else { - /* function already exists. */ handle = -1; } - - return handle; + + return (handle); } + /*@@ @routine IOUtil_PrepareFilename @date Fri Aug 21 14:54:38 1998 @author Gerd Lanfermann - @desc - This routine prepares the filenames for the checkpoint/recovery - and filereader files, paying attention to the different types: - * it returns the full filename (directory+filename) - - * it prepends "Ln_" level indicators to the filename - and "low_"/"med_" for convergence levels > 1 - - * for checkpoint files it prepends the iteration number as "it_%d" - - * for chunked files it prepends the file number as "file_%d" + @desc + This routine prepares the filenames for the checkpoint/recovery + and filereader files, paying attention to the different types: + + * it returns the full filename (directory+filename) + + * it prepends "Ln_" level indicators to the filename + and "low_"/"med_" for convergence levels > 1 + + * for cp files it prepends the iteration number as "it_%d" + + * for chunked files it prepends the file number as "file_%d" + @enddesc + @calls + @history + @hdate Nov 4 1998 @hauthor Gabrielle Allen + @hdesc A file_* in the name indicates it needs recombining + @hdate Apr 14 1999 @hauthor Thomas Radke + @hdesc Removed code for expanding "basedir" and "nameofparfile" + @hdate May 06 1999 @hauthor Thomas Radke + @hdesc Added parameter unchunked to be independent of + current chunking mode for recovery + @endhistory - @enddesc - @calls - @calledby FlexIO_DumpGH HDF5IO_DumpGH @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @var basename @@ -139,7 +161,7 @@ int IOUtil_RegisterRecover(const char *name, int (*func)(cGH *, const char *, in @endvar @var called_from @vdesc indicates the caller function: - * either Filereader (FILEREADER_DATA) + * either Filereader (FILEREADER_DATA) * or IOUtil_RecoverGH() (CP_RECOVER_DATA) @vtype int @vio in @@ -154,62 +176,67 @@ int IOUtil_RegisterRecover(const char *name, int (*func)(cGH *, const char *, in @vtype int @vio in @endvar - @history - @hdate Nov 4 1998 @hauthor Gabrielle Allen - @hdesc A file_* in the name indicates it needs recombining - @hdate Apr 14 1999 @hauthor Thomas Radke - @hdesc Removed code for expanding "basedir" and "nameofparfile" - @hdate May 06 1999 @hauthor Thomas Radke - @hdesc Added parameter unchunked to be independent of current chunking mode - for recovery - @endhistory - @@*/ - -void IOUtil_PrepareFilename (cGH *GH, const char *basename, char *fname, - int called_from, int file_ioproc, int file_unchunked) +void IOUtil_PrepareFilename (cGH *GH, + const char *basename, + char *fname, + int called_from, + int file_ioproc, + int file_unchunked) { DECLARE_CCTK_PARAMETERS + /* get the right parameters */ - switch (called_from) { - case CP_INITIAL_DATA: + switch (called_from) + { + case CP_INITIAL_DATA: sprintf (fname, "%s/%s", checkpoint_dir, checkpoint_ID_file); break; + case CP_EVOLUTION_DATA: sprintf (fname, "%s/%s", checkpoint_dir, checkpoint_file); break; + case CP_RECOVER_DATA: case CP_RECOVER_PARAMETERS: - sprintf (fname, "%s/%s", recovery_dir, basename ? basename:recover_file); - break; case FILEREADER_DATA: - strcpy (fname, basename); + sprintf (fname, "%s/%s", recovery_dir, basename ? basename:recover_file); break; default: - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unknown calling mode %d", called_from); + CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOUtil_PrepareFilename: Unknown calling mode %d", + called_from); break; } /* add refinement factor and convergence level (med/low) inbetween: */ /* FIXME Gab ... asymmetric levfac */ - if (GH) { + if (GH) + { if (GH->cctk_levfac[0] > 1) + { sprintf (fname, "%sL%d_", fname, GH->cctk_levfac[0]); + } if (GH->cctk_convlevel > 0) + { strcat (fname, GH->cctk_convlevel == 1 ? "med_" : "low_"); + } } /* If checkpoint filename, merge in the iteration number and for chunked files also the file number */ if (called_from == CP_INITIAL_DATA || called_from == CP_EVOLUTION_DATA) + { sprintf (fname, "%s.it_%d", fname, (int) GH->cctk_iteration); + } /* If not one unchunked file give a file number */ if (! file_unchunked) + { sprintf (fname, "%s.file_%d", fname, file_ioproc); + } } @@ -217,14 +244,17 @@ void IOUtil_PrepareFilename (cGH *GH, const char *basename, char *fname, @routine IOUtil_RecoverFromFile @date Jun 14 1999 @author Thomas Radke - @desc - Recover from a given file. - This routine loops through all XXX_RecoverGH routines - registered by IO thorns. - @enddesc + @desc + Recover from a given file. + This routine loops through all XXX_RecoverGH routines + registered by IO thorns. + @enddesc + @calls Util_GetHandledData + <registered RecoverGH routines> + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @var basename @@ -234,22 +264,20 @@ void IOUtil_PrepareFilename (cGH *GH, const char *basename, char *fname, @endvar @var called_from @vdesc indicates the caller function: - * either Filereader (FILEREADER_DATA) + * either Filereader (FILEREADER_DATA) * or IOUtil_RecoverGH() (CP_RECOVER_DATA) @vtype int @vio in @endvar - - @history - @endhistory - @@*/ +@@*/ static int IOUtil_RecoverFromFile (cGH *GH, const char *basename, int called_from) { int handle; int retval; - int (*recoverFn) (cGH *GH, const char *basename, int called_from); + int (*recoverFn) (cGH *, const char *, int); + retval = -1; @@ -262,14 +290,19 @@ static int IOUtil_RecoverFromFile (cGH *GH, { retval = recoverFn (GH, basename, called_from); if (retval >= 0) + { break; + } } } if (num_functions <= 0) - CCTK_WARN (1, "No recovery routines were registered"); + { + CCTK_WARN (1, "IOUtil_RecoverFromFile: No recovery routines " + "were registered"); + } - return retval; + return (retval); } @@ -277,31 +310,33 @@ static int IOUtil_RecoverFromFile (cGH *GH, @routine IOUtil_RecoverGH @date Jun 14 1999 @author Thomas Radke - @desc - The rfr-registered recovery routine. - Just calls IOUtil_RecoverFromFile() with called_from == CP_RECOVER_DATA. - @enddesc + @desc + The rfr-registered recovery routine. + Just calls IOUtil_RecoverFromFile() + with called_from == CP_RECOVER_DATA. + @enddesc + @calls IOUtil_RecoverFromFile + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar - @history - @endhistory - @@*/ +@@*/ void IOUtil_RecoverGH (cGH *GH) { ioGH *myGH; - myGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + myGH = (ioGH *) CCTK_GHExtension (GH, "IO"); myGH->recovered = IOUtil_RecoverFromFile (GH, NULL, CP_RECOVER_DATA) >= 0; /* stop if recovery failed */ if (! myGH->recovered) + { CCTK_WARN (0, "Failed to restart from recovery !"); - + } } @@ -309,17 +344,19 @@ void IOUtil_RecoverGH (cGH *GH) @routine IOUtil_RecoverVarsFromDatafiles @date Wed Apr 19 2000 @author Thomas Radke - @desc - IOUtil's function interface to recover variables from data files. - Any thorn can call this routine with a list of data filenames and - a list of variables to read in from these files. - - It just calls IOUtil_RecoverFromFile() with called_from == FILEREADER_DATA - for each data file from the given file list. - @enddesc + @desc + IOUtil's function interface to recover variables from data files. + Any thorn can call this routine with a list of datafile names + and a list of variables to read in from these files. <BR> + + It just calls IOUtil_RecoverFromFile() with + called_from == FILEREADER_DATA for each data file + from the given file list. + @enddesc + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @var in_files @@ -332,19 +369,17 @@ void IOUtil_RecoverGH (cGH *GH) @vtype const char * @vio in @endvar - @history - @endhistory - @@*/ +@@*/ void IOUtil_RecoverVarsFromDatafiles (cGH *GH, const char *in_files, const char *in_vars) { DECLARE_CCTK_PARAMETERS ioGH *myGH; - char *basename; + char *basename, *delim, delim_char; - myGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + myGH = (ioGH *) CCTK_GHExtension (GH, "IO"); if (CCTK_NumVars () > 0) { @@ -357,20 +392,44 @@ void IOUtil_RecoverVarsFromDatafiles (cGH *GH, myGH->do_inVars = NULL; } - /* Get the filename from the filename list */ - basename = strtok ((char *) in_files, " \t\n"); - while (basename != NULL) + /* duplicate the filename list and parse it */ + basename = strdup (in_files); + while (basename) { + /* skip leading spaces */ + while (isspace ((int) *basename)) + { + basename++; + } + if (! *basename) + { + break; + } + + /* find delimiter for current filename and cut there */ + for (delim = basename + 1; ! isspace ((int) *delim) && *delim; delim++); + delim_char = *delim; + *delim = 0; if (verbose) + { CCTK_VInfo (CCTK_THORNSTRING, "Reading variables from data file '%s'", basename); + } if (IOUtil_RecoverFromFile (GH, basename, FILEREADER_DATA) < 0) + { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to read variables from data file '%s'", basename); + } + + *delim = delim_char; + basename = delim; + } - basename = strtok (NULL, " \t\n"); + if (basename) + { + free (basename - strlen (in_files)); } if (myGH->do_inVars) @@ -378,7 +437,6 @@ void IOUtil_RecoverVarsFromDatafiles (cGH *GH, free (myGH->do_inVars); myGH->do_inVars = NULL; } - } @@ -386,26 +444,24 @@ void IOUtil_RecoverVarsFromDatafiles (cGH *GH, @routine IOUtil_RecoverIDFromDatafiles @date Wed Apr 19 2000 @author Thomas Radke - @desc - The rfr-registered initial data recovery routine. - Just calls IOUtil's generic routine IOUtil_RecoverVarsFromDatafiles() - with the recover_ID_XXX parameters. - @enddesc + @desc + The rfr-registered initial data recovery routine. + Just calls IOUtil's generic routine + IOUtil_RecoverVarsFromDatafiles() with the recover_ID_XXX + parameters. + @enddesc @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar - @history - @endhistory - @@*/ +@@*/ void IOUtil_RecoverIDFromDatafiles (cGH *GH) { DECLARE_CCTK_PARAMETERS - IOUtil_RecoverVarsFromDatafiles (GH, (const char *) recover_ID_files, - (const char *) recover_ID_vars); + IOUtil_RecoverVarsFromDatafiles (GH, recover_ID_files, recover_ID_vars); } @@ -413,12 +469,14 @@ void IOUtil_RecoverIDFromDatafiles (cGH *GH) @routine IOUtil_RecoverParameters @date Apr 22 2000 @author Thomas Radke - @desc - The generic parameter recovery routine. - It is called by the IO thorns' parameter recovery routines scheduled - at CCTK_RECOVER_PARAMETERS, and simply calls the given callback routine - with its arguments plus a recovery file name. - @enddesc + @desc + The generic parameter recovery routine. + It is called by the IO thorns' parameter recovery routines + scheduled at CCTK_RECOVER_PARAMETERS, and simply calls + the given callback routine with its arguments + plus a recovery file name. + @enddesc + @var recoverFn @vdesc callback function for recovery of parameters from a given recovery file @@ -436,9 +494,7 @@ void IOUtil_RecoverIDFromDatafiles (cGH *GH) @vtype const char * @vio in @endvar - @history - @endhistory - @@*/ +@@*/ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH, const char *basename, int called_from), @@ -468,25 +524,32 @@ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH, /* get the list of potential recovery files */ nRecoverFiles = scandir (recovery_dir, &recoverFileList, - IOUtil_RecoverFileSelect, IOUtil_RecoverFileCompare); + IOUtil_RecoverFileSelect, + IOUtil_RecoverFileCompare); if (nRecoverFiles <= 0) + { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No %s checkpoint files with basename '%s' found in " "recovery directory '%s'", fileType, recover_file, recovery_dir); + } /* loop over all recovery files found and call the callback routine skip all following files after the first successful recovery */ for (i = 0; i < nRecoverFiles; i++) { if (retval < 0) + { retval = (*recoverFn) (dummyGH, recoverFileList [i]->d_name, CP_RECOVER_PARAMETERS); + } free (recoverFileList [i]); } if (recoverFileList) + { free (recoverFileList); + } #else @@ -506,7 +569,6 @@ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH, } return (retval); - } @@ -514,23 +576,21 @@ int IOUtil_RecoverParameters (int (*recoverFn) (cGH *GH, @routine IOUtil_GetAllParameters @date Mon Apr 10 2000 @author Thomas Radke - @desc - Collect all parameters of active implementations into a single string - which can then be dumped as an attribute. - @enddesc + @desc + Collect all parameters of active implementations + into a single string which can then be dumped as an attribute. + @enddesc + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @returntype char * @returndesc the allocated string or NULL @endreturndesc - - @history - @endhistory - @@*/ +@@*/ char *IOUtil_GetAllParameters (cGH *GH) { int i, first; @@ -542,15 +602,19 @@ char *IOUtil_GetAllParameters (cGH *GH) char *parameters = NULL; + /* avoid compiler warning about unused parameter */ + GH = GH; + /* loop over all thorns */ for (i = CCTK_NumCompiledThorns () - 1; i >= 0; i--) { - thorn = CCTK_CompiledThorn (i); /* skip all inactive thorns */ if (! CCTK_IsThornActive (thorn)) + { continue; + } /* now walk through all parameters of given thorn */ first = 1; @@ -565,9 +629,12 @@ char *IOUtil_GetAllParameters (cGH *GH) { value = CCTK_ParameterValString (pdata->name, pdata->thorn); if (value == NULL) + { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't get value for parameter '%s'", param); - else { + } + else + { int addLen = strlen (param) + strlen (value) + 5; if (currentLen + addLen >= maxLen) @@ -576,8 +643,10 @@ char *IOUtil_GetAllParameters (cGH *GH) newBuffer = (char*) realloc(parameters, maxLen+=BUFFER_INCREMENT); if (! newBuffer) + { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to allocate buffer of %d bytes", maxLen); + } parameters = newBuffer; } @@ -601,19 +670,17 @@ char *IOUtil_GetAllParameters (cGH *GH) @routine IOUtil_SetAllParameters @date Mon Apr 10 2000 @author Thomas Radke - @desc - Parse the given string for parameters and call CCTK_SetParameter() - for each. - @enddesc + @desc + Parse the given string for parameters + and call CCTK_SetParameter() for each. + @enddesc + @var parameters @vdesc the parameter string @vtype char * @vio in @endvar - - @history - @endhistory - @@*/ +@@*/ void IOUtil_SetAllParameters (char *parameters) { DECLARE_CCTK_PARAMETERS @@ -622,52 +689,63 @@ void IOUtil_SetAllParameters (char *parameters) char *name, *thorn_impl; const char *thorn; + while (*parameters) { nextparam = parameters; while (*nextparam != '\n' && *nextparam) + { nextparam++; + } oldchar = *nextparam; *nextparam = 0; tmp = parameters; while (*tmp != ' ') + { tmp++; + } *tmp = 0; param = parameters; avalue = tmp + 3; - name = thorn_impl = NULL; - if (Util_SplitString (þ_impl, &name, param, "::") == 0) - { - - /* find out the implementing thorn of the parameter given */ - thorn = CCTK_IsImplementationActive (thorn_impl) ? - CCTK_ImplementationThorn (thorn_impl) : thorn_impl; + name = thorn_impl = NULL; + if (Util_SplitString (þ_impl, &name, param, "::") == 0) + { + /* find out the implementing thorn of the parameter given */ + thorn = CCTK_IsImplementationActive (thorn_impl) ? + CCTK_ImplementationThorn (thorn_impl) : thorn_impl; - /* set parameter only if it belongs to an active implementation */ - if (CCTK_IsThornActive (thorn)) - { - if (CCTK_ParameterSet (name, thorn, avalue) < 0) - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't set parameter '%s' to '%s'", param, avalue); - } - else if (verbose) - { + /* set parameter only if it belongs to an active implementation */ + if (CCTK_IsThornActive (thorn)) + { + if (CCTK_ParameterSet (name, thorn, avalue) < 0) CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Ignoring inactive parameter '%s' for recovery", param); - } - if (name) - free (name); - if (thorn_impl) - free (thorn_impl); + "Couldn't set parameter '%s' to '%s'", param, avalue); + } + else if (verbose) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Ignoring inactive parameter '%s' for recovery", param); } + if (name) + { + free (name); + } + if (thorn_impl) + { + free (thorn_impl); + } + } + *nextparam = oldchar; parameters = nextparam; if (*parameters == '\n') + { parameters++; + } } } @@ -711,23 +789,35 @@ static int IOUtil_RecoverFileSelect (struct dirent *entry) /* At first check for recoverFilePrefix in the beginning of the filename */ if (strncmp (entry->d_name, recoverFilePrefix, prefixLen)) + { return (0); + } /* Now check if there is an iteration number following the file prefix. */ for (p = (char *) entry->d_name + prefixLen; *p && *p != '.'; p++) - if (! isdigit (*p)) + { + if (! isdigit ((int) *p)) + { return (0); + } + } /* Check for a '.file_<processor>' suffix for chunked output. We only select the chunked output file of processor 0 in that case. */ if (p - entry->d_name < len) + { if (! strncmp (p, ".file_", 6) && strncmp (p, ".file_0", 7)) + { return (0); + } + } /* Finally check the suffix */ extLen = strlen (recoverFileExtension); if (len < extLen || strcmp (entry->d_name+len-extLen, recoverFileExtension)) + { return (0); + } /* Cut the file name after the iteration number field because we only need the basename later on. */ @@ -741,36 +831,25 @@ static int IOUtil_RecoverFileSelect (struct dirent *entry) files by their iteration number (see IOUtil_RecoverParameters()) */ static int IOUtil_RecoverFileCompare (struct dirent **a, struct dirent **b) { - int it_a, it_b; int len = strlen (recoverFilePrefix); - /* extract the iteration numbers */ - it_a = atoi ((*a)->d_name + len); - it_b = atoi ((*b)->d_name + len); - /* note that this causes the file list to be sorted in descendent order */ - if (it_a > it_b) - return (-1); - if (it_a < it_b) - return (+1); - return (0); + return (atoi ((*b)->d_name + len) - atoi ((*a)->d_name + len)); } #endif /* HAVE_SCANDIR */ /* callback for CCTK_TraverseString() to set the input flag for the given variable */ -static void SetInputFlag (int vindex, const char *optstring, void *arg) +static void SetInputFlag (int vindex, const char *optstring, void *flags) { - char *flags = (char *) arg; - - - flags[vindex] = 1; + ((char *) flags)[vindex] = 1; if (optstring) { CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Optional string '%s' in variable name ignored", optstring); + "SetInputFlag: Optional string '%s' in variable name ignored", + optstring); } } |