Class PythonGenerator
- java.lang.Object
-
- org.orekit.files.ccsds.utils.generation.PythonGenerator
-
- All Implemented Interfaces:
AutoCloseable
,Generator
public class PythonGenerator extends Object implements Generator
-
-
Field Summary
Fields Modifier and Type Field Description protected long
pythonObject
Part of JCC Python interface to object
-
Constructor Summary
Constructors Constructor Description PythonGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the generator.String
dateToCalendarString(TimeConverter converter, AbsoluteDate date)
Convert a date to calendar string value with high precision.String
dateToString(int year, int month, int day, int hour, int minute, double seconds)
Convert a date to string value with high precision.String
dateToString(TimeConverter converter, AbsoluteDate date)
Convert a date to string value with high precision.String
doubleToString(double value)
Convert a double to string value with high precision.void
endMessage(String root)
End CCSDS message.void
enterSection(String name)
Enter into a new section.String
exitSection()
Exit last section.void
finalize()
FileFormat
getFormat()
Get the generated file format.String
getOutputName()
Get the name of the output (for error messages).void
newLine()
Finish current line.void
pythonDecRef()
long
pythonExtension()
void
pythonExtension(long pythonObject)
String
siToCcsdsName(String siName)
Convert a SI unit name to a CCSDS name.void
startMessage(String root, String messageTypeKey, double version)
Start CCSDS message.String
unitsListToString(List<Unit> units)
Convert a list of units to a bracketed string.void
writeComments(List<String> comments)
Write comment lines.void
writeEntry(String key, char value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, double value, Unit unit, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, int value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, Double value, Unit unit, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, Enum<?> value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, String value, Unit unit, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, List<String> value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, TimeConverter converter, AbsoluteDate date, boolean forceCalendar, boolean mandatory)
Write a single key/value entry.void
writeRawData(char data)
Write raw data.void
writeRawData(CharSequence data)
Write raw data.
-
-
-
Method Detail
-
pythonExtension
public void pythonExtension(long pythonObject)
-
pythonExtension
public long pythonExtension()
-
finalize
public void finalize() throws Throwable
-
pythonDecRef
public void pythonDecRef()
-
getOutputName
public String getOutputName()
Get the name of the output (for error messages).- Specified by:
getOutputName
in interfaceGenerator
- Returns:
- name of the output
-
getFormat
public FileFormat getFormat()
Get the generated file format.
-
startMessage
public void startMessage(String root, String messageTypeKey, double version) throws IOException
Start CCSDS message.- Specified by:
startMessage
in interfaceGenerator
- Parameters:
root
- root element for XML filesmessageTypeKey
- key for message typeversion
- format version- Throws:
IOException
- if an I/O error occurs.
-
endMessage
public void endMessage(String root) throws IOException
End CCSDS message.- Specified by:
endMessage
in interfaceGenerator
- Parameters:
root
- root element for XML files- Throws:
IOException
- if an I/O error occurs.
-
writeComments
public void writeComments(List<String> comments) throws IOException
Write comment lines.- Specified by:
writeComments
in interfaceGenerator
- Parameters:
comments
- comments to write- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, String value, Unit unit, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writeunit
- output unit (may be null)mandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, List<String> value, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, Enum<?> value, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, TimeConverter converter, AbsoluteDate date, boolean forceCalendar, boolean mandatory) throws IOException
Description copied from interface:Generator
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writeconverter
- converter to use for datesdate
- the date to writeforceCalendar
- if true, the date is forced to calendar formatmandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, char value, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, int value, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, double value, Unit unit, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to write (in SI units)unit
- output unitmandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
writeEntry
public void writeEntry(String key, Double value, Unit unit, boolean mandatory) throws IOException
Write a single key/value entry.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to write (in SI units)unit
- output unitmandatory
- if true, null values triggers exception, otherwise they are silently ignored- Throws:
IOException
- if an I/O error occurs.
-
newLine
public void newLine() throws IOException
Finish current line.- Specified by:
newLine
in interfaceGenerator
- Throws:
IOException
- if an I/O error occurs.
-
writeRawData
public void writeRawData(char data) throws IOException
Write raw data.- Specified by:
writeRawData
in interfaceGenerator
- Parameters:
data
- raw data to write- Throws:
IOException
- if an I/O error occurs.
-
writeRawData
public void writeRawData(CharSequence data) throws IOException
Write raw data.- Specified by:
writeRawData
in interfaceGenerator
- Parameters:
data
- raw data to write- Throws:
IOException
- if an I/O error occurs.
-
enterSection
public void enterSection(String name) throws IOException
Enter into a new section.- Specified by:
enterSection
in interfaceGenerator
- Parameters:
name
- section name- Throws:
IOException
- if an I/O error occurs.
-
exitSection
public String exitSection() throws IOException
Exit last section.- Specified by:
exitSection
in interfaceGenerator
- Returns:
- section name
- Throws:
IOException
- if an I/O error occurs.
-
close
public void close() throws IOException
Close the generator.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceGenerator
- Throws:
IOException
- if an I/O error occurs.
-
dateToString
public String dateToString(TimeConverter converter, AbsoluteDate date)
Convert a date to string value with high precision.- Specified by:
dateToString
in interfaceGenerator
- Parameters:
converter
- converter for datesdate
- date to write- Returns:
- date as a string
-
dateToCalendarString
public String dateToCalendarString(TimeConverter converter, AbsoluteDate date)
Description copied from interface:Generator
Convert a date to calendar string value with high precision.- Specified by:
dateToCalendarString
in interfaceGenerator
- Parameters:
converter
- converter for datesdate
- date to write- Returns:
- date as a calendar string
-
dateToString
public String dateToString(int year, int month, int day, int hour, int minute, double seconds)
Convert a date to string value with high precision.- Specified by:
dateToString
in interfaceGenerator
- Parameters:
year
- yearmonth
- monthday
- dayhour
- hourminute
- minuteseconds
- seconds- Returns:
- date as a string
-
doubleToString
public String doubleToString(double value)
Convert a double to string value with high precision.We don't want to loose internal accuracy when writing doubles but we also don't want to have ugly representations like STEP = 1.25000000000000000 so we try a few simple formats first and fall back to scientific notation if it doesn't work.
- Specified by:
doubleToString
in interfaceGenerator
- Parameters:
value
- value to format- Returns:
- formatted value, with all original value accuracy preserved, or null
if value is null or
Double.NaN
-
unitsListToString
public String unitsListToString(List<Unit> units)
Convert a list of units to a bracketed string.- Specified by:
unitsListToString
in interfaceGenerator
- Parameters:
units
- lists to output (may be null or empty)- Returns:
- bracketed string (null if units list is null or empty)
-
siToCcsdsName
public String siToCcsdsName(String siName)
Convert a SI unit name to a CCSDS name.- Specified by:
siToCcsdsName
in interfaceGenerator
- Parameters:
siName
- si unit name- Returns:
- CCSDS name for the unit
-
-