11/*
22Name: geodeform500.c
3- Version: 2.8
4- Date: 2021-12-15
3+ Version: 2.9
4+ Date: 2021-12-19
55Author: zvezdochiot (https://github.com/zvezdochiot)
66*
77build:
@@ -30,6 +30,8 @@ C* 2748.808 5314.058 109.855
3030*
3131output file gpsout.dat:
3232*
33+ Mean: 3
34+ M 2508.9040 5588.8650 124.2887 2508.7340 5589.0163 124.5183
3335Deformation coordinate base: 3
3436(CONST)
3537A 2303.4430 5622.9030 149.3070 2302.8540 5623.2230 148.8560
@@ -57,7 +59,7 @@ C* 2748.8080 5314.0580 109.8550 2749.1000 5314.5570 110.5850
5759#include <unistd.h>
5860
5961#define PNAME "GeoDeform500"
60- #define PVERSION "2.8 "
62+ #define PVERSION "2.9 "
6163
6264#define defEps 0.000001
6365#define defMode "CONST"
@@ -94,6 +96,8 @@ void geodeform500usage()
9496 fprintf (stderr , " C* 2748.808 5314.058 109.855\n" );
9597 fprintf (stderr , "\n" );
9698 fprintf (stderr , "report-file(sample):\n" );
99+ fprintf (stderr , " Mean: 3\n" );
100+ fprintf (stderr , " M 2508.9040 5588.8650 124.2887 2508.7340 5589.0163 124.5183\n" );
97101 fprintf (stderr , " Deformation coordinate base: 3\n" );
98102 fprintf (stderr , " (CONST)\n" );
99103 fprintf (stderr , " A 2303.4430 5622.9030 149.3070 2302.8540 5623.2230 148.8560\n" );
@@ -116,7 +120,7 @@ void geodeform500usage()
116120int main (int argc , char * argv [])
117121{
118122 char buf [1024 ], name [32 ], format4 [128 ], format7 [128 ];
119- double x [3 ], y [3 ], wgt , dy [3 ];
123+ double x [3 ], y [3 ], xcp [ 3 ], ycp [ 3 ], wgt , dy [3 ];
120124 double xd [1500 ], dxd [1500 ], r2 , r2d [500 ], w [500 ], s ;
121125 unsigned n , i , j , k ;
122126 int np ;
@@ -175,6 +179,39 @@ int main(int argc, char *argv[])
175179 exit (EXIT_FAILURE );
176180 }
177181
182+ for (j = 0 ; j < 3 ; j ++ )
183+ {
184+ xcp [j ] = 0.0 ;
185+ ycp [j ] = 0.0 ;
186+ }
187+ n = 0 ;
188+ s = 0 ;
189+ while (fgets (buf , 1024 , fp0 ) != NULL )
190+ {
191+ np = sscanf (buf , "%s %lf %lf %lf %lf %lf %lf %lf" , name , & x [0 ], & x [1 ], & x [2 ], & y [0 ], & y [1 ], & y [2 ], & wgt );
192+ if (np >= 8 )
193+ {
194+ for (i = 0 ; i < 3 ; i ++ )
195+ {
196+ xcp [i ] += (x [i ] * wgt );
197+ ycp [i ] += (y [i ] * wgt );
198+ }
199+ s += wgt ;
200+ n ++ ;
201+ }
202+ }
203+ if (s > 0.0 )
204+ {
205+ for (j = 0 ; j < 3 ; j ++ )
206+ {
207+ xcp [j ] /= s ;
208+ ycp [j ] /= s ;
209+ }
210+ }
211+ fprintf (fp1 , "Mean: %d\n" , n );
212+ fprintf (fp1 , format7 , "M" , xcp [0 ], xcp [1 ], xcp [2 ], ycp [0 ], ycp [1 ], ycp [2 ]);
213+ rewind (fp0 );
214+
178215 n = 0 ;
179216 for (j = 0 ; j < 1500 ; j ++ )
180217 {
@@ -192,7 +229,7 @@ int main(int argc, char *argv[])
192229 for (i = 0 ; i < 3 ; i ++ )
193230 {
194231 xd [j + i ] = x [i ];
195- dxd [j + i ] = y [i ] - x [i ];
232+ dxd [j + i ] = ( y [i ] - ycp [ i ]) - ( x [i ] - xcp [ i ]) ;
196233 r2 += (dxd [i + j ] * dxd [i + j ]);
197234 }
198235 r2d [n ] = r2 * wgt ;
@@ -210,7 +247,7 @@ int main(int argc, char *argv[])
210247 np = sscanf (buf , "%s %lf %lf %lf %lf %lf %lf %lf" , name , & x [0 ], & x [1 ], & x [2 ], & y [0 ], & y [1 ], & y [2 ], & wgt );
211248 if (np >= 4 )
212249 {
213- s = 0 ;
250+ s = 0.0 ;
214251 for (i = 0 ; i < n ; i ++ )
215252 {
216253 if (r2d [i ] >= 0.0 )
@@ -233,7 +270,7 @@ int main(int argc, char *argv[])
233270 w [i ] = 0.0 ;
234271 }
235272 }
236- if (s > 0 )
273+ if (s > 0.0 )
237274 {
238275 s = 1.0 / s ;
239276 for (i = 0 ; i < n ; i ++ )
@@ -249,7 +286,7 @@ int main(int argc, char *argv[])
249286 dy [i ] += dxd [k ] * w [j ];
250287 k += 3 ;
251288 }
252- y [i ] = x [i ] + dy [i ];
289+ y [i ] = x [i ] + dy [i ] + ( ycp [ i ] - xcp [ i ]) ;
253290 }
254291 }
255292 else
0 commit comments