fprintf: invalid stream number = -1 anomaly

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

fprintf: invalid stream number = -1 anomaly

Postby kgarb » Mon Jun 01, 2015 9:25 pm

Hello All,

I'm trying to do something of a ground-up build working towards replication of papers like Medina and Soto (2007) and Beidas-Strom and Poghosyan (2011).

I've gotten the deterministic form of most of the household consumption block from Beidas-Strom and Poghosyan (2011) to stop giving pre-processor errors, but now it's telling me that there's an error in the automatically-generated JamTest1.m Matlab file that Dynare creates:

Code: Select all
Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 4 equation(s).
Evaluating expressions...done
Computing static model derivatives:
 - order 1
Computing dynamic model derivatives:
 - order 1
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.

parse error near line 110 of file JamTest1.m

  syntax error

>>> end;
      ^

error: called from:
error:   c:\dynare\4.4.3\matlab\dynare.m at line 180, column 1


I've attached both JamTest1.mod and JamTest1.m; I imagine the problem is in JamTest1.mod, but without knowing Dynare better I'm not sure where to look for my error or what the nature of the error is since it's not being caught by the preprocessor.

I'm using Octave 3.8.2 and Dynare 4.4.3.

Thank you in advance for your comments!
Attachments
JamTest1.m
(4.53 KiB) Downloaded 85 times
JamTest1.mod
(743 Bytes) Downloaded 133 times
Last edited by kgarb on Wed Jun 03, 2015 4:52 pm, edited 1 time in total.
kgarb
 
Posts: 34
Joined: Thu May 28, 2015 9:19 pm

Re: Error in filename.m

Postby HoutanBastani » Tue Jun 02, 2015 8:42 am

remove the "end;" on line 11 of your .mod file
Best,
Houtan
HoutanBastani
 
Posts: 197
Joined: Fri Jan 22, 2010 4:11 pm
Location: Paris, France

Re: Error in filename.m

Postby kgarb » Tue Jun 02, 2015 2:01 pm

Thank you!
kgarb
 
Posts: 34
Joined: Thu May 28, 2015 9:19 pm

fprintf: invalid stream number = -1 anomaly

Postby kgarb » Wed Jun 03, 2015 4:48 pm

Hello All,

I'm still working on constructing the model described in the first post (based on Beidas-Strom and Poghosyan, 2011; see their paper for equations/parameterizations if needed), but I've run into something of an anomaly. I ran the model after finalizing a new equation block, and got the result below:

Code: Select all
㯿Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 20 equation(s).
Evaluating expressions...done
Computing static model derivatives:
 - order 1
Computing dynamic model derivatives:
 - order 1
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.


SOLVE: maxit has been reached




Residuals of the static equations:

Equation number 1 : 1.2003e-005
Equation number 2 : 2.3483e-006
Equation number 3 : 2.1968e-005
Equation number 4 : 0
Equation number 5 : 0
Equation number 6 : -0.00017995
Equation number 7 : -9.2869e-006
Equation number 8 : -2.317e-005
Equation number 9 : -4.7734e-006
Equation number 10 : 0
Equation number 11 : 0
Equation number 12 : -3.5556e-006
Equation number 13 : 0
Equation number 14 : -5.6631e-006
Equation number 15 : 2.3031e-005
Equation number 16 : 0
Equation number 17 : -2.5151e-005
Equation number 18 : 0
Equation number 19 : -0.00015429
Equation number 20 : -0.00011251


error: Impossible to find the steady state. Either the model does
n't have a steady state, there are an infinity of steady states,
 or the guess values are too far from the solution
error: called from:
error:   c:\dynare\4.4.3\matlab\print_info.m at line 74, column 9

error:   c:\dynare\4.4.3\matlab\steady.m at line 92, column 5
error:  JamTest1.m at line 358, column 1
error:   c:\dynare\4.4.3\matlab\dynare.m at line 180, column 1
>> dynare JamTest1.mod


I didn't expect it to converge or find a steady state since the model isn't fully specified yet, I just wanted to make sure the code would run without any errors in the preprocessor or matlab file.

However, I then changed the values of the shocks from 0.1 to 0.0, just to see if it would calculate a deterministic steady state if there weren't any shocks, and the program started to output the results below, with the main component being "error: fprintf: invalid stream number = -1"
Code: Select all
Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 20 equation(s).
Evaluating expressions...done
Computing static model derivatives:
 - order 1
Computing dynamic model derivatives:
 - order 1
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.

error: fprintf: invalid stream number = -1
error: called from:
error:   c:\dynare\4.4.3\matlab\dynare.m at line 168, column 5


I then tried changing the shock values back to 0.1 from 0.0, and Dynare persists in giving me the above error. There are no other components of the program I changed other than the shock block values, and changing them back or increasing simul from 2100 periods to 20100 periods didn't do anything either. Dynare is still giving me the "error: fprintf: invalid stream number = -1".

