コード例 #1
0
void output_saveSubcatchResults(double reportTime, FILE* file)
//
//  Input:   reportTime = elapsed simulation time (millisec)
//           file = ptr. to binary output file
//  Output:  none
//  Purpose: writes computed subcatchment results to binary file.
//
{
    int      j;
    double   f;
    double   area;
    REAL4    totalArea = 0.0f; 
    DateTime reportDate = getDateTime(reportTime);

    // --- update reported rainfall at each rain gage
    for ( j=0; j<Nobjects[GAGE]; j++ )
    {
        gage_setReportRainfall(j, reportDate);
    }

    // --- find where current reporting time lies between latest runoff times
    f = (reportTime - OldRunoffTime) / (NewRunoffTime - OldRunoffTime);

    // --- write subcatchment results to file
    for ( j=0; j<Nobjects[SUBCATCH]; j++)
    {
        // --- retrieve interpolated results for reporting time & write to file
        subcatch_getResults(j, f, SubcatchResults);
        if ( Subcatch[j].rptFlag )                                             //(5.0.014 - LR)
            fwrite(SubcatchResults, sizeof(REAL4), NsubcatchResults, file);    //(5.0.014 - LR)

        // --- update system-wide results
        area = Subcatch[j].area * UCF(LANDAREA);
        totalArea += (REAL4)area;
        SysResults[SYS_RAINFALL] +=
            (REAL4)(SubcatchResults[SUBCATCH_RAINFALL] * area);
        SysResults[SYS_SNOWDEPTH] +=
            (REAL4)(SubcatchResults[SUBCATCH_SNOWDEPTH] * area);
        SysResults[SYS_LOSSES] +=
            (REAL4)(SubcatchResults[SUBCATCH_LOSSES] * area);
        SysResults[SYS_RUNOFF] += (REAL4)SubcatchResults[SUBCATCH_RUNOFF];
    }

    // --- normalize system-wide results to catchment area
    if ( UnitSystem == SI ) f = (5./9.) * (Temp.ta - 32.0);
    else f = Temp.ta;
    SysResults[SYS_TEMPERATURE] = (REAL4)f;
    SysResults[SYS_EVAPORATION] = (REAL4)(Evap.rate * UCF(EVAPRATE));
    SysResults[SYS_RAINFALL]  /= totalArea;
    SysResults[SYS_SNOWDEPTH] /= totalArea;
    SysResults[SYS_LOSSES]    /= totalArea;
}
コード例 #2
0
ファイル: runoff.c プロジェクト: Giswater/giswater_models
void  runoff_saveToFile(float tStep)
//
//  Input:   tStep = runoff time step (sec)
//  Output:  none
//  Purpose: saves current runoff results to Runoff Interface file.
//
{
    int j;
    int n = MAX_SUBCATCH_RESULTS + Nobjects[POLLUT] - 1;
    

    fwrite(&tStep, sizeof(float), 1, Frunoff.file);
    for (j=0; j<Nobjects[SUBCATCH]; j++)
    {
        subcatch_getResults(j, 1.0, SubcatchResults);
        fwrite(SubcatchResults, sizeof(float), n, Frunoff.file);
    }
}
コード例 #3
0
ファイル: output.c プロジェクト: HydroCouple/FVHMComponent
void output_saveSubcatchResults(Project* project, double reportTime, FILE* file)
//
//  Input:   reportTime = elapsed simulation time (millisec)
//           file = ptr. to binary output file
//  Output:  none
//  Purpose: writes computed subcatchment results to binary file.
//
{
    int      j;
    double   f;
    double   area;
    REAL4    totalArea = 0.0f; 
    DateTime reportDate = getDateTime(project,reportTime);

    // --- update reported rainfall at each rain gage
    for ( j=0; j<project->Nobjects[GAGE]; j++ )
    {
        gage_setReportRainfall(project,j, reportDate);
    }

    // --- find where current reporting time lies between latest runoff times
    f = (reportTime - project->OldRunoffTime) / (project->NewRunoffTime - project->OldRunoffTime);

    // --- write subcatchment results to file
    for ( j=0; j<project->Nobjects[SUBCATCH]; j++)
    {
        // --- retrieve interpolated results for reporting time & write to file
		subcatch_getResults(project, j, f, project->SubcatchResults);
        if ( project->Subcatch[j].rptFlag )
            fwrite(project->SubcatchResults, sizeof(REAL4), project->NsubcatchResults, file);

        // --- update system-wide results
        area = project->Subcatch[j].area * UCF(project,LANDAREA);
        totalArea += (REAL4)area;
        project->SysResults[SYS_RAINFALL] +=
            (REAL4)(project->SubcatchResults[SUBCATCH_RAINFALL] * area);
        project->SysResults[SYS_SNOWDEPTH] +=
            (REAL4)(project->SubcatchResults[SUBCATCH_SNOWDEPTH] * area);
        project->SysResults[SYS_EVAP] +=
            (REAL4)(project->SubcatchResults[SUBCATCH_EVAP] * area);
        if ( project->Subcatch[j].groundwater ) project->SysResults[SYS_EVAP] += 
            (REAL4)(project->Subcatch[j].groundwater->evapLoss * UCF(project,EVAPRATE) * area);
        project->SysResults[SYS_INFIL] +=
            (REAL4)(project->SubcatchResults[SUBCATCH_INFIL] * area);
        project->SysResults[SYS_RUNOFF] += (REAL4)project->SubcatchResults[SUBCATCH_RUNOFF];
    }

    // --- normalize system-wide results to catchment area
    if ( project->UnitSystem == SI ) f = (5./9.) * (project->Temp.ta - 32.0);
    else f = project->Temp.ta;
    project->SysResults[SYS_TEMPERATURE] = (REAL4)f;
    
    f = project->Evap.rate * UCF(project,EVAPRATE);                                             //(5.1.010)
    project->SysResults[SYS_PET] = (REAL4)f;                                            //(5.1.010)

    if ( totalArea > 0.0 )                                                     //(5.1.008)
    {
        project->SysResults[SYS_EVAP]      /= totalArea;
        project->SysResults[SYS_RAINFALL]  /= totalArea;
        project->SysResults[SYS_SNOWDEPTH] /= totalArea;
        project->SysResults[SYS_INFIL]     /= totalArea;
    }
}
コード例 #4
0
ファイル: output.c プロジェクト: Giswater/giswater_models
void output_saveSubcatchResults(double reportTime, FILE* file)
//
//  Input:   reportTime = elapsed simulation time (millisec)
//           file = ptr. to binary output file
//  Output:  none
//  Purpose: writes computed subcatchment results to binary file.
//
{
    int      j;
    double   f;
    double   area;
    REAL4    totalArea = 0.0f; 
    DateTime reportDate = getDateTime(reportTime);
	FILE *fptr;

	// --- dbf variables
	DBFHandle	hDBF;
	char		fieldName[128];
	int			n;
	double		f1,f0;
	double		value;
	int numFields;

    // --- update reported rainfall at each rain gage
    for ( j=0; j<Nobjects[GAGE]; j++ )
    {
        gage_setReportRainfall(j, reportDate);
    }

    // --- find where current reporting time lies between latest runoff times
    f = (reportTime - OldRunoffTime) / (NewRunoffTime - OldRunoffTime);
	f1 = 1.0 - f;
	f0 = f;

    // --- write subcatchment results to file
    for ( j=0; j<Nobjects[SUBCATCH]; j++)
    {
        // --- retrieve interpolated results for reporting time & write to file
        subcatch_getResults(j, f, SubcatchResults);
        if ( Subcatch[j].rptFlag )
            fwrite(SubcatchResults, sizeof(REAL4), NsubcatchResults, file);

        // --- update system-wide results
        area = Subcatch[j].area * UCF(LANDAREA);
        totalArea += (REAL4)area;
        SysResults[SYS_RAINFALL] +=
            (REAL4)(SubcatchResults[SUBCATCH_RAINFALL] * area);
        SysResults[SYS_SNOWDEPTH] +=
            (REAL4)(SubcatchResults[SUBCATCH_SNOWDEPTH] * area);
        SysResults[SYS_EVAP] +=
            (REAL4)(SubcatchResults[SUBCATCH_EVAP] * area);
        if ( Subcatch[j].groundwater ) SysResults[SYS_EVAP] += 
            (REAL4)(Subcatch[j].groundwater->evapLoss * UCF(EVAPRATE) * area);
        SysResults[SYS_INFIL] +=
            (REAL4)(SubcatchResults[SUBCATCH_INFIL] * area);
        SysResults[SYS_RUNOFF] += (REAL4)SubcatchResults[SUBCATCH_RUNOFF];
    }

    // --- normalize system-wide results to catchment area
    if ( UnitSystem == SI ) f = (5./9.) * (Temp.ta - 32.0);
    else f = Temp.ta;
    SysResults[SYS_TEMPERATURE] = (REAL4)f;
    SysResults[SYS_EVAP]      /= totalArea;
    SysResults[SYS_RAINFALL]  /= totalArea;
    SysResults[SYS_SNOWDEPTH] /= totalArea;
    SysResults[SYS_INFIL]     /= totalArea;

	// --- open DBF
	hDBF = DBFOpen(F2Dmesh.name, "r+b");
	if( hDBF == NULL )
	{
		//TODO
		//printf( "DBFOpen(%s,\"rb+\") failed.\n", argv[1] );
		//exit( 2 );
	}

	// --- create new field name
	n=sprintf (fieldName, "h_%07.0f", (reportTime / 1000.f));
	if( DBFAddField( hDBF, fieldName, FTDouble, 12, 6 ) == -1 )
    {
		//TODO
		//printf( "DBFAddField(%s,FTDouble,%d,%d) failed.\n", fieldName, 12, 3 );
		//exit( 4 );
    }

	n=sprintf (fieldName, "V_%07.0f", (reportTime / 1000.f));
	if( DBFAddField( hDBF, fieldName, FTDouble, 12, 6 ) == -1 )
    {
		//TODO
		//printf( "DBFAddField(%s,FTDouble,%d,%d) failed.\n", fieldName, 12, 3 );
		//exit( 4 );
    }

	// --- number of existing fields
	numFields = DBFGetFieldCount( hDBF );

    // --- write subcatchment results to file
    for ( j=0; j<Nobjects[SUBCATCH]; j++)
    {
		if (Subcatch[j].isStreet)
		{

			value = ( f1 * Subcatch[j].oldGlobalDepth + f0 * Subcatch[j].newGlobalDepth ) * UCF(LENGTH);

			//Write value
			DBFWriteDoubleAttribute(hDBF, Subcatch[j].dbf_record, numFields - 2, value );

			value = ( f1 * Subcatch[j].oldVel + f0 * Subcatch[j].newVel ) * UCF(LENGTH);

			//Write value
			DBFWriteDoubleAttribute(hDBF, Subcatch[j].dbf_record, numFields - 1, value );

		}
	}

	//CLose
	DBFClose( hDBF );

	// --- create file to print outflow
	fptr = fopen(F2Doutflow.name, "a+");

	if (fptr == NULL)
	{
		printf("ERROR: Impossible to create Outflow.txt\n");
	} else {
		fprintf(fptr, "%12.3f  %12.3f\n", (reportTime / 1000.f), M2DControl.totalOutflow);

		fclose(fptr);
	}


}