#include #include #include #include #include #include #include using namespace std; /* Uday Khankhoje, 09 November 2009 * Program to generate a grayscale PNG file from an asci file. Assumptions of input file are that it contains tab separated values on each line. The number of tabs is equal to the number of data entries and each line ends with a newline character.*/ struct detail { float * ptr; int size_x; int size_y; float maxval; float minval; bool hasneg; }; /*This function takes in a file as specified on the command line, then generates a 2D array that contains the information and returns a pointer to the array, the maximum & minimul value in the array and if the data has negative values or not. A suitable struct is created to hold the return values.*/ detail filein_dataout(string fname) { ifstream in(fname.c_str()); string tmp; detail p; p.hasneg=false; p.size_x=0; p.size_y=0; p.maxval=-1e10; p.minval=1e10; /*Get file dimensions by parsing the file. Using the getline function as defined in the string library.*/ while(getline(in,tmp,'\n')) { /*Next line ensures that inner for loop is executed only once.*/ if(!p.size_y) { for (int k=0;kp.maxval) {p.maxval=px[i];} if(px[i] (optional) (optional)"<=3) { filename_out=argv[2]; } else { filename_out=filename_in + ".png"; } if(argc==4) { comp=atoi(argv[3]); } /*End of file information gathering. Send in input file and extract all info */ detail pmap = filein_dataout(filename_in); /*Create blank output file:*/ pngwriter png(pmap.size_x,pmap.size_y,0.0,filename_out.c_str()); /*Now fill up the output file:*/ int i=0,x,y;double px; cout<<"("<