Is there any reason why this would be happening? The relevant code from dynare.m is below:
Code: Select all
% Save preprocessor result in logfile (if `no_log' option not present)
no_log = 0;
for i=2:nargin
    no_log = no_log || strcmp(varargin{i-1}, 'nolog');
end
if ~no_log
    logname = [fname(1:end-4) '.log'];
    fid = fopen(logname, 'w');
    fprintf(fid, '%s', result);
    fclose(fid);
end


Thank you in advance for your comments!

Edit:
Turns out I can get the fprintf error to go away by removing pr_M from the varlist and initval list and the last equation from the model block:
Code: Select all
pr_M=(c_Fm_steady)*rer+(OM_steady)*prstar_O;

What about this equation could be causing the fprintf error?
Attachments
JamTest1.mod
(3.22 KiB) Downloaded 85 times
kgarb
 
Posts: 34
Joined: Thu May 28, 2015 9:19 pm

Re: fprintf: invalid stream number = -1 anomaly

Postby kgarb » Thu Jun 04, 2015 7:11 pm

There's something else to the problem that I've just found.

If I open Octave 3.8.2 and simply run the file (with the equation
Code: Select all
 pr_M=(c_Fm_steady)*rer+(OM_steady)*prstar_O;
included), I get the expected error message:

Code: Select all
Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 20 equation(s).
Evaluating expressions...done
Computing static model derivatives:
 - order 1
Computing dynamic model derivatives:
 - order 1
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.


SOLVE: maxit has been reached




Residuals of the static equations:

Equation number 1 : 1.2003e-005
Equation number 2 : 2.3483e-006
Equation number 3 : 2.1968e-005
Equation number 4 : 0
Equation number 5 : 0
Equation number 6 : -0.00017995
Equation number 7 : -9.2869e-006
Equation number 8 : -2.317e-005
Equation number 9 : -4.7734e-006
Equation number 10 : 0
Equation number 11 : 0
Equation number 12 : -3.5556e-006
Equation number 13 : 0
Equation number 14 : -5.6631e-006
Equation number 15 : 2.3031e-005
Equation number 16 : 0
Equation number 17 : -2.5151e-005
Equation number 18 : 0
Equation number 19 : -0.00015429
Equation number 20 : -0.00011251


error: Impossible to find the steady state. Either the model doesn't have a steady state, there are an infinity of steady states, or the guess values are too far from the solution
error: called from:
error:   c:\dynare\4.4.3\matlab\print_info.m at line 74, column 9

error:   c:\dynare\4.4.3\matlab\steady.m at line 92, column 5
error:  JamTest1.m at line 359, column 1
error:   c:\dynare\4.4.3\matlab\dynare.m at line 180, column 1


However, if I then SAVE the JamTest1.mod file without making any changes after it's been run in Octave, I get the fprintf: invalid stream number = -1 error
Code: Select all
⡒Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 20 equation(s).
Evaluating expressions...done
Computing static model derivatives:
 - order 1
Computing dynamic model derivatives:
 - order 1
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.

error: fprintf: invalid stream number = -1
error: called from:
error:   c:\dynare\4.4.3\matlab\dynare.m at line 168, column 5


I can run the .mod file as much as I want without getting the fprintf error so long as I don't save it. Is there some kind of a glitch here where some variables/equations are causing errors in the dynare program such that it doesn't know how to overwrite an already-existing log file for the same program?

Like I said before, removing pr_M from the "vars" and "initval" sections and removing the equation listed above gets rid of the problem. Any thoughts on what could be going on?

Thanks in advance for your comments!
kgarb
 
Posts: 34
Joined: Thu May 28, 2015 9:19 pm

Re: fprintf: invalid stream number = -1 anomaly

Postby jpfeifer » Fri Jun 05, 2015 8:08 am

This rather looks like a problem of Octave with writing the log file after a crash. Have you tried whether it really has to do with pr_M or whether closing and reopening Octave solves the problem?
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: fprintf: invalid stream number = -1 anomaly

Postby kgarb » Fri Jun 05, 2015 1:21 pm

Yes, I should've mentioned that closing and opening Octave resets the problem until I save the file again, but as of right now the problem only triggers if I have pr_M in the file (removing it means no fprintf error).

I'll keep fiddling with it to see if I can figure out anything else about what's triggering the error. Initially I googled it with respect to dynare since the error triggered from dynare.m (i.e. search: dynare error: fprintf: invalid stream number = -1) and nothing came up, but there are a couple (7 unique, 34 total) google results about it related with Octave itself. Still, it's a little weird that a specific variable/equation (as it seems right now, but I'll keep looking) would trigger that error under such a strange set of circumstances

Edit: As a sidenote, setting "no_log=0" to "no_log=1" on line 161 of dynare.m avoids the problem by forcing dynare to not try to access/write to the log file. Still no clue on what's actually causing the problem though.
kgarb
 
Posts: 34
Joined: Thu May 28, 2015 9:19 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 8 guests

cron