update source for windows
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <fstream>
|
||||
#include <iostream> // Added by Zhang Yi on 2021-08-26
|
||||
#include <string>
|
||||
|
||||
#define MAX_GRID_POINTS 16000
|
||||
|
||||
#define GRID_FORMAT "%lf %lf %f %lf"
|
||||
|
||||
#if defined(_MSC_VER) /* Added for windows by Yi Zhang on 2021-08-26*/
|
||||
#include <BaseTsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
|
||||
void printresult_withalt(double* longitudes, double* latitudes, float* altitudes, double* values, int n_values)
|
||||
{
|
||||
|
||||
@@ -40,7 +47,8 @@ int main(int argc, char**argv)
|
||||
|
||||
double factor = 1;
|
||||
|
||||
char * line = NULL;
|
||||
//char * line = NULL;
|
||||
std::string line;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
@@ -48,20 +56,24 @@ int main(int argc, char**argv)
|
||||
|
||||
for (int i = 0; i < n_files; i++)
|
||||
{
|
||||
FILE * fp = fopen(argv[1+2*i], "r");
|
||||
//FILE * fp = fopen(argv[1+2*i], "r");
|
||||
std::ifstream fp(argv[1+2*i], std::ios::in);
|
||||
sscanf(argv[1+2*i+1], "%lf", &factor);
|
||||
|
||||
if (fp == NULL)
|
||||
//if (fp == NULL)
|
||||
if (!fp)
|
||||
{
|
||||
printf("ERROR: Can not open file with grid values.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
n_lines = 0;
|
||||
while ((read = getline(&line, &len, fp )) != -1)
|
||||
//while ((read = getline(&line, &len, fp )) != -1)
|
||||
while (std::getline(fp, line))
|
||||
{
|
||||
|
||||
if ((line[0] != '#') && (strlen(line) > 2))
|
||||
//if ((line[0] != '#') && (strlen(line) > 2))
|
||||
if ((line[0] != '#') && (line.length() > 2))
|
||||
{
|
||||
n_lines++;
|
||||
if (n_lines>MAX_GRID_POINTS)
|
||||
@@ -71,12 +83,13 @@ int main(int argc, char**argv)
|
||||
}
|
||||
double value;
|
||||
|
||||
sscanf(line, GRID_FORMAT, &lons[n_lines-1], &lats[n_lines-1], &alts[n_lines-1], &value);
|
||||
sscanf(line.c_str(), GRID_FORMAT, &lons[n_lines-1], &lats[n_lines-1], &alts[n_lines-1], &value);
|
||||
vals[n_lines-1] = vals[n_lines-1] + value*factor;
|
||||
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
//fclose(fp);
|
||||
fp.close();
|
||||
}
|
||||
|
||||
int no_alt = 0;
|
||||
|
||||
Reference in New Issue
Block a user