About file I/O

G

GaLaKtIkUs™

Guest
Hi all,
Is it possible to define some parameter to some integer value than
convert it to a string to use it as a part of a filename to open it?
I tried the following but it doesn't work
parameter suffix=13;
parameter filen_ame={"some_name",suffix};

Cheers
 
GaLaKtIkUs™ wrote:
Hi all,
Is it possible to define some parameter to some integer value than
convert it to a string to use it as a part of a filename to open it?
I tried the following but it doesn't work
parameter suffix=13;
parameter filen_ame={"some_name",suffix};

Cheers
This worked in ModelSim:

parameter suffix = 8'h25;
integer stupid_file;
reg [31:0] file_name;
reg [7:0] file_number;
initial begin
file_number = suffix;
file_name = {"FN",4'h3,file_number[7:4],4'h3,file_number[3:0]};
$display ("%x %s", file_name, file_name);
stupid_file = $fopen (file_name);
if (stupid_file != 0) $fclose(stupid_file);
end

Note the simplistic number (BCD hex) to ASCII by just inserting
4'b3 in front of each hex digit. This generated a file called FN25
in the current directory.

Regards,
Gabor
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

GaLaKtIkUs? wrote:
Hi all,
Is it possible to define some parameter to some integer value than
convert it to a string to use it as a part of a filename to open it?
I tried the following but it doesn't work
parameter suffix=13;
parameter filen_ame={"some_name",suffix};
$sprintf may be of some use?

- --
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFCDJDrPt1Sc2b3ikRAt/pAKCByC0Uvm6OqUijBUuYll5iq6t/hwCgt90r
HJTRxr8YA3u2NLSvdjTQBQ4=
=5fz/
-----END PGP SIGNATURE-----
 
"GaLaKtIkUsT" <taileb.mehdi@gmail.com> a écrit dans le message de news:
1158149110.713988.55780@i3g2000cwc.googlegroups.com...
Hi all,
Is it possible to define some parameter to some integer value than
convert it to a string to use it as a part of a filename to open it?
I tried the following but it doesn't work
parameter suffix=13;
parameter filen_ame={"some_name",suffix};

Cheers
Here is what you want:

module str;

parameter n=125;
reg [8*32-1:0] file_name;
integer f;

initial begin
$sformat(file_name,"TOTO%0d",n);
f=$fopen(file_name);
$fclose(f);
end

endmodule

Serge Bedikian
 

Welcome to EDABoard.com

Sponsor

Back
Top