~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to tools/thermo_extract.c

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2013-11-20 22:41:36 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131120224136-tzx7leh606fqnckm
Tags: 0~20131119.git7162cf0-1
* [e65b919] Imported Upstream version 0~20131119.git7162cf0
* [f7bddd4] Fix some problems, introduced by upstream recently.
* [3616dfc] Use wrap-and-sort script.
* [7e92030] Ignore quilt dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Written by Vikas Varshney
2
 
  Dated Feb 22, 2007
3
 
  Contact Info: vikas.varshney@gmail.com
4
 
 
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.
9
 
 
10
 
Such plots are useful at initial stages of a simulation to make sure
11
 
the system is equilibrated.
12
 
 
13
 
To run this program please compile it as
14
 
 gcc -O3 thermo_extract.c -lm -o thermo_extract
15
 
 
16
 
To extract temperature as a function of timestep, run the code as
17
 
 
18
 
thermo_extract -p Temp -s/-m logfile1 logfile2 ... (all the log files)
19
 
 
20
 
Time and temperature is output as 2 columns of data.  It can
21
 
be re-directed to a file for plotting.
22
 
 
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
26
 
 
27
 
Few points
28
 
 
29
 
1. The log file must contain a "thermo N" command where N is the
30
 
  frequency of the thermo output.
31
 
 
32
 
2. The name of the property "Temp" (in previous example) has to match
33
 
  the thermo property in the logfile.
34
 
 
35
 
3. The log file(s) can contain thermo info for multiple runs.
36
 
 
37
 
4. Currently, you can only use one parameter as input, so for extracting
38
 
  multiple properties, you have to run the code again.
39
 
 
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. 
43
 
 
44
 
  PLEASE avoid using  
45
 
  "Dangerous", "Memory", "Step" and "Loop" in the input script
46
 
 
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.
49
 
 
50
 
*/
51
 
 
52
 
#include<stdio.h>
53
 
#include<stdlib.h>
54
 
#include<math.h>
55
 
#include <string.h>
56
 
#include <stddef.h>
57
 
 
58
 
FILE *input;
59
 
char filename_input[100];
60
 
char string1[100],*string2;
61
 
char temp[80];
62
 
int j,k,check,timestep;
63
 
double datapoint;
64
 
int thermostylecounter,thermocounter,runcounter,totalsteps;
65
 
int narg1;
66
 
char *token;
67
 
char templl[80];
68
 
int thermo[100];
69
 
int run[100];
70
 
 
71
 
void scan_first_part()
72
 
{
73
 
 while(strcmp(temp,"Memory"))
74
 
  fscanf(input,"%s ",&temp);
75
 
}
76
 
 
77
 
void scan_data_multi(int temp1,char* chartemp)
78
 
{
79
 
 totalsteps=run[temp1]/thermo[temp1]+1;
80
 
 for(j=0;j<totalsteps;j++)
81
 
  {
82
 
    while(strcmp(temp,"Step"))
83
 
      fscanf(input,"%s ",&temp);
84
 
 
85
 
    fscanf(input,"%s ",&temp);
86
 
    timestep=atoi(temp);
87
 
 
88
 
    while(strcmp(temp,chartemp))
89
 
      fscanf(input,"%s ",&temp);
90
 
 
91
 
    fscanf(input,"%s ",&temp);
92
 
    fscanf(input,"%s ",&temp);
93
 
    datapoint=atof(temp);
94
 
    if ((temp1!=0) && (j==0))
95
 
      {}
96
 
    else
97
 
      printf("%d %f\n",timestep,datapoint);
98
 
  }
99
 
}
100
 
 
101
 
void scan_data_single(int temp1,char* chartemp)
102
 
