From c976d14444eeea21bc2cb36770344c0456e94e79 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@debian.org>
Date: Thu, 19 Feb 2015 18:15:01 +0100
Subject: [PATCH] Fix CSV loading under Octave with IO package.

Also, for people who don't have the IO package, always use the fallback
code (even when the first line is <= 4096 bytes long).

Ref #2
---
 src/read/load_csv_file_data.m | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/read/load_csv_file_data.m b/src/read/load_csv_file_data.m
index 6767412..124d757 100644
--- a/src/read/load_csv_file_data.m
+++ b/src/read/load_csv_file_data.m
@@ -16,7 +16,7 @@ function [freq, init, data, varlist] = load_csv_file_data(file)
 %  names. Similarly, if the first column does not contain dates, then
 %  freq will be 1 and init will be year 1.
 
-% Copyright (C) 2012-2014 Dynare Team
+% Copyright (C) 2012-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -44,16 +44,11 @@ if isoctave
     fid = fopen(file, 'r');
     firstline = fgetl(fid, 4097);
     fclose(fid);
-    if length(firstline) < 4097
-        if ~user_has_octave_forge_package('io')
-            try
-                pkg load io
-            catch
-                error(['The io package is required to read CSV files from Octave. ' ...
-                       'It can be installed by running the following from the Octave ' ...
-                       ' command line: pkg install -forge io']);
-            end
-        end
+    if length(firstline) < 4097 && user_has_octave_forge_package('io')
+        A = csv2cell(file);
+        [data, T, L] = parsecell(A);
+        withvars = L.numlimits(2,1) > L.txtlimits(2,1);
+        withtime = L.numlimits(1,1) > L.txtlimits(1,1);
     else
         fid = fopen(file, 'r');
         bfile = fread(fid);
-- 
GitLab