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
051175d9
Commit
051175d9
authored
9 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Now gives running estimate of XTC length - kill using ctrl-C when happy
with estimate;
parent
5625ae9b
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
+23
-1
23 additions, 1 deletion
xtc-length.c
with
23 additions
and
1 deletion
xtc-length.c
+
23
−
1
View file @
051175d9
...
@@ -3,12 +3,20 @@
...
@@ -3,12 +3,20 @@
#include
<locale.h>
#include
<locale.h>
#include
<string.h>
#include
<string.h>
#include
<sys/stat.h>
/*
/*
* Program for finding the number of frames and atoms in a GROMACS XTC file.
* Program for finding the number of frames and atoms in a GROMACS XTC file.
* Inspired by a post on the gmx-developers mailing list in 2012:
* Inspired by a post on the gmx-developers mailing list in 2012:
* https://mailman-1.sys.kth.se/pipermail/gromacs.org_gmx-developers/2012-June/005937.html
* https://mailman-1.sys.kth.se/pipermail/gromacs.org_gmx-developers/2012-June/005937.html
*/
*/
long
file_size
(
const
char
*
filename
){
struct
stat
buffer
;
int
rc
=
stat
(
filename
,
&
buffer
);
return
rc
==
0
?
buffer
.
st_size
:
-
1
;
}
uint32_t
u4_from_buffer
(
const
uint8_t
*
b
){
uint32_t
u4_from_buffer
(
const
uint8_t
*
b
){
return
b
[
0
]
<<
24
|
b
[
1
]
<<
16
|
b
[
2
]
<<
8
|
b
[
3
]
<<
0
;
return
b
[
0
]
<<
24
|
b
[
1
]
<<
16
|
b
[
2
]
<<
8
|
b
[
3
]
<<
0
;
}
}
...
@@ -21,18 +29,32 @@ void print_header(const uint8_t header[92]){
...
@@ -21,18 +29,32 @@ void print_header(const uint8_t header[92]){
}
}
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
){
long
size
=
file_size
(
filename
);
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
if
(
!
xtc
)
return
-
1
;
if
(
!
xtc
)
return
-
1
;
uint8_t
header
[
92
];
uint8_t
header
[
92
];
*
nframes
=
0
;
*
nframes
=
0
;
double
avg_frame_size
=
0
.;
int
est_nframes
=
0
;
while
(
fread
(
header
,
92
,
1
,
xtc
)){
// Loop over frames
while
(
fread
(
header
,
92
,
1
,
xtc
)){
// Loop over frames
//print_header(header);
//print_header(header);
(
*
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
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
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
){
est_nframes
=
size
/
avg_frame_size
;
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
*
psec
*=
(
double
)
est_nframes
/
*
nframes
;
printf
(
"
\r
Estimated %'d frames (%'d ns) of %'d atoms. - %d%%"
,
est_nframes
,
(
int
)(
*
psec
/
1000
),
*
natoms
,
(
int
)(
100
.
*
*
nframes
)
/
est_nframes
);
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
);
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
...
@@ -57,6 +79,6 @@ int main(const int argc, const char *argv[]){
...
@@ -57,6 +79,6 @@ int main(const int argc, const char *argv[]){
return
-
1
;
return
-
1
;
}
}
printf
(
"Trajectory contains %'d frames (%'.2f ns) of %'d atoms.
\n
"
,
nframes
,
psec
/
1000
,
natoms
);
printf
(
"
\r
Trajectory contains %'d frames (%'.2f ns) of %'d atoms.
\n
"
,
nframes
,
psec
/
1000
,
natoms
);
return
0
;
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