📄 write.cpp
字号:
#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <iostream>#include <fstream>#include <stdlib.h>#include <stdio.h>#include "graph.h"using namespace std;bool existFile(char fname[]) { bool failed ; ifstream infile (fname,ios_base::in); failed = infile.fail() ; infile.close() ; return (!failed) ;}int main(int argc, char *argv[]) { /* variables needed for graph generation */ graphs *graph; int verbose=1; int vdegreesnum, cdegreesnum, vnodenum, cnodenum; int node, socket; int gap=-1; int *iphi; int i; int index=1; int errors=0; if (argc<2) { cout<<"Parameter(s) required: enter filenames of graphs\nThese graphs will be stored in graphs.c\n"; exit(1); } for (index=1; index<argc; index++) { if(!existFile(argv[index])) { cout<<"Cannot open "<<argv[index]<<"\n"; errors++; } } if (errors) exit(1); ofstream* pgraphs = new ofstream("graphs.c"); cout<<"Writing data\n"; for (index=1; index<argc; index++) { cout<<"Code "<<index<<"\n"; *pgraphs << "\nint code" <<index<<"[] = {"; /* allocate memory for graph */ graph=(graphs *)allocate(sizeof(graphs)); /* read in graph */ cout<<"reading graph "<<index<<" from "<<argv[index]<<"\n"; readgraph(graph, &gap, &iphi, argv[index], verbose); // start writing graphs cout<<"writing graph "<<index<<"\n"; *pgraphs <<(*graph).vnodenum<<","<<(*graph).cnodenum<<","<<(*graph).vdegreesnum<<","<<(*graph).cdegreesnum<<","<<(*graph).vmaxdegree<<","<<(*graph).cmaxdegree<<","; // assigning vdegrees for (i=0; i<(*graph).vdegreesnum; i++) { *pgraphs<<(*(*graph).vdegreelist).degree[i]<<","<<(*(*graph).vdegreelist).numofnodes[i]<<","; } //assigning cdegrees for (i=0; i<(*graph).cdegreesnum; i++) { *pgraphs<<(*(*graph).cdegreelist).degree[i]<<","<<(*(*graph).cdegreelist).numofnodes[i]<<","; } //assign vnodes cout<<"\nassign vnodes\n"; for (node=0; node<(*graph).vnodenum; node++) { *pgraphs<<vnodedegree<<","; for (socket=0; socket<vnodedegree; socket++) { *pgraphs<<vnodeedge.dest<<","<<vnodeedge.socket<<","; } } //assign cnodes cout<<"\nassign cnodes\n"; for (node=0; node<(*graph).cnodenum; node++) { *pgraphs<<cnodedegree<<","; for (socket=0; socket<cnodedegree; socket++) { *pgraphs<<cnodeedge.dest<<","<<cnodeedge.socket<<","; } } //assign encoder preprocessed data cout<<"\nassign encoder information if available\n"; *pgraphs<<gap<<","; if (gap>=0) { int row, col; for (row=0; row<gap; row++) for (col=0; col<gap; col++) { *pgraphs<<*(iphi+row*gap+col); if ((row!=gap-1) || (col!=gap-1)) *pgraphs<<","; } } *pgraphs<<"};\n"; cout<<"freeing graph "<<index<<"\n"; freegraph(graph); free(graph); } cout << "finished loop, ending graphs.c\n"; *pgraphs<<"\nint *codes[] = {"; for (index=1; index<argc; index++) { if (index != argc-1) *pgraphs<<"code"<<index<<","; else *pgraphs<<"code"<<index<<" };\n"; }#if 0 *pgraphs<<"\nint getGraph(int index, graphs *graph, int *gap, int **iphi);\nvoid freeGraph(graphs *graph,int *iphi);"; *pgraphs<<"\n#endif\n";#endif pgraphs->close(); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -