void Foam::heatFlux::end()
{
    if (active_)
    {
        calcAndPrint();
    }
}
Exemple #2
0
//----------------------------------------------------------------------------
//**** main ****
//----------------------------------------------------------------------------
int main( int argc, char* *argv )
{
    // check / get arguments
    //
    if ( argc < 3 )
        usage(argv[0]);
    if ( '-' == argv[1][0] )
        usage( argv[0] );

    CalData cd;

    char cfgFile[256];
    char etcCfgFile[256];
    char* pCfgFile = cfgFile;
    sprintf( cfgFile, "%s%s", argv[0], CFG_EXT );
    sprintf( etcCfgFile, "C:\\etc\\%s", cfgFile );

    ConfigFile cf( pCfgFile );
    if ( ConfigFile::OK != cf.status() ) {
        pCfgFile = etcCfgFile;
        // try etc
        if ( ConfigFile::OK != cf.filename( pCfgFile ) ) {
            fprintf( stderr,
                     "\nWarning: unable to find %s or %s:\n\n"
                     "- I'll try to create a 'template' file for you in the current directory.\n"
                     "- Edit this file to reflect your location.\n ", cfgFile, etcCfgFile );
            FILE* fp = fopen( cfgFile, "w" );
            if ( NULL != fp ) {
                fprintf( fp,
                         "# %s\n# Note: East and North are positive\n"
                         "# e.g., Philadelphia, PA, US is latitude -75.16, longitude 39.95,\n"
                         "#       and timeZone -5\n"
                         "longitude=0.0\nlatitude=0.0\ntimeZone=0\n\n"
                         "# Set this to true to ignore Daylight time:\n"
                         "ignoreDST=false\n\n"
                         "# Set this to true to use UTC (this overrides timeZone & DST)\n"
                         "useUTC=false\n\n"
                         "# Set this to true to output to an HTML file:\n"
                         "htmlOutput=false\n\n"
                         "# Set this to true to produce a text file with tab-delimited fields:\n"
                         "# (Note: html & tabs are mutually exclusive!)\n"
                         "tabDelimited=false\n", cfgFile );
                fclose( fp );
                exit(1);
            }
        }
    }
    printf( "Using %s.\n", pCfgFile );

    if ( cf.value( "longitude" ) )
        cd.loc.setLongitude( cf.dblValue( "longitude" ) );

    if ( cf.value( "latitude" ) )
        cd.loc.setLatitude( cf.dblValue( "latitude" ) );

    if ( cf.value( "timeZone" ) )
        cd.loc.setTimeZone( cf.intValue( "timeZone" ) );

    if ( cf.value( "htmlOutput" ) )
        g_html = cf.boolValue( "htmlOutput" );

    if ( cf.value( "ignoreDST" ) )
        g_ignoreDst = cf.boolValue( "ignoreDST" );

    if ( cf.value( "tabDelimited" ) )
        g_tabDelimited = cf.boolValue( "tabDelimited" );

    if ( cf.boolValue( "useUTC" ) ) {
        cd.loc.setTimeZone(0);
        g_ignoreDst = true;
    }

    cd.month = atoi( argv[1] );
    cd.year = atoi( argv[2] );
    if ( cd.month < 1 || cd.month > 12 || cd.year <= 0)
        usage(argv[0]);

    if ( argc > 3 ) {
        for (int i = 3; i < argc; i++ ) {
            if ( '-' != argv[i][0] )
                usage( argv[0] );
            else if ( 'd' == argv[i][1] )
                g_ignoreDst = true;
            else if ( 'h' == argv[i][1] )
                g_html = true;
            else if ( 't' == argv[i][1] )
                g_tabDelimited = true;
            else if ( 'u' == argv[i][1] ) {
                cd.loc.setTimeZone(0);
                g_ignoreDst = true;
            }
            else
                usage( argv[0] );
        }
    }

    if ( g_tabDelimited && g_html ) {
        fprintf( stderr, "Error: html and tabDelimited cannot both be specified.\n" );
        exit(-1);
    }

#if DEBUG
    if (g_tabDelimited)
        fprintf( stderr, "tab delimited\n");
    if (g_html)
        fprintf( stderr, "HTML output\n");
    if (g_ignoreDst) {
        if ( 0 == cd.loc.timeZone() )
            fprintf( stderr, "use UTC\n");
        else
            fprintf( stderr, "ignore DST\n");
    }
#endif
    if ( 0. == cd.loc.longitude() && 0. == cd.loc.latitude() )
        printf( "Latitude & Longitude are both set to 0. Is this what you intended?\n" );

    const char* pExt = 0;
    if (g_html)
        pExt = "html";
    else if (g_tabDelimited)
        pExt = "txt";

    if ( 0 != pExt ) {
        char filename[32];
        sprintf( filename, "%s%d.%s", monthNames[cd.month-1], cd.year, pExt );
        FILE* fp = fopen( filename, "w" );
        if ( NULL != fp ) {
            g_fp = fp;
            fprintf( stderr, "Writing output to %s\n", filename );
        }
    }

    calcAndPrint( cd );

    if ( stdout != g_fp )
        fclose( g_fp );

    return 0;
}