int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; /* Initialise MPI, get world info */ MPI_Init( &argc, &argv ); MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld ); MPI_Comm_size( CommWorld, &numProcessors ); MPI_Comm_rank( CommWorld, &rank ); BaseFoundation_Init( &argc, &argv ); BaseIO_Init( &argc, &argv ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } if( rank == procToWatch ) { XML_IO_Handler* io_handler = XML_IO_Handler_New(); Dictionary* dictionary = Dictionary_New(); Dictionary_Index index; Stream* stream = Journal_Register( InfoStream_Type, XML_IO_Handler_Type ); /* use the base class functions */ printf( "\ntest of raw data file:\n" ); IO_Handler_ReadAllFromFile( io_handler, "data/rawdata.xml", dictionary ); printf( "\ndictionary now contains:\n" ); printf( "Dictionary:\n" ); printf( "\tsize: %u\n", dictionary->size ); printf( "\tdelta: %u\n", dictionary->delta ); printf( "\tcount: %u\n", dictionary->count ); printf( "\tentryPtr[0-%u]: {\n", dictionary->count ); for( index = 0; index < dictionary->count; index++ ) { printf( "\t\t" ); Dictionary_Entry_Print( dictionary->entryPtr[index], stream ); printf( "\n" ); } printf( "\t}\n" ); /* Dictionary_Entry_Value_SetEncoding( Dictionary_Get( dictionary, "boundary_conditions2" ), RawASCII ); */ IO_Handler_WriteAllToFile( io_handler, "data/newrawdata.xml", dictionary ); Stg_Class_Delete( io_handler ); Stg_Class_Delete( dictionary ); } BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return EXIT_SUCCESS; }
int main( int argc, char* argv[] ) { Dictionary* dictionary=NULL; Dictionary* sources; XML_IO_Handler* ioHandler; Stream* msgs; char* outputFilename = DEFAULT_OUTPUT_FILE; int ii; MPI_Init( &argc, &argv ); if( !StGermainBase_Init( &argc, &argv ) ) { fprintf( stderr, "Error initialising StGermain, exiting.\n" ); exit( EXIT_FAILURE ); } msgs = Journal_Register( Info_Type, "Messages" ); for( ii = 0; ii < argc; ++ii ) { if( strstr( argv[ii], OUTPUT_FILE_FLAG ) == argv[ii] ) { outputFilename = argv[ii] + strlen( OUTPUT_FILE_FLAG ); if( strlen( outputFilename ) < 1 ) { Journal_Printf( msgs, "Invalid outputfile name: %s\n", outputFilename ); Journal_Printf( msgs, "Exiting...\n" ); StGermainBase_Finalise(); return 1; } argv[ii] = " "; /* remove it from the arg list */ } } dictionary = Dictionary_New(); sources = Dictionary_New(); /* Read input */ ioHandler = XML_IO_Handler_New(); IO_Handler_ReadAllFromCommandLine( ioHandler, argc, argv, dictionary, sources ); IO_Handler_WriteAllToFile( ioHandler, outputFilename, dictionary, sources ); Stg_Class_Delete( dictionary ); Stg_Class_Delete( sources ); Stg_Class_Delete( ioHandler ); StGermainBase_Finalise(); MPI_Finalize(); return 0; /* success */ }
void stgGenerateFlattenedXML( Dictionary* dictionary, Dictionary* sources, char* timeStamp ) { XML_IO_Handler* ioHandler; char* outputPath; char* flatFilename; char* flatFilenameStamped; char* slimFilename; Stream* s; Bool isEnabled; Bool ret; Bool outputSlim; s = Journal_Register( Info_Type, (Name)XML_IO_Handler_Type ); /* Avoid confusing messages from XML_IO_Handler. Turn it off temporarily. */ isEnabled = Stream_IsEnable( s ); Stream_EnableSelfOnly( s, False ); ioHandler = XML_IO_Handler_New(); if( sources == NULL ) ioHandler->writeSources = False; outputPath = StG_Strdup( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString( "./" ) ) ) ); outputSlim = Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputSlimmedXML", Dictionary_Entry_Value_FromBool( True ) ) ); if( ! Stg_DirectoryExists( outputPath ) ) { if( Stg_FileExists( outputPath ) ) Journal_Firewall( 0, s, "outputPath '%s' is a file an not a directory! Exiting...\n", outputPath ); Journal_Printf( s, "outputPath '%s' does not exist, attempting to create...\n", outputPath ); ret = Stg_CreateDirectory( outputPath ); Journal_Firewall( ret, s, "Unable to create non-existing outputPath to '%s'\n", outputPath ); Journal_Printf( s, "outputPath '%s' successfully created!\n", outputPath ); } /* Set file names. */ Stg_asprintf( &flatFilename, "%s/%s", outputPath, "input.xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilename, dictionary, sources ); /* Format; path/input-YYYY.MM.DD-HH.MM.SS.xml. */ if (timeStamp) { Stg_asprintf( &flatFilenameStamped, "%s/%s-%s.%s", outputPath, "input", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilenameStamped, dictionary, sources ); Memory_Free( flatFilenameStamped ); } if( outputSlim && timeStamp ) { ioHandler->writeSources = False; Stg_asprintf( &slimFilename, "%s/%s-%s.%s", outputPath, "input-basic", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, slimFilename, dictionary, NULL); } Stream_EnableSelfOnly( s, isEnabled ); Stg_Class_Delete( ioHandler ); Memory_Free( flatFilename ); }