Commit 24e77544 authored by Morales Hernandez, Mario's avatar Morales Hernandez, Mario
Browse files

Change some tools to allow long variables

Some of the tools did not include the change to allow big integer
numbers. Therefore, some of the variables have been changed to long
(instead of int) to make the tools compatible with large cases.
parent ff51a37e
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@ std::vector<std::string> split(const std::string &s, char delim)
	return split(s, delim, elems);
}

std::pair<int, int> get_dims_2d(string& filepath)
std::pair<long, long> get_dims_2d(string& filepath)
{
	int num_cols = 0, num_rows = 0;
	long num_cols = 0, num_rows = 0;
	bool first = false;
	ifstream infile(filepath.c_str());
		
@@ -60,24 +60,24 @@ std::pair<int, int> get_dims_2d(string& filepath)

	infile.close();

	return std::pair<int, int>(num_cols, num_rows);
	return std::pair<long, long>(num_cols, num_rows);
}

void ascii2bin(string input_file, string output_file){
	std::tuple<int, int> dims = get_dims_2d(input_file);
	int row = std::get<1>(dims);
	int col = std::get<0>(dims);
	std::tuple<long, long> dims = get_dims_2d(input_file);
	long nrows = std::get<1>(dims);
	long ncols = std::get<0>(dims);

    value_t *arr = new value_t [row*col];
    value_t *arr = new value_t [nrows*ncols];
	
	ifstream input(input_file.c_str());
	int i = 0;
	long i = 0;

	string line;

	while (input.good())
	{
		int j = 0;
		long j = 0;
		std::getline(input, line);
		std::vector<std::string> row = split(line, ' ');
		std::string val;
@@ -86,20 +86,20 @@ void ascii2bin(string input_file, string output_file){
		for (; strit != row.end(); strit++, j++)
		{
			val = *strit;
			arr[(col * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
			arr[(ncols * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
		}
		i++;
	}
	input.close();

    ofstream output(output_file.c_str(), std::ios::binary);
	value_t put_rows_value = (value_t)(row);
	value_t put_cols_value = (value_t)(col);
	value_t put_rows_value = (value_t)(nrows);
	value_t put_cols_value = (value_t)(ncols);
			
	output.write((char*) &put_rows_value, sizeof(value_t));
	output.write((char*) &put_cols_value, sizeof(value_t));

	output.write((char*)&arr[0], row*col * sizeof(value_t));
	output.write((char*)&arr[0], nrows*ncols * sizeof(value_t));
    output.close();

    delete[] arr;
+17 −17
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ std::vector<std::string> split(const std::string &s, char delim)

void ascii2bin_dem(string input_file, string output_file){
	ifstream ifs(input_file.c_str());
	int line_num = 0;
	long line_num = 0;
	
	int row, col, no_data_value;
	value_t xllcorner, yllcorner, cellsize;
	long nrows, ncols;
	value_t xllcorner, yllcorner, cellsize, no_data_value;

	while (true)
	{
@@ -67,12 +67,12 @@ void ascii2bin_dem(string input_file, string output_file){
			{
				case 1:
				{
					col = atoi(value);
					ncols = atoi(value);
					break;
				}
				case 2:
				{
					row = atoi(value);
					nrows = atoi(value);
					break;
				}
				case 3:
@@ -92,7 +92,7 @@ void ascii2bin_dem(string input_file, string output_file){
				}
				case 6:
				{
					no_data_value = atoi(value);
					no_data_value = atof(value);
					break;
				}
				default:
@@ -104,12 +104,12 @@ void ascii2bin_dem(string input_file, string output_file){
	}
	ifs.close();
	
	value_t *arr = new value_t [row*col];
	int i = 0;
	value_t *arr = new value_t [nrows*ncols];
	long i = 0;
	ifstream infile(input_file.c_str());
	std::string line;

	int line_number = 0;
	long line_number = 0;

	while (infile.good())
	{
@@ -119,7 +119,7 @@ void ascii2bin_dem(string input_file, string output_file){
		if (line_number <= DEM_HEADER_SIZE)
			continue;

		int j = 0;
		long j = 0;
		std::vector<std::string> row = split(line, ' ');
		std::string val;
		std::vector<std::string>::iterator strit = row.begin();
@@ -128,15 +128,15 @@ void ascii2bin_dem(string input_file, string output_file){
		{
			val = *strit;

			arr[(col * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
			arr[(ncols * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
		}
		i++;
	}
	infile.close();

    ofstream output(output_file.c_str(), std::ios::binary);
	value_t put_rows_value = (value_t)(row);
	value_t put_cols_value = (value_t)(col);
	value_t put_rows_value = (value_t)(nrows);
	value_t put_cols_value = (value_t)(ncols);
	value_t put_no_data_value = (value_t)(no_data_value);

	output.write((char*) &put_cols_value, sizeof(value_t));
@@ -144,9 +144,9 @@ void ascii2bin_dem(string input_file, string output_file){
	output.write((char*) &xllcorner, sizeof(value_t));
	output.write((char*) &yllcorner, sizeof(value_t));
	output.write((char*) &cellsize, sizeof(value_t));
	output.write((char*) &no_data_value, sizeof(value_t));
	output.write((char*) &put_no_data_value, sizeof(value_t));

	output.write((char*)&arr[0], row*col * sizeof(value_t));
	output.write((char*)&arr[0], nrows*ncols * sizeof(value_t));
    output.close();

    delete[] arr;
+13 −13
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@ std::vector<std::string> split(const std::string &s, char delim)
	return split(s, delim, elems);
}

std::pair<int, int> get_dims_2d(string& filepath)
std::pair<long, long> get_dims_2d(string& filepath)
{
	int num_cols = 0, num_rows = 0;
	long num_cols = 0, num_rows = 0;
	bool first = false;
	ifstream infile(filepath.c_str());
		
@@ -60,24 +60,24 @@ std::pair<int, int> get_dims_2d(string& filepath)

	infile.close();

	return std::pair<int, int>(num_cols, num_rows);
	return std::pair<long, long>(num_cols, num_rows);
}

void ascii2bin(string input_file, string output_file){
	std::tuple<int, int> dims = get_dims_2d(input_file);
	int row = std::get<1>(dims);
	int col = std::get<0>(dims);
	std::tuple<long, long> dims = get_dims_2d(input_file);
	long nrows = std::get<1>(dims);
	long ncols = std::get<0>(dims);

    value_t *arr = new value_t [row*col];
    value_t *arr = new value_t [nrows*ncols];
	
	ifstream input(input_file.c_str());
	int i = 0;
	long i = 0;

	string line;

	while (input.good())
	{
		int j = 0;
		long j = 0;
		std::getline(input, line);
		std::vector<std::string> row = split(line, ' ');
		std::string val;
@@ -86,20 +86,20 @@ void ascii2bin(string input_file, string output_file){
		for (; strit != row.end(); strit++, j++)
		{
			val = *strit;
			arr[(col * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
			arr[(ncols * i) + j] = (val.find(".") != std::string::npos) ? (value_t)atof(val.c_str()) : (value_t)atoi(val.c_str());
		}
		i++;
	}
	input.close();

    ofstream output(output_file.c_str(), std::ios::binary);
	value_t put_rows_value = (value_t)(row);
	value_t put_cols_value = (value_t)(col);
	value_t put_rows_value = (value_t)(nrows);
	value_t put_cols_value = (value_t)(ncols);
			
	output.write((char*) &put_rows_value, sizeof(value_t));
	output.write((char*) &put_cols_value, sizeof(value_t));

	output.write((char*)&arr[0], row*col * sizeof(value_t));
	output.write((char*)&arr[0], nrows*ncols * sizeof(value_t));
    output.close();

    delete[] arr;
+9 −9
Original line number Diff line number Diff line
@@ -26,22 +26,22 @@ void bin2ascii(string input_file, string output_file){
	value_t *dim_arr = new value_t[HEADER];
	input.read((char*) dim_arr, HEADER * sizeof(value_t)); 

	int row = (int) dim_arr[0];
	int col = (int) dim_arr[1];
	long nrows = (long) dim_arr[0];
	long ncols = (long) dim_arr[1];

    value_t *arr = new value_t [row*col];
    value_t *arr = new value_t [nrows*ncols];

	input.seekg(HEADER * sizeof(value_t), std::ios::beg);
    input.read((char*) arr, sizeof(value_t) * row * col);
    input.read((char*) arr, sizeof(value_t) * nrows * ncols);
    input.close();

    ofstream output(output_file.c_str());
    output << std::setprecision(6) << std::fixed;

    for(int i=0; i<row; i++){
        for(int j=0; j<col; j++){
            output << arr[i*col+j];
            if(j<col-1){
    for(long i=0; i<nrows; i++){
        for(long j=0; j<ncols; j++){
            output << arr[i*ncols+j];
            if(j<ncols-1){
                output << " ";
            }
        }
+14 −14
Original line number Diff line number Diff line
@@ -27,33 +27,33 @@ void bin2ascii_dem(string input_file, string output_file){
	value_t *header_arr = new value_t[HEADER];
	input.read((char*) header_arr, HEADER * sizeof(value_t)); 

	int col = (int) header_arr[0];
	int row = (int) header_arr[1];
	long ncols = (long) header_arr[0];
	long nrows = (long) header_arr[1];
	value_t xll_corner = header_arr[2];
	value_t yll_corner = header_arr[3];
	value_t cell_size = header_arr[4];
	int no_data_value = (int)header_arr[5];
	value_t no_data_value = header_arr[5];

    value_t *arr = new value_t [row*col];
    value_t *arr = new value_t [nrows*ncols];

	input.seekg(HEADER * sizeof(value_t), std::ios::beg);
    input.read((char*) arr, sizeof(value_t) * row * col);
    input.read((char*) arr, sizeof(value_t) * nrows * ncols);
    input.close();

    ofstream output(output_file.c_str());
	output << "ncols         " << col << endl;
	output << "nrows         " << row << endl;
	output << "ncols         " << ncols << endl;
	output << "nrows         " << nrows << endl;
	output << "xllcorner     " << std::setprecision(std::numeric_limits<value_t>::max_digits10) << std::fixed << xll_corner << endl;
	output << "yllcorner     " << std::setprecision(std::numeric_limits<value_t>::max_digits10) << std::fixed << yll_corner << endl;
	output << "cellsize      " << std::setprecision(std::numeric_limits<value_t>::max_digits10) << std::fixed << cell_size << endl;
	output << "NODATA_value  " << no_data_value << endl;
	output << "NODATA_value  " << std::setprecision(std::numeric_limits<value_t>::max_digits10) << std::fixed << no_data_value << endl;
	
    output << std::setprecision(4) << std::fixed;
    output << std::setprecision(5) << std::fixed;

    for(int i=0; i<row; i++){
        for(int j=0; j<col; j++){
            output << arr[i*col+j];
            if(j<col-1){
    for(long i=0; i<nrows; i++){
        for(long j=0; j<ncols; j++){
            output << arr[i*ncols+j];
            if(j<ncols-1){
                output << " ";
            }
        }
Loading