This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use gomobile to build native libraries
- Loading branch information
Showing
16 changed files
with
194 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package geomag | ||
|
||
//go:generate bash -c "if [ ! -d libs ]; then mkdir libs; fi" | ||
//go:generate gomobile bind -target android -androidapi 26 -javapkg go -trimpath -v -o libs/geomag.aar | ||
|
||
import ( | ||
"github.com/proway2/go-igrf/igrf" | ||
"github.com/westphae/geomag/pkg/egm96" | ||
"github.com/westphae/geomag/pkg/wmm" | ||
"time" | ||
) | ||
|
||
//export igrf | ||
func IGRF(lat, lon, alt, date float64) *MagneticField { | ||
data := igrf.New() | ||
mag, _ := data.IGRF(lat, lon, alt, date) | ||
|
||
return newMagneticField( | ||
mag.Declination, | ||
mag.DeclinationSV, | ||
mag.Inclination, | ||
mag.InclinationSV, | ||
mag.HorizontalIntensity, | ||
mag.HorizontalSV, | ||
mag.NorthComponent, | ||
mag.NorthSV, | ||
mag.EastComponent, | ||
mag.EastSV, | ||
mag.VerticalComponent, | ||
mag.VerticalSV, | ||
mag.TotalIntensity, | ||
mag.TotalSV, | ||
) | ||
} | ||
|
||
//export wmm | ||
func WMM(lat, lon, alt, date float64) *MagneticField { | ||
tt := wmm.DecimalYear(date) | ||
loc := egm96.NewLocationGeodetic(lat, lon, alt) | ||
mag, _ := wmm.CalculateWMMMagneticField(loc, tt.ToTime()) | ||
x, y, z, dx, dy, dz := mag.Ellipsoidal() | ||
|
||
return newMagneticField( | ||
mag.D(), | ||
mag.DD(), | ||
mag.I(), | ||
mag.DI(), | ||
mag.H(), | ||
mag.DH(), | ||
x, | ||
dx, | ||
y, | ||
dy, | ||
z, | ||
dz, | ||
mag.F(), | ||
mag.DF(), | ||
) | ||
} | ||
|
||
//export toDecimalYears | ||
func ToDecimalYears(year, month, day, hour, min, sec, nsec int) float64 { | ||
dateTime := time.Date(year, time.Month(month), day, | ||
hour, min, sec, nsec, time.UTC) | ||
|
||
return float64(wmm.TimeToDecimalYears(dateTime)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package geomag | ||
|
||
type MagneticField struct { | ||
Declination float64 | ||
DeclinationSV float64 | ||
Inclination float64 | ||
InclinationSV float64 | ||
HorizontalIntensity float64 | ||
HorizontalSV float64 | ||
NorthComponent float64 | ||
NorthSV float64 | ||
EastComponent float64 | ||
EastSV float64 | ||
VerticalComponent float64 | ||
VerticalSV float64 | ||
TotalIntensity float64 | ||
TotalSV float64 | ||
} | ||
|
||
func newMagneticField( | ||
declination, declinationSV, | ||
inclination, inclinationSV, | ||
horizontalIntensity, horizontalSV, | ||
northComponent, northSV, | ||
eastComponent, eastSV, | ||
verticalComponent, verticalSV, | ||
totalIntensity, totalSV float64, | ||
) *MagneticField { | ||
return &MagneticField{ | ||
Declination: declination, | ||
DeclinationSV: declinationSV, | ||
Inclination: inclination, | ||
InclinationSV: inclinationSV, | ||
HorizontalIntensity: horizontalIntensity, | ||
HorizontalSV: horizontalSV, | ||
NorthComponent: northComponent, | ||
NorthSV: northSV, | ||
EastComponent: eastComponent, | ||
EastSV: eastSV, | ||
VerticalComponent: verticalComponent, | ||
VerticalSV: verticalSV, | ||
TotalIntensity: totalIntensity, | ||
TotalSV: totalSV, | ||
} | ||
} |
Oops, something went wrong.