J06 Writing float samples

Float samples may be written in form of float, double or BigDecimal values. Like with integers you may use arrays of float values.

Impulse supports 32bit (float), 64bit (double) floating point data and arrays of float/double:

    public final int FLOAT_WIDTH_32 = 0x01; // 4 bytes
    public final int FLOAT_WIDTH_64 = 0x02; // 8 bytes

Float data without limited precision (BigDecimal) is under discussion to be added.

Interface

The interface contains write functions for all supported data types. Additionally you find renamed wrapper functions for scripting purpose.

units
Domain position as a multiple of its domain base (e.g. domain base=1ms; units = 100; -> domain value = 100ms). Consecutive calls need to pass a value greater or equal.
conflict
If set to true, impulse will use conflict color (usually red) to paint the sample. Meaning of "conflict is use-case depended.
value
The given valuein different formats (float/double/BigDecimal)
public interface IFloatSamplesWriter extends ISamplesWriter {
	 
	boolean write(long units, double value);
	boolean write(long units, boolean conflict, float value);
	boolean write(long units, boolean conflict, double value);
	boolean write(long units, boolean conflict, BigDecimal value);
	boolean write(long units, boolean conflict, Number value);
	boolean write(long units, boolean conflict, float[] value);
	boolean write(long units, boolean conflict, double[] value);
	
	// scripting
	boolean writeFloat(long units, boolean conflict, float value);
	boolean writeDouble(long units, boolean conflict, double value);
	boolean writeBig(long units, boolean conflict, BigDecimal value);
	boolean writeFloatArray(long units, boolean conflict, float[] value);
	boolean writeFloatArgs(long units, boolean conflict, float... value);    
	boolean writeDoubleArray(long units, boolean conflict, double[] value);
	boolean writeDoubleArgs(long units, boolean conflict, double... value);
}
Open JavaDoc Reference

Signal definition

Below you find an example of how to create an integer and an integer array signal. The integer array definition requires a signal descriptor with the required array size (2).
// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
Signal signal1 = addSignal(signals, "Float1", "A float", 
	ProcessType.Discrete, SignalType.Float, SignalDescriptor.DEFAULT);

Signal signal2 = addSignal(signals, "Float2", "XY", 
	ProcessType.Discrete, SignalType.FloatArray, 
    new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,
    ISample.FLOAT_WIDTH_64,ISample.FORMAT_DEFAULT));

// JavaScript (recJs, scripted reader,..)
var signal1 = generator.addSignal(signals, "Float1", "A float",
	ProcessType.Discrete, SignalType.Float, SignalDescriptor.DEFAULT);
    
var signal2 = generator.addSignal(signals, "Float2", "A float array", 
	ProcessType.Discrete, SignalType.FloatArray, 
    new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.
    	FLOAT_WIDTH_64,ISample.FORMAT_DEFAULT));

Writing samples

Below some examples of using the writer methods for Java and JavaScript. The JavaDoc reference contains additional examples.
// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
float value = 3.0f; 
writer1.write(1000L, false, value);  

Number value = new BigDecimal(3.0f); 
writer1.write(1000L, false, value);  

float[] value = new float[]{10.0,20.0}; 
writer2.write(1000L, false, value);   
     
// JavaScript (recJs, scripted reader,..)
var value = 3.0; 
writer1.writeDouble(1000, false, value);

writer2.writeFloatArgs(1000,false,3,5.0);     

writer2.writeDoubleArgs(1000,false,3,5.0);  

Print

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive