-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPOT.c
49 lines (48 loc) · 1.1 KB
/
POT.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char command[1000]="cat ";
int detect_pos()
{
FILE *pos;
pos=fopen("POSCAR","r");
if(pos==NULL){
printf("There is no POSCAR file! Please check.");
putchar('\n');
exit(1);
}
else return 1;
}
void touch_temp()
{
system("touch .temp;cat POSCAR | head -n 6 | tail -n 1 > .temp;");
}
void read_generate_command()
{
FILE *pot;pot=fopen(".temp","r");
char elements[20][4];int count=0;
char root[1000]="$lib_PBE/";
while(fscanf(pot,"%s",elements[count])!=EOF){
strcat(root,elements[count]);strcat(root,"/POTCAR");
strcat(command,root);
strcat(command," ");
strcpy(root,"$lib_PBE/");
count++;
}
strcat(command," > POTCAR");
printf("You have %d type(s) of element in the POSCAR file:\n",count);
for(int j=0;j<count;j++)
printf("%s ",elements[j]);
}
int main(){
detect_pos();
touch_temp();
read_generate_command();
system(command);
system("rm .temp");
printf("\nThe POSCAR file has been created.\n");
printf("--------check information-------\n");
system("grep TIT POTCAR");
printf("-----------Done!----------------\n");
return 0;
}