11/*
22Name: geofindkey.c
33OldName: findkey.c
4- Version: 2.5
5- Date: 2021-10-10
4+ Version: 2.6
5+ Date: 2021-11-09
66Author: Игорь Белов (https://gis-lab.info/forum/memberlist.php?mode=viewprofile&u=10457)
77Author: zvezdochiot (https://github.com/zvezdochiot)
88Author: Zoltan Siki (https://github.com/zsiki)
@@ -22,7 +22,8 @@ input file doc/data.dat:
2222*
2323output file report.dat:
2424*
25- key(normal):
25+ key:
26+ (NORM)
2627--0-----
272882135.4073
282947128.1437
@@ -49,10 +50,14 @@ key(normal):
4950#include <stdio.h>
5051#include <stdlib.h>
5152#include <math.h>
53+ #include <string.h>
5254#include <unistd.h>
5355
5456#define PNAME "GeoFindKey"
55- #define PVERSION "2.5"
57+ #define PVERSION "2.6"
58+
59+ #define defMScale "NORM"
60+ #define defREarth 6370009.0
5661
5762void geofindkeytitle ()
5863{
@@ -64,7 +69,8 @@ void geofindkeyusage()
6469 fprintf (stderr , "usage: geofindkey [option] input-file report-file\n" );
6570 fprintf (stderr , "options:\n" );
6671 fprintf (stderr , " -d N decimal after comma, default=4\n" );
67- fprintf (stderr , " -r rescale mode (bool, optional, default = false)\n" );
72+ fprintf (stderr , " -m str rescale mode {NORM,EQUAL,EARCH}, default=NORM\n" );
73+ fprintf (stderr , " -r N.N radius Earth, default=6370009.0\n" );
6874 fprintf (stderr , " -h this help\n" );
6975 fprintf (stderr , "\n" );
7076 fprintf (stderr , "input-file(sample):\n" );
@@ -79,7 +85,7 @@ void geofindkeyusage()
7985 fprintf (stderr , "\n" );
8086 fprintf (stderr , "report-file(sample):\n" );
8187 fprintf (stderr , " key:\n" );
82- fprintf (stderr , " (normal )\n" );
88+ fprintf (stderr , " (NORM )\n" );
8389 fprintf (stderr , " --0-----\n" );
8490 fprintf (stderr , " 82135.4073\n" );
8591 fprintf (stderr , " 47128.1437\n" );
@@ -106,6 +112,17 @@ void geofindkeyusage()
106112 fprintf (stderr , " 0.0269 0.0248 0.0115 0.0003672639 0.0292\n" );
107113}
108114
115+ int IndexMScale (char * mscale )
116+ {
117+ if (!strcmp (mscale ,"NORM" ))
118+ return 0 ;
119+ if (!strcmp (mscale ,"EQUAL" ))
120+ return 1 ;
121+ if (!strcmp (mscale ,"EARTH" ))
122+ return 2 ;
123+ return 0 ;
124+ }
125+
109126int main (int argc , char * argv [])
110127{
111128 char buf [1024 ], name [32 ], format5 [128 ], format7 [128 ], format13 [128 ];
@@ -118,18 +135,24 @@ int main(int argc, char *argv[])
118135 FILE * fp0 , * fp1 ;
119136
120137 int opt ;
138+ char * mscale ;
121139 int decimals = 4 ; /* number of decimals in the calculated coordinates */
140+ double RE = defREarth ;
122141 int frescale = 0 ;
142+ mscale = defMScale ;
123143 int fhelp = 0 ;
124- while ((opt = getopt (argc , argv , "d:rh " )) != -1 )
144+ while ((opt = getopt (argc , argv , "d:m:r:h " )) != -1 )
125145 {
126146 switch (opt )
127147 {
128148 case 'd' :
129149 decimals = atoi (optarg );
130150 break ;
151+ case 'm' :
152+ mscale = optarg ;
153+ break ;
131154 case 'r' :
132- frescale = 1 ;
155+ RE = atof ( optarg ) ;
133156 break ;
134157 case 'h' :
135158 fhelp = 1 ;
@@ -163,6 +186,9 @@ int main(int argc, char *argv[])
163186 exit (EXIT_FAILURE );
164187 }
165188
189+ frescale = IndexMScale (mscale );
190+ if (frescale == 0 ) mscale = defMScale ;
191+
166192 /* подсчитать сумму координат */
167193 n = 0 ;
168194 for (i = 0 ; i < 8 ; i ++ ) {s [i ] = 0.0 ;}
@@ -264,12 +290,25 @@ int main(int argc, char *argv[])
264290 /* найти вторичные параметры */
265291 scale = hypot (a [1 ][0 ], a [1 ][1 ]);
266292 rotation = atan2 (a [1 ][1 ], a [1 ][0 ]);
267- if (frescale > 0 && scale != 0.0 )
293+
294+ if (frescale > 0 )
268295 {
269- a [1 ][0 ] /= scale ;
270- a [1 ][1 ] /= scale ;
271- a [1 ][2 ] = 1.0 ;
296+ if (scale > 0.0 )
297+ {
298+ a [1 ][0 ] /= scale ;
299+ a [1 ][1 ] /= scale ;
300+ }
301+ a [1 ][2 ] = 1.0 ;
302+ if (frescale > 1 )
303+ {
304+ if (RE > 0.0 )
305+ {
306+ a [1 ][0 ] *= (1.0 - yc [2 ] / RE );
307+ a [1 ][1 ] *= (1.0 - yc [2 ] / RE );
308+ }
309+ }
272310 }
311+
273312 a [0 ][0 ] = yc [0 ] - a [1 ][0 ] * xc [0 ] + a [1 ][1 ] * xc [1 ];
274313 a [0 ][1 ] = yc [1 ] - a [1 ][1 ] * xc [0 ] - a [1 ][0 ] * xc [1 ];
275314 a [0 ][2 ] = yc [2 ] - a [1 ][2 ] * xc [2 ];
@@ -281,12 +320,7 @@ int main(int argc, char *argv[])
281320 exit (EXIT_FAILURE );
282321 }
283322 fprintf (fp1 , "key:\n" );
284- if (frescale > 0 )
285- {
286- fprintf (fp1 , "(rescale)\n" );
287- } else {
288- fprintf (fp1 , "(normal)\n" );
289- }
323+ fprintf (fp1 , "(%s)\n" , mscale );
290324 fprintf (fp1 , "--0-----\n" );
291325 fprintf (fp1 , "%.4f\n" , a [0 ][0 ]);
292326 fprintf (fp1 , "%.4f\n" , a [0 ][1 ]);
0 commit comments