source: util/src/VibrAlyzer.c@ 086db0

Last change on this file since 086db0 was ef87ee, checked in by Frederik Heber <heber@…>, 16 years ago

Added versioning to each executable.

  • credits to Ralf Wildenhues for writing the Makefile.am code
  • version.c section added to Makefile.am (pcp, molecuilder and util)
  • src/version.h to each pcp, molecuilder and util
  • each of the executables includes version.h and prints version in main()

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/* Molecular Vibrations Analyser - VibrAlyzer
2 *
3 * This programme fourier transforms input from ESPACK (temperature output)
4 * in order to make the automated retrieval of vibrational frequencies possible.
5*/
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10
11#include "version.h"
12
13/** Main routine.
14 * The routine needs a file name to be read as the temperature file, and also
15 * a frequency range (start and steps). Standard one-dimensional fourier-trans-
16 * formation via a simple discrete integration over the given values from the
17 * file is performed and the result returned on stdout.
18 * \param argc parameter count
19 * \param **argv array of parameter (array of chars)
20 * \return error code
21*/
22int main(int argc, char **argv)
23{
24 FILE *temperature_file; // file with temperature values
25 double *time_steps, *temperatures; // contain data value pairs
26 int counter; // keeps track of data pairs array size
27 double freq_start, freq_step, freq_end; // frequency start and step width (end determined by number of points in temp.file)
28 char *filename; // filename of temp.file
29 char line[255]; // line buffer for parsing the temperature file
30 int i; // runtime variable
31 double result, iresult; // temporary result value for fourier transformation
32 double frequency; // current frequency during dumb O(N^2) integration
33 double gauge; // conversion to atomic units for time axis
34
35 printf("Molecular Vibrations Analyser - VibrAlyzer\n%s\n", ESPACKVersion);
36
37 // Check for needed arguments
38 if (argc < 4) {
39 printf("Usage: %s <time gauge> <freq.step> <temperature file>\n", argv[0]);
40 printf("\t<time gauge>\tConversion factor from step count to atomic time\n");
41 printf("\t<freq.start>\tstart of frequency for fourier transform in atomic units\n");
42 printf("\t<freq.step>\tstep width of frequency for fourier transform in atomic units\n");
43 printf("\t<temperature file>\tfile with (time step, temperature)-pairs\n");
44 exit(1);
45 } else {
46 gauge = atof(argv[1]);
47 freq_start = atof(argv[2]);
48 freq_step = atof(argv[3]);
49 filename = argv[4];
50 }
51
52 // read in file into buffer array
53 temperature_file=fopen(filename, "r");
54 if (temperature_file == NULL) { // check whether file could be opened
55 printf("Could not open temperature file named '%s'!\n", filename);
56 exit(255);
57 }
58 // check number of pairs
59 counter=0;
60 while (fgets(line,255, temperature_file)) {
61 sscanf(line,"%lg %lg", &result, &iresult);
62 counter++;
63 }
64 // ... allocate ...
65 time_steps = malloc(counter*sizeof(double));
66 temperatures = malloc(counter*sizeof(double));
67 fclose(temperature_file);
68 // ... and parse in
69 temperature_file=fopen(filename, "r");
70 counter=0;
71 while (fgets(line,255, temperature_file)) {
72 sscanf(line,"%lg %lg", &time_steps[counter], &temperatures[counter]);
73 //fprintf(stderr, "%lg\t%lg\n", time_steps[counter], temperatures[counter]);
74 counter++;
75 }
76 // auto-set good values for start and step based on step range
77 if ((freq_start == -1) || (freq_step == -1)) {
78 // we cannot detect frequencies above twice a time step and not below half the time range
79 freq_start = 1./(fabs(time_steps[counter-1] - time_steps[0])*gauge);
80 freq_step = ( 1./(fabs(time_steps[1] - time_steps[0])*gauge) - 1./(fabs(time_steps[counter-1] - time_steps[0])*gauge) )/counter;
81 fprintf(stderr, "Using %lg and frequency start and %lg as step size.\n", freq_start/(2.*2.*M_PI), freq_step/(2.*2.*M_PI));
82 } else {
83 freq_start *= (2.*2.*M_PI);
84 freq_step *= (2.*2.*M_PI);
85 }
86
87 // for debugging only: print read values
88 //for(i=0;i<(counter-1);i++) {
89 // printf("%lg\t%lg\n",time_steps[i],temperatures[i]);
90 //}
91
92 printf("#frequency(a.u.)\tcos\tsin");
93 // discretely integrate over desired frequency range
94 freq_end = freq_start+freq_step*counter-1;
95 for(frequency = freq_start;frequency < freq_end;frequency += freq_step) {
96 result = iresult = 0.;
97 for(i=0;i<(counter-1);i++) {
98 result += temperatures[i] * cos(frequency * time_steps[i]*gauge);
99 iresult += temperatures[i] * sin(frequency * time_steps[i]*gauge);
100 }
101 // NOTE: It is by definition freq over 2*pi, however as the temperature curve counts double (there are two
102 // standstills, one at the perihel one at the aphel!) we insert this factor to make the plots automatically
103 // have the correct frequency!
104 printf("%lg\t%lg\t%lg\n",frequency/(2.*2.*M_PI),result/(counter-1),iresult/(counter-1));
105 }
106
107 // dis'alloc and end
108 exit(0);
109}
Note: See TracBrowser for help on using the repository browser.