Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
src
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
H5hut
src
Commits
97516866
Commit
97516866
authored
Apr 15, 2016
by
gsell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/H5Block: attach_field_attribs and dump_field_attribs added
parent
1dfcd9f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
266 additions
and
0 deletions
+266
-0
.gitignore
.gitignore
+2
-0
examples/H5Block/Makefile.am
examples/H5Block/Makefile.am
+4
-0
examples/H5Block/attach_field_attributes.c
examples/H5Block/attach_field_attributes.c
+66
-0
examples/H5Block/dump_field_attributes.c
examples/H5Block/dump_field_attributes.c
+194
-0
No files found.
.gitignore
View file @
97516866
...
...
@@ -10,6 +10,8 @@
Makefile
Makefile.in
aclocal.m4
attach_field_attributes
dump_field_attributes
autom4te.cache/
compile
config.guess
...
...
examples/H5Block/Makefile.am
View file @
97516866
...
...
@@ -25,6 +25,8 @@ noinst_PROGRAMS =
if
ENABLE_C
noinst_PROGRAMS
+=
\
attach_field_attributes
\
dump_field_attributes
\
fields
\
has_field
\
read_write_scalar_field
\
...
...
@@ -37,6 +39,8 @@ noinst_PROGRAMS += read_write_scalar_fieldf
endif
endif
attach_field_attributes_SOURCES
=
attach_field_attributes.c
dump_field_attributes_SOURCES
=
dump_field_attributes.c
fields_SOURCES
=
fields.c
has_field_SOURCES
=
has_field.c
read_write_scalar_field_SOURCES
=
read_write_scalar_field.c
...
...
examples/H5Block/attach_field_attributes.c
0 → 100644
View file @
97516866
/*
Copyright (c) 2006-2015, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
License: see file COPYING in top level of source distribution.
*/
#include "H5hut.h"
// name of output file
const
char
*
fname
=
"example_field.h5"
;
// H5hut verbosity level
const
h5_int64_t
h5_verbosity
=
H5_VERBOSE_DEFAULT
;
int
main
(
int
argc
,
char
*
argv
[]
){
// initialize MPI & H5hut
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm
comm
=
MPI_COMM_WORLD
;
int
comm_size
=
1
;
MPI_Comm_size
(
comm
,
&
comm_size
);
int
comm_rank
=
0
;
MPI_Comm_rank
(
comm
,
&
comm_rank
);
H5AbortOnError
();
H5SetVerbosityLevel
(
h5_verbosity
);
//H5SetDebugMask (-1);
// open file and create first step
h5_file_t
file
=
H5OpenFile
(
fname
,
H5_O_RDWR
,
H5_PROP_DEFAULT
);
H5SetStep
(
file
,
0
);
if
(
!
H5BlockHasField
(
file
,
"data"
))
{
printf
(
"Doesn't have field data with name 'data' in step#0
\n
"
);
goto
done
;
}
h5_int32_t
attrib
[
1
]
=
{
42
};
H5BlockWriteFieldAttribInt32
(
file
,
"data"
,
"The answer"
,
attrib
,
sizeof
(
attrib
)
/
sizeof
(
*
attrib
));
h5_float64_t
origin
[
3
]
=
{
0
.
0
,
0
.
0
,
1
.
0
};
H5Block3dSetFieldOrigin
(
file
,
"data"
,
origin
[
0
],
origin
[
1
],
origin
[
2
]);
h5_float64_t
spacing
[
3
]
=
{
1
.
0
,
2
.
0
,
3
.
0
};
H5Block3dSetFieldSpacing
(
file
,
"data"
,
spacing
[
0
],
spacing
[
1
],
spacing
[
2
]);
done:
// done
H5CloseFile
(
file
);
MPI_Finalize
();
return
0
;
}
examples/H5Block/dump_field_attributes.c
0 → 100644
View file @
97516866
/*
Copyright (c) 2006-2015, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
License: see file COPYING in top level of source distribution.
*/
#include "H5hut.h"
// name of output file
const
char
*
fname
=
"example_field.h5"
;
// H5hut verbosity level
const
h5_int64_t
h5_verbosity
=
H5_VERBOSE_DEFAULT
;
static
inline
void
dump_int64_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_size_t
attrib_nelems
)
{
h5_int64_t
attrib_data
[
attrib_nelems
];
H5BlockReadFieldAttribInt64
(
file
,
field_name
,
attrib_name
,
attrib_data
);
printf
(
"Attribute: '%s'
\n
"
,
attrib_name
);
printf
(
" Type: H5_INT64_T
\n
"
);
printf
(
" Data: %lld"
,
attrib_data
[
0
]);
for
(
size_t
i
=
1
;
i
<
attrib_nelems
;
i
++
)
{
printf
(
", %lld"
,
attrib_data
[
i
]);
}
printf
(
"
\n
"
);
}
static
inline
void
dump_int32_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_size_t
attrib_nelems
)
{
h5_int32_t
attrib_data
[
attrib_nelems
];
H5BlockReadFieldAttribInt32
(
file
,
field_name
,
attrib_name
,
attrib_data
);
printf
(
"Attribute: '%s'
\n
"
,
attrib_name
);
printf
(
" Type: H5_INT32_T
\n
"
);
printf
(
" Data: %ld"
,
(
long
)
attrib_data
[
0
]);
for
(
size_t
i
=
1
;
i
<
attrib_nelems
;
i
++
)
{
printf
(
", %ld"
,
(
long
)
attrib_data
[
i
]);
}
printf
(
"
\n
"
);
}
static
inline
void
dump_float64_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_size_t
attrib_nelems
)
{
h5_float64_t
attrib_data
[
attrib_nelems
];
H5BlockReadFieldAttribFloat64
(
file
,
field_name
,
attrib_name
,
attrib_data
);
printf
(
"Attribute: '%s'
\n
"
,
attrib_name
);
printf
(
" Type: H5_FLOAT64_T
\n
"
);
printf
(
" Data: %2f"
,
attrib_data
[
0
]);
for
(
size_t
i
=
1
;
i
<
attrib_nelems
;
i
++
)
{
printf
(
", %2f"
,
attrib_data
[
i
]);
}
printf
(
"
\n
"
);
}
static
inline
void
dump_float32_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_size_t
attrib_nelems
)
{
h5_float32_t
attrib_data
[
attrib_nelems
];
H5BlockReadFieldAttribFloat32
(
file
,
field_name
,
attrib_name
,
attrib_data
);
printf
(
"Attribute: '%s'
\n
"
,
attrib_name
);
printf
(
" Type: H5_FLOAT32_T
\n
"
);
printf
(
" Data: %2f"
,
attrib_data
[
0
]);
for
(
size_t
i
=
1
;
i
<
attrib_nelems
;
i
++
)
{
printf
(
", %2f"
,
attrib_data
[
i
]);
}
printf
(
"
\n
"
);
}
inline
void
dump_string_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_size_t
attrib_nelems
)
{
}
void
dump_attrib
(
h5_file_t
file
,
const
char
*
const
field_name
,
const
char
*
const
attrib_name
,
h5_int64_t
attrib_type
,
h5_size_t
attrib_nelems
)
{
if
(
attrib_type
==
H5_INT64_T
)
{
dump_int64_attrib
(
file
,
field_name
,
attrib_name
,
attrib_nelems
);
}
else
if
(
attrib_type
==
H5_INT32_T
)
{
dump_int32_attrib
(
file
,
field_name
,
attrib_name
,
attrib_nelems
);
}
else
if
(
attrib_type
==
H5_FLOAT64_T
)
{
dump_float64_attrib
(
file
,
field_name
,
attrib_name
,
attrib_nelems
);
}
else
if
(
attrib_type
==
H5_FLOAT32_T
)
{
dump_float32_attrib
(
file
,
field_name
,
attrib_name
,
attrib_nelems
);
}
else
if
(
attrib_type
==
H5_STRING_T
)
{
dump_string_attrib
(
file
,
field_name
,
attrib_name
,
attrib_nelems
);
}
}
int
main
(
int
argc
,
char
*
argv
[]
){
// initialize MPI & H5hut
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm
comm
=
MPI_COMM_WORLD
;
int
comm_size
=
1
;
MPI_Comm_size
(
comm
,
&
comm_size
);
int
comm_rank
=
0
;
MPI_Comm_rank
(
comm
,
&
comm_rank
);
H5AbortOnError
();
H5SetVerbosityLevel
(
h5_verbosity
);
//H5SetDebugMask (-1);
// open file and create first step
h5_file_t
file
=
H5OpenFile
(
fname
,
H5_O_RDWR
,
H5_PROP_DEFAULT
);
H5SetStep
(
file
,
0
);
// test wheter field exists
const
char
field_name
[]
=
"data"
;
if
(
!
H5BlockHasField
(
file
,
field_name
))
{
printf
(
"Doesn't have field data with name 'data' in step#0
\n
"
);
goto
done
;
}
// get number of attributes attached to field
h5_ssize_t
n_attribs
=
H5BlockGetNumFieldAttribs
(
file
,
field_name
);
printf
(
"Field has %lld attributes attached.
\n
"
,
n_attribs
);
// dump all attached attributes
for
(
h5_size_t
i
=
0
;
i
<
n_attribs
;
i
++
)
{
char
attrib_name
[
128
];
h5_size_t
sizeof_attrib_name
=
sizeof
(
attrib_name
);
h5_int64_t
attrib_type
;
h5_size_t
attrib_nelems
;
H5BlockGetFieldAttribInfo
(
file
,
field_name
,
i
,
attrib_name
,
sizeof_attrib_name
,
&
attrib_type
,
&
attrib_nelems
);
dump_attrib
(
file
,
field_name
,
attrib_name
,
attrib_type
,
attrib_nelems
);
}
done:
// done
H5CloseFile
(
file
);
MPI_Finalize
();
return
0
;
}
Write
Preview
Markdown
is supported
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