Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. BEGIN header
  2.  
  3. Real Lattice(A) Lattice parameters(A) Cell Angles
  4. 2.4675850 0.0000000 0.0000000 a = 2.467585 alpha = 90.000000
  5. 0.0000000 30.0000000 0.0000000 b = 30.000000 beta = 90.000000
  6. 0.0000000 0.0000000 30.0000000 c = 30.000000 gamma = 90.000000
  7.  
  8. 1 ! nspins
  9. 25 300 300 ! fine FFT grid along <a,b,c>
  10. END header: data is "<a b c> pot" in units of Hartrees
  11.  
  12. 1 1 1 0.042580
  13. 1 1 2 0.049331
  14. 1 1 3 0.038605
  15. 1 1 4 0.049181
  16.  
  17. int readinputfile() {
  18. FILE *potential = fopen("orderedfile.txt", "r");
  19. for (i=0; i<size; i++) {
  20. fscanf(potential, "%lf %lf %*f %lf", &x[i], &y[i], &V[i]);
  21. }
  22. fclose(potential);
  23. }
  24.  
  25. int res = fscanf(potential, "%lf %lf %*f %lf", &x, &y, &v);
  26. if (res == EOF) break;
  27. if (res != 3) {
  28. fscanf(potential, "%*[^n]");
  29. }
  30.  
  31. #include <stdio.h>
  32.  
  33. int main()
  34. {
  35. /* maybe the buffer must be greater */
  36. char lineBuffer[256];
  37. FILE *potential = fopen("orderedfile.txt", "r");
  38.  
  39. /* loop through every line */
  40. while (fgets(lineBuffer, sizeof(lineBuffer), potential) != NULL)
  41. {
  42. double a, b, c;
  43. /* if there are 3 items matched print them */
  44. if (3 == sscanf(lineBuffer, "%lf %lf %*f %lf", &a, &b, &c))
  45. {
  46. printf("%f %f %fn", a, b, c);
  47. }
  48. }
  49. fclose(potential);
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement