Error accessing the file,

** Warning: (vsim-3535) [FOFIA] - Failed to open file “mem_trace.txt” for appending.

Permission denied. (errno = EACCES) : pdp11_pkg.sv(178)

Time: 0 ns Iteration: 0 Instance: /PDP11_ISA

** Error (suppressible): (vsim-PLI-3085) pdp11_pkg.sv(178): $fwrite : Argument 1 is an unknown file descriptor.

Time: 0 ns Iteration: 0 Instance: /PDP11_ISA

I am getting an error message from the tool - PDP11_ISA and pdp11_pkg.sv are files , Is it because of the way I coded or is it a tool error ?

I would like to know the reason for the bug caused this error

In reply to DurgaKundan:

Because you show no code, no one can tell you if the problem is from your coding.

From the error message, PDP11_ISA appears to be an instance name in your source code, not a file.

Does the file mem_trace.txt" exist in the same directory from where you ran your simulation?

In reply to dave_59:

Yes, mem_trace.txt is a file in the same directory,

code in PDP11_pkg.sv

function logic [`INSTR_WORD-1:0] get_Mem_Value( input logic [`INSTR_WORD-1:0]Address, input logic [`WORD-1:0] bytemode,input logic [`WORD-1:0] mem_op);
integer file, fp;
fp = $fopen("mem_trace.txt","a");
$display("fp: %d",fp);
if(mem_op === FETCH)
	$fwrite(fp,"%3d\t\t%6o\n",FETCH,Address);
else if(mem_op === READ)
	$fwrite(fp,"%3d\t\t%6o\n",READ,Address);
$fclose(fp);
endfunction
code in PDP11_ISA.sv

`include PDP11_pkg.sv

module PDP11_ISA();

logic [`INSTR_WORD-1:0] start_addr, opcode, temp_PC, temp_eff_addr, src_data, dst_data, dst_data_temp;

instr_fetch_decode(strt_addr.atooct());	
while(1)begin
dst_data = get_Mem_Value(temp_eff_addr,bytemode,READ);

end
task instr_fetch_decode (input logic [`INSTR_WORD-1:0] start_addr);

integer fp;
PC = start_addr;
fp = $fopen("mem_trace.txt","w");
$display("fp: %d",fp);   	//logging a memory trace file
$fclose(fp);



endtask

endmodule

In reply to DurgaKundan:
You are getting the error because you do not have permission to either create the file if it doesn’t exist, or modify if it exists.