OpenCPN Partial API docs
Loading...
Searching...
No Matches
georef.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: OpenCPN Georef utility
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25
26 ***************************************************************************
27 * Parts of this file were adapted from source code found in *
28 * John F. Waers (jfwaers@csn.net) public domain program MacGPS45 *
29 ***************************************************************************
30
31 */
32
33#ifndef _GEOREF_H__
34#define _GEOREF_H__
35
36#include <stdio.h>
37#include <string.h>
38#include <ctype.h>
39
40//------------------------
41struct DATUM {
42 const char *name;
43 short ellipsoid;
44 double dx;
45 double dy;
46 double dz;
47};
48
49struct ELLIPSOID {
50 const char *name; // name of ellipsoid
51 double a; // semi-major axis, meters
52 double invf; // 1/f
53};
54
55struct GeoRef {
56 int status;
57 int count;
58 int order;
59 double *tx;
60 double *ty;
61 double *lon;
62 double *lat;
63 double *pwx;
64 double *pwy;
65 double *wpx;
66 double *wpy;
67 int txmax;
68 int tymax;
69 int txmin;
70 int tymin;
71 double lonmax;
72 double lonmin;
73 double latmax;
74 double latmin;
75};
76
77#ifndef PI
78#define PI 3.1415926535897931160E0 /* pi */
79#endif
80#define DEGREE (PI / 180.0)
81#define RADIAN (180.0 / PI)
82
83#define DATUM_INDEX_WGS84 101
84#define DATUM_INDEX_UNKNOWN -1
85
86static const double WGS84_semimajor_axis_meters =
87 6378137.0; // WGS84 semimajor axis
88static const double mercator_k0 = 0.9996;
89static const double WGSinvf = 298.257223563; /* WGS84 1/f */
90
91void datumParams(short datum, double *a, double *es);
92
93// Make these conversion routines useable by C or C++
94
95#ifdef __cplusplus
96extern "C" void toDMS(double a, char *bufp, int bufplen);
97extern "C" void toDMM(double a, char *bufp, int bufplen);
98extern "C" void todmm(int flag, double a, char *bufp, int bufplen);
99
100extern "C" void toTM(float lat, float lon, float lat0, float lon0, double *x,
101 double *y);
102extern "C" void fromTM(double x, double y, double lat0, double lon0,
103 double *lat, double *lon);
104
105extern "C" void toSM(double lat, double lon, double lat0, double lon0,
106 double *x, double *y);
107extern "C" double toSMcache_y30(double lat0);
108extern "C" void toSMcache(double lat, double lon, double y30, double lon0,
109 double *x, double *y);
110extern "C" void fromSM(double x, double y, double lat0, double lon0,
111 double *lat, double *lon);
112extern "C" void fromSMR(double x, double y, double lat0, double lon0,
113 double axis_meters, double *lat, double *lon);
114
115extern "C" void toSM_ECC(double lat, double lon, double lat0, double lon0,
116 double *x, double *y);
117extern "C" void fromSM_ECC(double x, double y, double lat0, double lon0,
118 double *lat, double *lon);
119
120extern "C" void toPOLY(double lat, double lon, double lat0, double lon0,
121 double *x, double *y);
122extern "C" void fromPOLY(double x, double y, double lat0, double lon0,
123 double *lat, double *lon);
124
125extern "C" void cache_phi0(double lat0, double *sin_phi0, double *cos_phi0);
126
127extern "C" void toORTHO(double lat, double lon, double sin_phi0,
128 double cos_phi0, double lon0, double *x, double *y);
129extern "C" void fromORTHO(double x, double y, double lat0, double lon0,
130 double *lat, double *lon);
131
132extern "C" double toPOLARcache_e(double lat0);
133extern "C" void toPOLAR(double lat, double lon, double e, double lat0,
134 double lon0, double *x, double *y);
135extern "C" void fromPOLAR(double x, double y, double lat0, double lon0,
136 double *lat, double *lon);
137
138extern "C" void toSTEREO(double lat, double lon, double sin_phi0,
139 double cos_phi0, double lon0, double *x, double *y);
140extern "C" void fromSTEREO(double x, double y, double lat0, double lon0,
141 double *lat, double *lon);
142
143extern "C" void toGNO(double lat, double lon, double sin_phi0, double cos_phi0,
144 double lon0, double *x, double *y);
145extern "C" void fromGNO(double x, double y, double lat0, double lon0,
146 double *lat, double *lon);
147
148extern "C" void toEQUIRECT(double lat, double lon, double lat0, double lon0,
149 double *x, double *y);
150extern "C" void fromEQUIRECT(double x, double y, double lat0, double lon0,
151 double *lat, double *lon);
152
154extern "C" void ll_gc_ll(double lat, double lon, double crs, double dist,
155 double *dlat, double *dlon);
156extern "C" void ll_gc_ll_reverse(double lat1, double lon1, double lat2,
157 double lon2, double *bearing, double *dist);
158
159extern "C" void PositionBearingDistanceMercator(double lat, double lon,
160 double brg, double dist,
161 double *dlat, double *dlon);
162extern "C" double DistGreatCircle(double slat, double slon, double dlat,
163 double dlon);
164extern "C" double DistLoxodrome(double slat, double slon, double dlat,
165 double dlon);
166
167extern "C" int GetDatumIndex(const char *str);
168extern "C" void MolodenskyTransform(double lat, double lon, double *to_lat,
169 double *to_lon, int from_datum_index,
170 int to_datum_index);
171
172extern "C" void DistanceBearingMercator(double lat1, double lon1, double lat0,
173 double lon0, double *brg, double *dist);
174
175extern "C" int Georef_Calculate_Coefficients(struct GeoRef *cp, int nlin_lon);
176extern "C" int Georef_Calculate_Coefficients_Proj(struct GeoRef *cp);
177extern "C" double lat_gc_crosses_meridian(double lat1, double lon1, double lat2,
178 double lon2, double lon);
179extern "C" double lat_rl_crosses_meridian(double lat1, double lon1, double lat2,
180 double lon2, double lon);
181
182#else
183void toDMS(double a, char *bufp, int bufplen);
184void toDMM(double a, char *bufp, int bufplen);
185int GetDatumIndex(const char *str);
186void MolodenskyTransform(double lat, double lon, double *to_lat, double *to_lon,
187 int from_datum_index, int to_datum_index);
188double lat_gc_crosses_meridian(double lat1, double lon1, double lat2,
189 double lon2, double lon);
190double lat_rl_crosses_meridian(double lat1, double lon1, double lat2,
191 double lon2, double lon);
192
193#endif
194
195//--------------------
196
197/*
198 * lmfit
199 *
200 * Solves or minimizes the sum of squares of m nonlinear
201 * functions of n variables.
202 *
203 * From public domain Fortran version
204 * of Argonne National Laboratories MINPACK
205 * argonne national laboratory. minpack project. march 1980.
206 * burton s. garbow, kenneth e. hillstrom, jorge j. more
207 * C translation by Steve Moshier
208 * Joachim Wuttke converted the source into C++ compatible ANSI style
209 * and provided a simplified interface
210 */
211
212// parameters for calling the high-level interface lmfit
213// ( lmfit.c provides lm_initialize_control which sets default values ):
214typedef struct {
215 double ftol; // relative error desired in the sum of squares.
216 double xtol; // relative error between last two approximations.
217 double gtol; // orthogonality desired between fvec and its derivs.
218 double epsilon; // step used to calculate the jacobian.
219 double stepbound; // initial bound to steps in the outer loop.
220 double fnorm; // norm of the residue vector fvec.
221 int maxcall; // maximum number of iterations.
222 int nfev; // actual number of iterations.
223 int info; // status of minimization.
225
226// the subroutine that calculates fvec:
227typedef void(lm_evaluate_ftype)(double *par, int m_dat, double *fvec,
228 void *data, int *info);
229// default implementation therof, provided by lm_eval.c:
230void lm_evaluate_default(double *par, int m_dat, double *fvec, void *data,
231 int *info);
232
233// the subroutine that informs about fit progress:
234typedef void(lm_print_ftype)(int n_par, double *par, int m_dat, double *fvec,
235 void *data, int iflag, int iter, int nfev);
236// default implementation therof, provided by lm_eval.c:
237void lm_print_default(int n_par, double *par, int m_dat, double *fvec,
238 void *data, int iflag, int iter, int nfev);
239
240// compact high-level interface:
241void lm_initialize_control(lm_control_type *control);
242void lm_minimize(int m_dat, int n_par, double *par, lm_evaluate_ftype *evaluate,
243 lm_print_ftype *printout, void *data,
244 lm_control_type *control);
245double lm_enorm(int, double *);
246
247// low-level interface for full control:
248void lm_lmdif(int m, int n, double *x, double *fvec, double ftol, double xtol,
249 double gtol, int maxfev, double epsfcn, double *diag, int mode,
250 double factor, int *info, int *nfev, double *fjac, int *ipvt,
251 double *qtf, double *wa1, double *wa2, double *wa3, double *wa4,
252 lm_evaluate_ftype *evaluate, lm_print_ftype *printout,
253 void *data);
254
255#ifndef _LMDIF
256extern const char *lm_infmsg[];
257extern const char *lm_shortmsg[];
258#endif
259
260// This is an opaque (to lmfit) structure set up before the call to lmfit()
261typedef struct {
262 double *user_tx;
263 double *user_ty;
264 double *user_y;
265 double (*user_func)(double user_tx_point, double user_ty_point, int n_par,
266 double *par);
267 int print_flag;
268 int n_par;
270
271#endif // guard
Definition: georef.h:41
Definition: georef.h:55