00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <unistd.h>
00027 #include <stdlib.h>
00028 #include <fcntl.h>
00029 #include <time.h>
00030 #include <errno.h>
00031 #include <math.h>
00032
00033 #include "../type.h"
00034 #include "../graph.h"
00035
00036 #include "opt.h"
00037
00038 static int _clipper(dglGraph_s * pgraphIn,
00039 dglGraph_s * pgraphOut,
00040 dglSpanClipInput_s * pArgIn,
00041 dglSpanClipOutput_s * pArgOut,
00042 void * pvArg)
00043 {
00044 return 0;
00045 }
00046
00047 int main( int argc , char ** argv )
00048 {
00049 dglGraph_s graph;
00050 #define MY_MAX_COMPONENTS 1024
00051 dglGraph_s agraphComponents[MY_MAX_COMPONENTS];
00052 int nret , fd , i , cComponents;
00053 char szGraphOutFilename[1024];
00054
00055
00056
00057 char * pszGraph;
00058 char * pszGraphOut;
00059
00060 GNO_BEGIN
00061 GNO_OPTION( "g", "graph", NULL , & pszGraph , "Input Graph file" )
00062 GNO_OPTION( "o", "graphout", NULL , & pszGraphOut , "Output Graph file" )
00063 GNO_END
00064
00065
00066 if ( GNO_PARSE( argc , argv ) < 0 ) {
00067 return 1;
00068 }
00069
00070
00071
00072
00073 if ( pszGraph == NULL || pszGraphOut == NULL ) {
00074 GNO_HELP("components usage");
00075 return 1;
00076 }
00077
00078
00079 printf( "Graph read:\n" );
00080 if ( (fd = open( pszGraph , O_RDONLY )) < 0 ) {
00081 perror( "open" ); return 1;
00082 }
00083 nret = dglRead( & graph , fd );
00084 if ( nret < 0 ) {
00085 fprintf( stderr , "dglRead error: %s\n", dglStrerror( & graph ) );
00086 return 1;
00087 }
00088 close( fd );
00089 printf( "Done.\n" );
00090
00091
00092
00093 printf( "Graph depth components spanning:\n" );
00094 cComponents = dglDepthComponents( & graph , agraphComponents , MY_MAX_COMPONENTS , _clipper , NULL );
00095 if ( cComponents < 0 ) {
00096 fprintf( stderr , "dglDepthSpanning error: %s\n", dglStrerror( & graph ) );
00097 return 1;
00098 }
00099 printf( "Done.\n" );
00100
00101 printf( "Connected Component(s) Found: %d\n", cComponents );
00102
00103 for( i = 0 ; i < cComponents ; i ++ ) {
00104 printf( "Component %d of %d: ", i+1 , cComponents ); fflush(stdout);
00105
00106 printf( "[flatten..." ); fflush(stdout);
00107 nret = dglFlatten( & agraphComponents[i] );
00108 printf( "done] " ); fflush(stdout);
00109
00110 if ( dglGet_EdgeCount( & agraphComponents[i] ) > 0 ) {
00111 if ( pszGraphOut ) {
00112 snprintf( szGraphOutFilename, sizeof(szGraphOutFilename), "%s-component-%d", pszGraphOut, i );
00113 printf( "[write <%s>...", szGraphOutFilename ); fflush(stdout);
00114 if ( (fd = open( szGraphOutFilename , O_WRONLY | O_CREAT | O_TRUNC, 0666 )) < 0 ) {
00115 perror( "open" ); return 1;
00116 }
00117 dglWrite( & agraphComponents[i], fd );
00118 if ( nret < 0 ) {
00119 fprintf( stderr , "dglWrite error: %s\n" , dglStrerror( & graph ) );
00120 return 1;
00121 }
00122 close( fd );
00123 printf( "done] " ); fflush(stdout);
00124 }
00125 }
00126 else {
00127 printf( "component is empty. No output produced.\n" );
00128 }
00129
00130 printf( "[release..." );
00131 dglRelease( & agraphComponents[i] );
00132 printf( "done]\n" );
00133 }
00134
00135 dglRelease( & graph );
00136 return 0;
00137 }