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
cc60fcd8
Commit
cc60fcd8
authored
8 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Added usage info and quiet flag
parent
051175d9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
xtc-length.c
+17
-5
17 additions, 5 deletions
xtc-length.c
with
17 additions
and
5 deletions
xtc-length.c
+
17
−
5
View file @
cc60fcd8
...
...
@@ -2,6 +2,7 @@
#include
<stdint.h>
#include
<locale.h>
#include
<string.h>
#include
<stdbool.h>
#include
<sys/stat.h>
...
...
@@ -28,7 +29,7 @@ void print_header(const uint8_t header[92]){
printf
(
"
\n
"
);
}
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
,
float
*
psec
){
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
,
float
*
psec
,
bool
quiet
){
long
size
=
file_size
(
filename
);
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
...
...
@@ -40,13 +41,12 @@ int get_xtc_num_frames(const char *filename, int *nframes, int *natoms, float *p
double
avg_frame_size
=
0
.;
int
est_nframes
=
0
;
while
(
fread
(
header
,
92
,
1
,
xtc
)){
// Loop over frames
//print_header(header);
(
*
nframes
)
++
;
*
natoms
=
u4_from_buffer
(
header
+
4
);
uint32_t
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 bytes
avg_frame_size
+=
(
skip
-
avg_frame_size
+
92
)
/
*
nframes
;
if
(
*
nframes
%
10
==
0
){
if
(
!
quiet
&&
*
nframes
%
10
==
0
){
est_nframes
=
size
/
avg_frame_size
;
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
...
...
@@ -65,20 +65,32 @@ int get_xtc_num_frames(const char *filename, int *nframes, int *natoms, float *p
}
int
main
(
const
int
argc
,
const
char
*
argv
[]){
const
char
*
help_text
=
"Count number of frames and simulation time of GROMACS XTC file
\n
"
"Usage: xtc-length <xtc name> [-q]
\n\n
"
"Default behaviour is to provide running estimate of file length
\n
"
"This can be suppressed using the '-q' flag
\n
"
;
setlocale
(
LC_ALL
,
""
);
if
(
argc
<
2
){
printf
(
"ERROR: Incorrect usage - must give input filename
\n
"
);
return
-
1
;
}
if
(
!
strcmp
(
argv
[
1
],
"-h"
)
||
!
strcmp
(
argv
[
1
],
"--help"
)){
printf
(
"%s"
,
help_text
);
return
0
;
}
bool
quiet
=
false
;
if
(
argc
>=
3
&&
!
strcmp
(
argv
[
2
],
"-q"
))
quiet
=
true
;
int
nframes
,
natoms
;
float
psec
;
if
(
get_xtc_num_frames
(
argv
[
1
],
&
nframes
,
&
natoms
,
&
psec
)){
if
(
get_xtc_num_frames
(
argv
[
1
],
&
nframes
,
&
natoms
,
&
psec
,
quiet
)){
printf
(
"ERROR: Error reading XTC file
\n
"
);
return
-
1
;
}
printf
(
"
\r
Trajectory contains %'d frames (%'.2f ns) of %'d atoms.
\n
"
,
nframes
,
psec
/
1000
,
natoms
);
if
(
!
quiet
)
printf
(
"
\r
"
);
printf
(
"Trajectory contains %'d frames (%'.2f ns) of %'d atoms.
\n
"
,
nframes
,
psec
/
1000
,
natoms
);
return
0
;
}
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