Skip to content

Commit

Permalink
works now
Browse files Browse the repository at this point in the history
  • Loading branch information
a2ray committed Mar 7, 2024
1 parent 469edf3 commit 69f0ea3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
26 changes: 8 additions & 18 deletions src/CommonToAll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2103,34 +2103,24 @@ function formatasegfield(sfmt::Vector)
return sfmt_fortran
end

function writeasegdfn(vall::Vector, channel_names::Vector, sfmt::Vector, outfile::String)
#Write the definition file

function writeasegdfnfromonerow(vonerow::Vector, channel_names::Vector, sfmt::Vector, outfile::String)
sfmt_fortran = formatasegfield(sfmt)

#Get the lengths of each element in the data vector
record = Array{Int}(undef, length(sfmt))
for i = 1:length(sfmt)
record[i] = length(vall[1][i])
end

open(outfile*".dfn", "w") do io
#println(io, "DEFN ST=RECD,RT=COMM;RT:A4;COMMENTS:A76") #Geosoft

for i=1:length(channel_names[1])
if (length(vall[1][i]) == 1)
println(io, "DEFN $(i) ST=RECD,RT=; $(channel_names[1][i]): $(sfmt_fortran[i]): NULL=-99999.99, UNITS=$(channel_names[2][i]), LONGNAME=$(channel_names[3][i])")
else
println(io, "DEFN $(i) ST=RECD,RT=; $(channel_names[1][i]): $(record[i])$(sfmt_fortran[i]): NULL=-99999.99, UNITS=$(channel_names[2][i]), LONGNAME=$(channel_names[3][i])")
end
for (i, el) in enumerate(vonerow)
pre = isa(el, Array) ? string(length(el)) : ""
println(io, "DEFN $i ST=RECD,RT=; $(channel_names[1][i]): "*pre*"$(sfmt_fortran[i]): NULL=-9999999.99, UNITS=$(channel_names[2][i]), LONGNAME=$(channel_names[3][i])")
end

println(io, "DEFN $(length(channel_names[1])+1) ST=RECD,RT=; END DEFN")
flush(io)
close(io)
end
end

function writeasegdfn(vall::Vector, channel_names::Vector, sfmt::Vector, outfile::String)
writeasegdfnfromonerow(vall[1], channel_names::Vector, sfmt::Vector, outfile::String)
end

function readxyzrhoϕ(linenum::Int, nlayers::Int; pathname="")
# get the rhos
fnameρ = joinpath(pathname, "rho_avg_line_$(linenum)_summary_xyzrho.txt")
Expand Down
4 changes: 2 additions & 2 deletions test/verify_aseggdf_write.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using HiQGA
vall=[[100, 1, [2., 3.]], [100, 2, [3., 4.]]]
sfmt = ["%4i", "%3i", "%4.1f"]
outfile = "myfile"
outfile = "myfile2"
channel_names = [["Line", "FID", "dBzdt"], ["", "","pV/Am4"],["Line", "FID", "dBz/dt"]]
transD_GP.CommonToAll.writeasegdat(vall, sfmt, outfile, channel_names)
transD_GP.CommonToAll.writeasegdat(vall, sfmt, outfile)
transD_GP.CommonToAll.writeasegdfn(vall, channel_names, sfmt, outfile)
6 changes: 3 additions & 3 deletions zz_portalcurtains/RDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ function writeaseggdffromxyzrho(nlayers::Int; src_dir="", dst_dir="",
]
outfile = joinpath(dst_dir, fname*"_EPSG_$src_epsg")
lines = transD_GP.getprobabilisticlinesfromdirectory(src_dir)
map(lines) do ln
map(enumerate(lines)) do (iline, ln)
@info "Doing Line $ln"
X, Y, Z, zall, ρlow, ρmid, ρhigh, ρavg, ϕmean, ϕsdev = transD_GP.readxyzrhoϕ(ln, nlayers; pathname=src_dir)
for i in 1:length(X)
mode = (iline == 1) & (i ==1) ? "w" : "a"
vonerow = [ln, X[i], Y[i], Z[i], zall, -ρhigh[:,i], -ρmid[:,i], -ρlow[:,i], -ρavg[:,i], ϕmean[i], ϕsdev[i]]
mode = i == 1 ? "w" : "a"
transD_GP.CommonToAll.writeasegdat(vonerow, sfmt, outfile, mode)
transD_GP.CommonToAll.writeasegdfn(vonerow, channel_names, sfmt, outfile)
transD_GP.CommonToAll.writeasegdfnfromonerow(vonerow, channel_names, sfmt, outfile)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion zz_portalcurtains/makeaseggdf_from_xyzrho.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includet("RDP.jl")
src_epsg = 28354
nlayers = 52
src_dir = "/Users/anray/Documents/work/projects/largeaem/final_01/summaries_all/AusAEM_03_ERC/2021_ERC_01/summary"
dst_dir = "/Users/anray/Documents/work/projects/curtainstuff/ERC_01_dat"
dst_dir = "/Users/anray/Documents/work/projects/largeaem/final_01/aseggdf/"
parts = split(src_dir,"/")
fname = parts[end-2]*"_"*parts[end-1]
RDP.writeaseggdffromxyzrho(nlayers; src_dir, dst_dir,
Expand Down

0 comments on commit 69f0ea3

Please sign in to comment.