Skip to content

Commit 8a78e36

Browse files
committed
Merge branch 'master' of github.com:sandialabs/SpecUtils
2 parents 0b469de + 92e5bf3 commit 8a78e36

File tree

6 files changed

+110
-6
lines changed

6 files changed

+110
-6
lines changed

SpecUtils/SpecFile.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ class Measurement
614614
*/
615615
float exposure_rate() const;
616616

617+
/** Returns the application specific "tag" character, used by the PCF file format.
618+
Values of '\0' or ' ' generally indicate it is not set.
619+
*/
620+
char pcf_tag() const;
621+
617622
//position_time(): returns the (local, or detector) time of the GPS fix, if
618623
// known. Returns time_point_t{} otherwise.
619624
const time_point_t position_time() const;
@@ -812,6 +817,9 @@ class Measurement
812817

813818
//To set real and live times, see SpecFile::set_live_time(...)
814819

820+
/** Sets the application specific "tag" character, used by the PCF file format. */
821+
void set_pcf_tag( const char tag_char );
822+
815823
/** returns the number of channels in #gamma_counts_.
816824
Note: energy calibration could still be invalid and not have channel energies defined, even
817825
when this returns a non-zero value.
@@ -1133,6 +1141,18 @@ class Measurement
11331141
*/
11341142
float exposure_rate_;
11351143

1144+
/** A application-specific data element used by the PCF format.
1145+
1146+
For the PCF format, the meaning of the 'tag' character is highly overloaded, and can mean,
1147+
among other uses:
1148+
'-' not occupied, and anything else occupied - for RPM data
1149+
'-' use a dashed line when plotting
1150+
'<' Use filled region style when plotting
1151+
'T' Calibration from thorium
1152+
'K' Calibration from potassium
1153+
*/
1154+
char pcf_tag_;
1155+
11361156
/** The #LocationState indicates the position, speed, and/or orientation of the instrument,
11371157
detector, or item being measured. At the moment, only one of these quantities are recorded,
11381158
primarily to reduce complexity since the author hasnt encountered any files that actually

bindings/c/SpecUtils_c.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,22 @@ bool SpecUtils_Measurement_set_start_time_str( SpecUtils_Measurement *instance,
16691669
m->set_start_time( tp );
16701670
}
16711671

1672+
char SpecUtils_Measurement_pcf_tag( const SpecUtils_Measurement * const instance )
1673+
{
1674+
auto m = reinterpret_cast<const SpecUtils::Measurement *>( instance );
1675+
assert( m );
1676+
return m ? m->pcf_tag() : '\0';
1677+
}
1678+
1679+
1680+
void SpecUtils_Measurement_set_pcf_tag( SpecUtils_Measurement *instance,
1681+
const char tag_char )
1682+
{
1683+
auto m = reinterpret_cast<SpecUtils::Measurement *>( instance );
1684+
assert( m );
1685+
if( m )
1686+
m->set_pcf_tag( tag_char );
1687+
}
16721688

16731689
uint32_t SpecUtils_Measurement_number_gamma_channels( const SpecUtils_Measurement * const instance )
16741690
{

bindings/c/SpecUtils_c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ DLLEXPORT bool CALLINGCONVENTION
768768
SpecUtils_Measurement_set_start_time_str( SpecUtils_Measurement *instance,
769769
const char * const start_time_str );
770770

771+
/** Returns the application-specific "tag" characters used by the PCF file format. */
772+
DLLEXPORT char CALLINGCONVENTION
773+
SpecUtils_Measurement_pcf_tag( const SpecUtils_Measurement * const instance );
774+
775+
/** Sets the application-specific "tag" characters used by the PCF file format. */
776+
DLLEXPORT void CALLINGCONVENTION
777+
SpecUtils_Measurement_set_pcf_tag( SpecUtils_Measurement *instance,
778+
const char tag_char );
771779

772780
DLLEXPORT uint32_t CALLINGCONVENTION
773781
SpecUtils_Measurement_number_gamma_channels( const SpecUtils_Measurement * const instance );

src/SpecFile.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ void Measurement::reset()
15911591

15921592
dose_rate_ = exposure_rate_ = -1.0f;
15931593

1594+
pcf_tag_ = '\0';
1595+
15941596
location_.reset();
15951597
}//void reset()
15961598

