Changeset 6c96f4


Ignore:
Timestamp:
May 21, 2008, 1:42:05 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
f75030
Parents:
a6e314
Message:

lots of small changes

-1 as either freq_start or freq_step lets VibrAlyzer determine necessary start and step values automatically by considering smallest and greatest possible determinably frequencies. Used start and step values are printed.
In parsing temperatures and timesteps counter-1 instead of counter was used as array index.
outer loop over frequency was done in a overly-correct manner (extra j for the loop, now we calculate freq_end and check for that.
command line values of start and step are now multiplied with 2*2*M_PI, so that they match ranges in the plot later.
Parsing of values was checked and is correct.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • util/VibrAlyzer.c

    ra6e314 r6c96f4  
    2323        double *time_steps, *temperatures;      // contain data value pairs
    2424        int counter;            // keeps track of data pairs array size
    25         double freq_start, freq_step;   // frequency start and step width (end determined by number of points in temp.file)
     25        double freq_start, freq_step, freq_end; // frequency start and step width (end determined by number of points in temp.file)
    2626        char *filename; // filename of temp.file
    2727        char line[255]; // line buffer for parsing the temperature file
    28         int i,j;        // runtime variable
     28        int i;  // runtime variable
    2929        double result, iresult;         // temporary result value for fourier transformation
    3030        double frequency;               // current frequency during dumb O(N^2) integration
     
    6767  counter=0;
    6868  while (fgets(line,255, temperature_file)) {
    69     sscanf(line,"%lg %lg", &time_steps[counter-1], &temperatures[counter-1]);
     69    sscanf(line,"%lg %lg", &time_steps[counter], &temperatures[counter]);
     70    //fprintf(stderr, "%lg\t%lg\n", time_steps[counter], temperatures[counter]);
    7071    counter++;
    7172  }
    72         // for debugging only: print read values
     73  // auto-set good values for start and step based on step range
     74  if ((freq_start == -1) || (freq_step == -1)) {
     75    // we cannot detect frequencies above twice a time step and not below half the time range
     76    freq_start = 1./(fabs(time_steps[counter-1] - time_steps[0])*gauge); 
     77    freq_step = ( 1./(fabs(time_steps[1] - time_steps[0])*gauge) - 1./(fabs(time_steps[counter-1] - time_steps[0])*gauge) )/counter;
     78    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));
     79  } else {
     80    freq_start *= (2.*2.*M_PI);
     81    freq_step *= (2.*2.*M_PI); 
     82  }
     83
     84  // for debugging only: print read values
    7385        //for(i=0;i<(counter-1);i++) {
    7486        //      printf("%lg\t%lg\n",time_steps[i],temperatures[i]);
    7587        //}
    7688 
     89  printf("#frequency(a.u.)\tcos\tsin");
    7790  // discretely integrate over desired frequency range
    78         frequency = freq_start;
    79         for(j=0;j<(counter-1);j++) {
     91  freq_end = freq_start+freq_step*counter-1;
     92        for(frequency = freq_start;frequency < freq_end;frequency += freq_step) {
    8093                result = iresult = 0.;
    8194                for(i=0;i<(counter-1);i++) {
     
    87100    // have the correct frequency!
    88101                printf("%lg\t%lg\t%lg\n",frequency/(2.*2.*M_PI),result/(counter-1),iresult/(counter-1));
    89                 frequency += freq_step;
    90102        }
    91103
Note: See TracChangeset for help on using the changeset viewer.