[Swift-commit] r8132 - SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Wed Aug 13 11:35:59 CDT 2014
Author: wozniak
Date: 2014-08-13 11:35:59 -0500 (Wed, 13 Aug 2014)
New Revision: 8132
Modified:
SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
Log:
Make one big TRJ file
Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c 2014-08-13 16:30:05 UTC (rev 8131)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c 2014-08-13 16:35:59 UTC (rev 8132)
@@ -1,3 +1,4 @@
+# include <assert.h>
# include <stdlib.h>
# include <stdio.h>
# include <time.h>
@@ -17,6 +18,9 @@
void snap ( int np, int nd, double pos[], double vel[], double f[],
double acc[], double mass, double dt );
+static void snap_file_open(void);
+static void snap_file_close(void);
+
void simulate (int step_num, int step_print_num,
int step_print, int step_print_index,
int np, int nd,
@@ -44,6 +48,9 @@
printf ( "\n" );
printf ( " Initializing positions, velocities, and accelerations.\n" );
+
+ snap_file_open();
+
/*
Set initial positions, velocities, and accelerations.
*/
@@ -108,6 +115,7 @@
free ( vel );
fclose(ofile);
+ snap_file_close();
}
/******************************************************************************/
@@ -572,22 +580,32 @@
}
static int snapid = 0;
+static FILE *snap_file = NULL;
+static void snap_file_open()
+{
+ char snapfile[100];
+ sprintf(snapfile, "md%02d.trj", snapid);
+ snap_file = fopen(snapfile, "w");
+ assert(snap_file != NULL);
+}
+
+static void snap_file_close()
+{
+ fclose(snap_file);
+ snap_file = NULL;
+}
+
void snap ( int np, int nd, double pos[], double vel[], double f[],
double acc[], double mass, double dt )
{
int j;
-
- char snapfile[100];
- sprintf(snapfile, "md%02d.trj", snapid);
- FILE *sf = fopen(snapfile, "w");
-
for ( j = 0; j < np; j++ )
{
- fprintf(sf, "s %f %f %f %s\n", scale(pos[0+j*nd]), scale(pos[1+j*nd]), scale(pos[2+j*nd]), printinfo);
+ fprintf(snap_file, "s %f %f %f %s\n",
+ scale(pos[0+j*nd]), scale(pos[1+j*nd]), scale(pos[2+j*nd]), printinfo);
}
- fclose(sf);
snapid++;
}
More information about the Swift-commit
mailing list