|
62 | 62 | # --------------------------------------------------------------------------------------------------- |
63 | 63 | function gmtconvert_helper(cmd0::String, arg1, d::Dict{Symbol,Any}) |
64 | 64 |
|
65 | | - cmd, = parse_common_opts(d, "", [:V_params :write :append :a :b :bo :d :e :f :g :h :i :o :q :s :w :yx]) |
| 65 | + cmd, = parse_common_opts(d, "", [:V_params :append :a :b :bo :d :e :g :h :i :o :q :s :w :yx]) |
| 66 | + cmd, opt_f = parse_f(d, cmd) # Must have easier acces to opt_f |
| 67 | + |
| 68 | + # GMT is not able to return a converted time table, so we create a temporary file if time conversions are involved |
| 69 | + used_tmp_file = false |
| 70 | + if (contains(opt_f, "-fo") && is_in_dict(d, [:write :savefile :|>]) === nothing) |
| 71 | + s = split(opt_f)[end] |
| 72 | + if (contains(s, 'T') || contains(s, 't')) |
| 73 | + fname = TMPDIR_USR.dir * "/" * "GMTjl_time_" * TMPDIR_USR.username * TMPDIR_USR.pid_suffix * ".txt" |
| 74 | + d[:write] = fname |
| 75 | + used_tmp_file = true |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + cmd = parse_write(d, cmd) |
66 | 80 | cmd = parse_these_opts(cmd, d, [[:A :hcat], [:C :n_records], [:D :dump], [:E :first_last], [:F :conn_method], |
67 | 81 | [:I :invert :reverse], [:L :list_only], [:N :sort], [:Q :segments], [:S :select_hdr], [:T :suppress :skip], [:W :word2num], [:Z :transpose]]) |
68 | 82 |
|
| 83 | + |
69 | 84 | out = common_grd(d, cmd0, cmd, "gmtconvert ", arg1) # Finish build cmd and run it |
70 | | - (!contains(cmd, " -b") && isa(out, GDtype) && cmd0 != "" && guess_T_from_ext(cmd0) == " -Td") && file_has_time!(cmd0, out) # Try to guess if time columns |
| 85 | + if (used_tmp_file) # Read the conversion results and clean up temporary file. |
| 86 | + out = gmtread(fname) |
| 87 | + rm(fname, force=true) |
| 88 | + else |
| 89 | + (!contains(cmd, " -b") && isa(out, GDtype) && cmd0 != "" && guess_T_from_ext(cmd0) == " -Td") && file_has_time!(cmd0, out) # Try to guess if time columns |
| 90 | + end |
71 | 91 | return out |
72 | 92 | end |
0 commit comments