/************************************************************************** *** *** Copyright (c) 2004 Regents of the University of Michigan, *** Hayward H. Chan and Igor L. Markov *** *** Contact author(s): hhchan@umich.edu, imarkov@umich.edu *** Original Affiliation: EECS Department, *** The University of Michigan, *** Ann Arbor, MI 48109-2122 *** *** Permission is hereby granted, free of charge, to any person obtaining *** a copy of this software and associated documentation files (the *** "Software"), to deal in the Software without restriction, including *** without limitation *** the rights to use, copy, modify, merge, publish, distribute, sublicense, *** and/or sell copies of the Software, and to permit persons to whom the *** Software is furnished to do so, subject to the following conditions: *** *** The above copyright notice and this permission notice shall be included *** in all copies or substantial portions of the Software. *** *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *** THE USE OR OTHER DEALINGS IN THE SOFTWARE. *** *** ***************************************************************************/ #include #include using namespace std; const int MAX_SIZE = 100000; const char outname[] = "out"; int main(int argc, char* argv[]) { double dimen[MAX_SIZE][2]; double loca[MAX_SIZE][2]; double width, height; double area = 0; int perSize; ifstream infile; ofstream outfile; bool print_label = false; bool ascending = true; int startfrom = -1; if (argc < 3) { cout << "usage: " << argv[0] << " " << endl; exit(1); } for (int i = 3; i < argc; i++) if (!strcmp(argv[i], "-l")) print_label = true; else if (!strcmp(argv[i], "-n")) print_label = false; else if (!strcmp(argv[i], "-s")) { i++; startfrom = atoi(argv[i]); } else if (!strcmp(argv[i], "-a")) ascending = true; else if (!strcmp(argv[i], "-d")) ascending = false; else { cout << "unrecognized option \"" << argv[i] << "\"." << endl; exit(1); } infile.open(argv[1]); infile >> width >> height; infile >> perSize; if (perSize > MAX_SIZE) { cout << "number of block (" << perSize << ") exceeds maximum allowed (" << MAX_SIZE << ")" << endl; exit(1); } for (int i = 0; i < perSize; i++) { infile >> dimen[i][0] >> dimen[i][1]; area += dimen[i][0] * dimen[i][1]; } for (int j = 0; j < perSize; j++) infile >> loca[j][0] >> loca[j][1]; // ----- OUTPUT FILE ------ //outfile.setf(ios::fixed); //outfile.precision(2); outfile.open(outname); outfile << "set noxtics" << endl; outfile << "set noytics" << endl; outfile << "set nox2tics" << endl; outfile << "set noy2tics" << endl; outfile << "set size ratio -1" << endl; outfile << "set terminal postscript landscape solid" << endl; outfile << "set output \""; outfile << argv[2]; outfile << "\"" << endl; outfile.setf(ios::fixed); outfile.precision(3); outfile << "set title \"-----" << argv[2] << "-----\\n"; outfile << "# blocks = " << perSize << "\\n"; outfile << "width = " << width << "\\n"; outfile << "height = " << height << "\\n"; outfile << "area = " << width * height << "\\n"; outfile << "total block area = " << area << "\\n"; outfile.precision(6); outfile << "dead space = " << ((width * height / area) - 1) * 100 << "%"; outfile.precision(3); outfile << "\"" << endl; if (startfrom == -1) // startfrom is not specified startfrom = ascending? 1 : perSize; for (int s = 0; s < perSize; s++) { double XLoca = loca[s][0]; double YLoca = loca[s][1]; double bWidth = dimen[s][0]; double bHeight = dimen[s][1]; outfile << "set label \""; if (ascending) outfile << s+startfrom; else outfile << startfrom-s; outfile << "\" at " << XLoca+(bWidth/2) << ", " << YLoca+(bHeight/2) << " center" << endl; } if (!print_label) outfile << "set nolabel" << endl; outfile << "plot [0:" << (width * 1.1) << "][0:" << (height * 1.1) << "] "; for (int q = 0; q < perSize; q++) { //outfile << "\"-\" title \"" << char(perX[q]+OFFSET) << "\" w l"; outfile << "\"-\" notitle w l"; if (q < perSize-1) outfile << ","; } outfile << endl; for (int r = 0; r < perSize; r++) { double BWidth = dimen[r][0]; double BHeight = dimen[r][1]; double XLoc = loca[r][0]; double YLoc = loca[r][1]; outfile << XLoc << " " << YLoc << endl; outfile << XLoc << " " << YLoc + BHeight << endl; outfile << XLoc + BWidth << " " << YLoc + BHeight << endl; outfile << XLoc + BWidth << " " << YLoc << endl; outfile << XLoc << " " << YLoc << endl; outfile << "END" << endl; } infile.close(); outfile.close(); return 0; }