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
b2cc72a3
Commit
b2cc72a3
authored
9 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Added final simulation time to output, added locale - breaks ANSI;
parent
eafa1f21
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
+18
-3
18 additions, 3 deletions
xtc-length.c
with
18 additions
and
3 deletions
xtc-length.c
+
18
−
3
View file @
b2cc72a3
#include
<stdio.h>
#include
<inttypes.h>
#include
<locale.h>
#include
<string.h>
/*
* Program for finding the number of frames and atoms in a GROMACS XTC file.
...
...
@@ -11,7 +13,14 @@ uint32_t u4_from_buffer(const uint8_t *b){
return
b
[
0
]
<<
24
|
b
[
1
]
<<
16
|
b
[
2
]
<<
8
|
b
[
3
]
<<
0
;
}
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
){
void
print_header
(
const
uint8_t
header
[
92
]){
printf
(
"%4d"
,
u4_from_buffer
(
header
+
0
));
printf
(
"%8d"
,
u4_from_buffer
(
header
+
4
));
printf
(
"%12d"
,
u4_from_buffer
(
header
+
8
));
printf
(
"
\n
"
);
}
int
get_xtc_num_frames
(
const
char
*
filename
,
int
*
nframes
,
int
*
natoms
,
float
*
psec
){
FILE
*
xtc
=
fopen
(
filename
,
"rb"
);
if
(
!
xtc
)
return
-
1
;
...
...
@@ -19,29 +28,35 @@ int get_xtc_num_frames(const char *filename, int *nframes, int *natoms){
*
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
fseek
(
xtc
,
skip
,
SEEK_CUR
);
// Skip to next header
}
uint32_t
ps_tmp
=
u4_from_buffer
(
header
+
12
);
memcpy
(
psec
,
&
ps_tmp
,
4
);
fclose
(
xtc
);
return
0
;
}
int
main
(
const
int
argc
,
const
char
*
argv
[]){
setlocale
(
LC_ALL
,
""
);
if
(
argc
<
2
){
printf
(
"ERROR: Incorrect usage - must give input filename
\n
"
);
return
-
1
;
}
int
nframes
,
natoms
;
if
(
get_xtc_num_frames
(
argv
[
1
],
&
nframes
,
&
natoms
)){
float
psec
;
if
(
get_xtc_num_frames
(
argv
[
1
],
&
nframes
,
&
natoms
,
&
psec
)){
printf
(
"ERROR: Error reading XTC file
\n
"
);
return
-
1
;
}
printf
(
"Trajectory contains %d frames of %d atoms.
\n
"
,
nframes
,
natoms
);
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