From 5b7acbf514667586648a9fc8d85f756357a4bbe8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Jul 2015 16:03:59 +0200 Subject: [PATCH] julia: first draft: call preprocessor, define model, utils --- julia/Dynare.jl | 43 +++++++++++++++++ julia/model.jl | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ julia/utils.jl | 36 ++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 julia/Dynare.jl create mode 100644 julia/model.jl create mode 100644 julia/utils.jl diff --git a/julia/Dynare.jl b/julia/Dynare.jl new file mode 100644 index 000000000..f9355a6dd --- /dev/null +++ b/julia/Dynare.jl @@ -0,0 +1,43 @@ +module Dynare +## + # Copyright (C) 2015 Dynare Team + # + # This file is part of Dynare. + # + # Dynare is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # Dynare is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with Dynare. If not, see . +## + +export dynare + +function dynare(modfile) + # Process modfile + println(string("Using ", WORD_SIZE, "-bit preprocessor")) + preprocessor = string(dirname(@__FILE__()), "/preprocessor", WORD_SIZE, "/dynare_m") + run(`$preprocessor $modfile`) + + # Temporary: clean up Matlab output + basename = split(modfile, ".mod", false) + mfiles = filter(r".*\.m", readdir()) + for file in mfiles + if isempty(search(file, ".mod")) + rm(file) + end + end + rm(basename[1], recursive=true) + + # Load module created by preprocessor + require(basename[1]) +end + +end diff --git a/julia/model.jl b/julia/model.jl new file mode 100644 index 000000000..e983e8d57 --- /dev/null +++ b/julia/model.jl @@ -0,0 +1,122 @@ +module model +## + # Copyright (C) 2015 Dynare Team + # + # This file is part of Dynare. + # + # Dynare is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # Dynare is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with Dynare. If not, see . +## + +export modeldescription + +type modeldescription + fname::ASCIIString + dname::ASCIIString + exonames::Array{ASCIIString,1} + tex_exonames::Array{ASCIIString,1} + long_exonames::Array{ASCIIString,1} + exodetnames::Array{ASCIIString,1} + tex_exodetnames::Array{ASCIIString,1} + long_exodetnames::Array{ASCIIString,1} + endonames::Array{ASCIIString,1} + tex_endonames::Array{ASCIIString,1} + long_endonames::Array{ASCIIString,1} + paramnames::Array{ASCIIString,1} + tex_paramnames::Array{ASCIIString,1} + long_paramnames::Array{ASCIIString,1} + aux_vars::Array{ASCIIString,1} + exo_nbr::Int + endo_nbr::Int + param_nbr::Int + orig_endo_nbr::Int + orig_eq_nbr::Int + eq_nbr::Int + ramsey_eq_nbr::Int + nstatic::Int + nfwrd::Int + npred::Int + nboth::Int + nsfwrd::Int + nspred::Int + ndynamic::Int + maximum_lag::Int + maximum_lead::Int + maximum_endo_lag::Int + maximum_endo_lead::Int + maximum_exo_lag::Int + maximum_exo_lead::Int + lead_lag_incidence::Matrix{Int} + NNZDerivatives::Vector{Int} + static_and_dynamic_models_differ::Bool + equations_tags::Array{ASCIIString,1} + exo_names_orig_ord::Array{Int, 1} + Sigma_e::Matrix{Float64} + Correlation_matrix::Matrix{Float64} + H::Matrix{Float64} + Correlation_matrix_ME::Matrix{Float64} + sigma_e_is_diagonal::Bool + params::Vector{Float64} +end + +function modeldescription() + return modeldescription("", # fname + "", # dname + Array(ASCIIString,0), # exonames + Array(ASCIIString,0), # t_exonames + Array(ASCIIString,0), # l_exonames + Array(ASCIIString,0), # exodetnames + Array(ASCIIString,0), # t_exodetnames + Array(ASCIIString,0), # l_exodetnames + Array(ASCIIString,0), # endonames + Array(ASCIIString,0), # t_endonames + Array(ASCIIString,0), # l_endonames + Array(ASCIIString,0), # paramnames + Array(ASCIIString,0), # t_paramnames + Array(ASCIIString,0), # l_paramnames + Array(ASCIIString,0), # aux_vars + 0, # exo_nbr + 0, # endo_nbr + 0, # param_nbr + 0, # orig_endo_nbr + 0, # orig_eq_nbr + 0, # eq_nbr + 0, # ramsey_eq_nbr + 0, # nstatic + 0, # nfwrd + 0, # npred + 0, # nboth + 0, # nsfwrd + 0, # nspred + 0, # ndynamic + 0, # maximum_lag + 0, # maximum_lead + 0, # maximum_endo_lag + 0, # maximum_endo_lead + 0, # maximum_exo_lag + 0, # maximum_exo_lead + Array(Int, 3, 0), # lead_lag_incidence + zeros(Int, 3), # NNZDerivatives + false, # static_and_dynamic_models_differ + Array(ASCIIString,0), # equations_tags + Array(Int64,1), # exo_names_orig_ord + Array(Float64, 0, 0), # Sigma_e (Covariance matrix of the structural innovations) + Array(Float64, 0, 0), # Correlation_matrix (Correlation matrix of the structural innovations) + Array(Float64, 0, 0), # H (Covariance matrix of the measurement errors) + Array(Float64, 0, 0), # Correlation_matrix_ME (Covariance matrixof the measurement errors) + true, # sigma_e_is_diagonal + Array(Float64, 0) # params + ) +end + +end diff --git a/julia/utils.jl b/julia/utils.jl new file mode 100644 index 000000000..fb4eb7a30 --- /dev/null +++ b/julia/utils.jl @@ -0,0 +1,36 @@ +module utils +## + # Copyright (C) 2015 Dynare Team + # + # This file is part of Dynare. + # + # Dynare is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # Dynare is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with Dynare. If not, see . +## + +export getPowerDeriv + +function getPowerDeriv(x::Float64, p::Real, k::Int) + if abs(x)<1e-12 && p>0 && k>p && typeof(p)==Int + dxp = .0 + else + dxp = x^(p-k) + for i = 0:k-1 + dxp *= p + p -= 1 + end + end + return dxp +end + +end