Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
12993a81
Commit
12993a81
authored
Aug 27, 2010
by
Houtan Bastani
Browse files
SWZ: replace malloc with swzMalloc
parent
3bbfc056
Changes
2
Hide whitespace changes
Inline
Side-by-side
matlab/swz/c-code/sbvar/var/forecast.c
View file @
12993a81
...
...
@@ -9,6 +9,8 @@
#include
<stdlib.h>
#include
<string.h>
#include
"modify_for_mex.h"
/*
Assumes
f_out : valid FILE pointer
...
...
@@ -43,7 +45,7 @@ int forecast_percentile(FILE *f_out, TVector percentiles, int draws, FILE *poste
if
(
T
>
p
->
nobs
)
return
0
;
// allocate memory
S
=
(
int
*
)
m
alloc
(
h
*
sizeof
(
int
));
S
=
(
int
*
)
swzM
alloc
(
h
*
sizeof
(
int
));
forecast
=
CreateMatrix
(
h
,
p
->
nvars
);
histogram
=
CreateMatrixHistogram
(
h
,
p
->
nvars
,
100
,
HISTOGRAM_VARIABLE
);
initial
=
CreateVector
(
p
->
npre
);
...
...
@@ -166,7 +168,7 @@ int forecast_percentile_regime(FILE *f_out, TVector percentiles, int draws,
if
(
T
>
p
->
nobs
)
return
0
;
// allocate memory
S
=
(
int
*
)
m
alloc
(
h
*
sizeof
(
int
));
S
=
(
int
*
)
swzM
alloc
(
h
*
sizeof
(
int
));
for
(
i
=
0
;
i
<
h
;
i
++
)
S
[
i
]
=
s
;
forecast
=
CreateMatrix
(
h
,
p
->
nvars
);
histogram
=
CreateMatrixHistogram
(
h
,
p
->
nvars
,
100
,
HISTOGRAM_VARIABLE
);
...
...
@@ -306,15 +308,15 @@ int main(int nargs, char **args)
// specification filename
if
(
buffer
=
dw_ParseString_String
(
nargs
,
args
,
"fs"
,(
char
*
)
NULL
))
strcpy
(
spec
=
(
char
*
)
m
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
strcpy
(
spec
=
(
char
*
)
swzM
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
// parameter filename
if
(
buffer
=
dw_ParseString_String
(
nargs
,
args
,
"fp"
,(
char
*
)
NULL
))
strcpy
(
parm
=
(
char
*
)
m
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
strcpy
(
parm
=
(
char
*
)
swzM
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
// header
if
(
buffer
=
dw_ParseString_String
(
nargs
,
args
,
"ph"
,(
char
*
)
NULL
))
strcpy
(
head
=
(
char
*
)
m
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
strcpy
(
head
=
(
char
*
)
swzM
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
// file tag
if
(
tag
=
dw_ParseString_String
(
nargs
,
args
,
"ft"
,(
char
*
)
NULL
))
...
...
@@ -323,11 +325,11 @@ int main(int nargs, char **args)
// specification filename
if
(
!
spec
)
sprintf
(
spec
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
sprintf
(
spec
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
// parameter filename
if
(
!
parm
)
sprintf
(
parm
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
sprintf
(
parm
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
}
// horizon
...
...
@@ -347,12 +349,12 @@ int main(int nargs, char **args)
}
if
(
!
parm
)
strcpy
(
parm
=
(
char
*
)
m
alloc
(
strlen
(
spec
)
+
1
),
spec
);
strcpy
(
parm
=
(
char
*
)
swzM
alloc
(
strlen
(
spec
)
+
1
),
spec
);
if
(
!
head
)
{
buffer
=
"Posterior mode: "
;
strcpy
(
head
=
(
char
*
)
m
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
strcpy
(
head
=
(
char
*
)
swzM
alloc
(
strlen
(
buffer
)
+
1
),
buffer
);
}
model
=
Read_VAR_Specification
((
FILE
*
)
NULL
,
spec
);
...
...
@@ -370,7 +372,7 @@ int main(int nargs, char **args)
/* if (dw_FindArgument_String(nargs,args,"mean") != -1) */
/* { */
/* fmt="forecasts_mean_%s.prn"; */
/* sprintf(out_filename=(char*)
m
alloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); */
/* sprintf(out_filename=(char*)
swzM
alloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); */
/* f_out=fopen(out_filename,"wt"); */
/* free(out_filename); */
/* printf("Constructing mean forecast\n"); */
...
...
@@ -386,7 +388,7 @@ int main(int nargs, char **args)
{
// Open posterior draws file
fmt
=
"draws_%s.dat"
;
sprintf
(
post
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
sprintf
(
post
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
if
(
!
(
posterior_file
=
fopen
(
post
,
"rt"
)))
{
printf
(
"Unable to open draws file: %s
\n
"
,
post
);
...
...
@@ -448,7 +450,7 @@ int main(int nargs, char **args)
{
rewind
(
posterior_file
);
fmt
=
"forecasts_percentiles_regime_%d_%s.prn"
;
sprintf
(
out_filename
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
3
),
fmt
,
s
,
tag
);
sprintf
(
out_filename
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
3
),
fmt
,
s
,
tag
);
f_out
=
fopen
(
out_filename
,
"wt"
);
free
(
out_filename
);
printf
(
"Constructing percentiles for forecasts - regime %d
\n
"
,
s
);
...
...
@@ -459,7 +461,7 @@ int main(int nargs, char **args)
if
(((
s
=
dw_ParseInteger_String
(
nargs
,
args
,
"regime"
,
-
1
))
>=
0
)
&&
(
s
<
p
->
nstates
))
{
fmt
=
"forecasts_percentiles_regime_%d_%s.prn"
;
sprintf
(
out_filename
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
3
),
fmt
,
s
,
tag
);
sprintf
(
out_filename
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
3
),
fmt
,
s
,
tag
);
f_out
=
fopen
(
out_filename
,
"wt"
);
free
(
out_filename
);
printf
(
"Constructing percentiles for forecasts - regime %d
\n
"
,
s
);
...
...
@@ -469,7 +471,7 @@ int main(int nargs, char **args)
else
{
fmt
=
"forecasts_percentiles_%s.prn"
;
sprintf
(
out_filename
=
(
char
*
)
m
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
sprintf
(
out_filename
=
(
char
*
)
swzM
alloc
(
strlen
(
fmt
)
+
strlen
(
tag
)
-
1
),
fmt
,
tag
);
f_out
=
fopen
(
out_filename
,
"wt"
);
free
(
out_filename
);
printf
(
"Constructing percentiles for forecasts - %d draws of shocks/regimes per posterior value
\n
"
,
draws
);
...
...
matlab/swz/c-code/utilities/DWCcode/histogram/dw_histogram.c
View file @
12993a81
...
...
@@ -6,6 +6,8 @@
#include
"dw_histogram.h"
#include
"dw_error.h"
#include
"modify_for_mex.h"
static
void
Resize
(
PRECISION
x
,
int
*
h
,
PRECISION
*
min
,
PRECISION
*
max
,
int
intervals
);
static
void
AddObservationVariable
(
PRECISION
x
,
int
*
h
,
PRECISION
*
min
,
PRECISION
*
max
,
int
intervals
);
static
void
AddObservationFixed
(
PRECISION
x
,
int
*
low
,
int
*
h
,
int
*
high
,
PRECISION
min
,
PRECISION
max
,
int
intervals
);
...
...
@@ -37,23 +39,23 @@ TMatrixHistogram *CreateMatrixHistogram(int rows, int cols, int intervals, int t
int
i
,
j
;
TMatrixHistogram
*
h
;
if
(
!
(
h
=
(
TMatrixHistogram
*
)
m
alloc
(
sizeof
(
TMatrixHistogram
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
=
(
TMatrixHistogram
*
)
swzM
alloc
(
sizeof
(
TMatrixHistogram
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
***
)
m
alloc
(
rows
*
sizeof
(
int
**
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
***
)
swzM
alloc
(
rows
*
sizeof
(
int
**
))))
dw_Error
(
MEM_ERR
);
for
(
i
=
rows
-
1
;
i
>=
0
;
i
--
)
{
if
(
!
(
h
->
freq
[
i
]
=
(
int
**
)
m
alloc
(
cols
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
[
i
]
=
(
int
**
)
swzM
alloc
(
cols
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
for
(
j
=
cols
-
1
;
j
>=
0
;
j
--
)
if
(
!
(
h
->
freq
[
i
][
j
]
=
(
int
*
)
m
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
[
i
][
j
]
=
(
int
*
)
swzM
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
}
if
(
!
(
h
->
low
=
(
int
**
)
m
alloc
(
rows
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
low
=
(
int
**
)
swzM
alloc
(
rows
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
for
(
i
=
rows
-
1
;
i
>=
0
;
i
--
)
if
(
!
(
h
->
low
[
i
]
=
(
int
*
)
m
alloc
(
cols
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
low
[
i
]
=
(
int
*
)
swzM
alloc
(
cols
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
high
=
(
int
**
)
m
alloc
(
rows
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
high
=
(
int
**
)
swzM
alloc
(
rows
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
for
(
i
=
rows
-
1
;
i
>=
0
;
i
--
)
if
(
!
(
h
->
high
[
i
]
=
(
int
*
)
m
alloc
(
cols
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
high
[
i
]
=
(
int
*
)
swzM
alloc
(
cols
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
h
->
Min
=
CreateMatrix
(
rows
,
cols
);
h
->
Max
=
CreateMatrix
(
rows
,
cols
);
...
...
@@ -193,15 +195,15 @@ TVectorHistogram *CreateVectorHistogram(int dim, int intervals, int type)
int
i
;
TVectorHistogram
*
h
;
if
(
!
(
h
=
(
TVectorHistogram
*
)
m
alloc
(
sizeof
(
TVectorHistogram
))))
if
(
!
(
h
=
(
TVectorHistogram
*
)
swzM
alloc
(
sizeof
(
TVectorHistogram
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
**
)
m
alloc
(
dim
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
**
)
swzM
alloc
(
dim
*
sizeof
(
int
*
))))
dw_Error
(
MEM_ERR
);
for
(
i
=
dim
-
1
;
i
>=
0
;
i
--
)
if
(
!
(
h
->
freq
[
i
]
=
(
int
*
)
m
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
[
i
]
=
(
int
*
)
swzM
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
low
=
(
int
*
)
m
alloc
(
dim
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
high
=
(
int
*
)
m
alloc
(
dim
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
low
=
(
int
*
)
swzM
alloc
(
dim
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
high
=
(
int
*
)
swzM
alloc
(
dim
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
h
->
Min
=
CreateVector
(
dim
);
h
->
Max
=
CreateVector
(
dim
);
...
...
@@ -333,9 +335,9 @@ TScalarHistogram *CreateScalarHistogram(int intervals, int type)
{
TScalarHistogram
*
h
;
if
(
!
(
h
=
(
TScalarHistogram
*
)
m
alloc
(
sizeof
(
TScalarHistogram
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
=
(
TScalarHistogram
*
)
swzM
alloc
(
sizeof
(
TScalarHistogram
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
*
)
m
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
if
(
!
(
h
->
freq
=
(
int
*
)
swzM
alloc
(
intervals
*
sizeof
(
int
))))
dw_Error
(
MEM_ERR
);
h
->
intervals
=
intervals
;
h
->
sample_size
=
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment