コード例 #1
0
ファイル: outputAPI.c プロジェクト: OpenWaterAnalytics/pyswmm
int DLLEXPORT SMO_open(SMOutputAPI* smoapi, const char* path)
//
//  Purpose: Open the output binary file and read epilogue.
//
{
	int version, err, errorcode = 0;
	F_OFF offset;

	strncpy(smoapi->name, path, MAXFILENAME);

	// --- open the output file
	if ((smoapi->file = fopen(path, "rb")) == NULL) errorcode = 434;
    // --- validate the output file
	else if ((err = validateFile(smoapi)) != 0) errorcode = err;

	else {
		// --- otherwise read additional parameters from start of file
		fread(&version, RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->FlowUnits), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nsubcatch), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nnodes), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nlinks), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Npolluts), RECORDSIZE, 1, smoapi->file);

		// Skip over saved subcatch/node/link input values
		offset = (smoapi->Nsubcatch + 2) * RECORDSIZE  // Subcatchment area
			  + (3 * smoapi->Nnodes + 4) * RECORDSIZE  // Node type, invert & max depth
			  + (5 * smoapi->Nlinks + 6) * RECORDSIZE; // Link type, z1, z2, max depth & length
		offset += smoapi->ObjPropPos;

		fseeko64(smoapi->file, offset, SEEK_SET);

		// Read number & codes of computed variables
		fread(&(smoapi->SubcatchVars), RECORDSIZE, 1, smoapi->file); // # Subcatch variables
		fseeko64(smoapi->file, smoapi->SubcatchVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->NodeVars), RECORDSIZE, 1, smoapi->file);     // # Node variables
		fseeko64(smoapi->file, smoapi->NodeVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->LinkVars), RECORDSIZE, 1, smoapi->file);     // # Link variables
		fseeko64(smoapi->file, smoapi->LinkVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->SysVars), RECORDSIZE, 1, smoapi->file);     // # System variables

		// --- read data just before start of output results
		offset = smoapi->ResultsPos - 3 * RECORDSIZE;
		fseeko64(smoapi->file, offset, SEEK_SET);
		fread(&(smoapi->StartDate), DATESIZE, 1, smoapi->file);
		fread(&(smoapi->ReportStep), RECORDSIZE, 1, smoapi->file);

		// --- compute number of bytes of results values used per time period
		smoapi->BytesPerPeriod = DATESIZE +      // date value (a double)
			(smoapi->Nsubcatch*smoapi->SubcatchVars +
			smoapi->Nnodes*smoapi->NodeVars +
			smoapi->Nlinks*smoapi->LinkVars +
			smoapi->SysVars)*RECORDSIZE;
	}

	if (errorcode) SMO_close(smoapi);

	return errorcode;

}
コード例 #2
0
int testGetSubcatchResult(char* path)
{
	int error = 0;
	long length;
	float* array;

	SMOutputAPI* smoapi = SMO_init();
	error = SMO_open(smoapi, path);

	array = SMO_newOutValueArray(smoapi, getResult, subcatch, &length, &error);
	error = SMO_getSubcatchResult(smoapi, 1, 0, array);

	if (!error)
	{
		for (int i = 0; i < length; i++)
			printf("%f\n", array[i]);
	}
	printf("\n");

	SMO_free(array);
	error = SMO_close(smoapi);

	return error;
}