Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault #1

Open
lkdo opened this issue Feb 13, 2024 · 1 comment
Open

Segmentation Fault #1

lkdo opened this issue Feb 13, 2024 · 1 comment

Comments

@lkdo
Copy link

lkdo commented Feb 13, 2024

Function void TeosBase::gsw_util_sort_dbl(double *dArray,int nx,int *iArray,bool ASC) seems to be called with a partially uninitialized iArray parameter, for example in gsw_util_interp1q_int(), causing segmentation fault. The call is gsw_util_sort_dbl(xi, n, k); where the k array is only initialized from index n circa.

The following code was used as main() for a quick test:

#include <iostream>
#include "TeosSea.h"

int main()
{

	// https://www.teos-10.org/pubs/gsw/html/gsw_geo_strf_dyn_height.html

	TeosSea mTB;

	// INPUT 
	const int N = 6;
	double SA[N] = { 34.7118, 34.8915, 35.0256, 34.8472, 34.7366, 34.7324 };
	double CT[N] = { 28.8099, 28.439, 22.7862, 10.2262,  6.8272,  4.3236 };
	double p[N] = { 10, 50, 125, 250, 600, 1000 };
	double p_ref[1] = { 1000 };

	// OUTPUT 
	double dynamic_anomaly_result[N] = { 16.829126675036644, 14.454693755102685, 10.727894578402342,  7.699845274649316,  3.578081589449148,  0 };

	// CALCULATE
	double dynamic_anomaly[N];
	int k = 0;
	if (mTB.gsw_geo_strf_dyn_height(&SA[k], &CT[k], &p[k], p_ref[0], N, &dynamic_anomaly[k]) == NULL)
	{
		std::cout << "FAILURE NULL\n";
		return -1;
	}
	
	// VERIFY RESULT
	for (int i = 0; i < N; i++)
		std::cout << "Expected:\t" << dynamic_anomaly_result[i] << "; Actual:\t" << dynamic_anomaly[i] << "\n";

	return 0;
}
@rkwhited
Copy link

Did you run "in funnel" to validate your parameters?
/***************************************************************************
% gsw_geo_strf_dyn_height dynamic height anomaly
% (75-term equation)
%==========================================================================

% Note that the 75-term equation has been fitted in a restricted range of
% parameter space, and is most accurate inside the "oceanographic funnel"
% described in McDougall et al. (2003). For dynamical oceanography we may
% take the 75-term rational function expression for specific volume as
% essentially reflecting the full accuracy of TEOS-10. The GSW library
% function "gsw_infunnel(SA,CT,p)" is avaialble to be used if one wants to
% test if some of one's data lies outside this "funnel".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants