From 47c704c545867e9a80bfc1b7bbf879ca79dd40bd Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Mon, 15 Aug 2016 11:18:45 +0000
Subject: [PATCH] proc_common_read_integer_file(): Return zeros when file is
 UNUSED. Report failure when nof_row > nof lines in file.

---
 .../base/common/tb/vhdl/tb_common_pkg.vhd     | 39 +++++++++++--------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/libraries/base/common/tb/vhdl/tb_common_pkg.vhd b/libraries/base/common/tb/vhdl/tb_common_pkg.vhd
index dfd1e86eb0..4167e7db44 100644
--- a/libraries/base/common/tb/vhdl/tb_common_pkg.vhd
+++ b/libraries/base/common/tb/vhdl/tb_common_pkg.vhd
@@ -990,23 +990,30 @@ PACKAGE BODY tb_common_pkg IS
     VARIABLE v_string      : STRING(1 TO 80);
     VARIABLE v_row_arr     : t_integer_arr(0 TO nof_col-1);
   BEGIN
-    -- Open the file for reading
-    proc_common_open_file(v_file_status, v_in_file, file_name, READ_MODE); 
-    -- Read and skip the header
-    FOR J IN 0 TO nof_header_lines-1  LOOP
-      proc_common_readline_file(v_file_status, v_in_file, v_string); 
-    END LOOP;
-    FOR J IN 0 TO nof_row-1  LOOP
-      proc_common_readline_file(v_file_status, v_in_file, v_row_arr, nof_col);
-      FOR I IN 0 TO nof_col-1 LOOP
-        return_array(J*nof_col + I) <= v_row_arr(I);  -- use loop to be independent of t_integer_arr downto or to range
+    IF file_name/="UNUSED" AND file_name/="unused" THEN
+      -- Open the file for reading
+      proc_common_open_file(v_file_status, v_in_file, file_name, READ_MODE); 
+      -- Read and skip the header
+      FOR J IN 0 TO nof_header_lines-1  LOOP
+        proc_common_readline_file(v_file_status, v_in_file, v_string); 
       END LOOP;
-      IF ENDFILE(v_in_file) THEN
-        EXIT;
-      END IF;
-    END LOOP;
-    -- Close the file 
-    proc_common_close_file(v_file_status, v_in_file);             
+      FOR J IN 0 TO nof_row-1  LOOP
+        proc_common_readline_file(v_file_status, v_in_file, v_row_arr, nof_col);
+        FOR I IN 0 TO nof_col-1 LOOP
+          return_array(J*nof_col + I) <= v_row_arr(I);  -- use loop to be independent of t_integer_arr downto or to range
+        END LOOP;
+        IF ENDFILE(v_in_file) THEN
+          IF J/=nof_row-1 THEN
+            REPORT "COMMON : Unexpected end of file" SEVERITY FAILURE;
+          END IF;
+          EXIT;
+        END IF;
+      END LOOP;
+      -- Close the file 
+      proc_common_close_file(v_file_status, v_in_file);
+    ELSE
+      return_array <= (return_array'RANGE=>0);
+    END IF;
   END proc_common_read_integer_file;
 
   ------------------------------------------------------------------------------
-- 
GitLab