IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 26, 2010, 3:19:05 PM (16 years ago)
Author:
Paul Price
Message:

Handling errors from closing files and dumping configuration as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSub.c

    r27088 r27109  
    6363
    6464 die:
    65     if (data && data->stats && data->statsFile) {
    66         psString stats = psMetadataConfigFormat(data->stats); // Statistics to output
    67         if (!stats || strlen(stats) == 0) {
    68             psError(PPSUB_ERR_IO, false, "Unable to format statistics file");
    69         } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) {
    70             psError(PPSUB_ERR_IO, true, "Unable to write statistics file");
     65    {
     66        psExit exitValue = ppSubExitCode(PS_EXIT_SUCCESS); // Exit code
     67
     68        if (data && data->stats && data->statsFile) {
     69            psString stats = psMetadataConfigFormat(data->stats); // Statistics to output
     70            if (!stats || strlen(stats) == 0) {
     71                psError(PPSUB_ERR_IO, false, "Unable to format statistics file");
     72            } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) {
     73                psError(PPSUB_ERR_IO, true, "Unable to write statistics file");
     74            }
     75            psFree(stats);
     76            if (fclose(data->statsFile) == EOF) {
     77                psError(PPSUB_ERR_IO, true, "Unable to close statistics file");
     78            }
     79            data->statsFile = NULL;
     80            pmConfigRunFilenameAddWrite(data->config, "STATS", data->statsName);
     81            exitValue = ppSubExitCode(exitValue);
    7182        }
    72         psFree(stats);
    73         if (fclose(data->statsFile) == EOF) {
    74             psError(PPSUB_ERR_IO, true, "Unable to close statistics file");
     83
     84        if (config && !ppSubFilesIterateUp(config, PPSUB_FILES_ALL)) {
     85            psError(psErrorCodeLast(), false, "Unable to close files.");
     86            exitValue = ppSubExitCode(exitValue);
    7587        }
    76         data->statsFile = NULL;
    77         pmConfigRunFilenameAddWrite(data->config, "STATS", data->statsName);
     88
     89        if (data) {
     90            psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
     91            if (dump_file) {
     92                if (!pmConfigDump(data->config, dump_file)) {
     93                    psError(PPSUB_ERR_IO, false, "Unable to dump configuration.");
     94                    exitValue = ppSubExitCode(exitValue);
     95                }
     96            }
     97            psFree(data);
     98        }
     99
     100        psTrace("ppSub", 1, "Finished at %f sec\n", psTimerMark("ppSub"));
     101        psTimerStop();
     102
     103        pmVisualClose(); //close plot windows, if -visual is set
     104        pmModelClassCleanup();
     105        pmConfigDone();
     106        psLibFinalize();
     107
     108        exitValue = ppSubExitCode(exitValue);
     109        exit(exitValue);
    78110    }
    79 
    80     psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
    81     psErrorCode errorCode = psErrorCodeLast(); // Error code
    82     if (errorCode != PS_ERR_NONE) {
    83         psErrorStackPrint(stderr, "Unable to perform subtraction.");
    84         switch (errorCode) {
    85           case PPSUB_ERR_UNKNOWN:
    86           case PS_ERR_UNKNOWN:
    87             exitValue = PS_EXIT_UNKNOWN_ERROR;
    88             break;
    89           case PS_ERR_IO:
    90           case PS_ERR_DB_CLIENT:
    91           case PS_ERR_DB_SERVER:
    92           case PS_ERR_BAD_FITS:
    93           case PS_ERR_OS_CALL_FAILED:
    94           case PPSUB_ERR_IO:
    95             exitValue = PS_EXIT_SYS_ERROR;
    96             break;
    97           case PS_ERR_BAD_PARAMETER_VALUE:
    98           case PS_ERR_BAD_PARAMETER_TYPE:
    99           case PS_ERR_BAD_PARAMETER_NULL:
    100           case PS_ERR_BAD_PARAMETER_SIZE:
    101           case PPSUB_ERR_ARGUMENTS:
    102           case PPSUB_ERR_CONFIG:
    103             exitValue = PS_EXIT_CONFIG_ERROR;
    104             break;
    105           case PPSUB_ERR_DATA:
    106           case PPSUB_ERR_NO_OVERLAP:
    107             exitValue = PS_EXIT_DATA_ERROR;
    108             break;
    109           case PS_ERR_UNEXPECTED_NULL:
    110           case PS_ERR_PROGRAMMING:
    111           case PPSUB_ERR_NOT_IMPLEMENTED:
    112           case PPSUB_ERR_PROG:
    113           default:
    114             // It's a programming error if we're not dealing with the error correctly
    115             exitValue = PS_EXIT_PROG_ERROR;
    116             break;
    117         }
    118     }
    119 
    120     if (config && !ppSubFilesIterateUp(config, PPSUB_FILES_ALL)) {
    121         psErrorStackPrint(stderr, "Unable to close files.");
    122     }
    123 
    124     if (data) {
    125         psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
    126         if (dump_file) {
    127             if (!pmConfigDump(data->config, dump_file)) {
    128                 psError(PPSUB_ERR_IO, false, "Unable to dump configuration.");
    129             }
    130         }
    131         psFree(data);
    132     }
    133 
    134     psTrace("ppSub", 1, "Finished at %f sec\n", psTimerMark("ppSub"));
    135     psTimerStop();
    136 
    137     pmVisualClose(); //close plot windows, if -visual is set
    138     pmModelClassCleanup();
    139     pmConfigDone();
    140     psLibFinalize();
    141 
    142     exit(exitValue);
    143111}
Note: See TracChangeset for help on using the changeset viewer.