00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #ifdef WIN32
00043 # include <sys\stat.h>
00044 #else
00045 # include <sys/stat.h>
00046 #endif
00047
00048 #include "rio.h"
00049 #include "nfi.h"
00050 #include "sll.h"
00051
00052
00053
00054
00055 FILE *nf = 0L;
00056 FILE *pos = 0L;
00057 FILE *cfg = 0L;
00058 FILE *ndlr = 0L;
00059 FILE *elmr = 0L;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 typedef struct _tmptag
00071 {
00072 struct _tmptag *next;
00073 int id;
00074 long ndlrpos;
00075 long elmrpos;
00076 } sTmpFileTags;
00077
00078
00079
00080
00081
00082 static char arqnf[BUFSIZ];
00083 static char arqpos[BUFSIZ];
00084 static char arqdat[BUFSIZ];
00085 static char arqcfg[BUFSIZ];
00086 static char arqndlr[BUFSIZ];
00087 static char arqelmr[BUFSIZ];
00088
00089
00090
00091
00092
00093 static int _iNumFileTags = 0;
00094
00095
00096
00097
00098
00099 static sTmpFileTags *TmpFileTag = 0L;
00100
00101
00102
00103
00104
00105
00106 static void _IoInitScreen ( void );
00107 static int _IoCopyInputFile ( void );
00108 static void _IoRemoveTempFiles( void );
00109
00110
00111
00112
00113
00114 static void _IoInitScreen( void )
00115 {
00116
00117 printf( "\n\n\n\n\n\n\n\n" );
00118 #if 0
00119 printf( "\t====================================================\n\n" );
00120 printf( "\t PONTIFICIA UNIVERSIDADE CATOLICA DO RIO DE JANEIRO \n" );
00121 printf( "\t DEPARTMENT OF CIVIL ENGINEERING \n" );
00122 printf( "\t GEOTECHNICAL DIVISION \n" );
00123 printf( "\t R E L A X \n" );
00124 printf( "\t FINITE ELEMENT METHOD - Dynamic relaxation alg. \n\n" );
00125 printf( "\t Version: 2.9.94C - February/2001 \n" );
00126 printf( "\t Version: 3.0.00A - August/2005 \n" );
00127 printf( "\t====================================================\n\n" );
00128 #endif
00129 printf( "\tEnter the input file name [.nf|.dat]: " );
00130
00131 }
00132
00133
00134
00135
00136
00137 static int _IoCopyInputFile( void )
00138 {
00139 char s[BUFSIZ+1], *c;
00140
00141
00142
00143 rewind( nf );
00144
00145
00146
00147 c = fgets( s, BUFSIZ+1, nf );
00148 while( (strncmp( s, "%END", 4 ) != 0) && (c != 0L) )
00149 {
00150 fprintf( pos, "%s", s );
00151 c = fgets( s, BUFSIZ+1, nf );
00152 }
00153
00154 if( c == 0L )
00155 {
00156 printf( "\n\nNo END label was found in input file.\n\n" );
00157 return 0;
00158 }
00159
00160 rewind( nf );
00161
00162 return 1;
00163
00164 }
00165
00166
00167
00168
00169
00170 static void _IoRemoveTempFiles( void )
00171 {
00172 sTmpFileTags *item = 0L;
00173
00174
00175
00176 remove( arqndlr );
00177 remove( arqelmr );
00178
00179
00180
00181 while( TmpFileTag != 0L )
00182 {
00183 item = TmpFileTag;
00184 TmpFileTag = (sTmpFileTags *)RSllRmvTop( (RSll *)item );
00185 free( item );
00186 }
00187
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 int IoOpenFiles( int argc, char *argv[] )
00204 {
00205
00206
00207 _IoInitScreen( );
00208
00209
00210
00211 if( argc > 1 )
00212 {
00213 strcpy( arqnf, argv[argc-1] );
00214 printf( "%s\n\n\n", arqnf );
00215 }
00216 else
00217 {
00218 fscanf( stdin, "%s", arqnf );
00219 printf( "\n\n" );
00220 }
00221
00222
00223
00224 strcpy( arqpos, arqnf );
00225 strcpy( arqdat, arqnf );
00226 strcpy( arqndlr, arqnf );
00227 strcpy( arqelmr, arqnf );
00228
00229
00230
00231 strcat( arqnf, ".nf" );
00232 strcat( arqdat, ".dat" );
00233 strcat( arqpos, ".pos" );
00234 strcat( arqndlr, "_1.tmp" );
00235 strcat( arqelmr, "_2.tmp" );
00236
00237
00238
00239
00240 if( (nf = fopen( arqnf, "r" )) == 0L )
00241 {
00242 if( (nf = fopen( arqdat, "r" )) == 0L )
00243 {
00244 printf( "\n\n\tCould not open the given input file.\n\n" );
00245 return 0;
00246 }
00247 }
00248
00249
00250
00251 if( (pos = fopen( arqpos, "w" )) == 0L )
00252 {
00253 printf( "\n\n\tCould not open the given output file.\n\n" );
00254 return 0;
00255 }
00256
00257
00258
00259 if( !_IoCopyInputFile( ) ) return 0;
00260
00261 return 1;
00262
00263 }
00264
00265
00266
00267
00268
00269 void IoCloseFiles( void )
00270 {
00271
00272
00273 fclose( nf );
00274 fclose( pos );
00275
00276 }
00277
00278
00279
00280
00281
00282
00283
00284 int IoReadFile( void )
00285 {
00286
00287
00288 printf( "\tReading input file..................." );
00289 fflush( stdin );
00290
00291
00292
00293 NfiSetFileHandle( nf );
00294
00295
00296
00297 if ( !NfiInterpFile() ) return 0;
00298
00299
00300
00301
00302 if( !NfiCheckParameters() ) {
00303
00304
00305 struct stat statres;
00306 if( stat( "relax.cfg", &statres ) == -1 ) {
00307 char *apldir;
00308 if( (apldir = getenv( "TECTOSDIR" )) != 0L )
00309 #ifdef WIN32
00310 sprintf( arqcfg, "%s\\%s", apldir, "relax.cfg" );
00311 #else
00312 sprintf( arqcfg, "%s/%s", apldir, "relax.cfg" );
00313 #endif
00314 else
00315 strcpy( arqcfg, "relax.cfg" );
00316 }
00317 else {
00318 strcpy( arqcfg, "relax.cfg" );
00319 }
00320
00321
00322
00323 if( (cfg = fopen( arqcfg, "r" )) == 0L ) {
00324 printf( "\n\n\tCould not open the given config file.\n\n" );
00325 return 0;
00326 }
00327 NfiSetFileHandle( cfg );
00328 if( !NfiReadConfigFile() ) return 0;
00329
00330
00331
00332 fclose( cfg );
00333 }
00334
00335
00336
00337 printf( "\n\n\n" );
00338
00339 return 1;
00340
00341 }
00342
00343
00344
00345
00346
00347
00348
00349 int IoWriteFile( void )
00350 {
00351
00352
00353 NfiSetFileHandle( pos );
00354
00355
00356
00357
00358 if( !NfiWriteResults( ) ) return 0;
00359
00360
00361
00362 _IoRemoveTempFiles( );
00363
00364 return 1;
00365
00366 }
00367
00368
00369
00370
00371
00372 int IoStartSave( void )
00373 {
00374 sTmpFileTags *item = 0L;
00375
00376
00377
00378 item = (sTmpFileTags *)calloc(1, sizeof(sTmpFileTags));
00379
00380
00381
00382 item->id = _iNumFileTags++;
00383 item->ndlrpos = 0L;
00384 item->elmrpos = 0L;
00385 item->next = 0L;
00386
00387
00388
00389 if( (ndlr == 0L) && (elmr == 0L) )
00390 {
00391 ndlr = fopen( arqndlr, "w+b" );
00392 elmr = fopen( arqelmr, "w+b" );
00393 if( (ndlr == 0L) || (elmr == 0L) )
00394 {
00395 printf( "\n\n\tCould not open a temporary result file.\n\n" );
00396 return 0;
00397 }
00398 }
00399
00400
00401
00402 item->ndlrpos = ftell( ndlr );
00403 item->elmrpos = ftell( elmr );
00404
00405
00406
00407 TmpFileTag = (sTmpFileTags *)RSllAddEnd( (RSll *)TmpFileTag, (RSll *)item );
00408
00409 return 1;
00410
00411 }
00412
00413
00414
00415
00416
00417
00418 void IoEndSave( void )
00419 {
00420
00421
00422 if( ndlr != 0L )
00423 fclose( ndlr );
00424
00425 if( elmr != 0L )
00426 fclose( elmr );
00427
00428 }
00429
00430
00431
00432
00433
00434 int IoFindResultTag( int id, long *ndlrpos, long *elmrpos )
00435 {
00436 sTmpFileTags *item = 0L;
00437
00438
00439
00440 item = TmpFileTag;
00441 while( (item != 0L) && (item->id != id) )
00442 item = item->next;
00443
00444 if( item == 0L )
00445 {
00446 printf( "\n\n\tCould not find a result file tag.\n\n" );
00447 return 0;
00448 }
00449
00450
00451
00452 (*ndlrpos) = item->ndlrpos;
00453 (*elmrpos) = item->elmrpos;
00454
00455 fseek( ndlr, item->ndlrpos, SEEK_SET );
00456 fseek( elmr, item->elmrpos, SEEK_SET );
00457
00458 return 1;
00459
00460 }
00461
00462
00463
00464
00465
00466 void IoCloseTempFile( void )
00467 {
00468
00469
00470 IoEndSave( );
00471
00472 }
00473
00474
00475
00476
00477
00478 void IoReset( void )
00479 {
00480 _iNumFileTags = 0;
00481 TmpFileTag = 0L;
00482 nf = 0L;
00483 pos = 0L;
00484 cfg = 0L;
00485 ndlr = 0L;
00486 elmr = 0L;
00487
00488 }
00489
00490
00491
00492