/* * Copyright(c) 2005-2008 University College London * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * 3. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE * * $Id: map.cc 98 2008-04-08 22:36:34Z soohyunc $ */ #include #include #include #include #include using namespace std; // print instruction void print_instruction () { cout << "Usage: ./map [file] [option]" << endl; exit (0); } // main body int main (int argc, char *argv[]) { // print instruction if (argc < 3) { print_instruction(); } ifstream fin (argv[1]); // input file stream ofstream fout; // output file stream string nil, hex, option; double time, val; option = argv[2]; // map declaration map > values; // iterator declaration map >::iterator pitr; map ::iterator itr; if(fin.is_open()) { while (!fin.eof()) { fin >> nil; // do not need this column fin >> nil; // do not need this column fin >> val; // actual value fin >> time; // time stamp fin >> hex; // pointer value // record map value values[hex][time] = val; } fin.close(); // close file } else { cout << "error opening file!" << endl; exit (1); } int i; int size = values.size(); // map size (no. of pointers) string str[size], index; // for the use of file names for (i=0, pitr=values.begin(); i> index; // convert integer to string str[i].append(option.c_str()); // start file name with "option" str[i].append("_"); str[i].append(index.c_str()); // append thread number str[i].append(".xg"); // end with ".xg" fout.open(str[i].c_str()); // create a file and open to write // recording values for (itr = pitr->second.begin(); itr != pitr->second.end(); ++itr) { fout << itr->first << "\t" << itr->second << endl; } fout.close(); // close file } return 0; }