1
/* Written by Vikas Varshney
3
Contact Info: vikas.varshney@gmail.com
5
The main purpose of this simple code is to extract thermodynamic
6
information such as Temperature, Pressure, Energy, etc from LAMMPS log
7
files, to plot them as a function of timestep in a simple plotting
8
programs such as xmgrace.
10
Such plots are useful at initial stages of a simulation to make sure
11
the system is equilibrated.
13
To run this program please compile it as
14
gcc -O3 thermo_extract.c -lm -o thermo_extract
16
To extract temperature as a function of timestep, run the code as
18
thermo_extract -p Temp -s/-m logfile1 logfile2 ... (all the log files)
20
Time and temperature is output as 2 columns of data. It can
21
be re-directed to a file for plotting.
23
-p for thermo parameter to extract
24
-s if the output format is single line, or
25
-m is the output format is multi line
29
1. The log file must contain a "thermo N" command where N is the
30
frequency of the thermo output.
32
2. The name of the property "Temp" (in previous example) has to match
33
the thermo property in the logfile.
35
3. The log file(s) can contain thermo info for multiple runs.
37
4. Currently, you can only use one parameter as input, so for extracting
38
multiple properties, you have to run the code again.
40
5. The Program uses the following keywords to keep track of the data in
41
the file. In general, these keywords are not used in input script (which
42
in turn get printed in log file) but are worth mentioning.
45
"Dangerous", "Memory", "Step" and "Loop" in the input script
47
"thermo" and "run" except when they are used to specify frequency of
48
thermo output and total number of steps to be run, respectively.
59
char filename_input[100];
60
char string1[100],*string2;
62
int j,k,check,timestep;
64
int thermostylecounter,thermocounter,runcounter,totalsteps;
71
void scan_first_part()
73
while(strcmp(temp,"Memory"))
74
fscanf(input,"%s ",&temp);
77
void scan_data_multi(int temp1,char* chartemp)
79
totalsteps=run[temp1]/thermo[temp1]+1;
80
for(j=0;j<totalsteps;j++)
82
while(strcmp(temp,"Step"))
83
fscanf(input,"%s ",&temp);
85
fscanf(input,"%s ",&temp);
88
while(strcmp(temp,chartemp))
89
fscanf(input,"%s ",&temp);
91
fscanf(input,"%s ",&temp);
92
fscanf(input,"%s ",&temp);
94
if ((temp1!=0) && (j==0))
97
printf("%d %f\n",timestep,datapoint);
101
void scan_data_single(int temp1,char* chartemp)
103
fgets(string1,100,input);
104
fgets(string1,100,input);
106
for(j=0;j<strlen(string1);j++)
110
token=strtok(string1," ");
114
token=strtok(NULL," ");
115
if (!strcmp(token,chartemp))
126
printf("Couldn't recognize parameter\n");
130
totalsteps=run[temp1]/thermo[temp1]+1;
131
for(j=0;j<totalsteps;j++)
133
fscanf(input,"%s ",&temp);
136
fscanf(input,"%s ",&temp);
137
datapoint=atof(temp);
138
for(k=0;k<narg1-1-check;k++)
139
fscanf(input,"%s ",&temp);
140
if ((temp1!=0) && (j==0))
143
printf("%d %f\n",timestep,datapoint);
147
int main(int arg, char **argv)
149
int singleoutput,next,eofpointer,i,file;
154
printf("Insufficient number of arguements\n");
155
printf("Please make sure the systax has the following format\n");
156
printf("thermo_extract -p parameter -m/-s logfile1 logfile2 ...\n");
159
for(file=4;file<arg;file++)
161
sprintf(filename_input,argv[file]);
162
if ((input=fopen(filename_input,"r"))==NULL)
164
printf("Error reading %dth file.\n",file);
170
fscanf(input,"%s ",&firsttemp);
171
if (!strcmp(firsttemp,"Dangerous"))
181
for(i=0;i<iterations;i++)
183
while(strcmp(firsttemp,"run"))
185
fscanf(input,"%s ",&firsttemp);
186
if (!strcmp(firsttemp,"thermo"))
188
fscanf(input,"%s ",&firsttemp);
189
thermo[i]=atoi(firsttemp);
192
fscanf(input,"%s ",&firsttemp);
193
run[i]=atoi(firsttemp);
194
if ((i==0) && (thermo[i]==0))
196
printf("thermo info not found in the file.. Exiting\n");
200
thermo[i]=thermo[i-1];
205
if (!strcmp(argv[3],"-m"))
206
thermostylecounter=1;
207
else if (!strcmp(argv[3],"-s"))
208
thermostylecounter=0;
211
printf("Couldn't recognize file format. Please use either -m or -s\n");
215
if (thermostylecounter==1)
216
for(i=0;i<iterations;i++)
219
scan_data_multi(i,argv[2]);
220
while(strcmp(temp,"Loop"))
221
fscanf(input,"%s ",&temp);
223
fgets(temp,80,input);
226
for(i=0;i<iterations;i++)
229
scan_data_single(i,argv[2]);
230
while(strcmp(temp,"Loop"))
231
fscanf(input,"%s ",&temp);
233
fgets(temp,80,input);