-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_ecef_from_wgs84.f90
48 lines (42 loc) · 1.53 KB
/
get_ecef_from_wgs84.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# include "fortran_lib.h"
program runner
USE_FORTRAN_LIB_H
use, intrinsic:: iso_fortran_env, only: INPUT_UNIT, OUTPUT_UNIT, ERROR_UNIT, REAL128
use, non_intrinsic:: character_lib, only: str, s
use, non_intrinsic:: geodetic_lib, only: ecef_from_wgs84
implicit none
Real(kind = REAL128):: lon, lat, h
Integer:: ios
Character(len = 2**7):: format
if(command_argument_count() >= 1)then
write(OUTPUT_UNIT, *) 'Read lon-lat-height data from stdin and return x-y-z data to stdout.'
write(OUTPUT_UNIT, *) 'Note that order is lon-lat, not lat-lon.'
write(OUTPUT_UNIT, *) 'STDIN:'
write(OUTPUT_UNIT, *) ' lon, lat, height: Coordinates in WGS84 (deg, deg, m).'
write(OUTPUT_UNIT, *) 'STDOUT:'
write(OUTPUT_UNIT, *) ' x, y, z: Coordinates in ECEF (m, m, m).'
write(OUTPUT_UNIT, *) 'EXAMPLE:'
write(OUTPUT_UNIT, *)
write(OUTPUT_UNIT, *) 'cat <<EOF | get_ecef_from_wgs84.exe'
write(OUTPUT_UNIT, *) '32.2 32.1 239812'
write(OUTPUT_UNIT, *) '-122.2 -32 12470978'
write(OUTPUT_UNIT, *) 'EOF'
write(OUTPUT_UNIT, *)
stop
end if
format = '(3g' // str(precision(lon) + 9) // '.' // str(precision(lon)) // ')'
do
read(INPUT_UNIT, *, iostat = ios) lon, lat, h
select case(ios)
case(:-2)
ERROR('Must not happen')
case(-1) ! EOF
exit
case(0)
write(OUTPUT_UNIT, s(format)) ecef_from_wgs84(lon, lat, h)
case(1:)
ERROR('Bad input')
end select
end do
stop
end program runner