Is there any package or method that replicates Delphi's formatfloat method?
Examples of the intended output when given 1234.567:
##### : 1235
00000 : 01235
0 : 1235
#,##0 : 1,235
,0 : 1,235
0.#### : 1234.567
0.0000 : 1234.5670
Edit:
The formatting masks would still need to be in the same format as Delphi (preferably, can be parsed and treated if need be), as they are present in an external file and it needs to be compatible with both.
Related
I'm currently having issues parsing some numbers starting with 0 in Go.
fmt.Println(strconv.ParseInt("0491031", 0, 64))
0 strconv.ParseInt: parsing "0491031": invalid syntax
GoPlayground: https://go.dev/play/p/TAv7IEoyI8I
I think this is due to some base conversion error, but I don't have ideas about how to fix it.
I'm getting this error parsing a 5GB+ csv file with gocsv, if you need more details.
[This error was caused by the GoCSV library that doesn't allow to specify a base for the numbers you're going to parse.]
Quoting from strconv.ParseInt()
If the base argument is 0, the true base is implied by the string's prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise. Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.
You are passing 0 for base, so the base to parse in will be inferred from the string value, and since it starts with a '0' followed by a non '0', your number is interpreted as an octal (8) number, and the digit 9 is invalid there.
Note that this would work:
fmt.Println(strconv.ParseInt("0431031", 0, 64))
And output (try it on the Go Playground):
143897 <nil>
(Octal 431031 equals 143897 decimal.)
If your input is in base 10, pass 10 for base:
fmt.Println(strconv.ParseInt("0491031", 10, 64))
Then output will be (try it on the Go Playground):
491031 <nil>
I have the array_axis_vcs VUNIT example running.
Now I want to customize the example to my needs, a.o. increasing the data_width size (32 bit in the example).
Doing this, the error below appears.
It seems there is a limitation to 32 bit for the AXIS data width in the packages.
Is there a fundamental reason why this is? Maybe a workaround?
Actually I want to transmit 32 signed(9 downto 0) values per clock cycle, which I would then map to std_logic_vector(319 downto 0).
I would expect the AXIS code just treat this payload as std_logic_vector, but somewhere it tries to convert it to signed.
# Stack trace result from 'tb' command
# /usr/lib/python2.7/site-packages/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd 220 return [address 0x7feff05dbae7] Subprogram set_word_size
# called from /usr/lib/python2.7/site-packages/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd 273 return [address 0x7feff05d8215] Subprogram new_3d
# called from /usr/lib/python2.7/site-packages/vunit/vhdl/array/src/array_pkg.vhd 210 return [address 0x7feff0b9a75b] Subprogram array_t.init_3d
# called from /usr/lib/python2.7/site-packages/vunit/vhdl/array/src/array_pkg.vhd 196 return [address 0x7feff0b9a642] Subprogram array_t.init_2d
# called from /hsdtlvob/impala/design_sources/dpu_common/axis_buffer/src/test/tb_axis_loop.vhd 122 return [address 0x7feff0ba5ddb] Process save
#
#
# Surrounding code from 'see' command
# 215 : procedure set_word_size(variable arr : inout integer_array_t;
# 216 : bit_width : natural := 32;
# 217 : is_signed : boolean := true) is
# 218 : begin
# 219 : assert (1 <= bit_width and bit_width < 32) or (bit_width = 32 and is_signed)
# ->220 : report "Unsupported combination of bit_width and is_signed";
# 221 : arr.bit_width := bit_width;
# 222 : arr.is_signed := is_signed;
# 223 :
# 224 : if arr.is_signed then
The problem you're experiencing is not related to the AXI Stream verification components but the array type used when reading/writing stimuli/result from/to file. The array type is based on 32-bit integers and can't handle larger vectors. To handle larger vectors you would have to use several integers in the CSV files for every stimuli/result vector, for example 2 integers for a 64-bit vector.
I also recommend that you use the newer integer_array_t instead of array_t. array_t is based on protected types which has a number of limitations which integer_array_t doesn't have. There is also work being done to support dynamic arrays of arbitrary type so that you can use your std_logic_vector(319 downto 0) directly or, maybe even better, create an array of arrays containing 32 signed(9 downto 0). Have a look at this issue for more information on that work.
I have a permanent ampl syntax error when I define matrix parameters. Here is how I defined my parameters :
D is a vector of 7 integers !
#
data; reset;
param NP:=7; param NT:=4;
param D:=
1 12000 2 32000 3 25000 4 36000 5 25000 6 30000 7 18000 ;
So, I get the syntax error :
prod_elec.dat, line 8 (offset 53): syntax error context: 1 >>>
12000 <<<
Please help me, I have no idea how to solve that, I followed the definitions of the book that used to work for me too..
Thank you very much in advance !
It looks as if you mean for D to be an indexed parameter, but the code you posted doesn't declare it as being indexed. Even if there was a previous model statement which did declare it as indexed, that would be deleted by your reset statement. So AMPL expects a single value, and when it sees a second value (here 12000) it gives an error.
Something like this should work:
reset;
model;
param NP;
param NT;
param D{1..NP};
data;
param NP:=7; param NT:=4;
param D:= 1 12000 2 32000 3 25000 4 36000 5 25000 6 30000 7 18000 ;
I’m using ARM-GCC 4.7.4 to compile Code for a Cortex-M4. For our Debug tool I need knowledge about names, types and addresses of all variables in human readable format (e.g. .txt). The map file provides most of the information, unfortunately not for structure contents like below:
typedef struct { float32_t Ref; // Input: Reference Value
float32_t Fdb; // Variable: Feedback Value
float32_t Err; // Input: Control Error
float32_t Kp; // Parameter: Gain of the Proportional Part
float32_t Up; // Output: Output of Proportional Part
float32_t Ki; // Parameter: Gain of the Integral Part
float32_t Ui; // Output: Output of the Integral Part
float32_t OutPreSat; // Output: Not saturated Output
float32_t OutMax; // Parameter: Maximum Output
float32_t OutMin; // Parameter: Minimum Output
float32_t Out; // Output: Saturated Output
} PI_REG;
PI_REG BU_Uctrl_Udc_PI_Reg = BU_UCTRL_UDC_PI_REG_INIT;
Therefore I tried the tools nm, readelf and objdump to get something out of the .elf file which is compiled with parameter –g3 in dwarf-2 format. Only with objdump I could find the information I searched for:
objdump –Wi myfile.elf >symbols.txt
The following information about the typedef PI_REG can be found in symbols.txt file:
<1><38883>: Abbrev Number: 2 (DW_TAG_base_type)
<38884> DW_AT_byte_size : 4
<38885> DW_AT_encoding : 4 (float)
<38886> DW_AT_name : (indirect string, offset: 0x2c63e): float
<1><38891>: Abbrev Number: 11 (DW_TAG_typedef)
<38892> DW_AT_name : (indirect string, offset: 0xb336d): float32_t
<38896> DW_AT_decl_file : 4
<38897> DW_AT_decl_line : 370
<38899> DW_AT_type : <0x38883>
<1><390d7>: Abbrev Number: 14 (DW_TAG_structure_type)
<390d8> DW_AT_byte_size : 44
<390d9> DW_AT_decl_file : 6
<390da> DW_AT_decl_line : 26
<390db> DW_AT_sibling : <0x39176>
<2><390df>: Abbrev Number: 16 (DW_TAG_member)
<390e0> DW_AT_name : Ref
<390e4> DW_AT_decl_file : 6
<390e5> DW_AT_decl_line : 26
<390e6> DW_AT_type : <0x38891>
<390ea> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<2><390ed>: Abbrev Number: 16 (DW_TAG_member)
<390ee> DW_AT_name : Fdb
<390f2> DW_AT_decl_file : 6
<390f3> DW_AT_decl_line : 27
<390f4> DW_AT_type : <0x38891>
<390f8> DW_AT_data_member_location: 2 byte block: 23 4 (DW_OP_plus_uconst: 4)
[left out structure members with offsets 6-32]
<2><39159>: Abbrev Number: 15 (DW_TAG_member)
<3915a> DW_AT_name : (indirect string, offset: 0xc1d9a): OutMin
<3915e> DW_AT_decl_file : 6
<3915f> DW_AT_decl_line : 35
<39160> DW_AT_type : <0x38891>
<39164> DW_AT_data_member_location: 2 byte block: 23 24 (DW_OP_plus_uconst: 36)
<2><39167>: Abbrev Number: 16 (DW_TAG_member)
<39168> DW_AT_name : Out
<3916c> DW_AT_decl_file : 6
<3916d> DW_AT_decl_line : 36
<3916e> DW_AT_type : <0x38891>
<39172> DW_AT_data_member_location: 2 byte block: 23 28 (DW_OP_plus_uconst: 40)
<1><39176>: Abbrev Number: 3 (DW_TAG_typedef)
<39177> DW_AT_name : (indirect string, offset: 0xc00d0): PI_REG
<3917b> DW_AT_decl_file : 6
<3917c> DW_AT_decl_line : 37
<3917d> DW_AT_type : <0x390d7>
<1><3c348>: Abbrev Number: 29 (DW_TAG_variable)
<3c349> DW_AT_name : (indirect string, offset: 0xc3ece): BU_Uctrl_Udc_PI_Reg
<3c34d> DW_AT_decl_file : 1
<3c34e> DW_AT_decl_line : 40
<3c34f> DW_AT_type : <0x39176>
<3c353> DW_AT_external : 1
<3c354> DW_AT_location : 5 byte block: 3 fc 67 0 20 (DW_OP_addr: 200067fc)
If I want to get information about variables, e.g. the structure BU_Uctrl_Udc_PI_Reg, I have to do the following:
Find an entry called “DW_TAG_variable” and gather following information:
------------------------------------------------------------------------
- DW_AT_name: The name is BU_Uctrl_Udc_PI_Reg
- DW_OP_addr: Base address is 200067fc
- DW_AT_type: The data type can be found at line 39176
Search line 39176 and gather following information:
-----------------------------------------------------
- It is a typedef (DW_TAG_typedef)
- DW_AT_name: The typedef name is PI_REG
- DW_AT_type: The definition can be found at line 390d7
Search line 390d7 and gather following information:
---------------------------------------------------
- It is a structure (DW_TAG_structure_type)
- DW_AT_byte_size: It is 44 bytes wide
Search the structure Members in upcoming lines until 44 bytes are reached:
--------------------------------------------------------
1. Member (DW_TAG_member):
- DW_AT_name: Ref
- DW_AT_data_member_location: 200067fc + 0
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
2. Member (DW_TAG_member):
- DW_AT_name: Fdb
- DW_AT_data_member_location: 200067fc + 4
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
[left out Members 3-9]
10. Member (DW_TAG_member):
- DW_AT_name: OutMin
- DW_AT_data_member_location: 200067fc + 36
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
11. Member (DW_TAG_member):
- DW_AT_name: Out
- DW_AT_data_member_location: 200067fc + 40
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
Frankly speaking, a script file, which automatically gathers the information as above mentioned, would be more complex than my application. Additionally I have to admit that I not really know how I could write such a script. Is there a more easy way to get this type of information? Is there maybe some parameter for the objdump which would help me with that, although I think I tried all the relevant ones? Or does a tool exist which is able to do this? In the end I need a table like this (additionally it would be nice to have all the enums which of course can also be found within the .elf file):
0x200067fc float BU_Uctrl_Udc_PI_Reg.Ref
0x20006800 float BU_Uctrl_Udc_PI_Reg.Fdb
[…]
0x20006832 float BU_Uctrl_Udc_PI_Reg.OutMin
0x20006836 float BU_Uctrl_Udc_PI_Reg.Out
The tool Fromelf http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0477c/index.html (included in Keil µVision) with the parameter --text exactly delivers such a table, but unfortunately I can’t use this because it supposedly needs the .elf or in this case called .axf files compiled with Arm Compiler Toolchain to work. Additionally there are license issues.
Thanks for any hints.
is pahole what you need? it can dump variable structure with size and offset.
pahole −−reorganize −C foo xxx.out
struct foo {
int a; / 0 4 /
char c[4]; / 4 4 /
void b; / 8 8 /
long g; / 16 8 /
}; / size: 24, cachelines: 1 /
/ last cacheline: 24 bytes /
/ saved 8 bytes! /
You should be able to ask GDB to print this info for you, e.g.
gdb -q a.out
(gdb) ptype PI_REG
You can use eclipse CDT's gdb mi interface to programatically get this information.
private def loadElfFile(String elfFilePath) {
var plugin = new MIPlugin
var file = new File(elfFilePath)
var cmdFactory = new CommandFactory("mi2")
session = plugin.createSession(
MISession::PROGRAM,
'gdb',
cmdFactory,
file,
#[],
true,
new NullProgressMonitor
)
}
There you can query global variables and their types. Addresses are stored in the hexAddress property of values.
The problem with this approach is its slowness. A struct with 50 members takes almost 10 seconds to process. Querying all structs would take minutes. For IDE tool use cases (like a model transformation) this is impractical. You have to deep dive to elf and dwarf.
I'm trying to read that string in a formatted file: " PARAMETER (NE_M=10,NL_M=12)".
I want to replace the 12 by 11.
I tried to read the sting like this :
integer :: i
character(len=30) :: text
10 format(6x,24a,2i) text,i
read(text_data,10) text, i
write(6,100) text, 11
But it doesn't work. Any idea?
The reading and writing you have written will not do what you want. The input statement you presented for reading is 33 characters wide, and your formatting only accounts for 32 of those characters and your write will not contain the closing ).
Consider the following code, if you do not need to capture the 12 in the input.
program test
character(len=30) :: text
101 format(a30, i2, ')')
open(unit=10, file='testinput.f')
read(10,101) text
write(*,101) text, 11
end program
and the input (with 6 leading spaces) in file testinput.f:
PARAMETER (NE_M=10,NL_M=12)
when run, produces the output:
% ./test
PARAMETER (NE_M=10,NL_M=11)
This code was compiled and tested with GNU gfortran 4.8.2.
assuming test_data is a unit number of an open file and 100 is a
format statement number.
integer :: i
character(len=30) :: text
10 format(6x,a24,i2)
read(text_data,10) text, i
write(6,100) text(:24), i
fixing those other issues:
integer :: i
character(len=30) :: text
open(unit=20,file='filename')
10 format(6x,a24,i2)
read(20,10) text, i
write(6,10) text(:24), i