UtilsJSON.cpp 843 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <ITABase/UtilsJSON.h>
#include <libjson.h>
#include <fstream>

void ITABase::Utils::JSON::Export( const CITASpectrum* pSpectrum, const std::string& sTargetFilePath )
{
	JSONNode jnRoot;
	jnRoot.push_back( JSONNode( "name", pSpectrum->GetName() ) );
	jnRoot.push_back( JSONNode( "num_bands", pSpectrum->GetNumBands() ) );
	jnRoot.push_back( JSONNode( "value_unit", pSpectrum->GetValueUnit() ) );
	
	JSONNode jnBins;
	for( int i = 0; i < pSpectrum->GetNumBands(); i++ )
	{
		JSONNode jnBin;
		jnBin.set_name( "bin" + std::to_string( i ) );
		jnBin.push_back( JSONNode( "center_frequency", pSpectrum->GetCenterFrequencies()[ i ] ) );
		jnBin.push_back( JSONNode( "value", pSpectrum->GetValues()[ i ] ) );

		jnBins.push_back( jnBin );
	}

	std::ofstream fsOut( sTargetFilePath );
	fsOut << jnRoot.write_formatted();
	fsOut.close();
}