@@ -1621,6 +1623,18 @@ float Measurement::exposure_rate() const
16211623
{
16221624
return exposure_rate_;
16231625
}
1626+
1627+
1628+
char Measurement::pcf_tag() const
1629+
{
1630+
return pcf_tag_;
1631+
}
1632+
1633+
1634+
void Measurement::set_pcf_tag( const char tag_char )
1635+
{
1636+
pcf_tag_ = tag_char;
1637+
}
16241638

16251639

16261640
void Measurement::combine_gamma_channels( const size_t ncombine )
@@ -3548,6 +3562,12 @@ void Measurement::equal_enough( const Measurement &lhs, const Measurement &rhs )
35483562
+ " while RHS is " + std::to_string(rhs.exposure_rate_) );
35493563
}
35503564

3565+
if( lhs.pcf_tag_ != rhs.pcf_tag_ )
3566+
{
3567+
issues.push_back( string("Measurement: The PCF tag of LHS is ") + lhs.pcf_tag_
3568+
+ " while RHS is " + std::to_string(rhs.pcf_tag_) );
3569+
}
3570+
35513571
if( (!lhs.location_) != (!rhs.location_) )
35523572
{
35533573
issues.push_back( "Measurement: The "
@@ -4402,6 +4422,8 @@ const Measurement &Measurement::operator=( const Measurement &rhs )
44024422
dose_rate_ = rhs.dose_rate_;
44034423
exposure_rate_ = rhs.exposure_rate_;
44044424

4425+
pcf_tag_ = rhs.pcf_tag_;
4426+
44054427
location_ = rhs.location_;
44064428

44074429
return *this;
@@ -7830,6 +7852,9 @@ std::shared_ptr<Measurement> SpecFile::sum_measurements( const std::set<int> &sa
78307852
dataH->exposure_rate_ += meas->exposure_rate_;
78317853
}//if( meas->dose_rate_ >= 0.0f )
78327854

7855+
if( meas->pcf_tag_ != '\0' )
7856+
dataH->pcf_tag_ = meas->pcf_tag_;
7857+
78337858
if( meas->has_gps_info() )
78347859
{
78357860
num_gps += 1;

src/SpecFile_n42.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,14 @@ void add_spectra_to_measurement_node_in_2012_N42_xml( ::rapidxml::xml_node<char>
12521252
Spectrum->append_node( remark );
12531253
}
12541254

1255+
if( m->pcf_tag() != '\0' )
1256+
{
1257+
const string tag_remark = string("Tag: ") + m->pcf_tag();
1258+
val = doc->allocate_string( tag_remark.c_str(), tag_remark.size()+1 );
1259+
xml_node<char> *remark = doc->allocate_node( node_element, "Remark", val );
1260+
Spectrum->append_node( remark );
1261+
}//
1262+
12551263
const std::vector<std::string> &remarks = m->remarks();
12561264
for( size_t i = 0; i < remarks.size(); ++i )
12571265
{
@@ -1331,6 +1339,14 @@ void add_spectra_to_measurement_node_in_2012_N42_xml( ::rapidxml::xml_node<char>
13311339
GrossCounts->append_node( remark );
13321340
}//if( m->title_.size() )
13331341

1342+
if( m->pcf_tag() != '\0' )
1343+
{
1344+
const string tag_remark = string("Tag: ") + m->pcf_tag();
1345+
val = doc->allocate_string( tag_remark.c_str(), tag_remark.size()+1 );
1346+
xml_node<char> *remark = doc->allocate_node( node_element, "Remark", val );
1347+
GrossCounts->append_node( remark );
1348+
}//
1349+
13341350
const auto &remarks = m->remarks();
13351351
for( size_t i = 0; i < remarks.size(); ++i )
13361352
{
@@ -2603,6 +2619,13 @@ struct N42DecodeHelper2006
26032619
meas.title_ = remark;
26042620
continue;
26052621
}
2622+
2623+
if( SpecUtils::istarts_with( remark, "Tag:") )
2624+
{
2625+
const string tag_str = SpecUtils::trim_copy( remark.substr(4) );
2626+
meas.pcf_tag_ = tag_str.empty() ? '\0' : tag_str[0];
2627+
continue;
2628+
}
26062629

26072630
meas.remarks_.push_back( remark );
26082631

@@ -3615,6 +3638,10 @@ struct N42DecodeHelper2012
36153638
rel_loc->from_cartesian( dx, dy, dz );
36163639
}
36173640
*/
3641+
}else if( SpecUtils::istarts_with( remark, "Tag:") )
3642+
{
3643+
const string tag_str = SpecUtils::trim_copy( remark.substr(4) );
3644+
meas->pcf_tag_ = tag_str.empty() ? '\0' : tag_str[0];
36183645
}else if( remark.size() )
36193646
{
36203647
meas->remarks_.emplace_back( std::move(remark) );
@@ -4008,6 +4035,11 @@ struct N42DecodeHelper2012
40084035
{
40094036
//See notes in equivalent portion of code for the <Spectrum> tag
40104037
meas->title_ += SpecUtils::trim_copy( remark.substr(6) );
4038+
}else if( SpecUtils::istarts_with( remark, "Tag:") )
4039+
{
4040+
//See notes in equivalent portion of code for the <Spectrum> tag
4041+
const string tag_str = SpecUtils::trim_copy( remark.substr(4) );
4042+
meas->pcf_tag_ = tag_str.empty() ? '\0' : tag_str.front();
40114043
}else if( !remark.empty() )
40124044
{
40134045
meas->remarks_.push_back( remark );
@@ -9293,6 +9325,9 @@ namespace SpecUtils
92939325
if( title_.size() )
92949326
remarks.push_back( "Title: " + title_ );
92959327

9328+
if( pcf_tag_ != '\0' )
9329+
remarks.push_back( string("Tag: ") + pcf_tag_ );
9330+
92969331
bool wroteSurvey = false, wroteName = false, wroteSpeed = false;
92979332

92989333
for( size_t i = 0; i < remarks_.size(); ++i )

src/SpecFile_pcf.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ bool SpecFile::write_pcf( std::ostream &outputstrm ) const
751751
string spectrum_title; //ex: 'Survey 1 Det=Aa1 Background @250cm'
752752
string collection_time; //Formatted like: '2010-02-24T00:08:24.82Z'
753753

754-
char character_tag;
755754
float live_time, true_time, halflife = 0.0, molecular_weight = 0.0,
756755
spectrum_multiplier = 0.0, offset, gain, quadratic, cubic, low_energy,
757756
neutron_counts;
@@ -959,18 +958,18 @@ bool SpecFile::write_pcf( std::ostream &outputstrm ) const
959958
else
960959
collection_time = " "; //"01-Jan-1900 00:00:00.00"; //23 characters
961960

962-
character_tag = ' ';
961+
char character_tag = meas->pcf_tag();
963962

964963
//From phone conversation with Dean 20170816:
965964
// The meaning of the 'tag' character is highly overloaded, and can mean,
966-
// among other usses:
965+
// among other uses:
967966
// '-' not occupied, and anything else occupied - for RPM data
968967
// '-' use a dashed line when plotting
969968
// '<' Use filled region style when plotting
970969
// 'T' Calibration from thorium
971-
// 'K' Calibration from potasium
970+
// 'K' Calibration from potassium
972971

973-
if( passthrough() )
972+
if( ((character_tag == '\0') || (character_tag == ' ')) && passthrough() )
974973
{
975974
if( (meas->occupied() == OccupancyStatus::NotOccupied)
976975
&& (meas->source_type() != SourceType::Background) )
@@ -1693,6 +1692,7 @@ bool SpecFile::load_from_pcf( std::istream &input )
16931692
if( !source_list.empty() )
16941693
meas->remarks_.push_back( "Source: " + source_list );
16951694

1695+
meas->pcf_tag_ = character_tag;
16961696
if( character_tag == '-' )
16971697
{
16981698
meas->occupied_ = OccupancyStatus::NotOccupied;
@@ -1702,7 +1702,7 @@ bool SpecFile::load_from_pcf( std::istream &input )
17021702
meas->occupied_ = OccupancyStatus::Occupied;
17031703

17041704
//Background spectra should not have the tag character be a dash, as the
1705-
// tag chacter could indicate calibration isotope.
1705+
// tag character could indicate calibration isotope.
17061706
if( meas->source_type_ == SourceType::Background )
17071707
meas->occupied_ = OccupancyStatus::NotOccupied;
17081708
}else

0 commit comments

Comments
 (0)