From: yifanhu Date: Mon, 14 Apr 2008 00:18:39 +0000 (+0000) Subject: utilities for extrating coordinates from a dot file X-Git-Tag: LAST_LIBGRAPH~32^2~4329 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d624540c71e7a8a2402d147c029854ebb1f1d1b8;p=graphviz utilities for extrating coordinates from a dot file --- diff --git a/lib/sfdpgen/Makefile_dot2coord b/lib/sfdpgen/Makefile_dot2coord new file mode 100644 index 000000000..068c90f3c --- /dev/null +++ b/lib/sfdpgen/Makefile_dot2coord @@ -0,0 +1,49 @@ +PROG = dot2coord + +SRCS = dot2coord.c SparseMatrix.c general.c DotIO.c + +OBJS = dot2coord.o SparseMatrix.o general.o DotIO.o + + +LIBS = -lm +#GVIZ_BUILD_PATH = .. +GVIZ_BUILD_PATH = /home/yifanhu/GraphViz/graphviz2/build +#GVIZ_BUILD_PATH = /Users/yifanhu/graphviz2/built + +LIBS = -L$(GVIZ_BUILD_PATH)/lib -lgraph -lcdt -lm + + +CC = cc +#CFLAGS = -g -Wall -DDEBUG -DDEBUG_PRINT +#CFLAGS = -O3 -Wall -DDEBUG_PRINT +CFLAGS = -g -DHAVE_DOT -I$(GVIZ_BUILD_PATH)/include/graphviz/ -Wall -DDEBUG_PRINT -DTIME +CFLAGS = -g -pg -DHAVE_DOT -I$(GVIZ_BUILD_PATH)/include/graphviz/ -Wall -DDEBUG_PRINT -DTIME +CFLAGS = -O3 -DHAVE_DOT -I$(GVIZ_BUILD_PATH)/include/graphviz/ -Wall -DDEBUG_PRINT -DTIME +#CFLAGS = -O3 -Wall +#CFLAGS = -pg -g -Wall -DDEBUG_PRINT +FC = f77 +FFLAGS = -O +F90 = f90 +F90FLAGS = -O +LDFLAGS = -g +LDFLAGS = $(CFLAGS) + + +all: $(PROG) + +$(PROG): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +clean: + rm -f $(PROG) $(OBJS) *.mod + +.SUFFIXES: $(SUFFIXES) .f90 + +.f90.o: + $(F90) $(F90FLAGS) -c $< + +dot2coord.o: SparseMatrix.h +SparseMatrix.o: SparseMatrix.h general.h +general.o: general.h + + diff --git a/lib/sfdpgen/dot2coord.c b/lib/sfdpgen/dot2coord.c new file mode 100644 index 000000000..33e5cbd5b --- /dev/null +++ b/lib/sfdpgen/dot2coord.c @@ -0,0 +1,57 @@ +#include +#include +#include "general.h" +#include "SparseMatrix.h" +#include "DotIO.h" + +int Verbose; + +static FILE* openF (char* fname, char* mode) +{ + FILE* f = fopen (fname, mode); + if (!f) { + fprintf (stderr, "Could not open %s for %s\n", fname, + ((*mode == 'r') ? "reading" : "writing")); + exit (1); + } + return f; +} + +real distance(real *x, int dim, int i, int j){ + int k; + real dist = 0.; + for (k = 0; k < dim; k++) dist += (x[i*dim+k] - x[j*dim + k])*(x[i*dim+k] - x[j*dim + k]); + dist = sqrt(dist); + return dist; +} + + +int main(int argc, char *argv[]) +{ + Agraph_t* g = 0; + char *infile; + FILE *f; + real *x; + real *label_sizes = NULL; + int i; + SparseMatrix A; + + /* ======================= read graph ==================== */ + if (argc < 2) { + fprintf(stderr, "usage: dot2coord dotfile"); + exit(1); + } + infile = argv[1]; + f = openF (infile, "r"); + + aginit (); + g = agread (f); + A = SparseMatrix_import_dot(g, 2, &label_sizes, &x, FORMAT_CSR); + + for (i = 0; i < A->m; i++) fprintf(stdout, "%lf %lf\n",x[2*i],x[2*i+1]); + + SparseMatrix_delete(A); + FREE(x); + if (label_sizes) FREE(label_sizes); + return 0; +}