-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 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 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,46 @@ | ||
## Description ############################################################################# | ||
# | ||
# Implement the copy for the structures related to the SGP4 propagator. | ||
# | ||
############################################################################################ | ||
|
||
# Define the copy function for the structure `Sgp4DeepSpace`. | ||
@generated function Base.copy(sgp4ds::Sgp4DeepSpace{T}) where T<:Number | ||
fields = fieldnames(sgp4ds) | ||
|
||
expressions = Expr[:(new_sgp4ds = Sgp4DeepSpace{$T}())] | ||
sizehint!(expressions, length(fields) + 1) | ||
|
||
@inbounds for f in fields | ||
push!(expressions, :(new_sgp4ds.$f = sgp4ds.$f)) | ||
end | ||
|
||
return :( | ||
$(expressions...); | ||
return new_sgp4ds | ||
) | ||
end | ||
|
||
# Define the copy function for the structure `Sgp4Propagator`. | ||
@generated function Base.copy( | ||
sgp4d::Sgp4Propagator{Tepoch, T} | ||
) where {Tepoch<:Number, T<:Number} | ||
fields = fieldnames(sgp4d) | ||
|
||
expressions = Expr[:(new_sgp4d = Sgp4Propagator{$Tepoch, $T}())] | ||
sizehint!(expressions, length(fields) + 1) | ||
|
||
@inbounds for f in fields | ||
if f != :sgp4ds | ||
push!(expressions, :(new_sgp4d.$f = sgp4d.$f)) | ||
else | ||
# `sgp4ds` is the only mutable element inside this structure. | ||
push!(expressions, :(new_sgp4d.$f = copy(sgp4d.$f))) | ||
end | ||
end | ||
|
||
return :( | ||
$(expressions...); | ||
return new_sgp4d | ||
) | ||
end |
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 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,43 @@ | ||
## Description ############################################################################# | ||
# | ||
# Test structure copying. | ||
# | ||
############################################################################################ | ||
|
||
@testset "Sgp4Propagator and Spg4DeepSpace" begin | ||
for sgp4c in (sgp4c_wgs84, sgp4c_wgs84_f32) | ||
|
||
sgp4d = sgp4_init( | ||
tle""" | ||
1 24208U 96044A 06177.04061740 -.00000094 00000-0 10000-3 0 1600 | ||
2 24208 3.8536 80.0121 0026640 311.0977 48.3000 1.00778054 36119 | ||
"""; | ||
sgp4c = sgp4c | ||
) | ||
|
||
# We need to propagate the orbit to initialize all the internal terms related to the | ||
# deep space structure. | ||
sgp4!(sgp4d, 0) | ||
|
||
new_sgp4d = copy(sgp4d) | ||
|
||
@test typeof(new_sgp4d) == typeof(sgp4d) | ||
|
||
for f in fieldnames(typeof(sgp4d)) | ||
if f != :sgp4ds | ||
@test getfield(new_sgp4d, f) == getfield(sgp4d, f) | ||
end | ||
end | ||
|
||
for f in fieldnames(typeof(sgp4d.sgp4ds)) | ||
@test getfield(new_sgp4d.sgp4ds, f) == getfield(sgp4d.sgp4ds, f) | ||
end | ||
|
||
# Test if both structures does not share the same memory region. | ||
new_sgp4d.epoch = 100 | ||
@test new_sgp4d.epoch != sgp4d.epoch | ||
|
||
new_sgp4d.sgp4ds.atime = 123 | ||
@test new_sgp4d.sgp4ds.atime != sgp4d.sgp4ds.atime | ||
end | ||
end |
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