funkalicious 0.1

func_sum.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib-2.0/glib.h>
#include <libdotcode/function_parser.h>
#include "config.h"
#include "common.h"
Include dependency graph for func_sum.c:

Go to the source code of this file.

Defines

#define EV_PER_HARTREE   27.2113834
#define NM_PER_BOHR   0.05291772083
#define INSET   10

Functions

int main (int argv, char *argc[])

Define Documentation

#define EV_PER_HARTREE   27.2113834

Definition at line 30 of file func_sum.c.

#define INSET   10

Definition at line 34 of file func_sum.c.

Referenced by main().

#define NM_PER_BOHR   0.05291772083

Definition at line 31 of file func_sum.c.


Function Documentation

int main ( int  argv,
char *  argc[] 
)

Definition at line 36 of file func_sum.c.

References INSET, wavefunc_header::Nc, wavefunc_header::Nx, wavefunc_header::Ny, wavefunc_header::Nz, and read_wavefunction().

                                 {
  g_type_init();
  int i;
  struct wavefunc_header header;
  double *matrix;
  int err;
  int retval;
  /*probability of being within the specified region*/
  double prob;
  int x, y, z, band;
  double re, im;
  /*TOTAL sum*/
  double tsum;
  if(argv == 1) {
    fprintf(stderr, "Umm, you probably want to pass me a file or space-separated list of files to read.\n");
    exit(1);
  }
  for(i=1; i<argv; i++) {
    retval = read_wavefunction(argc[i], &header, &matrix, &err);
    if(retval != 0) {
      fprintf(stderr, "ERROR: read_wavefunction returned %d, err=%d (%s).\n", retval, err, strerror(err));
    }
    tsum=prob=0;
    for(z=0; z<header.Nz; ++z) {
      for(y=0; y<header.Ny; ++y) {
  for(x=0; x<header.Nx; ++x) {
    for(band=0; band<header.Nc; ++band) {
      re = matrix[band*2 + x*header.Nc*2 + y*header.Nx*header.Nc*2 + z*header.Ny*header.Nx*header.Nc*2];
      im = matrix[1 + band*2 + x*header.Nc*2 + y*header.Nx*header.Nc*2 + z*header.Ny*header.Nx*header.Nc*2];
      #ifdef DEBUG
      fprintf(stderr, "x=%d,y=%d,z=%d,b=%d: %g + i%g\n", x, y, z, band, re, im);
      #endif
      tsum += re*re + (im*im);
      if(
         (x < INSET) || ((header.Nx-x-1) < INSET)
         || (y < INSET) || ((header.Ny-y-1) < INSET)
         || (z < INSET) || ((header.Nz-z-1) < INSET)
         ){ 
        prob += re*re + (im*im);
      }
    }
  }
      }
    }
    printf("%s\t%g\n", argc[i], prob);
  }
  exit(0);
}

Here is the call graph for this function:

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines