How to change the floating point format

A place for discussing the creation of test driver schemas, customizing of object mapping files, developing Perl script subroutines to enhance the test driver schema language, and the generation of test drivers.

How to change the floating point format

Postby jack » Sun Dec 14, 2008 2:05 am

Hi

The default floating point format in the driver which generated by TVGS is scientific notation.
How can i change this?

For example,i want the data generated by TVGS from 1.44e +001 change to 14.4.

Regards

Jack
jack
 
Posts: 16
Joined: Sat Mar 15, 2008 9:59 am

Re: How to change the floating point format

Postby busser » Mon Dec 15, 2008 12:39 pm

The easiest way to customize the information being written into a test driver file is to utilize the PERL interpreter facility that is built into the test driver generator. Your object mappings and/or schema can pass the value meta-tokens that you would like formatted differently into a perl function that you include in your perl routines file that you can supply via the EMBED_PERL directive

EMBED_PERL 'my_perl_routines.pl';

that is normally included in the object mappings file for each subsystem. For example, you could place a perl routine called format_fp_number into your perl routine file.

sub format_fp_number
{
# number to format
my($fp_input_number) = @_;

return (sprintf("%3.1f",$fp_input_number));
}
}

Then, in your map files and/or schema files, any location where there is a value that needs to be formatted in this way should be modified to pass the value to the perl routine, which then reformats the number and returns the new string form. For example, a "set descriptor" for an output variable can be changed from

temperature
{
NAME_DESCRIPTOR '<inputStruct>.temperature';
GET_DESCRIPTOR '<inputStruct>.temperature';
SET_DESCRIPTOR '<inputStruct>.temperature = <binding->value>';
TYPE_DESCRIPTOR 'double';
USER_DESCRIPTOR["1"] 'INPUT';
USER_DESCRIPTOR["2"] 'USE_VAL';
USER_DESCRIPTOR["3"] '';
USER_DESCRIPTOR["4"] '';
USER_DESCRIPTOR["ARG_NAME"] 'rtu_0';
USER_DESCRIPTOR["BUS_LABEL"] '';
USER_DESCRIPTOR["CONSTANT"] 'false';
USER_DESCRIPTOR["INPORT"] '1';
USER_DESCRIPTOR["INPUT_TYPE"] 'scalar';
USER_DESCRIPTOR["ONCONSTBLOCKIO"] 'false';
USER_DESCRIPTOR["ORIGIN"] 'temperatureSensor';
USER_DESCRIPTOR["REGULAR_BLOCK_INPUT"] 'true';
USER_DESCRIPTOR["TIME_DELAY_INPUT"] 'false';
USER_DESCRIPTOR["VARIABLE_REQUIRED"] 'true';
}

to

temperature
{
NAME_DESCRIPTOR '<inputStruct>.temperature';
GET_DESCRIPTOR '<inputStruct>.temperature';
SET_DESCRIPTOR '<inputStruct>.temperature = <eval(format_fp_number("<binding->value>"))>';
TYPE_DESCRIPTOR 'double';
USER_DESCRIPTOR["1"] 'INPUT';
USER_DESCRIPTOR["2"] 'USE_VAL';
USER_DESCRIPTOR["3"] '';
USER_DESCRIPTOR["4"] '';
USER_DESCRIPTOR["ARG_NAME"] 'rtu_0';
USER_DESCRIPTOR["BUS_LABEL"] '';
USER_DESCRIPTOR["CONSTANT"] 'false';
USER_DESCRIPTOR["INPORT"] '1';
USER_DESCRIPTOR["INPUT_TYPE"] 'scalar';
USER_DESCRIPTOR["ONCONSTBLOCKIO"] 'false';
USER_DESCRIPTOR["ORIGIN"] 'temperatureSensor';
USER_DESCRIPTOR["REGULAR_BLOCK_INPUT"] 'true';
USER_DESCRIPTOR["TIME_DELAY_INPUT"] 'false';
USER_DESCRIPTOR["VARIABLE_REQUIRED"] 'true';
}


This would result in the value of temperature that was originally being written from the test vector into the test driver as

flow_control_U.temperature = 1.0e+012;

now being written as

flow_control_U.temperature = -1000000000000.0;
busser
Site Admin
 
Posts: 52
Joined: Thu Mar 13, 2008 7:42 pm


Return to Test Driver Generation

Who is online

Users browsing this forum: No registered users and 1 guest

cron