Skip to content

Commit a950c60

Browse files
committed
read comment from netcdf spectra
1 parent 3c0d50a commit a950c60

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/spectrum_functions.jl

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ function expand_range(start::Float64, stop::Float64)::Tuple{Float64,Float64}
2121
end
2222

2323

24+
"""gets comment from spectrum"""
25+
function get_comment(spectrum::SpmSpectrum)::String
26+
comment = ""
27+
28+
# Nanonis files have these numbered comment lines
29+
for i in 1:99
30+
comment_key = (i < 10) ? "Comment0$(i)" : "Comment$(i)"
31+
if haskey(spectrum.header, comment_key)
32+
if i > 1
33+
comment *= "\n"
34+
end
35+
comment *= utf8ify(spectrum.header[comment_key])
36+
else
37+
break
38+
end
39+
end
40+
41+
# GXSM has a special comment field
42+
if haskey(spectrum.header, "GXSM-Main-Comment")
43+
comment *= utf8ify(spectrum.header["GXSM-Main-Comment"])
44+
end
45+
46+
return comment
47+
end
48+
49+
2450
"""Get the units for channel and channel2"""
2551
function get_channel_units(griditem::SpmGridItem, spectrum::SpmSpectrum)::Tuple{String,String}
2652
units = map((griditem.channel_name, griditem.channel2_name)) do c
@@ -554,19 +580,6 @@ function parse_spectrum!(griditems::Dict{String, SpmGridItem}, virtual_copies_di
554580
end
555581
end
556582

557-
comment = ""
558-
for i in 1:99
559-
comment_key = (i < 10) ? "Comment0$(i)" : "Comment$(i)"
560-
if haskey(spectrum.header, comment_key)
561-
if i > 1
562-
comment *= "\n"
563-
end
564-
comment *= utf8ify(spectrum.header[comment_key])
565-
else
566-
break
567-
end
568-
end
569-
570583
if haskey(griditems, id)
571584
griditem = griditems[id]
572585
# still update a few fields (the files may have changed) - but most of these fields should stay unchanged
@@ -581,7 +594,7 @@ function parse_spectrum!(griditems::Dict{String, SpmGridItem}, virtual_copies_di
581594
griditem.z_feedback_setpoint = z_feedback_setpoint
582595
griditem.z_feedback_setpoint_unit = z_feedback_setpoint_unit
583596
griditem.z = spectrum.position[3]
584-
griditem.comment = comment
597+
griditem.comment = get_comment(spectrum)
585598
griditem.status = 0
586599
else
587600
# get the respective image channel (depending on whether the feedback was on or not)
@@ -592,7 +605,7 @@ function parse_spectrum!(griditems::Dict{String, SpmGridItem}, virtual_copies_di
592605
center=spectrum.position .* 1e9, scan_direction=2,
593606
bias=spectrum.bias, z_feedback=spectrum.z_feedback,
594607
z_feedback_setpoint=z_feedback_setpoint, z_feedback_setpoint_unit=z_feedback_setpoint_unit, z=spectrum.position[3],
595-
comment=comment
608+
comment=get_comment(spectrum)
596609
)
597610
if only_new
598611
push!(griditems_new, id)
@@ -618,7 +631,7 @@ function parse_spectrum!(griditems::Dict{String, SpmGridItem}, virtual_copies_di
618631
virtual_copy.z_feedback_setpoint = z_feedback_setpoint
619632
virtual_copy.z_feedback_setpoint_unit = z_feedback_setpoint_unit
620633
virtual_copy.z = spectrum.position[3]
621-
virtual_copy.comment = comment
634+
virtual_copy.comment = get_comment(spectrum)
622635
virtual_copy.status = 0
623636

624637
t = Threads.@spawn create_spectrum!(virtual_copy, spectrum, dir_cache=dir_cache, use_existing=use_existing)

0 commit comments

Comments
 (0)