update source for windows

This commit is contained in:
张壹 2021-08-26 21:27:06 +08:00
parent 83c03e5231
commit 2209673ee5
6 changed files with 94 additions and 43 deletions

View File

@ -1,6 +1,8 @@
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
# openblas
include_directories(D:/Library/include)
endif()
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
@ -36,6 +38,11 @@ set_target_properties(magtess PROPERTIES VERSION 1.0 SOVERSION 1.0)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
target_link_libraries(magtess PUBLIC openblas)
target_link_libraries(magtess PUBLIC m)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
#
find_library(OPENBLAS_LIBRARY libopenblas D:/Library/lib)
target_link_libraries(magtess PUBLIC ${OPENBLAS_LIBRARY})
target_link_libraries(magtess_static ${OPENBLAS_LIBRARY})
endif()
#

View File

@ -12,6 +12,8 @@ Functions matrix and vector multiplications.
#ifdef __linux__ // Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, Centos and other
#include <cblas.h>
#elif _WINDOWS || __WIN32__ // Added for windows by Yi Zhang on 2021-08-26
#include <cblas.h>
#elif defined(__APPLE__) && defined(__MACH__)
#include <Accelerate/Accelerate.h>
#else

View File

@ -36,12 +36,13 @@ add_tools(tessbz)
add_tools(tessutil_combine_grids)
add_tools(tessutil_gradient_calculator)
#add_tools(tessutil_magnetize_model)
#
add_executable(tessutil_magnetize_model tessutil_magnetize_model.c)
#
set_target_properties(tessutil_magnetize_model PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
#
target_link_libraries(tessutil_magnetize_model PUBLIC magtess)
# bin
install(TARGETS tessutil_magnetize_model RUNTIME DESTINATION sbin)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
#
add_executable(tessutil_magnetize_model tessutil_magnetize_model.c)
#
set_target_properties(tessutil_magnetize_model PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
#
target_link_libraries(tessutil_magnetize_model PUBLIC magtess)
# bin
install(TARGETS tessutil_magnetize_model RUNTIME DESTINATION sbin)
endif()

View File

@ -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;

View File

@ -1,7 +1,9 @@
#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>
#include "../lib/constants.h"
#include "../lib/parsers.h"
@ -11,6 +13,11 @@
#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
// TODO conversion of input/output units nT/km pT/km nT/m pT/m
@ -106,14 +113,17 @@ int main(int argc, char**argv)
double bz[MAX_GRID_POINTS];
//read file with bx
char * line = NULL;
//char * line = NULL;
std::string line;
size_t len = 0;
ssize_t read;
FILE * bxfp = fopen(args.gridbx_fn, "r");
if (bxfp == NULL)
//FILE * bxfp = fopen(args.gridbx_fn, "r");
//if (bxfp == NULL)
std::ifstream bxfp(args.gridbx_fn, std::ios::in); // Updated by Yi Zhang on 2021-08-26
if (!bxfp)
{
printf("ERROR: Can not open file with Bx values.\n");
exit(EXIT_FAILURE);
@ -123,10 +133,12 @@ int main(int argc, char**argv)
while ((read = getline(&line, &len, bxfp )) != -1)
//while ((read = getline(&line, &len, bxfp )) != -1)
while (getline(bxfp, 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)
@ -135,11 +147,12 @@ int main(int argc, char**argv)
exit(EXIT_FAILURE);
}
sscanf(line, GRID_FORMAT, &lons[n_lines-1], &lats[n_lines-1], &alts[n_lines-1], &bx[n_lines-1]);
sscanf(line.c_str(), GRID_FORMAT, &lons[n_lines-1], &lats[n_lines-1], &alts[n_lines-1], &bx[n_lines-1]);
}
}
fclose(bxfp);
//fclose(bxfp);
bxfp.close();
/*number of grid points*/
@ -183,27 +196,33 @@ int main(int argc, char**argv)
/* read other grids */
// By
FILE * byfp = fopen(args.gridby_fn, "r");
if (byfp == NULL)
//FILE * byfp = fopen(args.gridby_fn, "r");
//if (byfp == NULL)
std::ifstream byfp(args.gridby_fn, std::ios::in);
if (!byfp)
{
printf("ERROR: Can not open file with Bx values.\n");
exit(EXIT_FAILURE);
}
int n_lines2 = 0;
while ((read = getline(&line, &len, byfp )) != -1)
//while ((read = getline(&line, &len, byfp )) != -1)
while (getline(byfp, line))
{
if ((line[0] != '#') && (strlen(line) > 2))
{
n_lines2++;
//printf("%s", line);
double dummy1, dummy2;
float dummy3;
sscanf(line, GRID_FORMAT , &dummy1, &dummy2, &dummy3, &by[n_lines2-1]);
}
//if ((line[0] != '#') && (strlen(line) > 2))
if ((line[0] != '#') && (line.length() > 2))
{
n_lines2++;
//printf("%s", line);
double dummy1, dummy2;
float dummy3;
sscanf(line.c_str(), GRID_FORMAT , &dummy1, &dummy2, &dummy3, &by[n_lines2-1]);
}
}
fclose(byfp);
//fclose(byfp);
byfp.close();
if (n_lines2 != n_lines)
{
@ -212,29 +231,33 @@ int main(int argc, char**argv)
}
// Bz
FILE * bzfp = fopen(args.gridbz_fn, "r");
if (bzfp == NULL)
//FILE * bzfp = fopen(args.gridbz_fn, "r");
//if (bzfp == NULL)
std::ifstream bzfp(args.gridbz_fn, std::ios::in);
if (!bzfp)
{
printf("ERROR: Can not open file with Bx values.\n");
exit(EXIT_FAILURE);
}
n_lines2 = 0;
while ((read = getline(&line, &len, bzfp )) != -1)
//while ((read = getline(&line, &len, bzfp )) != -1)
while (getline(bzfp, line))
{
if ((line[0] != '#') && (strlen(line) > 2))
if ((line[0] != '#') && (line.length() > 2))
{
n_lines2++;
//printf("%s", line);
double dummy1, dummy2;
float dummy3;
double bz_curr;
sscanf(line, GRID_FORMAT, &dummy1, &dummy2, &dummy3,&bz_curr);
sscanf(line.c_str(), GRID_FORMAT, &dummy1, &dummy2, &dummy3,&bz_curr);
bz[n_lines2-1] = args.bz_NEU_NED* bz_curr; //COORDINATE SYSTEM NEU or NED
}
}
fclose(byfp);
//fclose(byfp);
byfp.close();
if (n_lines2 != n_lines)
{

View File

@ -22,6 +22,11 @@ int my_isnan(double d)
return (d != d); /* IEEE: only NaN is not equal to itself */
}
#if defined(_MSC_VER) /* Added for windows by Yi Zhang on 2021-08-26*/
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
#define NaN log(-1.0)
#define FT2KM (1.0/0.0003048)
#define RAD2DEG (180.0/PI)