The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 crash with ocmath_d_cumulative_sum
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

couturier

France
291 Posts

Posted - 10/16/2019 :  10:55:42 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2019b
Operating System:10
Hi
I have this function to compute traveled distance from GPS coordinates:

void odo_GPS(vector lat, vector lon, vector& dist)
{
	int iSize = lat.GetSize()-1;
	vector distance(iSize), diffLat(iSize), diffLon(iSize), lat0(iSize), lat1(iSize); 
	
	lat *= pi/180;
	lon *= pi/180;
	
	lat.Difference(diffLat);
	lon.Difference(diffLon);
	lat.GetSubVector(lat0, 0, iSize);
	lat.GetSubVector(lat1, 1, iSize);
	
	distance = 2*6378137 * asin( sqrt( (sin((diffLat)/2))^2 + cos(lat0)*cos(lat1)*(sin((diffLon)/2))^2 ) );
	
	distance.InsertAt(0, 0);
	ocmath_d_cumulative_sum(distance, 0, iSize+1, dist);
	dist = round(dist, 0);
}

This function works correctly when called from an ogs script
But if called from script window, ocmath_d_cumulative_sum crashes Origin
Any hint ?

Castiel

343 Posts

Posted - 10/17/2019 :  12:22:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by couturier

Origin Ver. and Service Release (Select Help-->About Origin): 2019b
Operating System:10
Hi
I have this function to compute traveled distance from GPS coordinates:

void odo_GPS(vector lat, vector lon, vector& dist)
{
	int iSize = lat.GetSize()-1;
	vector distance(iSize), diffLat(iSize), diffLon(iSize), lat0(iSize), lat1(iSize); 
	
	lat *= pi/180;
	lon *= pi/180;
	
	lat.Difference(diffLat);
	lon.Difference(diffLon);
	lat.GetSubVector(lat0, 0, iSize);
	lat.GetSubVector(lat1, 1, iSize);
	
	distance = 2*6378137 * asin( sqrt( (sin((diffLat)/2))^2 + cos(lat0)*cos(lat1)*(sin((diffLon)/2))^2 ) );
	
	distance.InsertAt(0, 0);
	ocmath_d_cumulative_sum(distance, 0, iSize+1, dist);
	dist = round(dist, 0);
}

This function works correctly when called from an ogs script
But if called from script window, ocmath_d_cumulative_sum crashes Origin
Any hint ?



You should have explicitly allocated enough memory for dist before calling that function:
dist.SetSize(iSize + 1 - 0 + 1);

In your ogs it did not crash probably because the memory had been allocated in the context.


                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************
Go to Top of Page

couturier

France
291 Posts

Posted - 10/17/2019 :  07:28:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot Castiel, that was it.

In the ogs script, I was overwritting a column (hence with correct size)
In script window, the output column was empty.

dist.SetSize(iSize + 1);


and everything works
Go to Top of Page

Castiel

343 Posts

Posted - 10/17/2019 :  07:43:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by couturier

Thanks a lot Castiel, that was it.

In the ogs script, I was overwritting a column (hence with correct size)
In script window, the output column was empty.

dist.SetSize(iSize + 1);


and everything works



Right, iSize + 1 is enough.


                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000