SPModel: libSPModel/src/SurfaceMeshLoader.c Source File
VPAC - Computational Software Development
Main | SPModel | StGermain FrameWork |
Main Page | Alphabetical List | Class List | Directories | File List | Class Members | File Members

SurfaceMeshLoader.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 */
00031 #include <mpi.h>
00032 #include <StGermain/StGermain.h>
00033 #include <Cascade/cascade.h>
00034 
00035 
00036 #include "types.h"
00037 #include "SurfaceMesh.h"
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #include <assert.h>
00043 #include <math.h>
00044 #include "SurfaceMesh.h"
00045 #include "SurfaceMeshLoader.h"
00046 
00047 
00048 /* Textual name of this class */
00049 const Type SurfaceMeshLoader_Type = "SurfaceMeshLoader";
00050 
00051 const char* MESH_TYPE_AUTOGENERATED="autoGenerate";
00052 const char* MESH_TYPE_FROM_TEXT_INPUT="fromTextInput";
00053 const char* MESH_TYPE_FROM_ENVI_INPUT="fromEnviInput";
00054 const char* MESH_TYPE_FROM_SPM_INPUT="fromSPMInput";
00055 const char* MESH_TYPE_FROM_OUTPUT_FILES="fromOutputFiles";
00056 
00057 SurfaceMeshLoader *SurfaceMeshLoader_DefaultNew( Name name )
00058 {
00059     return _SurfaceMeshLoader_New( sizeof( SurfaceMeshLoader ),
00060                                 SurfaceMeshLoader_Type,
00061                                 _SurfaceMeshLoader_Delete,
00062                                 _SurfaceMeshLoader_Print,
00063                                 NULL,
00064                                 (void*)SurfaceMeshLoader_DefaultNew,
00065                                 _SurfaceMeshLoader_Construct,
00066                                 _SurfaceMeshLoader_Build,
00067                                 _SurfaceMeshLoader_Initialise,
00068                                 _SurfaceMeshLoader_Execute,
00069                                 _SurfaceMeshLoader_Destroy,
00070                                 name,
00071                                 False,
00072                                 NULL );
00073 
00074 }
00075 
00076 SurfaceMeshLoader *SurfaceMeshLoader_New( Name name, Dictionary *dictionary )
00077 {
00078     return _SurfaceMeshLoader_New( sizeof( SurfaceMeshLoader ),
00079                                 SurfaceMeshLoader_Type,
00080                                 _SurfaceMeshLoader_Delete,
00081                                 _SurfaceMeshLoader_Print,
00082                                 NULL,
00083                                 (void*)SurfaceMeshLoader_DefaultNew,
00084                                 _SurfaceMeshLoader_Construct,
00085                                 _SurfaceMeshLoader_Build,
00086                                 _SurfaceMeshLoader_Initialise,
00087                                 _SurfaceMeshLoader_Execute,
00088                                 _SurfaceMeshLoader_Destroy,
00089                                 name,
00090                                 True,
00091                                 dictionary );
00092 }
00093 
00094 SurfaceMeshLoader                   *_SurfaceMeshLoader_New( SizeT                          _sizeOfSelf,
00095                                     Type                            type,
00096                                     Stg_Class_DeleteFunction*               _delete,
00097                                     Stg_Class_PrintFunction*                _print,
00098                                     Stg_Class_CopyFunction*             _copy, 
00099                                     Stg_Component_DefaultConstructorFunction*   _defaultConstructor,
00100                                     Stg_Component_ConstructFunction*            _construct,
00101                                     Stg_Component_BuildFunction*        _build,
00102                                     Stg_Component_InitialiseFunction*       _initialise,
00103                                     Stg_Component_ExecuteFunction*      _execute,
00104                                     Stg_Component_DestroyFunction*      _destroy,
00105                                     Name                            name,
00106                                     Bool                            initFlag,
00107                                     Dictionary                      *dictionary )
00108 {
00109     SurfaceMeshLoader* self;
00110     
00111     /* Allocate memory */
00112     assert( _sizeOfSelf >= sizeof(SurfaceMeshLoader) );
00113     self = (SurfaceMeshLoader*)_Stg_Component_New( _sizeOfSelf, type, _delete, _print, _copy, _defaultConstructor, _construct, _build, 
00114             _initialise, _execute, _destroy, name, NON_GLOBAL );
00115 
00116     self->dictionary = dictionary;
00117     
00118     if( initFlag ){
00119         _SurfaceMeshLoader_Init( self );
00120     }
00121     
00122     return self;
00123 }
00124 
00125 void _SurfaceMeshLoader_Init( SurfaceMeshLoader *self )
00126 {
00127     Dictionary* meshDict = NULL;
00128     
00129     assert( self );
00130     meshDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( self->dictionary, "mesh" ) ); 
00131     
00132     if ( !meshDict ) {
00133         self->inputType = (char*)MESH_TYPE_AUTOGENERATED;
00134         meshDict = self->dictionary;
00135     }
00136     else {
00137         self->inputType = Dictionary_GetString_WithDefault( meshDict, "type", (char*)MESH_TYPE_AUTOGENERATED );
00138     }
00139     
00140     if ( 0 == strcmp( self->inputType, MESH_TYPE_AUTOGENERATED ) ) {
00141         self->nx = Dictionary_GetUnsignedInt_WithDefault( meshDict, "nx", 6); /* Number of nodes in x-direction */
00142         self->ny = Dictionary_GetUnsignedInt_WithDefault( meshDict, "ny", 6); /* Number of nodes in y-direction */
00143     }
00144     else if ( 0 == strcmp( self->inputType, MESH_TYPE_FROM_TEXT_INPUT ) ) {
00145         self->inputFile = Dictionary_GetString_WithDefault( meshDict, "inputFile",
00146             "inputFiles/input.dat" );
00147     }
00148     else if ( 0 == strcmp( self->inputType, MESH_TYPE_FROM_ENVI_INPUT ) ) {
00149 
00150     }
00151     else if ( 0 == strcmp( self->inputType, MESH_TYPE_FROM_SPM_INPUT ) ) {
00152         
00153         self->inputDirectory = Dictionary_GetString_WithDefault( meshDict, "inputDirectory",
00154             "input" );
00155     }
00156     else if( 0 == strcmp( self->inputType, MESH_TYPE_FROM_OUTPUT_FILES ) ){
00157         Dictionary *fileOutputDict = NULL;
00158         char *temp;
00159 
00160         fileOutputDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( self->dictionary, "fileOutput" ) );
00161 
00162         assert( fileOutputDict );
00163         
00164         self->inputDirectory = Dictionary_GetString_WithDefault( fileOutputDict, "outputDirectory",
00165             "meshDump" );
00166 
00167         temp = Dictionary_GetString_WithDefault( fileOutputDict, "outputFormat",
00168             "text" );
00169 
00170         if( strcmp( temp, "binary" ) == 0 ){
00171             fprintf( stderr, "Cannot load binary files..!\n" );
00172             exit( EXIT_FAILURE );
00173         }
00174         
00175         self->inputFile = Dictionary_GetString_WithDefault( meshDict, "inputFile",
00176             "meshDump/topography1.txt" );
00177     }
00178     else { 
00179         Journal_Printf( SPModel_Warning, "Error: unknown input type selected \"%s\": exiting.\n",
00180             self->inputType);
00181         MPI_Abort( MPI_COMM_WORLD, EXIT_FAILURE );
00182     }   
00183 }
00184 
00185 void _SurfaceMeshLoader_Print( void *surfaceMeshLoader, Stream *stream )
00186 {
00187     SurfaceMeshLoader *self = (SurfaceMeshLoader*) surfaceMeshLoader;
00188 
00189     assert( self );
00190     assert( stream );
00191 
00192     /* print parent */
00193     _Stg_Component_Print( (void*) self, stream );
00194 
00195     /* general info */
00196     Journal_Printf( stream, "SurfaceMeshLoader (ptr): (%p)\n", self );
00197 
00198     /* Virtual Info */
00199 
00200     /* SurfaceMeshLoader Info */
00201 
00202 }
00203 
00204 void _SurfaceMeshLoader_Delete( void *surfaceMeshLoader )
00205 {
00206     SurfaceMeshLoader *self = (SurfaceMeshLoader*) surfaceMeshLoader;
00207 
00208     assert( self );
00209 
00210     _Stg_Component_Delete( self );
00211 }
00212 
00213 void _SurfaceMeshLoader_Construct( void *surfaceMeshLoader, Stg_ComponentFactory *cf )
00214 {
00215     
00216 }
00217 
00218 void _SurfaceMeshLoader_Build( void *surfaceMeshLoader, void *data )
00219 {
00220     
00221 }
00222 
00223 void _SurfaceMeshLoader_Initialise( void *surfaceMeshLoader, void *data )
00224 {
00225     
00226 }
00227 
00228 void _SurfaceMeshLoader_Execute( void *surfaceMeshLoader, void *data )
00229 {
00230     
00231 }
00232 
00233 void _SurfaceMeshLoader_Destroy( void *surfaceMeshLoader, void *data )
00234 {
00235     
00236 }
00237 
00238 /* public functions */
00239 void SurfaceMeshLoader_LoadMesh( SurfaceMeshLoader *surfaceMeshLoader,  SurfaceMesh *mesh )
00240 {
00241     float surfmin;
00242     int i;
00243     FILE *fptr;     
00244     float xmin, xmax, ymin, ymax, snode; 
00245 
00246     assert( surfaceMeshLoader );
00247     assert( mesh );
00248     
00249     /* The input data could either be read from a file or generated by initialize_nodal_geometry() */
00250     if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_AUTOGENERATED ) ) {
00251         
00252         /* Call the Fortran function to generate the input data */
00253         initialize_nodal_geometry( &mesh->numNodes, &surfaceMeshLoader->nx, &surfaceMeshLoader->ny, &mesh->numNodes,
00254                 &mesh->sideX, &mesh->sideY, mesh->x, mesh->y, mesh->h, mesh->boundaryConditions, &mesh->delta, &mesh->iAdapt,
00255                 &mesh->surfScale );
00256 
00257         surfmin = mesh->surfScale/4;
00258         
00259         for (i=0; i<mesh->numNodes; i++) {
00260             mesh->id[i] = i+1;
00261         }
00262     }
00263     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_TEXT_INPUT ) ) {
00264 
00265         /* Read the input data from a text file, assuming the following input file format */
00266         if ( (fptr=fopen(surfaceMeshLoader->inputFile, "r")) == NULL ) {    
00267             printf ("Could not open input file - %s\n", surfaceMeshLoader->inputFile );
00268             exit(0);
00269         }
00270         printf("Numnodes %i \n", mesh->numNodes);
00271         for (i=0; i<mesh->numNodes; i++) { 
00272             fscanf( fptr, "%f %f %f %f", &mesh->x[i], &mesh->y[i], &mesh->h[i],
00273                     &mesh->boundaryConditions[i] );
00274     
00275             if (mesh->boundaryConditions[i] == 0){
00276                 mesh->boundaryConditions[i] = 1;
00277             }
00278             else{
00279                 mesh->boundaryConditions[i] = 0;
00280             }
00281 
00282             mesh->x[i]*=1.0f;
00283             mesh->y[i]*=1.0f;
00284 
00285             mesh->id[i] = i + 1;
00286         }
00287         
00288         xmin=mesh->x[0];
00289         xmax=mesh->x[0];
00290         ymin=mesh->y[0];
00291         ymax=mesh->y[0];
00292         
00293         for (i=1; i<mesh->numNodes; i++) {
00294             if (mesh->x[i] < xmin) xmin = mesh->x[i];
00295             if (mesh->x[i] > xmax) xmax = mesh->x[i];
00296             if (mesh->y[i] < ymin) ymin = mesh->y[i];
00297             if (mesh->y[i] > ymax) ymax = mesh->y[i];
00298         }
00299         
00300         mesh->sideX = xmax-xmin;
00301         mesh->sideY = ymax-ymin;
00302         snode = sqrt(mesh->numNodes);
00303         mesh->delta = (mesh->sideX/snode+mesh->sideY/snode)/2;
00304         mesh->surfScale = mesh->sideX*mesh->sideY/mesh->numNodes;
00305         surfmin = mesh->surfScale/4;
00306         fclose (fptr);
00307 
00308     }
00309     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_ENVI_INPUT ) ) {
00310     }
00311     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_SPM_INPUT ) ) {
00312         FILE *nodeCoordsFile = NULL;
00313         char nodeCoordsFileName[512];
00314         /*FILE *neighboursFile = NULL;
00315         char neighboursFileName[512];
00316         FILE *triangleFile = NULL;
00317         char triangleFileName[512];*/
00318         FILE *bcFile = NULL;
00319         char bcFileName[512];
00320         char buffer[1024];
00321         int nodeCount = 0;
00322         int temp;
00323         float dummy;
00324         /*int dummy1, dummy2, dummy3;
00325         float approxSides = 0;*/
00326 
00327 
00328         memset( nodeCoordsFileName, 0, sizeof( nodeCoordsFileName ) );
00329         sprintf( nodeCoordsFileName, "%s/%s", surfaceMeshLoader->inputDirectory, "particles.dat" );
00330         
00331         nodeCoordsFile = fopen( nodeCoordsFileName, "r" );
00332 
00333         if( nodeCoordsFile == NULL ){
00334             fprintf( stderr, "failed to open %s\n", nodeCoordsFileName );
00335             exit( 0 );
00336         }
00337 
00338         memset( buffer, 0, sizeof( buffer ) );
00339         fgets( buffer, 1024, nodeCoordsFile );
00340         if ( mesh->numNodes != atoi( buffer ) ){
00341             fprintf( stderr, "Number of nodes not equal to the value set in the XML file" );
00342             exit( 0 );
00343         }
00344 
00345         nodeCount = 0;
00346         while(  fgets( buffer, 1024, nodeCoordsFile ) != NULL ){
00347             sscanf( buffer, "%f%f%f%f", 
00348                     &mesh->x[nodeCount],
00349                     &mesh->y[nodeCount],
00350                     &mesh->h[nodeCount],
00351                     &mesh->surface[nodeCount] );
00352 
00353             mesh->id[nodeCount] = nodeCount + 1;
00354 
00355             nodeCount++;
00356         }
00357 #if 0
00358         memset( neighboursFileName, 0, sizeof( neighboursFileName ) );
00359         sprintf( neighboursFileName, "%s/%s", mesh->inputDirectory, "neighbour.dat" );
00360         
00361         neighboursFile = fopen( neighboursFileName, "r" );
00362 
00363         if( neighboursFile == NULL ){
00364             fprintf( stderr, "failed to open %s\n", neighboursFileName );
00365             exit( 0 );
00366         }
00367         
00368         nodeCount = 0;
00369         while( nodeCount < mesh->numNodes ){
00370             
00371             fscanf( neighboursFile, "%d", &temp );
00372             mesh->numNeigh[nodeCount] = temp;
00373             
00374             mesh->globalNodes[nodeCount].neighbourList = malloc( sizeof( int ) * temp );
00375             memset( mesh->globalNodes[nodeCount].neighbourList, 0, sizeof( int ) * temp );
00376             
00377             mesh->globalNodes[nodeCount].sides = malloc( sizeof( float ) * temp );
00378             memset( mesh->globalNodes[nodeCount].sides, 0, sizeof( float ) * temp );
00379 
00380             approxSides = 2 * sqrt(PI * mesh->globalNodes[nodeCount].surface)/temp;
00381 
00382             for( i=0; i<temp; i++ ){
00383                 if( fscanf( neighboursFile, "%d%f", &mesh->globalNodes[nodeCount].neighbourList[i], 
00384                 &dummy ) < 0 ){
00385                     break;
00386                 }
00387                 mesh->globalNodes[nodeCount].sides[i] = approxSides;
00388             }
00389 
00390             
00391             nodeCount++;
00392         }
00393         
00394         memset( triangleFileName, 0, sizeof( triangleFileName ) );
00395         sprintf( triangleFileName, "%s/%s", mesh->inputDirectory, "topology.dat" );
00396         
00397         triangleFile = fopen( triangleFileName, "r" );
00398 
00399         if( triangleFile == NULL ){
00400             fprintf( stderr, "failed to open %s\n", triangleFileName );
00401             exit( 0 );
00402         }
00403 
00404         memset( buffer, 0, sizeof(buffer) );
00405         fgets( buffer, sizeof(buffer), triangleFile );
00406         mesh->elementGlobalCount = atoi( buffer );
00407 
00408         mesh->vertices = (int**)malloc( sizeof( int* ) * mesh->elementGlobalCount );
00409 
00410         mesh->vertices[0] = (int*) malloc( 3 * sizeof( int ) * mesh->elementGlobalCount );
00411 
00412         for( i=0; i<mesh->elementGlobalCount; i++ ){
00413             mesh->vertices[i] = mesh->vertices[0] + i * 3;
00414         }
00415 
00416         i = 0;
00417         while( fgets( buffer, sizeof( buffer ), triangleFile ) != NULL ){
00418             sscanf( buffer, "%d%d%d%d%d%d", &mesh->vertices[i][0],
00419                             &mesh->vertices[i][1],
00420                             &mesh->vertices[i][2],
00421                             &dummy1, 
00422                             &dummy2, 
00423                             &dummy3 );
00424             memset( buffer, 0, sizeof( buffer ) );
00425             i++;
00426         }
00427 #endif
00428         
00429         memset( bcFileName, 0, sizeof( bcFileName ) );
00430         sprintf( bcFileName, "%s/%s", surfaceMeshLoader->inputDirectory, "bc.dat" );
00431         
00432         bcFile = fopen( bcFileName, "r" );
00433 
00434         if( bcFile == NULL ){
00435             fprintf( stderr, "failed to open %s\n", bcFileName );
00436             exit( 0 );
00437         }
00438         
00439         fgets( buffer, sizeof( buffer ), bcFile );
00440         
00441         for( i=0; i<mesh->numNodes; i++ ){
00442             mesh->boundaryConditions[i] = 1.0f;
00443         }
00444         
00445         while( fgets( buffer, sizeof( buffer ), bcFile ) != NULL ){
00446 
00447             sscanf( buffer, "%d%f", &temp, &dummy );
00448             
00449             mesh->boundaryConditions[temp-1] = dummy;
00450             
00451             memset( buffer, 0, sizeof( buffer ) );
00452         }
00453 
00454         fclose( nodeCoordsFile );
00455         /*fclose( neighboursFile );
00456         fclose( triangleFile );*/
00457         fclose( bcFile );
00458         
00459         xmin=mesh->x[0];
00460         xmax=mesh->x[0];
00461         ymin=mesh->y[0];
00462         ymax=mesh->y[0];
00463         for (i=1; i<mesh->numNodes; i++) {
00464             if (mesh->x[i] < xmin) xmin = mesh->x[i];
00465             if (mesh->x[i] > xmax) xmax = mesh->x[i];
00466             if (mesh->y[i] < ymin) ymin = mesh->y[i];
00467             if (mesh->y[i] > ymax) ymax = mesh->y[i];
00468         }
00469         mesh->sideX = xmax-xmin;
00470         mesh->sideY = ymax-ymin;
00471         snode = sqrt(mesh->numNodes);
00472         mesh->delta = (mesh->sideX/snode+mesh->sideY/snode)/2;
00473         mesh->surfScale = mesh->sideX*mesh->sideY/mesh->numNodes;
00474         surfmin = mesh->surfScale/4;
00475         
00476     }
00477     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_OUTPUT_FILES ) ) {
00478         char buffer[512];
00479         
00480         /* Read the input data from a text file, assuming the following input file format */
00481         if ( (fptr=fopen(surfaceMeshLoader->inputFile, "r")) == NULL ) {    
00482             printf ("Could not open input file - %s\n", surfaceMeshLoader->inputFile );
00483             exit(0);
00484         }
00485 
00486         printf("Numnodes %i \n", mesh->numNodes);
00487 
00488         for( i=0; i<3; i++ ){
00489             fgets( buffer, sizeof(buffer), fptr );
00490         }
00491         
00492         for (i=0; i<mesh->numNodes; i++) { 
00493             fscanf( fptr, "%f %f %f %f", &mesh->x[i], &mesh->y[i], &mesh->h[i],
00494                     &mesh->boundaryConditions[i] );
00495     
00496             if (mesh->boundaryConditions[i] == 0){
00497                 mesh->boundaryConditions[i] = 1;
00498             }
00499             else{
00500                 mesh->boundaryConditions[i] = 0;
00501             }
00502 
00503             mesh->x[i]*=1.0f;
00504             mesh->y[i]*=1.0f;
00505 
00506             mesh->id[i] = i + 1;
00507         }
00508         
00509         xmin=mesh->x[0];
00510         xmax=mesh->x[0];
00511         ymin=mesh->y[0];
00512         ymax=mesh->y[0];
00513         
00514         for (i=1; i<mesh->numNodes; i++) {
00515             if (mesh->x[i] < xmin) xmin = mesh->x[i];
00516             if (mesh->x[i] > xmax) xmax = mesh->x[i];
00517             if (mesh->y[i] < ymin) ymin = mesh->y[i];
00518             if (mesh->y[i] > ymax) ymax = mesh->y[i];
00519         }
00520         
00521         mesh->sideX = xmax-xmin;
00522         mesh->sideY = ymax-ymin;
00523         snode = sqrt(mesh->numNodes);
00524         mesh->delta = (mesh->sideX/snode+mesh->sideY/snode)/2;
00525         mesh->surfScale = mesh->sideX*mesh->sideY/mesh->numNodes;
00526         surfmin = mesh->surfScale/4;
00527         fclose (fptr);
00528     }
00529 }
00530 
00531 void SurfaceMeshLoader_ScanMesh( SurfaceMeshLoader *surfaceMeshLoader,  SurfaceMesh *mesh )
00532 {
00533     float surfmin;
00534     int i;
00535     FILE *fptr;     
00536     float xmin, xmax, ymin, ymax, snode; 
00537     float x, y, h, temp;
00538 
00539     assert( surfaceMeshLoader );
00540     assert( mesh );
00541     
00542     /* The input data could either be read from a file or generated by initialize_nodal_geometry() */
00543     if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_AUTOGENERATED ) ) {
00544         
00545     }
00546     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_TEXT_INPUT ) || 
00547                 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_OUTPUT_FILES ) ) {
00548 
00549         /* Read the input data from a text file, assuming the following input file format */
00550         if ( (fptr=fopen(surfaceMeshLoader->inputFile, "r")) == NULL ) {    
00551             printf ("Could not open input file - %s\n", surfaceMeshLoader->inputFile );
00552             exit(0);
00553         }
00554         
00555         xmin = 1e32;
00556         xmax = -1e32;
00557         ymin = 1e32;
00558         ymax = -1e32;
00559 
00560         if( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_OUTPUT_FILES ) ){
00561             char buffer[512];
00562             for( i=0; i<3; i++ ){
00563                 fgets( buffer, sizeof( buffer ), fptr );
00564             }
00565         }
00566         
00567         for (i=0; i<mesh->numNodes; i++) { 
00568             fscanf( fptr, "%f %f %f %f", &x, &y, &h, &temp );
00569             
00570             if ( x < xmin) xmin = x;
00571             if ( x > xmax) xmax = x;
00572             if ( y < ymin) ymin = y;
00573             if ( y > ymax) ymax = y;
00574         }
00575         
00576         mesh->sideX = xmax-xmin;
00577         mesh->sideY = ymax-ymin;
00578         snode = sqrt(mesh->numNodes);
00579         mesh->delta = (mesh->sideX/snode+mesh->sideY/snode)/2;
00580         mesh->surfScale = mesh->sideX*mesh->sideY/mesh->numNodes;
00581         surfmin = mesh->surfScale/4;
00582         fclose (fptr);
00583 
00584     }
00585     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_ENVI_INPUT ) ) {
00586     }
00587     else if ( 0 == strcmp( surfaceMeshLoader->inputType, MESH_TYPE_FROM_SPM_INPUT ) ) {
00588         FILE *nodeCoordsFile = NULL;
00589         char nodeCoordsFileName[512];
00590         char buffer[1024];
00591 
00592 
00593         memset( nodeCoordsFileName, 0, sizeof( nodeCoordsFileName ) );
00594         sprintf( nodeCoordsFileName, "%s/%s", surfaceMeshLoader->inputDirectory, "particles.dat" );
00595         
00596         nodeCoordsFile = fopen( nodeCoordsFileName, "r" );
00597 
00598         if( nodeCoordsFile == NULL ){
00599             fprintf( stderr, "failed to open %s\n", nodeCoordsFileName );
00600             exit( 0 );
00601         }
00602 
00603         memset( buffer, 0, sizeof( buffer ) );
00604         fgets( buffer, 1024, nodeCoordsFile );
00605         if ( mesh->numNodes != atoi( buffer ) ){
00606             fprintf( stderr, "Number of nodes not equal to the value set in the XML file" );
00607             exit( 0 );
00608         }
00609 
00610         xmin = 1e32;
00611         xmax = -1e32;
00612         ymin = 1e32;
00613         ymax = -1e32;
00614         while(  fgets( buffer, 1024, nodeCoordsFile ) != NULL ){
00615             sscanf( buffer, "%f%f%f%f", 
00616                     &x,
00617                     &y,
00618                     &h,
00619                     &temp );
00620             
00621             if ( x < xmin) xmin = x;
00622             if ( x > xmax) xmax = x;
00623             if ( y < ymin) ymin = y;
00624             if ( y > ymax) ymax = y;
00625         }
00626         
00627         mesh->sideX = xmax-xmin;
00628         mesh->sideY = ymax-ymin;
00629         snode = sqrt(mesh->numNodes);
00630         mesh->delta = (mesh->sideX/snode+mesh->sideY/snode)/2;
00631         mesh->surfScale = mesh->sideX*mesh->sideY/mesh->numNodes;
00632         surfmin = mesh->surfScale/4;
00633         
00634         fclose( nodeCoordsFile );
00635     }
00636 }
00637