| 1 |
/* |
| 2 |
* Copyright (C) 1996-2011 Daniel Waggoner and Tao Zha |
| 3 |
* |
| 4 |
* This free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* It is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* If you did not received a copy of the GNU General Public License |
| 15 |
* with this software, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "dw_switch.h" |
| 19 |
|
| 20 |
#ifdef __cplusplus |
| 21 |
extern "C" |
| 22 |
{ |
| 23 |
#endif |
| 24 |
|
| 25 |
/* |
| 26 |
Routines for reading/writing Markov state variable specifications, states, |
| 27 |
transition matrices parameters and transition matrices from a TStateModel |
| 28 |
structure. |
| 29 |
*/ |
| 30 |
TMarkovStateVariable* ReadMarkovSpecification(FILE *f, char *filename); |
| 31 |
int WriteMarkovSpecification(FILE *f, char *filename, TStateModel *model); |
| 32 |
int ReadTransitionMatrixParameters(FILE *f, char *filename, char *header, TStateModel *model); |
| 33 |
int WriteTransitionMatrixParameters(FILE *f, char *filename, char *header, TStateModel *model); |
| 34 |
int ReadBaseTransitionMatrices_t(int t, FILE *f, char *filename, char *header, TStateModel *model); |
| 35 |
#define ReadBaseTransitionMatrices(f,filename,header,model) ReadBaseTransitionMatrices_t(0,f,filename,header,model) |
| 36 |
int WriteGrandTransitionMatrix_t(int t, FILE *f, char *filename, char *header, TStateModel *model); |
| 37 |
int WriteBaseTransitionMatrices_t(int t, FILE *f, char *filename, char *header, TStateModel *model); |
| 38 |
#define WriteGrandTransitionMatrix(f,filename,header,model) WriteGrandTransitionMatrix_t(0,f,filename,header,model) |
| 39 |
#define WriteBaseTransitionMatrices(f,filename,header,model) WriteBaseTransitionMatrices_t(0,f,filename,header,model) |
| 40 |
int ReadStates(FILE *f, char *filename, char *header, TStateModel *model); |
| 41 |
int WriteStates(FILE *f, char *filename, char *header, TStateModel *model); |
| 42 |
int ReadTheta(FILE *f, char *filename, char *header, TStateModel *model); |
| 43 |
int WriteTheta(FILE *f, char *filename, char *header, TStateModel *model); |
| 44 |
int ReadFreeParameters(FILE *f, char *filename, TStateModel *model); |
| 45 |
int WriteFreeParameters(FILE *f, char *filename, TStateModel *model); |
| 46 |
|
| 47 |
/* |
| 48 |
Flat Files |
| 49 |
*/ |
| 50 |
int ReadBaseTransitionMatricesFlat_t(int t, FILE *f, char *filename, TStateModel *model); |
| 51 |
#define ReadBaseTransitionMatricesFlat(f,filename,model) ReadBaseTransitionMatricesFlat_t(0,f,filename,model) |
| 52 |
int WriteBaseTransitionMatricesFlat_t(int t, FILE *f, char *filename, TStateModel *model, char *fmt); |
| 53 |
#define WriteBaseTransitionMatricesFlat(f,filename,model,fmt) WriteBaseTransitionMatricesFlat_t(0,f,filename,model,fmt) |
| 54 |
int sv_ReadBaseTransitionMatricesFlat_t(int t, FILE *f_in, TMarkovStateVariable *sv, TStateModel *model); |
| 55 |
int sv_WriteBaseTransitionMatricesFlat(FILE *f_out, TMarkovStateVariable* sv, char *fmt); |
| 56 |
int WriteBaseTransitionMatricesFlat_Headers(FILE *f, TStateModel *model); |
| 57 |
int sv_WriteBaseTransitionMatricesFlat_Headers(FILE *f_out, TMarkovStateVariable* sv, char *idstring); |
| 58 |
|
| 59 |
/* |
| 60 |
Metropolis-Hastings routines |
| 61 |
*/ |
| 62 |
int Read_metropolis_theta(FILE *f, char *filename, char *header, struct TMetropolis_theta_tag *metropolis); |
| 63 |
int Write_metropolis_theta(FILE *f, char *filename, char *header, struct TMetropolis_theta_tag *metropolis); |
| 64 |
TMatrix dw_ReadPosteriorDraws(FILE *f_in, char *filename, char *tag, int nparameters); |
| 65 |
int dw_ReadPosteriorDraw(FILE *f_in, TStateModel *model); |
| 66 |
|
| 67 |
/* |
| 68 |
Base routines for recursively reading/writing Markov state variable |
| 69 |
specifications, transition matrices parameters and transition matrices |
| 70 |
from a TMarkovStateVariable structure. |
| 71 |
*/ |
| 72 |
TMarkovStateVariable* sv_ReadMarkovSpecification(FILE *f_in, char *idstring); |
| 73 |
int sv_WriteMarkovSpecification(FILE *f_out, TMarkovStateVariable *sv, char *idstring); |
| 74 |
int sv_ReadTransitionMatrixParameters(FILE *f_in, TMarkovStateVariable *sv, char *header); |
| 75 |
int sv_WriteTransitionMatrixParameters(FILE *f_out, TMarkovStateVariable *sv, char *header); |
| 76 |
int sv_ReadBaseTransitionMatrices_t(int t, FILE *f_in, char *header, char *idstring, TMarkovStateVariable* sv, TStateModel *model); |
| 77 |
int sv_WriteBaseTransitionMatrices(FILE *f, TMarkovStateVariable *sv, char *header, char *idstring); |
| 78 |
|
| 79 |
|
| 80 |
//====== Read flat markov state variable specification from file. ======// |
| 81 |
TMarkovStateVariable* CreateMarkovStateVariable_Simple(FILE *f_in, char *idstring); |
| 82 |
TMarkovStateVariable* CreateMarkovStateVariable_File(FILE *f, char *filename); |
| 83 |
|
| 84 |
int ReadDSGEControllingVariables(int *not_time_varying, int **n_coef, int **cum_total_coef, int*** idx_coef, |
| 85 |
int **n_var, int **cum_total_var, int ***idx_var, FILE *f_in, TMarkovStateVariable *sv); |
| 86 |
|
| 87 |
|
| 88 |
//====== TRestricted io routines ======// |
| 89 |
#include "dw_dirichlet_restrictions.h" |
| 90 |
TDirichletRestrictions* ReadSpecification_dirichlet_restrictions(FILE *f_in, char *trailer, int nstates); |
| 91 |
int WriteSpecification_dirichlet_restrictions(FILE *f_out, TMarkovStateVariable *sv, char *trailer); |
| 92 |
|
| 93 |
|
| 94 |
//====== Utility routines ======// |
| 95 |
#define SWITCHIO_LINE_ID_NOT_FOUND 1 |
| 96 |
#define SWITCHIO_ERROR_READING_DATA 2 |
| 97 |
#define SWITCHIO_FILE_ERROR 3 |
| 98 |
void ReadError(char *idformat, char *trailer, int error); |
| 99 |
int SetFilePosition(FILE *f_in, char *format, char *str); |
| 100 |
int ReadInteger(FILE *f_in, char *idformat, char *trailer, int *i); |
| 101 |
int ReadMatrix(FILE *f_in, char *idformat, char *trailer, TMatrix X); |
| 102 |
int ReadVector(FILE *f_in, char *idformat, char *trailer, TVector v); |
| 103 |
int ReadIntArray(FILE *f_in, char *idformat, char *trailer, void *X); |
| 104 |
char* CreateIntegerString(char *format, char *str, int k); |
| 105 |
|
| 106 |
#ifdef __cplusplus |
| 107 |
} |
| 108 |
#endif |