{
103
 
 fgets(string1,100,input);
104
 
 fgets(string1,100,input);
105
 
 narg1=0;
106
 
 for(j=0;j<strlen(string1);j++)
107
 
  if(string1[j]==' ')
108
 
    narg1++;
109
 
 
110
 
 token=strtok(string1," ");
111
 
 check=0;
112
 
 for(j=1;j<narg1;j++)
113
 
  {
114
 
    token=strtok(NULL," ");
115
 
    if (!strcmp(token,chartemp))
116
 
      {
117
 
        check=j;
118
 
        break;
119
 
      }
120
 
  }
121
 
 
122
 
 if (check>0)
123
 
  {}
124
 
 else
125
 
  {
126
 
    printf("Couldn't recognize parameter\n");
127
 
    exit(1);
128
 
  }
129
 
 
130
 
 totalsteps=run[temp1]/thermo[temp1]+1;
131
 
 for(j=0;j<totalsteps;j++)
132
 
  {
133
 
    fscanf(input,"%s ",&temp);
134
 
    timestep=atoi(temp);
135
 
    for(k=0;k<check;k++)
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))
141
 
      {}
142
 
    else
143
 
      printf("%d %f\n",timestep,datapoint);
144
 
  }
145
 
}
146
 
 
147
 
int main(int arg, char **argv)
148
 
{
149
 
 int singleoutput,next,eofpointer,i,file;
150
 
 char firsttemp[256];
151
 
 int iterations;
152
 
 if (arg<5)
153
 
  {
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");
157
 
    exit(1);
158
 
  }
159
 
 for(file=4;file<arg;file++)
160
 
  {
161
 
    sprintf(filename_input,argv[file]);
162
 
    if ((input=fopen(filename_input,"r"))==NULL)
163
 
      {
164
 
        printf("Error reading %dth file.\n",file);
165
 
        exit(1);
166
 
      }
167
 
    iterations=0;
168
 
    while(!feof(input))
169
 
      {
170
 
        fscanf(input,"%s ",&firsttemp);
171
 
        if (!strcmp(firsttemp,"Dangerous"))
172
 
          iterations++;
173
 
      }
174
 
    rewind(input);
175
 
    for(i=0;i<100;i++)
176
 
      {
177
 
        thermo[i]=0;
178
 
        run[i]=0;
179
 
      }
180
 
 
181
 
    for(i=0;i<iterations;i++)
182
 
      {
183
 
        while(strcmp(firsttemp,"run"))
184
 
          {
185
 
            fscanf(input,"%s ",&firsttemp);
186
 
            if (!strcmp(firsttemp,"thermo"))
187
 
              {
188
 
                fscanf(input,"%s ",&firsttemp);
189
 
                thermo[i]=atoi(firsttemp);
190
 
              }
191
 
          }
192
 
        fscanf(input,"%s ",&firsttemp);
193
 
        run[i]=atoi(firsttemp);
194
 
        if ((i==0) && (thermo[i]==0))
195
 
          {
196
 
            printf("thermo info not found in the file.. Exiting\n");
197
 
            exit(1);
198
 
          }
199
 
        if (thermo[i]==0)
200
 
          thermo[i]=thermo[i-1];
201
 
      }
202
 
 
203
 
    rewind(input);
204
 
 
205
 
    if (!strcmp(argv[3],"-m"))
206
 
      thermostylecounter=1;
207
 
    else if (!strcmp(argv[3],"-s"))
208
 
      thermostylecounter=0;
209
 
    else
210
 
      {
211
 
        printf("Couldn't recognize file format. Please use either -m or -s\n");
212
 
        exit(1);
213
 
      }
214
 
 
215
 
    if (thermostylecounter==1)
216
 
      for(i=0;i<iterations;i++)
217
 
        {
218
 
          scan_first_part();
219
 
          scan_data_multi(i,argv[2]);
220
 
          while(strcmp(temp,"Loop"))
221
 
            fscanf(input,"%s ",&temp);
222
 
          for(j=0;j<19;j++)
223
 
            fgets(temp,80,input);
224
 
        }
225
 
    else
226
 
      for(i=0;i<iterations;i++)
227
 
        {
228
 
          scan_first_part();
229
 
          scan_data_single(i,argv[2]);
230
 
          while(strcmp(temp,"Loop"))
231
 
            fscanf(input,"%s ",&temp);
232
 
          for(j=0;j<19;j++)
233
 
            fgets(temp,80,input);
234
 
        }
235
 
    fclose(input);
236
 
  }
237
 
 return 0;
238
 
}