SPModel: plugins/fileOutput/FileOutput.c Source File
VPAC - Computational Software Development
Main | SPModel | StGermain FrameWork |
Main Page | Alphabetical List | Class List | Directories | File List | Class Members | File Members

FileOutput.c

Go to the documentation of this file.
00001 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00002 **
00003 ** Copyright (C), 2004, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
00004 **
00005 ** Authors:
00006 **  Ogar R. Widjaja, Computational Scientist, VPAC.
00007 **  Raquibul Hassan, Software Engineer, VPAC. (raq@vpac.org)
00008 **  Keith Hsuan, Computational Scientist, VPAC (keith@vpac.org)
00009 **  William F. Appelbe, Director, VPAC. (bill@vpac.org)
00010 **  Stevan M. Quenette, Senior Software Engineer, VPAC. (steve@vpac.org)
00011 **  Patrick D. Sunter, Software Engineer, VPAC. (patrick@vpac.org)
00012 **
00013 ** This file may be distributed under the terms of the VPAC Public License
00014 ** as defined by VPAC of Australia and appearing in the file
00015 ** LICENSE.VPL included in the packaging of this file.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 ** $Id: Erosion.c 225 2005-12-22 00:01:19Z AlanLo $
00021 **
00022 **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00023 
00024 
00025 #include <mpi.h>
00026 #include <StGermain/StGermain.h>
00027 #include "SPModel/SPModel.h"
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <assert.h>
00031 #include "FileOutput.h"
00032 
00033 /* Textual name of this module */
00034 const Type SPModelFileOutput_Type = "SPModelFileOutput";
00035 
00036 ExtensionInfo_Index SPModel_Simulation_ContextExtHandle;
00037 
00038 void* _SPModelFileOutput_DefaultNew( Name name ) {
00039     return Codelet_New(
00040             SPModelFileOutput_Type,
00041             _SPModelFileOutput_DefaultNew,
00042             _SPModelFileOutput_Construct,
00043             _Codelet_Build,
00044             _Codelet_Initialise,
00045             _Codelet_Execute,
00046             _Codelet_Destroy,
00047             name );
00048 }
00049 
00050 void _SPModelFileOutput_Construct( void* component, Stg_ComponentFactory* data ) {  
00051     SPModel_Context*                context;
00052     
00053     context = (SPModel_Context*)Stg_ComponentFactory_ConstructByName( data, "context", SPModel_Context, True );
00054     
00055     _SPModelFileOutput_Init( context );
00056     
00057     Journal_DPrintf( context->debug, "In %s():\n", __func__ );
00058     ContextEP_Append( context, AbstractContext_EP_Dump, SPModelSimulationContextExtension_Gather );
00059     ContextEP_Append( context, AbstractContext_EP_FrequentOutput, SPModelSimulationContextExtension_Gather );
00060     ContextEP_Append( context, AbstractContext_EP_Dump, SPModelFileOutput_Dump );
00061 }
00062 
00063 void _SPModelFileOutput_Init( void* _context ) {
00064     SPModel_Context *context = (SPModel_Context*)_context;
00065     
00066     assert( context );
00067     
00068     SPModel_Simulation_ContextExtHandle = ExtensionManager_GetHandle( context->extensionMgr, "Simulation" );
00069 }
00070 
00071 void SPModelFileOutput_Dump ( void *_context )
00072 {
00073     SPModel_Context *self = (SPModel_Context*)_context;
00074     SPModelSimulationContextExtension *simulationExt = NULL;
00075     SurfaceMesh *mesh = NULL;
00076     int i = 0;
00077 
00078     assert( self );
00079     mesh = self->localMesh;
00080     simulationExt = (SPModelSimulationContextExtension*)ExtensionManager_Get
00081                 ( self->extensionMgr, self, SPModel_Simulation_ContextExtHandle );
00082     assert( simulationExt );
00083     
00084     if( self->rank == MASTER_PROC ){
00085     
00086         if( self->ierosion ){
00087             char fileName[500] = {0};
00088             FILE *f = NULL;
00089 
00090             if( self->outputFormat == TEXT ){
00091                 memset( fileName, 0, sizeof(fileName) );
00092                 sprintf( fileName, "%s/erosion%d.txt", self->outputPath, (int)self->currentTime );
00093                 f = fopen( fileName, "w+" );
00094                 assert( f );
00095 
00096                 fprintf( f, "Erosion\n" );
00097                 fprintf( f, "Column Description\n" );
00098                 fprintf( f, "accumulatedErosion\n" );
00099                 for( i=0; i<mesh->numNodes; i++ ){
00100                     fprintf( f, "%lf\n", simulationExt->globalErosion[i] );
00101                 }
00102                 fclose( f );
00103             }
00104             else if( self->outputFormat == BINARY ){
00105                 memset( fileName, 0, sizeof(fileName) );
00106                 sprintf( fileName, "%s/erosion%d", self->outputPath, (int)self->currentTime );
00107                 f = fopen( fileName, "w+" );
00108                 assert( f );
00109 
00110                 for( i=0; i<mesh->numNodes; i++ ){
00111                     fwrite( &(simulationExt->globalErosion[i]), sizeof( float ), 1, f);
00112                 }
00113                 fclose( f );
00114             }
00115         }
00116     
00117         if( self->isedimentation ){
00118             char fileName[500] = {0};
00119             FILE *f = NULL;
00120     
00121             if( self->outputFormat == TEXT ){
00122                 memset( fileName, 0, sizeof(fileName) );
00123                 sprintf( fileName, "%s/sedimentation%d.txt", self->outputPath, (int)self->currentTime );
00124                 f = fopen( fileName, "w+" );
00125                 assert( f );
00126 
00127                 fprintf( f, "Sedimentation\n" );
00128                 fprintf( f, "Column Description\n" );
00129                 fprintf( f, "accumulatedSedimentation\n" );
00130                 for( i=0; i<mesh->numNodes; i++ ){
00131                     fprintf( f, "%lf\n", simulationExt->globalSedimentHistory[i] );
00132                 }
00133                 fclose( f );
00134             }
00135             else if( self->outputFormat == BINARY ){
00136                 memset( fileName, 0, sizeof(fileName) );
00137                 sprintf( fileName, "%s/erosion%d", self->outputPath, (int)self->currentTime );
00138                 f = fopen( fileName, "w+" );
00139                 assert( f );
00140     
00141                 for( i=0; i<mesh->numNodes; i++ ){
00142                     fwrite( &(simulationExt->globalSedimentHistory[i]), sizeof( float ), 1, f);
00143                 }
00144                 fclose( f );
00145             }
00146         }
00147         
00148         if( self->iwater ){
00149             char fileName[500] = {0};
00150             FILE *f = NULL;
00151 
00152             if( self->outputFormat == TEXT ){
00153                 memset( fileName, 0, sizeof(fileName) );
00154                 sprintf( fileName, "%s/water%d.txt", self->outputPath, (int)self->currentTime );
00155                 f = fopen( fileName, "w+" );
00156                 assert( f );
00157 
00158                 fprintf( f, "Water\n" );
00159                 fprintf( f, "Column Description\n" );
00160                 fprintf( f, "Flux\n" );
00161                 for( i=0; i<mesh->numNodes; i++ ){
00162                     fprintf( f, "%lf\n", simulationExt->globalWater[i] );
00163                 }
00164                 fclose( f );
00165             }
00166             else if( self->outputFormat == BINARY ){
00167                 memset( fileName, 0, sizeof(fileName) );
00168                 sprintf( fileName, "%s/water%d", self->outputPath, (int)self->currentTime );
00169                 f = fopen( fileName, "w+" );
00170                 assert( f );
00171 
00172                 for( i=0; i<mesh->numNodes; i++ ){
00173                     fwrite( &(simulationExt->globalWater[i]), sizeof( float ), 1, f);
00174                 }
00175                 fclose( f );
00176             }
00177         }
00178 
00179         if( self->iuplift ){
00180             char fileName[500] = {0};
00181             FILE *f = NULL;
00182 
00183             if( self->outputFormat == TEXT ){
00184                 memset( fileName, 0, sizeof(fileName) );
00185                 sprintf( fileName, "%s/uplift%d.txt", self->outputPath, (int)self->currentTime );
00186                 f = fopen( fileName, "w+" );
00187                 assert( f );
00188 
00189                 fprintf( f, "Uplift\n" );
00190                 fprintf( f, "Column Description\n" );
00191                 fprintf( f, "accumulatedUplift\n" );
00192                 for( i=0; i<mesh->numNodes; i++ ){
00193                     fprintf( f, "%lf\n", simulationExt->globalUplift[i] );
00194                 }
00195                 fclose( f );
00196             }
00197             else if( self->outputFormat == BINARY ){
00198                 memset( fileName, 0, sizeof(fileName) );
00199                 sprintf( fileName, "%s/uplift%d", self->outputPath, (int)self->currentTime );
00200                 f = fopen( fileName, "w+" );
00201                 assert( f );
00202 
00203                 for( i=0; i<mesh->numNodes; i++ ){
00204                     fwrite( &(simulationExt->globalUplift[i]), sizeof( float ), 1, f);
00205                 }   
00206                 fclose( f );
00207             }
00208         }
00209         
00210         if( self->iisostacy ){
00211             char fileName[500] = {0};
00212             FILE *f = NULL;
00213 
00214             if( self->outputFormat == TEXT ){
00215                 memset( fileName, 0, sizeof(fileName) );
00216                 sprintf( fileName, "%s/isostacy%d.txt", self->outputPath, (int)self->currentTime );
00217                 f = fopen( fileName, "w+" );
00218                 assert( f );
00219 
00220                 fprintf( f, "Isostacy\n" );
00221                 fprintf( f, "Column Description\n" );
00222                 fprintf( f, "accumulatedIsostacy\n" );
00223                 for( i=0; i<mesh->numNodes; i++ ){
00224                     fprintf( f, "%lf\n", simulationExt->hisotot[i] );
00225                 }
00226                 fclose( f );
00227             }
00228             else if( self->outputFormat == BINARY ){
00229                 memset( fileName, 0, sizeof(fileName) );
00230                 sprintf( fileName, "%s/isostacy%d", self->outputPath, (int)self->currentTime );
00231                 f = fopen( fileName, "w+" );
00232                 assert( f );
00233 
00234                 for( i=0; i<mesh->numNodes; i++ ){
00235                     fwrite( &(simulationExt->hisotot[i]), sizeof( float ), 1, f);
00236                 }
00237                 fclose( f );
00238             }
00239         }
00240     }
00241 }
00242 
00243 Index SPModelFileOutput_Register( PluginsManager* pluginsManager )
00244 {
00245     return PluginsManager_Submit( pluginsManager, SPModelFileOutput_Type, "0", _SPModelFileOutput_DefaultNew );
00246 }
00247