Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xtc-length
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Graham
xtc-length
Commits
0aadc8a8
Commit
0aadc8a8
authored
7 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Compile using ANSI standard
parent
3928e539
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
README.md
+1
-1
1 addition, 1 deletion
README.md
xtc-length.c
+16
-13
16 additions, 13 deletions
xtc-length.c
with
18 additions
and
15 deletions
CMakeLists.txt
+
1
−
1
View file @
0aadc8a8
...
@@ -2,7 +2,7 @@ project(xtc-length)
...
@@ -2,7 +2,7 @@ project(xtc-length)
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
if
(
"
${
CMAKE_C_COMPILER_ID
}
"
STREQUAL
"GNU"
)
if
(
"
${
CMAKE_C_COMPILER_ID
}
"
STREQUAL
"GNU"
)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-
std=gnu90
"
)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-
ansi -O2
"
)
endif
()
endif
()
add_executable
(
xtc-length xtc-length.c
)
add_executable
(
xtc-length xtc-length.c
)
...
...
This diff is collapsed.
Click to expand it.
README.md
+
1
−
1
View file @
0aadc8a8
...
@@ -11,4 +11,4 @@ If you with to install to a directory other than default use `cmake . -DCMAKE_IN
...
@@ -11,4 +11,4 @@ If you with to install to a directory other than default use `cmake . -DCMAKE_IN
Since there is only one source file it is also possible to call the compiler directly if you prefer:
Since there is only one source file it is also possible to call the compiler directly if you prefer:
`gcc
-std=gnu90
-o xtc-length xtc-length.c`
`gcc -o xtc-length xtc-length.c`
This diff is collapsed.
Click to expand it.
xtc-length.c
+
16
−
13
View file @
0aadc8a8
...
@@ -30,34 +30,37 @@ void print_header(const uint8_t header[92]){
...
@@ -30,34 +30,37 @@ void print_header(const uint8_t header[92]){
}
}
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
,
float
*
psec
,
bool
quiet
){
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
,
float
*
psec
,
bool
quiet
){
uint8_t
header
[
92
];
uint32_t
frame_size
;
uint32_t
skip
;
uint32_t
ps_tmp
;
long
size
=
file_size
(
filename
);
long
size
=
file_size
(
filename
);
double
avg_frame_size
=
0
.;
int
est_nframes
=
0
;
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
if
(
!
xtc
)
return
-
1
;
if
(
!
xtc
)
return
-
1
;
uint8_t
header
[
92
];
*
nframes
=
0
;
*
nframes
=
0
;
double
avg_frame_size
=
0
.;
while
(
fread
(
header
,
92
,
1
,
xtc
)){
/* Loop over frames */
int
est_nframes
=
0
;
while
(
fread
(
header
,
92
,
1
,
xtc
)){
// Loop over frames
(
*
nframes
)
++
;
(
*
nframes
)
++
;
*
natoms
=
u4_from_buffer
(
header
+
4
);
*
natoms
=
u4_from_buffer
(
header
+
4
);
uint32_t
frame_size
=
u4_from_buffer
(
header
+
88
);
/
/
Read frame size from header
frame_size
=
u4_from_buffer
(
header
+
88
);
/
*
Read frame size from header
*/
uint32_t
skip
=
(
frame_size
+
3
)
&
~
((
uint32_t
)
3
);
/
/
Round up to 4 byte
s
skip
=
(
frame_size
+
3
)
&
~
((
uint32_t
)
3
);
/
*
Round up to 4 byte
boundary */
avg_frame_size
+=
(
skip
-
avg_frame_size
+
92
)
/
*
nframes
;
avg_frame_size
+=
(
skip
-
avg_frame_size
+
92
)
/
*
nframes
;
if
(
!
quiet
&&
*
nframes
%
10
==
0
){
if
(
!
quiet
&&
*
nframes
%
10
==
0
){
est_nframes
=
(
int
)(
size
/
avg_frame_size
);
est_nframes
=
(
int
)(
size
/
avg_frame_size
);
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
ps_tmp
=
u4_from_buffer
(
header
+
12
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
*
psec
*=
(
double
)
est_nframes
/
*
nframes
;
*
psec
*=
(
double
)
est_nframes
/
*
nframes
;
printf
(
"
\r
Estimated %'d frames (%'d ns) of %'d atoms. - %d%%"
,
printf
(
"
\r
Estimated %'d frames (%'d ns) of %'d atoms. - %d%%"
,
est_nframes
,
(
int
)(
*
psec
/
1000
),
*
natoms
,
(
int
)(
100
.
*
*
nframes
)
/
est_nframes
);
est_nframes
,
(
int
)(
*
psec
/
1000
),
*
natoms
,
(
int
)(
100
.
*
*
nframes
)
/
est_nframes
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
fseeko
(
xtc
,
skip
,
SEEK_CUR
);
/
/
Skip to next header
fseeko
(
xtc
,
skip
,
SEEK_CUR
);
/
*
Skip to next header
*/
}
}
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
ps_tmp
=
u4_from_buffer
(
header
+
12
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
fclose
(
xtc
);
fclose
(
xtc
);
...
@@ -69,6 +72,10 @@ int main(const int argc, const char *argv[]){
...
@@ -69,6 +72,10 @@ int main(const int argc, const char *argv[]){
"Usage: xtc-length [-q] xtc [xtc]...
\n\n
"
"Usage: xtc-length [-q] xtc [xtc]...
\n\n
"
"Default behaviour is to provide running estimate of file length
\n
"
"Default behaviour is to provide running estimate of file length
\n
"
"This can be suppressed using the '-q' flag
\n
"
;
"This can be suppressed using the '-q' flag
\n
"
;
int
i
;
bool
quiet
=
false
;
int
nframes
,
natoms
;
float
psec
;
setlocale
(
LC_ALL
,
""
);
setlocale
(
LC_ALL
,
""
);
...
@@ -76,13 +83,9 @@ int main(const int argc, const char *argv[]){
...
@@ -76,13 +83,9 @@ int main(const int argc, const char *argv[]){
printf
(
"%s"
,
help_text
);
printf
(
"%s"
,
help_text
);
return
0
;
return
0
;
}
}
bool
quiet
=
false
;
if
(
argc
>=
2
&&
!
strcmp
(
argv
[
1
],
"-q"
))
quiet
=
true
;
if
(
argc
>=
2
&&
!
strcmp
(
argv
[
1
],
"-q"
))
quiet
=
true
;
int
i
;
for
(
i
=
quiet
?
2
:
1
;
i
<
argc
;
i
++
){
for
(
i
=
quiet
?
2
:
1
;
i
<
argc
;
i
++
){
int
nframes
,
natoms
;
float
psec
;
printf
(
"%s
\n
"
,
argv
[
i
]);
printf
(
"%s
\n
"
,
argv
[
i
]);
if
(
get_xtc_num_frames
(
argv
[
i
],
&
nframes
,
&
natoms
,
&
psec
,
quiet
)){
if
(
get_xtc_num_frames
(
argv
[
i
],
&
nframes
,
&
natoms
,
&
psec
,
quiet
)){
printf
(
"ERROR: Error reading XTC file
\n
"
);
printf
(
"ERROR: Error reading XTC file
\n
"
);
...
...
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