| Quintiq file version 2.0 | 
| #parent: #root | 
| Function CalcATCFDistance | 
| { | 
|   TextBody: | 
|   [* | 
|     // boon kiat Dec-4-2013 (created) | 
|     /* | 
|     see http://mathworld.wolfram.com/GreatCircle.html | 
|     */ | 
|     value := 0.0; | 
|      | 
|     earthRadius := 6378 | 
|      | 
|     selectedunit := guard( this.Unit().GIS_UnitAddress().GIS_UnitGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) ); | 
|     selectedsp := guard( this.StockingPoint_MP().GIS_StockingPointAddress().GIS_StockingPointGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) ); | 
|      | 
|     if( not ( isnull( selectedunit ) or isnull( selectedsp ) ) ) | 
|     { | 
|      | 
|       unitlat := pi * selectedunit.Y() / 180.0 | 
|       unitlong := pi * selectedunit.X() / 180.0 | 
|       splat := pi * selectedsp.Y() / 180.0 | 
|       splong := pi * selectedsp.X() / 180.0 | 
|      | 
|       theCos := cos( splat ) * cos( unitlat )* cos( splong  - unitlong )  + sin( splat ) * sin ( unitlat ) | 
|      | 
|       // round-off errors. | 
|       // M AF Putting the 1.0 as the first parameter causes trouble, submited rfc | 
|       theCos := maxvalue( theCos,  -1.0 ) | 
|       theCos := minvalue( theCos,  1.0 ) | 
|      | 
|       angle :=  acos( theCos ) | 
|      | 
|       value := angle * earthRadius; | 
|     } | 
|      | 
|     this.ATCFDistance( value ); | 
|   *] | 
| } |