From cefc745efb3f96bac7c14a70c8f969da6238384a Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 3 Jun 2009 01:56:55 +0000 Subject: [PATCH] retoring damage to tools --- cmd/tools/Makefile.am | 31 ++- cmd/tools/Makefile.old | 14 - cmd/tools/matrix_market.c | 550 ++++++++++++++++++++------------------ cmd/tools/matrix_market.h | 25 +- cmd/tools/mmio.c | 528 ++++++++++++++++++------------------ cmd/tools/mmio.h | 48 ++-- 6 files changed, 622 insertions(+), 574 deletions(-) diff --git a/cmd/tools/Makefile.am b/cmd/tools/Makefile.am index 5ede926ae..8d42f8b5c 100644 --- a/cmd/tools/Makefile.am +++ b/cmd/tools/Makefile.am @@ -9,20 +9,22 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/pathplan \ -I$(top_srcdir)/lib/pack \ -I$(top_srcdir)/lib/neatogen \ - -I$(top_srcdir)/lib/sfdpgen \ + -I$(top_srcdir)/lib/sparse \ -I$(top_srcdir)/lib/gvc \ -I$(top_srcdir)/lib/common \ -I$(top_srcdir)/lib/ingraphs @EXPAT_INCLUDES@ pdfdir = $(pkgdatadir)/doc/pdf -noinst_HEADERS = colortbl.h convert.h -bin_PROGRAMS = gc gvcolor gxl2dot acyclic nop ccomps sccmap tred \ - unflatten gvpack dijkstra bcomps mm2gv -man_MANS = gc.1 gvcolor.1 gxl2dot.1 acyclic.1 nop.1 ccomps.1 sccmap.1 \ - tred.1 unflatten.1 gvpack.1 dijkstra.1 bcomps.1 -pdf_DATA = gc.pdf gvcolor.pdf gxl2dot.pdf acyclic.pdf nop.pdf ccomps.pdf \ - sccmap.pdf tred.pdf unflatten.pdf gvpack.pdf dijkstra.pdf bcomps.pdf +noinst_HEADERS = colortbl.h convert.h mmio.h matrix_market.h graph_generator.h +bin_PROGRAMS = gc gvcolor gxl2gv acyclic nop ccomps sccmap tred \ + unflatten gvpack dijkstra bcomps mm2gv gvgen +man_MANS = gc.1 gvcolor.1 gxl2gv.1 acyclic.1 nop.1 ccomps.1 sccmap.1 \ + tred.1 unflatten.1 gvpack.1 dijkstra.1 bcomps.1 mm2gv.1 gvgen.1 +pdf_DATA = gc.1.pdf gvcolor.1.pdf gxl2gv.1.pdf acyclic.1.pdf \ + nop.1.pdf ccomps.1.pdf sccmap.1.pdf tred.1.pdf \ + unflatten.1.pdf gvpack.1.pdf dijkstra.1.pdf \ + bcomps.1.pdf mm2gv.1.pdf gvgen.1.pdf install-data-hook: (cd $(DESTDIR)$(man1dir); rm -f gv2gxl.1; $(LN_S) gxl2gv.1 gv2gxl.1;) @@ -138,13 +140,18 @@ gvpack_LDADD = \ $(top_builddir)/lib/ingraphs/libingraphs_C.la \ $(top_builddir)/plugin/neato_layout/libgvplugin_neato_layout.la -mm2gv_SOURCES = mm2dot.c matrix_market.c mmio.c +gvpack.1.pdf: $(srcdir)/gvpack.1 + - @GROFF@ -Tps -man $(srcdir)/gvpack.1 | @PS2PDF@ - - >gvpack.1.pdf + +mm2gv_SOURCES = mm2gv.c matrix_market.c mmio.c mm2gv_LDADD = \ - $(top_builddir)/lib/gvc/libgvc.la \ - $(top_builddir)/lib/ingraphs/libingraphs_C.la \ - $(top_builddir)/plugin/neato_layout/libgvplugin_neato_layout.la + $(top_builddir)/lib/common/libcommon_C.la \ + $(top_builddir)/lib/sparse/libsparse_C.la \ + $(top_builddir)/lib/cgraph/libcgraph.la @MATH_LIBS@ +mm2gv.1.pdf: mm2gv.1 + - @GROFF@ -Tps -man mm2gv.1 | @PS2PDF@ - - >mm2gv.1.pdf dijkstra_SOURCES = dijkstra.c diff --git a/cmd/tools/Makefile.old b/cmd/tools/Makefile.old index 6745a3a38..f00a55857 100644 --- a/cmd/tools/Makefile.old +++ b/cmd/tools/Makefile.old @@ -68,24 +68,10 @@ CCOBJS = ccomps.o SCCOBJS = sccmap.o GXLOBJS = cvtgxl.o gv2gxl.o gxl2gv.o GVPOBJS = gvpack.o gvpack_builtins.o -MMGVOBJS = mm2dot.o matrix_market.o mmio.o - BCCOBJS = bcomps.o MANS = acyclic.1 gvcolor.1 nop.1 tred.1 ccomps.1 gc.1 sccmap.1 \ unflatten.1 gxl2gv.1 gv2gxl.1 gvpack.1 bcomps.1 -mm2gv : $(GVPOBJS) - $(CPP) $(LDFLAGS) $(MMGVOBJS) $(INGLIB) $(PDNLIBS) -o $@ - -mm2dot.o : mm2dot.c - $(CC) -c $(CCFLAGS) $(DEFINES) $(DNINCS) $(PINCS) mm2dot.c - -matrix_market.o : matrix_market.c - $(CC) -c $(CCFLAGS) $(DEFINES) $(DNINCS) $(PINCS) matrix_market.c - -mmio.o : mmio.c - $(CC) -c $(CCFLAGS) $(DEFINES) $(DNINCS) $(PINCS) mmio.c - gvpack : $(GVPOBJS) $(CPP) $(LDFLAGS) $(GVPOBJS) $(INGLIB) $(PDNLIBS) -o $@ diff --git a/cmd/tools/matrix_market.c b/cmd/tools/matrix_market.c index a8c956164..d96dc3804 100644 --- a/cmd/tools/matrix_market.c +++ b/cmd/tools/matrix_market.c @@ -1,304 +1,326 @@ +/* $Id$Revision: */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ #include "SparseMatrix.h" #include "mmio.h" #include "matrix_market.h" +#include "render.h" #define MALLOC gmalloc #define REALLOC grealloc #define FREE free #define MEMCPY memcpy -int mm_get_type(MM_typecode typecode){ - if (mm_is_complex(typecode)){ - return MATRIX_TYPE_COMPLEX; - } else if (mm_is_real(typecode)) { - return MATRIX_TYPE_REAL; - } else if (mm_is_integer(typecode)) { - return MATRIX_TYPE_INTEGER; - } else if (mm_is_pattern(typecode)){ - return MATRIX_TYPE_PATTERN; - } - return MATRIX_TYPE_UNKNOWN; +int mm_get_type(MM_typecode typecode) +{ + if (mm_is_complex(typecode)) { + return MATRIX_TYPE_COMPLEX; + } else if (mm_is_real(typecode)) { + return MATRIX_TYPE_REAL; + } else if (mm_is_integer(typecode)) { + return MATRIX_TYPE_INTEGER; + } else if (mm_is_pattern(typecode)) { + return MATRIX_TYPE_PATTERN; + } + return MATRIX_TYPE_UNKNOWN; } -static void set_mm_typecode(int type, MM_typecode *typecode){ - switch (type){ - case MATRIX_TYPE_COMPLEX: - mm_set_complex(typecode); - break; - case MATRIX_TYPE_REAL: - mm_set_real(typecode); - break; - case MATRIX_TYPE_INTEGER: - mm_set_integer(typecode); - break; - case MATRIX_TYPE_PATTERN: - mm_set_pattern(typecode); - break; - default: - break; - } +static void set_mm_typecode(int type, MM_typecode * typecode) +{ + switch (type) { + case MATRIX_TYPE_COMPLEX: + mm_set_complex(typecode); + break; + case MATRIX_TYPE_REAL: + mm_set_real(typecode); + break; + case MATRIX_TYPE_INTEGER: + mm_set_integer(typecode); + break; + case MATRIX_TYPE_PATTERN: + mm_set_pattern(typecode); + break; + default: + break; + } } -SparseMatrix SparseMatrix_import_matrix_market(FILE *f, int format){ - int ret_code, type; - MM_typecode matcode; - real *val = NULL, *v; - int *vali = NULL, i, m, n, *I = NULL, *J = NULL, nz; - void *vp = NULL; - SparseMatrix A = NULL; - int nzold; - int c; +SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) +{ + int ret_code, type; + MM_typecode matcode; + real *val = NULL, *v; + int *vali = NULL, i, m, n, *I = NULL, *J = NULL, nz; + void *vp = NULL; + SparseMatrix A = NULL; + int nzold; + int c; - if ((c=fgetc(f)) != '%'){ + if ((c = fgetc(f)) != '%') { + ungetc(c, f); + return NULL; + } ungetc(c, f); - return NULL; - } - ungetc(c, f); - if (mm_read_banner(f, &matcode) != 0) { + if (mm_read_banner(f, &matcode) != 0) { #ifdef DEBUG - printf("Could not process Matrix Market banner.\n"); + printf("Could not process Matrix Market banner.\n"); #endif - return NULL; - } - - - /* This is how one can screen matrix types if their application */ - /* only supports a subset of the Matrix Market data types. */ - - if (!mm_is_matrix(matcode) || - !mm_is_sparse(matcode) ){ - assert(0); - /* - printf("Sorry, this application does not support dense matrix"); - printf("Market Market type: [%s]\n", mm_typecode_to_str(matcode)); - */ - return NULL; - } - - /* find out size of sparse matrix .... */ - if ((ret_code = mm_read_mtx_crd_size(f, &m, &n, &nz)) !=0){ - assert(0); - return NULL; - } - /* reseve memory for matrices */ - - I = MALLOC(nz * sizeof(int)); - J = MALLOC(nz * sizeof(int)); - - + return NULL; + } - switch (format){ - case FORMAT_CSC: - assert(0);/* not supported yet */ - break; - case FORMAT_CSR: - case FORMAT_COORD: - /* NOTE: when reading in doubles, ANSI C requires the use of the "l" */ - /* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */ - /* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */ - type = mm_get_type(matcode); - switch (type) { - case MATRIX_TYPE_REAL: - val = (real *) malloc(nz * sizeof(real)); - for (i=0; itype, &matcode); + mm_initialize_typecode(&matcode); + mm_set_matrix(&matcode); + mm_set_sparse(&matcode); + mm_set_general(&matcode); + set_mm_typecode(A->type, &matcode); - mm_write_banner(file, matcode); - mm_write_comment(file, comment); + mm_write_banner(file, matcode); + mm_write_comment(file, comment); - SparseMatrix_export(file, A); + SparseMatrix_export(file, A); -} +} diff --git a/cmd/tools/matrix_market.h b/cmd/tools/matrix_market.h index 50b9f8297..6bfcd9f71 100644 --- a/cmd/tools/matrix_market.h +++ b/cmd/tools/matrix_market.h @@ -1,5 +1,26 @@ +/* $Id$Revision: */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ +#ifndef MATRIX_MARKET_H +#define MATRIX_MARKET_H + #include "mmio.h" #include "SparseMatrix.h" int mm_get_type(MM_typecode typecode); -void SparseMatrix_export_matrix_market(FILE *file, SparseMatrix A, char *comment); -SparseMatrix SparseMatrix_import_matrix_market(FILE *f, int format); +void SparseMatrix_export_matrix_market(FILE * file, SparseMatrix A, + char *comment); +SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format); + +#endif diff --git a/cmd/tools/mmio.c b/cmd/tools/mmio.c index 2e4cb8738..9a45bd01f 100644 --- a/cmd/tools/mmio.c +++ b/cmd/tools/mmio.c @@ -1,3 +1,18 @@ +/* $Id$Revision: */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ /* * Matrix Market I/O library for ANSI C * @@ -10,13 +25,12 @@ #include #include #include -/*#include */ #include #include "mmio.h" -int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, - double **val_, int **I_, int **J_) +int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, + int *nz_, double **val_, int **I_, int **J_) { FILE *f; MM_typecode matcode; @@ -24,170 +38,166 @@ int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, int i; double *val; int *I, *J; - + if ((f = fopen(fname, "r")) == NULL) - return -1; - - - if (mm_read_banner(f, &matcode) != 0) - { - fprintf(stderr, "mm_read_unsymetric: Could not process Matrix Market banner "); - fprintf(stderr, " in file [%s]\n", fname); - return -1; + return -1; + + + if (mm_read_banner(f, &matcode) != 0) { + fprintf(stderr, + "mm_read_unsymetric: Could not process Matrix Market banner "); + fprintf(stderr, " in file [%s]\n", fname); + return -1; } - - - - if ( !(mm_is_real(matcode) && mm_is_matrix(matcode) && - mm_is_sparse(matcode))) - { - fprintf(stderr, "Sorry, this application does not support "); - fprintf(stderr, "Market Market type: [%s]\n", - mm_typecode_to_str(matcode)); - return -1; + + + + if (!(mm_is_real(matcode) && mm_is_matrix(matcode) && + mm_is_sparse(matcode))) { + fprintf(stderr, "Sorry, this application does not support "); + fprintf(stderr, "Market Market type: [%s]\n", + mm_typecode_to_str(matcode)); + return -1; } - + /* find out size of sparse matrix: M, N, nz .... */ - - if (mm_read_mtx_crd_size(f, &M, &N, &nz) !=0) - { - fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n"); - return -1; + + if (mm_read_mtx_crd_size(f, &M, &N, &nz) != 0) { + fprintf(stderr, + "read_unsymmetric_sparse(): could not parse matrix size.\n"); + return -1; } - + *M_ = M; *N_ = N; *nz_ = nz; - + /* reseve memory for matrices */ - + I = (int *) malloc(nz * sizeof(int)); J = (int *) malloc(nz * sizeof(int)); val = (double *) malloc(nz * sizeof(double)); - + *val_ = val; *I_ = I; *J_ = J; - + /* NOTE: when reading in doubles, ANSI C requires the use of the "l" */ /* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */ /* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */ - - for (i=0; i