Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSource
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Willem Thorbecke
OpenSource
Commits
4c4bebe6
Commit
4c4bebe6
authored
5 years ago
by
Jan Willem Thorbecke
Browse files
Options
Downloads
Patches
Plain Diff
3D allocation efficient for 1D and 2D models
parent
b399efb4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fdelmodc3D/alloc3D.c
+73
-0
73 additions, 0 deletions
fdelmodc3D/alloc3D.c
with
73 additions
and
0 deletions
fdelmodc3D/alloc3D.c
0 → 100644
+
73
−
0
View file @
4c4bebe6
#include
<stdlib.h>
#include
"fdelmodc3D.h"
/* Copyright (c) Colorado School of Mines, 2011.*/
/* All rights reserved. */
/* allocate a 3-d array of floats */
float
***
alloc3float
(
modPar
mod
)
{
size_t
i3
,
i2
,
n1
,
n2
,
n3
,
size
;
float
***
p
;
n1
=
mod
.
naz
;
n2
=
mod
.
nax
;
n3
=
mod
.
nay
;
size
=
sizeof
(
float
);
/* allocate pointer arrays of n3 and n2 */
if
((
p
=
(
float
***
)
malloc
(
n3
*
sizeof
(
float
**
)))
==
NULL
)
return
NULL
;
if
((
p
[
0
]
=
(
float
**
)
malloc
(
n3
*
n2
*
sizeof
(
float
*
)))
==
NULL
)
{
free
(
p
);
return
NULL
;
}
/* allocate data size and assign pointers to n1, n2 and n3 */
if
(
mod
.
nfx
==
1
&&
mod
.
nfy
==
1
)
{
// 1D model
fprintf
(
stderr
,
"Allocating 1D model
\n
"
);
if
((
p
[
0
][
0
]
=
(
float
*
)
malloc
(
n1
*
size
))
==
NULL
)
{
free
(
p
);
return
NULL
;
}
for
(
i3
=
0
;
i3
<
n3
;
i3
++
)
{
p
[
i3
]
=
p
[
0
];
for
(
i2
=
0
;
i2
<
n2
;
i2
++
)
p
[
i3
][
i2
]
=
(
float
*
)
p
[
0
][
0
];
}
}
else
if
(
mod
.
nfy
==
1
)
{
// 2D model
fprintf
(
stderr
,
"Allocating 2D model
\n
"
);
if
((
p
[
0
][
0
]
=
(
float
*
)
malloc
(
n2
*
n1
*
size
))
==
NULL
)
{
free
(
p
);
return
NULL
;
}
for
(
i3
=
0
;
i3
<
n3
;
i3
++
)
{
p
[
i3
]
=
p
[
0
];
for
(
i2
=
0
;
i2
<
n2
;
i2
++
)
p
[
i3
][
i2
]
=
(
float
*
)
p
[
0
]
+
n1
*
i2
;
}
}
else
{
// 3D model
fprintf
(
stderr
,
"Allocating 3D model
\n
"
);
if
((
p
[
0
][
0
]
=
(
float
*
)
malloc
(
n3
*
n2
*
n1
*
size
))
==
NULL
)
{
free
(
p
[
0
]);
free
(
p
);
return
NULL
;
}
for
(
i3
=
0
;
i3
<
n3
;
i3
++
)
{
p
[
i3
]
=
p
[
0
]
+
n2
*
i3
;
for
(
i2
=
0
;
i2
<
n2
;
i2
++
)
p
[
i3
][
i2
]
=
(
float
*
)
p
[
0
][
0
]
+
n1
*
(
i2
+
n2
*
i3
);
}
}
return
p
;
}
void
free3float
(
float
***
p
)
{
free
(
p
[
0
][
0
]);
free
(
p
[
0
]);
free
(
p
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment