473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Extraction of function calls from C file

Hi,
I am using parse::recdescent module to parse C file.
Currently I having problem while creating a grammer to extract the function calls
from C file. Let me know if anybody worked on this module and help me out.

Thank you.

-Abhijeet
Oct 30 '07 #1
15 1600
numberwhun
3,509 Expert Mod 2GB
Hi,
I am using parse::recdescent module to parse C file.
Currently I having problem while creating a grammer to extract the function calls
from C file. Let me know if anybody worked on this module and help me out.

Thank you.

-Abhijeet
In order for the experts here to assist you, they are going to have to see the code that you are working on. Please post your code here, enclosed in the proper code tags, and we will have a look.

Regards,

Jeff
Oct 30 '07 #2
The code is not fixed one, it may vary as C file changes.

But still as a sample test code I am referring following program:
Expand|Select|Wrap|Line Numbers
  1. /* deMunck's multilayer model. */
  2. /* 
  3.    See J.C. Demunck and Maria J. Peters,
  4.    "A Fast Method to Compute the Potential 
  5.    in the Multisphere Model", IEEE Trans. 
  6.    Biomed. Eng. , Vo 40. N. 11, November 1993.
  7.    pp 1168-1174
  8.    All Units are MKS, dammit.
  9.  */
  10. #include <time.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <math.h>
  14. #include <malloc.h>
  15. #include <limits.h>
  16. /*#include <values.h>*/
  17. #include "matrixmalloc.h"
  18. #include <unistd.h>
  19. #include <getopt.h>
  20. #define FOUR_PI 12.5664f
  21. #define Pi 3.14159265358979
  22. #define pi Pi
  23. #include <signal.h>
  24.  
  25.  
  26. int I,J,K;
  27. int start_i=1,start_j=1,start_k=1;
  28. int curr_i,curr_j,curr_k;
  29.  
  30. int minimum_terms=50;
  31.  
  32. int slow=0,singleslice=0,sensorlist=0;
  33. int isotropic =1; 
  34.  
  35. double rad,mono=0.0f;
  36. int filemode; 
  37. double *r, *eps, *eta;
  38. int layers;
  39. double Mrad =0.0f,  Mtan =0.0f ;
  40. double  dx=1.0f,dy=1.0f,dz=1.0f,rbottom=0.0f,rbottom2=0.0f;
  41. double sx=0.0f,sy=0.0f,sz=0.0f;
  42. double tolerance =0.001f; 
  43. double *Rbottom, *Rright; 
  44. double * legendre;
  45. int rbsize; 
  46. void oopsie(int signum) { 
  47.   FILE * disasterfile; 
  48.   fprintf(stderr, "Caught signal %d, while on voxel %d %d %d.",
  49.      signum,curr_i,curr_j,curr_k); 
  50.   disasterfile=fopen("demunck.disaster","w");
  51.   fprintf(disasterfile, "Caught signal %d, while on voxel %d %d %d.",
  52.      signum,curr_i,curr_j,curr_k); 
  53.   fclose(disasterfile); 
  54.   exit(-22); 
  55.  
  56. #if 0
  57. int ijkton(int i, int j, int k){
  58.   return i+I*(j-1)+I*J*(k-1);
  59. }
  60. #endif
  61.  
  62. double nu(int j,int n)
  63. { /* equation 14 */
  64.   return
  65.     isotropic?
  66.     n:
  67.   ((-1+sqrt(1+
  68.         4*n*(n+1)*eta[j]/eps[j]))
  69.    /2);
  70. }
  71.  
  72. void smatrix(int sign, int j, double r_a, double r_b,int n, double out[3][3]) {
  73.   /* equations 30 and 29 */
  74.   double nu_val,nu2;
  75.  
  76.   nu_val=nu(j,n);
  77.   nu2= 2*nu_val+1;
  78.   if (sign == -1) {
  79.     out[1][1] = nu_val*r_a/(nu2*r_b);
  80.     out[1][2] = -r_a/(nu2*eps[j]);
  81.     out[2][1] = -(nu_val+1)*nu_val*eps[j]/(nu2*r_b);
  82.     out[2][2] = (nu_val+1)/nu2;
  83.   }  
  84.   if (sign == 1) {
  85.     out[1][1] = (nu_val+1)/nu2;
  86.     out[1][2] = r_b/(nu2*eps[j]);
  87.     out[2][1] = (nu_val+1)*nu_val*eps[j]/(nu2*r_a);
  88.     out[2][2] = nu_val*r_b/(nu2*r_a);
  89.   }
  90.  
  91. }
  92.  
  93. double beta(int j) {
  94.   return sqrt(eta[j]*eps[j]);
  95. }
  96.  
  97. double alpha(int j ) {
  98.   return sqrt(eta[j]/eps[j]);
  99. }
  100.  
  101. void matrix_prod_2x2(double a[3][3], double b[3][3], double prod[3][3]){
  102.  
  103.   prod[1][1] = a[1][1]*b[1][1]+a[1][2]*b[2][1];
  104.   prod[1][2] = a[1][1]*b[1][2]+a[1][2]*b[2][2];
  105.   prod[2][1] = a[2][1]*b[1][1]+a[2][2]*b[2][1];
  106.   prod[2][2] = a[2][1]*b[1][2]+a[2][2]*b[2][2];
  107.  
  108. }
  109.  
  110. void matrix_prod(double** a, double** b, double** prod){
  111.  
  112.   prod[1][1] = a[1][1]*b[1][1]+a[1][2]*b[2][1];
  113.   prod[1][2] = a[1][1]*b[1][2]+a[1][2]*b[2][2];
  114.   prod[2][1] = a[2][1]*b[1][1]+a[2][2]*b[2][1];
  115.   prod[2][2] = a[2][1]*b[1][2]+a[2][2]*b[2][2];
  116.  
  117. }
  118.  
  119. void clear_2x2 (double **matrix){
  120.  
  121.   free(matrix[1]);
  122.  
  123.   free(matrix);
  124. }
  125.  
  126. void matrix_sum_2x2(double a[3][3], double b[3][3]){
  127.   a[1][1]+=b[1][1];
  128.   a[1][2]+=b[1][2];
  129.   a[2][2]+=b[2][2];
  130.   a[2][1]+=b[2][1];
  131.  
  132. }
  133.  
  134. void copy_2x2 (double a[3][3], double b[3][3]){
  135.   a[1][1]=b[1][1];
  136.   a[1][2]=b[1][2];
  137.   a[2][1]=b[2][1];
  138.   a[2][2]=b[2][2];
  139. }
  140.  
  141. void matrix_scalar_2x2(double a[3][3], double b){
  142.   a[1][1]*=b;
  143.   a[1][2]*=b;
  144.   a[2][1]*=b;
  145.   a[2][2]*=b;
  146. }
  147. double lambda(int j,double nu_){/* equation 33 */
  148.   return pow(r[j+1]/r[j],nu_);
  149. }
  150.  
  151. void u_matrix(int n,int j, double r_a, double r_b, double out[3][3]){
  152.   /* equation 31 */
  153.   double sminus[3][3];
  154.   double splus[3][3];
  155.   double tempscalar,nu_;
  156.  
  157.   if (r_b>0.0f) { 
  158.  
  159.     tempscalar=pow(r_a/r_b,-2*nu(j,n)-2);
  160.  
  161.     smatrix(1,j,r_a,r_b,n,splus);/* r_a r_b*/
  162.     smatrix(-1,j,r_a,r_b,n,sminus);
  163.     matrix_scalar_2x2(sminus,tempscalar);
  164.  
  165.     matrix_sum_2x2(splus,sminus);
  166.     copy_2x2(out,splus);
  167.  
  168.   }else {
  169.     /* the problem for the deep cases lies HERE. */
  170.  
  171.     nu_=nu(layers,n);
  172.     out[1][1]=0.0f; 
  173.     out[2][1]=0.0f;
  174.     out[1][2]=1/(eps[layers]*(1+2*nu_)); 
  175.     out[2][2]=nu_/(r_a*(1+2*nu_)); 
  176.     if (!n) {
  177.       out[1][2]=-1/(r_a*eps[layers]);
  178.       out[2][2]=1/(r_a*r_a);
  179.     }
  180.   }
  181.  
  182. }
  183.  
  184.  
  185. double R(int n,double r_o, double r_e,
  186.      int Jo, int Je) {
  187.   /* equation 32 */
  188.   double nu_, nu_lJo, nu_lJe;
  189.   int j,lJe,lJo;
  190.   double lr_o,lr_e;
  191.   double Rout;
  192.   double mat_[3][3]; 
  193.   double mat_a[3][3]; 
  194.   double mat_b[3][3];
  195.   double mat_c[3][3];                    
  196.   double mat_d[3][3];
  197.   /* suspect situations : 
  198.      when there is a border between source and point. 
  199.      R() is symmetric when there aren't any borders. */
  200.  
  201.   if (r_o <= r_e) { 
  202.     lr_o=r_o;
  203.     lr_e=r_e;
  204.     lJe=Je;
  205.     lJo=Jo;
  206.   } else {
  207.     /* modify things for electrode deeper than dipole */
  208.     lr_o=r_e;
  209.     lr_e=r_o;
  210.     lJe=Jo;
  211.     lJo=Je;
  212.   }
  213.   nu_lJo=nu(lJo,n);
  214.   nu_lJe=nu(lJe,n);
  215.  
  216.   if (lJe > 1) { 
  217.     u_matrix(n,1,r[1],r[2],mat_c);
  218.     for (j=2; j<=lJe-1; j++) {
  219.  
  220.       u_matrix(n,j,r[j],r[j+1],mat_);
  221.  
  222.       copy_2x2(mat_d,mat_c);
  223.       matrix_prod_2x2(mat_d,mat_,mat_c);
  224.     }
  225.     u_matrix(n,lJe,r[lJe],lr_e,mat_a);
  226.  
  227.     matrix_prod_2x2(mat_c,mat_a,mat_d);
  228.     Rout= mat_d[2][2];
  229.   } else { 
  230.     if (!lJe) 
  231.       Rout=1.0f;
  232.     else { /* lje==1 */
  233.       u_matrix(n,1,r[1],lr_e,mat_a);
  234.       Rout= mat_a[2][2];
  235.     }
  236.   }
  237.  
  238.   u_matrix(n,lJo,lr_o,r[lJo+1],mat_c);
  239.  
  240.     for (j=lJo+1; j<=layers; j++) {
  241.       copy_2x2(mat_d,mat_c);
  242.       u_matrix(n,j,r[j],r[j+1],mat_);
  243.       matrix_prod_2x2(mat_d,mat_,mat_c);
  244.     }
  245.  
  246.     Rout*=
  247.       mat_c[1][2];
  248.  
  249.     if (n > rbsize) {
  250.       printf("-"); fflush(NULL);
  251.       rbsize +=200;
  252.       Rbottom = (double*)realloc(Rbottom,sizeof(double)*(rbsize+1));
  253.       legendre = (double*)realloc(legendre,sizeof(double)*(rbsize+2));
  254.       for (j=rbsize-200; j <= rbsize; j++)
  255.     Rbottom[j]=0.0f; 
  256.  
  257.     }
  258.     if (Rbottom[n] == 0.0f) {  
  259.       u_matrix(n,1,r[1],r[2],mat_c);
  260.       for (j=2; j<=layers; j++) {
  261.     copy_2x2(mat_d,mat_c);
  262.     u_matrix(n,j,r[j],r[j+1],mat_);
  263.     matrix_prod_2x2(mat_d,mat_,mat_c);
  264.       }
  265.       Rbottom[n] = -mat_c[2][2];
  266.     }
  267.     /* this ought to be very suspect: */
  268.     Rout/=lr_e*lr_e*Rbottom[n];
  269.   //  Rout/=r[1]*r[1]*Rbottom[n];
  270.  
  271.   Rout *=
  272.     pow(lr_o/r[lJo],nu_lJo)/
  273.     pow(lr_e/r[lJe],nu_lJe);
  274.   for (j=lJe; j<lJo; j++) {
  275.     nu_=nu(j,n);
  276.     Rout *=lambda(j,nu_);
  277.  
  278.   }
  279.  
  280.   return Rout;
  281.  
  282. }
  283.  
  284. double Rprime(int n,double r_o, double r_e,
  285.      int Jo, int Je) {
  286.   /* equation 60 */
  287.   int j,lJe,lJo,deep;
  288.   double nu_, nu_lJo, nu_lJe;
  289.   double lr_o,lr_e;
  290.   double Rpr;
  291.   double mat_[3][3]; 
  292.   double mat_a[3][3]; 
  293.   double mat_b[3][3];
  294.   double mat_c[3][3];   
  295.   double mat_d[3][3];
  296.  
  297.  
  298.   if (r_o <= r_e) { 
  299.     deep =0;
  300.     lr_o=r_o;
  301.     lr_e=r_e;
  302.     lJe=Je;
  303.     lJo=Jo;
  304.   } else {
  305.     /* modify things for electrode deeper than dipole */
  306.     deep=1;
  307.     lr_o=r_e;
  308.     lr_e=r_o;
  309.     lJe=Jo;
  310.     lJo=Je;
  311.   }
  312.  
  313.   nu_lJo=nu(lJo,n);
  314.   nu_lJe=nu(lJe,n);
  315.   /* outermost shell down to first of r_e and r_o */
  316.   /* can be automated only for the deep case. */
  317.   if (lJe > 1) { 
  318.     u_matrix(n,1,r[1],r[2],mat_c);
  319.     for (j=1; j<=lJe-1; j++) {
  320.  
  321.       u_matrix(n,j,r[j],r[j+1],mat_);
  322.  
  323.       copy_2x2(mat_d,mat_c);
  324.       matrix_prod_2x2(mat_d,mat_,mat_c);
  325.     }
  326.     u_matrix(n,lJe,r[lJe],lr_e,mat_a);
  327.  
  328.     matrix_prod_2x2(mat_c,mat_a,mat_d);
  329.     Rpr=deep?
  330.       mat_d[2][1]:mat_d[2][2];
  331.   } else { 
  332.     if (!lJe){
  333.  
  334.       Rpr=1.0f; 
  335.     }
  336.     else {
  337.       u_matrix(n,1,r[1],lr_e,mat_a);
  338.       Rpr= deep?
  339.     mat_a[2][1]:mat_a[2][2];/* [2][1] */
  340.     }    
  341.   }
  342.   if (n > rbsize) {
  343.     printf("-"); fflush(NULL);
  344.     rbsize +=100;
  345.     Rbottom = (double*)realloc(Rbottom,sizeof(double)*(rbsize+1));
  346.     Rright = (double*)realloc(Rright,sizeof(double)*(rbsize+1));
  347.     legendre = (double*)realloc(legendre,sizeof(double)*(rbsize+2));
  348.     for (j=rbsize-100; j <= rbsize; j++)
  349.       Rbottom[j]=0.0f; 
  350.  
  351.   }
  352.  
  353.   /* second of r_e and r_o through to the center. */
  354.   /* can be automated only for the shallow case. */
  355.   if (deep || (Rright[n]==0.0f)) {  
  356.     u_matrix(n,lJo,lr_o,r[lJo+1],mat_c);
  357.  
  358.     for (j=lJo+1; j<=layers; j++) {
  359.       copy_2x2(mat_d,mat_c);
  360.       u_matrix(n,j,r[j],r[j+1],mat_);
  361.       matrix_prod_2x2(mat_d,mat_,mat_c);
  362.     }
  363.     if (!deep)
  364.       Rright[n] =mat_c[2][2];
  365.  
  366.     Rpr*=  deep?mat_c[1][2]:mat_c[2][2];/* for deep 1 2 */
  367.   } else 
  368.     Rpr*=Rright[n];
  369.  
  370.   if (Rbottom[n] == 0.0f) {  
  371.     u_matrix(n,1,r[1],r[2],mat_c);
  372.     for (j=2; j<=layers; j++) {
  373.       copy_2x2(mat_d,mat_c);
  374.       u_matrix(n,j,r[j],r[j+1],mat_);
  375.       matrix_prod_2x2(mat_d,mat_,mat_c);
  376.     }
  377.     Rbottom[n] = -mat_c[2][2];
  378.  
  379.   }
  380.   Rpr/=lr_e*lr_e*Rbottom[n]*eps[Jo];
  381.  
  382.  
  383.   Rpr*=pow(lr_o/r[lJo],nu_lJo)/pow(lr_e/r[lJe],nu_lJe);       
  384.   for (j=lJe; j<=lJo-1; j++) {
  385.     nu_=nu(j,n);
  386.     Rpr *=lambda(j,nu_);
  387.   }
  388.  
  389.   return Rpr;
  390.  
  391. }
  392.  
  393.  
  394. int find_Jo(double r_o) { /* see 27*/ 
  395.   int temp=1;
  396.   while (r[temp]>=r_o)
  397.     temp++;
  398.   temp--;
  399.  
  400.   return temp;
  401. }
  402.  
  403. int find_Je(double r_e) {/* see 27*/ 
  404.   int temp=1;
  405.   while (r[temp]>r_e)
  406.     temp++;
  407.   temp--;
  408.  
  409.   return temp;
  410. }
  411.  
  412. #if 1
  413.  
  414. double Smono(double costheta, 
  415.          double r_o, double r_e) { 
  416.   /* equation 4 - monopole! */
  417.   double S,Rn,Sprev; 
  418.   int n,flag;
  419.  
  420.   S=Sprev=0.0f;
  421.   if (r_o<0.0f) 
  422.     return 0.0f;
  423.   legendre[0]=1;
  424.   legendre[1]=costheta; 
  425.   for (n=1,flag=1;flag;n++){
  426.     Sprev=S;
  427.     Rn=R(n,r_o,r_e,find_Jo(r_o),find_Je(r_e));
  428.     if (n>1)
  429.       legendre[n] =
  430.     ((2*n-1)*costheta*legendre[n-1]-
  431.      (n-1)*legendre[n-2])/n;    
  432.     S+=(2*n+1)*Rn*legendre[n];
  433.     if (n>minimum_terms &&(fabs((S-Sprev)/S) < tolerance))
  434.       flag = 0;
  435.     if (!finite(S)) {
  436.  
  437.       return Sprev; 
  438.     }
  439.   }
  440.   return S;
  441.  
  442.  
  443.  
  444. }
  445.  
  446. double S0 (double costheta,
  447.        double r_o, double r_e) { 
  448.   /* equation 57   */
  449.   /* tangential dipoles. */
  450.   double S,Ra,P,F0,Lambda,A,Rn;
  451.   double lp, Sprev;
  452.   int i,n,flag;
  453.   int Jo,Je;
  454.   Jo=find_Jo(r_o);  Je=find_Je(r_e);
  455.   if (!slow && (r_e>r_o) ){
  456.  
  457.     if (isotropic) { 
  458.       Lambda = r_o/r_e; 
  459.     }else { 
  460.       Lambda =
  461.     pow(r_o/r[Jo],alpha(Jo))/
  462.     pow(r_e/r[Je],alpha(Je));
  463.       A =
  464.     pow(r_o/r[Jo],0.5f*(alpha(Jo)-1))/
  465.     pow(r_e/r[Je],0.5f*(alpha(Je)-1)); 
  466.       for (i=Jo-1; i>= Je; i-- ) {
  467.  
  468.     lp = lambda(i,1.0f);
  469.     Lambda *= pow(lp, alpha(i));
  470.     A *= pow(lp,
  471.          0.5f*(alpha(i)-1)
  472.          );
  473.       }
  474.     }
  475.  
  476.     F0 = -A/(r_e*beta(Jo));
  477.     if (Je != Jo)
  478.       for (i=Je ; i<= Jo-1; i++ ) 
  479.     F0 *= 2*beta(i+1)/(beta(i) + beta(i+1));
  480.  
  481.  
  482.     Ra = 1-2*Lambda*costheta + Lambda*Lambda;
  483.     lp = 1.0f;
  484.   }
  485.   S = (slow ||(r_e<r_o))?0.0f: F0*Lambda/(r_o*Ra*sqrt(Ra));
  486.   legendre[0]=1;
  487.   legendre[1]=costheta; 
  488.  
  489.   for (n = flag = 1; flag > 0 ; n++) {
  490.     Sprev = S;
  491.     if (n>1)
  492.       legendre[n] =
  493.     ((2*n-1)*costheta*legendre[n-1]-
  494.      (n-1)*legendre[n-2])/n;
  495.     /* this is how it gets differentiated */
  496.     P = (n*costheta*legendre[n]-n*legendre[n-1])/(costheta*costheta-1);
  497.     Rn = R(n,r_o,r_e,find_Jo(r_o),find_Je(r_e));
  498.  
  499.     if (slow ||(r_e<r_o)) 
  500.       S+= (2*n+1)*Rn*P/r_o;
  501.     else{
  502.       lp *= Lambda;
  503.       S += ((2*n + 1) * Rn - F0*lp)*P/r_o;
  504.     }
  505.     if (n>minimum_terms &&(fabs((S-Sprev)/S) < tolerance))
  506.       flag = 0;
  507.     if (isnan(S)) {
  508.  
  509.       return Sprev; 
  510.     }
  511.   }
  512.   return S;
  513. }
  514.  
  515.  
  516. double S1 (double costheta,double r_o, double r_e) { 
  517.   /* equation 58 */  
  518.   /* radial dipoles */
  519.   double S,F0,F1,Ra,P,Lambda,A,Rn;
  520.   double lp, Sprev;
  521.  
  522.   int i,n,flag;
  523.   int Jo,Je;
  524.   Jo=find_Jo(r_o);  Je=find_Je(r_e);
  525.  
  526.   if (!slow && (r_e>r_o)){
  527.     if (isotropic) { 
  528.       Lambda = r_o/r_e; 
  529.       A=1.0f;
  530.     }else { 
  531.       Lambda =
  532.     pow(r_o/r[Jo],alpha(Jo))/
  533.     pow(r_e/r[Je],alpha(Je));
  534.       A =
  535.     pow(r_o/r[Jo],0.5f*(alpha(Jo)-1))/
  536.     pow(r_e/r[Je],0.5f*(alpha(Je)-1)); 
  537.       for (i=Jo-1; i>= Je; i-- ) {
  538.  
  539.     Lambda *= lambda(i, alpha(i));
  540.     A *= lambda(i,
  541.             0.5f*(alpha(i)-1)
  542.             );
  543.       }
  544.     }
  545.     F0 = -A/(r_e*beta(Jo));
  546.     for (i=Je ; i<= Jo-1; i++ ) {
  547.       F0 *= 2*beta(i+1)/(beta(i) + beta(i+1));
  548.     }
  549.     F1 =
  550.       F0 *
  551.       sqrt(eps[Jo]*eta[Jo]) /(r_o*eps[Jo]);
  552.  
  553.     Ra = 1.0f -2*Lambda*costheta + Lambda*Lambda;
  554.     Ra *=sqrt(Ra);  
  555.     lp = 1.0f;
  556.   }
  557.   S = (slow ||(r_e<r_o)) ?0.0f:F1*Lambda*(costheta-Lambda) /Ra;
  558.  
  559.   legendre[0]=1;
  560.   legendre[1]=costheta; 
  561.   for (n = 1; ; n++) {
  562.     Sprev = S;
  563.  
  564.     Rn = Rprime(n,r_o,r_e,Jo,Je);
  565.  
  566.     if (n>1)
  567.       legendre[n] =
  568.     ((2*n-1)*costheta*legendre[n-1]-
  569.      (n-1)*legendre[n-2])/n;
  570.     if (slow ||(r_e<r_o)) 
  571.       S+= (2*n+1)*Rn*legendre[n];
  572.     else { 
  573.       lp *= Lambda;
  574.       S += ((2*n + 1) * Rn - F1*n*lp)*legendre[n];
  575.     }
  576.     if (isnan(S))
  577.       return Sprev; 
  578.     if (n>minimum_terms && (fabs((S-Sprev)/S) < tolerance))
  579.       break;     
  580.   }
  581.   return S;
  582. }
  583. double psi_function(double r_o, double r_e,
  584.          double costheta, double cosphi,
  585.          double Mrad1, double Mtan1){
  586.  
  587.   double psi=0.0f;
  588.   double Sa,Sb; 
  589.   /* this worked for tangentials on 
  590.      June 1st, with S0 doing tangentials. */
  591.   find_Je(r_e);
  592.   if (mono>0.0f) {
  593.  
  594.     if (Mtan1 != 0.0f){ 
  595.       fprintf(stderr,
  596.           "Can't do tangential monopole pairs yet.\n");
  597.       exit(-22);
  598.     }
  599.     if (Mrad1 != 0.0f){
  600.       Sa=Smono(costheta,r_o,r_e);
  601. #if 0
  602.       Sb=Smono(costheta,r_o-mono*dz,r_e);
  603. #else 
  604.       Sb=0.0f;
  605. #endif
  606.       psi+= Mrad1*(Sa-Sb);
  607.  
  608.     }
  609.   } else {
  610.     if (Mtan1 != 0.0f) 
  611.       psi += Mtan1* cosphi* S0(costheta,r_o,r_e);
  612.     if (Mrad1 != 0.0f)
  613.       psi += Mrad1* S1 (costheta,r_o,r_e);
  614.   }
  615.   return psi/FOUR_PI;
  616. }
  617. #endif
  618. double r_e,r_o;
  619. #define MAXLINE 1024
  620. void calculate_sensors(double mrad ,double mtan,
  621.                char *infilename){
  622.   FILE * infile;
  623.   char line[MAXLINE];
  624.   int numsensors=0,n=0; 
  625.   double x,y,z,az,el,vi;
  626.   infile = fopen(infilename,"r"); 
  627.   if (!infile) {
  628.     fprintf(stderr,"%s not found.\n",infilename); 
  629.     exit(-1); 
  630.   }
  631.   rbsize = 1000; 
  632.   r_o=r[0];
  633.   find_Jo(r_o);
  634.   Rbottom = (double *)malloc(sizeof(double)*(rbsize+1)); 
  635.   Rright = (double *)malloc(sizeof(double)*(rbsize+1)); 
  636.   legendre = (double *)malloc(sizeof(double)*(rbsize+2)); 
  637.   for (n=0; n <= rbsize; n++)
  638.     Rbottom[n]=0.0f; 
  639.  
  640.   if (filemode>1) { 
  641.     if (!fscanf(infile,"%d\n",&numsensors))
  642.       fprintf(stderr,"File lacks correct format.\n");
  643.     for (n=0;n<numsensors;n++) {
  644.       if (!fscanf(infile,"%lf %lf %lf %*f %*f %*f\n",&x,&y,&z))
  645.     fprintf(stderr,"File goof.\n");; 
  646.       /* using the dx,dy,dz variables helps 
  647.      with unit conversions. */
  648.       r_e = sqrt(x*x*dx*dx+y*y*dy*dy+z*z*dz*dz); 
  649.       el=dz*z/r_e;    
  650.       az=dy*y/r_e;
  651.       vi = psi_function(r_o,r_e,el,az,mrad,mtan); 
  652.       printf("%f\n",vi);
  653.     }
  654.   } else { 
  655.     /* if it's a PPI file: */
  656.  
  657.     int ncom,c,i,j,ncol,laten,N_sensors;
  658.     float ftemp;
  659.     /* skip first line*/
  660.     fgets(line,MAXLINE,infile);
  661.  
  662.     /* read number of lines in the header */
  663.     fgets(line,MAXLINE,infile);
  664.     sscanf(line,"%4d%c",&ncom,&c);
  665.  
  666.     /* look for latencies and noise in header */
  667.     laten = 0; /* laten is set to 1 if the next input line 
  668.           will contain the latency values */
  669.     for (j=0; j<ncom ; j++)
  670.       {
  671.     fgets(line,MAXLINE,infile);
  672.       }
  673.  
  674.     /* read number of columns of data */
  675.     fgets(line,MAXLINE,infile);
  676.     sscanf(line,"%4d",&ncol);
  677.     /* measure page size */
  678.     N_sensors = 0;
  679.  
  680.     while (fgets(line,MAXLINE,infile))
  681.       if (strlen(line) > (size_t)10) (N_sensors)++;
  682.  
  683.     rewind(infile);
  684.  
  685.     /* Now skip the header, and read the sensor and amplitude data. */
  686.     for (i=0; i<ncom+3; i++)
  687.       fgets(line,MAXLINE,infile);
  688.  
  689.     for (i=0; i<N_sensors; i++) {
  690.       fscanf(infile, "%*f%*f%*f%*f%*f%*f%");
  691.  
  692.       fscanf(infile, "%lf %lf %lf", &x,&y,&z);
  693.       x+=sx;
  694.       y+=sy;
  695.       z+=sz;
  696.       for (j=0; j<3; j++)
  697.     {
  698.       fscanf(infile, "%*f");
  699.     }
  700.       for (j=0; j<ncol; j++)
  701.     {
  702.       fscanf(infile, "%*f",&ftemp);
  703.     }
  704.  
  705.       r_e = sqrt(x*x*dx*dx+y*y*dy*dy+z*z*dz*dz); 
  706.       el=z*dz/r_e;    
  707.       az=y*dy/r_e;
  708.       vi = psi_function(r_o,r_e,el,az,mrad,mtan); 
  709.       printf("%f\n",vi);
  710.     }
  711.  
  712.   } 
  713.  
  714.   fclose(infile);
  715. }
  716.  
  717.  
  718. void record_volume(
  719.                     double mrad ,double mtan,
  720.                     char *outfilename)
  721. {
  722.   double xc,yc,zc,az,el;
  723.   int kb,dummy;
  724.   double r_oe;
  725.   float temp_float; 
  726.   FILE *surfile;
  727.   surfile= fopen( outfilename,"w");
  728.   printf("Recording the surface.\n");
  729.   rbsize = 1000; 
  730.   Rbottom = (double *)malloc(sizeof(double)*(rbsize+1)); 
  731.   Rright = (double *)malloc(sizeof(double)*(rbsize+1)); 
  732.   legendre = (double *)malloc(sizeof(double)*(rbsize+2)); 
  733.   for (dummy=0; dummy <= rbsize; dummy++)
  734.     Rbottom[dummy]=0.0f; 
  735.  
  736.   r_o=r[0];
  737.   r[0]=-10000.0f;/* trap! */
  738.   find_Jo(r_o);
  739.   dummy=0;
  740.   for (curr_i=start_i,curr_j=start_j,curr_k=start_k;
  741.        curr_k<=K;
  742.        curr_k++) {
  743.     zc=dz*((double)curr_k-(double)(K/2)-sz);
  744.     printf("%d",curr_k%10);
  745.     if (dummy>0)
  746.       printf(".");
  747.     fflush(NULL);
  748.  
  749.     for (;curr_j<=J;curr_j++){
  750.  
  751.       yc=dy*((double)curr_j-(double)(J/2)-sy);
  752.       for (;curr_i<=I;curr_i++){
  753.     xc=dx*((double)curr_i-(double)(I/2)-sx);
  754.  
  755.     r_e=sqrt(xc*xc+yc*yc+zc*zc);    
  756.     //    r_oe = sqrt(xc*xc+yc*yc+(zc-r_o)*(zc-r_o));
  757.     /* we're generating our own volumes now */
  758.     if (/*(voxel_radius >r_o)&&*/
  759.         (r_e<= r[1])) {
  760.       dummy++;
  761.       /* no orientation switches.
  762.          We be standardising for the bakeoff.
  763.          Dipole is always on the slowest changing axis,
  764.          and pointing to the second slowest in the case 
  765.          of tangentials. */
  766.  
  767.       el=zc/r_e;
  768.  
  769.       az=yc/r_e;
  770.  
  771.       temp_float=(float)psi_function(r_o,r_e,el,az,mrad,mtan);
  772.  
  773.     } else 
  774.       temp_float = 0.0f; 
  775.     if (isnan(temp_float))
  776.       temp_float = 0.0f; 
  777.     fwrite(&temp_float, sizeof(float) , 1, surfile);
  778.  
  779.       }
  780.       curr_i=1;
  781.     }
  782.     curr_j=1;
  783.   }
  784.  
  785.   fclose(surfile);
  786.   printf("\n");
  787.  
  788. }
  789. extern char *optarg;
  790. extern int optind, opterr, optopt;
  791.  
  792. int main(int argc, char *argv[])
  793. {
  794.   int i,j,k;
  795.   int surfmode,index,option_index;
  796.   FILE *infile;
  797.  
  798.   char * comma;
  799.   char c;
  800.  
  801.   struct option long_options[] =
  802.   {
  803.     {"I",1,0,'I'},
  804.     {"J",1,0,'J'},
  805.     {"K",1,0,'K'},
  806.     {"filemode",1,0,'f'},
  807.     {"sensorlist",0,0,'F'},
  808.     {"or",1,0,'o'},
  809.     {"orientation",1,0,'o'},
  810.     {"resolution",1,0,'d'},
  811.     {"recenter",1,0,'S'},
  812.     {"dxdydz",1,0,'d'},
  813.     {"layers",1,0,'l'},
  814.     {"eta",1,0,'h'},
  815.     {"eps",1,0,'e'},
  816.     {"radii",1,0,'r'},
  817.     {"Mrad",1,0,'R'},  
  818.     {"Mtan",1,0,'T'},
  819.     {"minimum",1,0,'m'},
  820.     {"Tolerance",1,0,'t'},
  821.     {"i",1,0,'i'},
  822.     {"j",1,0,'j'},
  823.     {"k",1,0,'k'},
  824.     {0, 0, 0, 0}
  825.   };
  826.  
  827.   signal(SIGHUP,oopsie); 
  828.   signal(SIGINT,oopsie); 
  829.  
  830.   layers=4;
  831.  
  832.   I=100;
  833.  
  834.   J=100;
  835.   K=100;
  836.  
  837.   r=fvector(layers+1);
  838.   eps=fvector(layers);
  839.   eta=fvector(layers);
  840.  
  841.  
  842.  
  843.   Mrad=1000;
  844.   Mtan=0;
  845.   filemode=1;
  846.  
  847.   /* Because I am an MKS bigot, the units are as follow: */
  848.   while(1) {
  849.     c = getopt_long (argc, argv, "I:J:K:R:T:r:e:h:f:o:l:d:t:m:S:scFH",
  850.              long_options, &option_index);
  851.     if (c==-1) 
  852.       break; 
  853.     switch(c){
  854.     case 'H':
  855.       fprintf(stderr,"Usage:\n"
  856.           "demunck filename -I I -J J -K K \n"
  857.           "-l (number of layers) -r [radii]\n"
  858.           "-e [radial conductivity] -h [tangential]\n"
  859.           "-R (radial dipole) -T (tangential) \n"
  860.           "-d [resolution] -S [displacement] \n"
  861.           "Bunch of others.\n");
  862.       exit(0);
  863.     case 'm':
  864.       minimum_terms = atoi(optarg);
  865.       break;
  866.     case 'c': 
  867.       singleslice=1;
  868.       break;
  869.     case 's': /* forget the addition-subtraction speedup. */
  870.       slow =1;
  871.       break;
  872.     case 'd': /* resolution of our cube in meters */
  873.       sscanf(optarg,"%lf,%lf,%lf",&dx,&dy,&dz);
  874.       break;
  875.     case 'f': 
  876.       filemode=atoi(optarg);
  877.       break;
  878.     case 'I':   /* number of voxels (for when we generate cubes) */
  879.       I=atoi(optarg);
  880.       break; 
  881.     case 'J':
  882.       J=atoi(optarg);
  883.       break;
  884.     case 'K':
  885.       K=atoi(optarg);
  886.       break; 
  887.     case 'i': /* starting dimensions */
  888.       start_i=atoi(optarg);
  889.       break; 
  890.     case 'j':
  891.       start_j=atoi(optarg);
  892.       break;
  893.     case 'k':
  894.       start_k=atoi(optarg);
  895.       break; 
  896.     case 'o':
  897.       mono=atof(optarg);
  898.       break;
  899.     case 'S':
  900.       sscanf(optarg,"%lf,%lf,%lf",&sx,&sy,&sz);
  901.       break;
  902.  
  903.     case 'l': /* number of spherical layers */
  904.         layers=atoi(optarg);
  905.     r=re_fvector(r,layers+1);
  906.     eps=re_fvector(eps,layers);
  907.     eta=re_fvector(eta,layers);
  908.     break;
  909.     case 'F':
  910.       sensorlist =1; 
  911.       break;
  912.     case 'R':
  913.       Mrad=atof(optarg);/* ampere*meters */
  914.       break;
  915.     case 't': 
  916.       tolerance = atof(optarg);
  917.       break; 
  918.     case 'T':
  919.       Mtan=atof(optarg); /* ampere*meters */
  920.       break;
  921.     case 'r': /* radii, r0 being radius of dipole, r1-N 
  922.          radii of the layers, descending order */
  923.       index=0; 
  924.       comma=optarg;
  925.       while ((index <=layers) && (comma != NULL)) {
  926.     sscanf(comma,"%lf",&r[index]); /* meters */
  927.     comma = (char*)strchr(comma,',');
  928.     if (comma!=NULL) 
  929.       comma++; 
  930.     index++;
  931.       }
  932.       r[layers+1]=0.0f;
  933.       break;
  934.     case 'h': /* tangential conductivity (S/m) */
  935.       index=1; 
  936.       comma=optarg;
  937.       while (comma != NULL) {
  938.     sscanf(comma,"%lf",&eta[index]); /* siemens per meter */
  939.     comma = (char*)strchr(comma,',');
  940.     if (comma!=NULL) 
  941.       comma++; 
  942.  
  943.     index++;
  944.       }
  945.  
  946.       break;
  947.     case 'e':/* radial conductivity (S/m) */
  948.       index=1; 
  949.       comma=optarg;
  950.       while (comma != NULL) {
  951.     sscanf(comma,"%lf",&eps[index]);/* siemens per meter */
  952.     comma =(char*) strchr(comma,',');
  953.     if (comma!=NULL) 
  954.       comma++; 
  955.     index++;
  956.       }
  957.  
  958.     }
  959.   }
  960.   fprintf(stderr,"I %d. ",I);
  961.  
  962.   fprintf(stderr,"J %d. ",J);
  963.  
  964.   fprintf(stderr,"K %d. ",K);
  965.  
  966.   fprintf(stderr," filemode %d\n",filemode);
  967.   fflush(NULL);
  968.   fprintf(stderr,"Mrad: %f Mtan: %f \n",
  969.          Mrad, Mtan);
  970.   for (index=1; index<=layers; index++) { 
  971.     if (eps[index] != eta[index])
  972.       isotropic =0 ;
  973.   }
  974.   fprintf(stderr,"Resolution: %f %f %f\n",dx,dy,dz);
  975.   fprintf(stderr,"radii: ");
  976.   for (i=0; i<=layers+1; i++)
  977.     fprintf(stderr,"%f ",
  978.        r[i]);
  979.   fprintf(stderr,"\neta: ");
  980.   for (i=1; i<=layers; i++)
  981.     fprintf(stderr,"%f ",
  982.        eta[i]);         
  983.   fprintf(stderr,"\neps: ");
  984.   for (i=1; i<=layers; i++)
  985.     fprintf(stderr,"%f ",
  986.        eps[i]);         
  987.   fprintf(stderr,"\n");
  988.   fprintf(stderr,"S %f %f %f\n", sx,sy,sz);
  989.   if (tolerance == 0.0f) {
  990.     fprintf(stderr, "Nonzero tolerance value req'd. \n");
  991.     exit(-1);
  992.   }
  993.  
  994.   if (!sensorlist)
  995.     record_volume(Mrad,Mtan,argv[argc-1]);
  996.   else 
  997.     calculate_sensors(Mrad,Mtan,argv[argc-1]);
  998.  
  999.   return 0; 
  1000. }
  1001. /*fid=fopen('/var/tmp/homo2.flt','r','ieee-le'); a=fread(fid,inf,'float'); fclose(fid); a=reshape(a,[150 150 150]); 
  1002.  pcolor(atan(squeeze(a(:,75,:)))); shading flat
  1003.  
  1004. */
  1005.  
Input to Grammar: Any C file
Output: List of function calls present in C file
Description: Grammer should be able to extract the list of function calls (only the text where function is getting called) used in C file whereever they may present.


-Abhijeet
Oct 30 '07 #3
I posted my reply with sample code let me know if it visible or not.

-Abhijeet
Oct 30 '07 #4
numberwhun
3,509 Expert Mod 2GB
I posted my reply with sample code let me know if it visible or not.

-Abhijeet
No, it is not visible. Unfortunately, the forum is limited to the amount of text it will display. The best idea is to take and split the code up over a few replies, that way, it will display properly.

Regards,

Jeff
Oct 30 '07 #5
The code is not fixed one, it may vary as C file changes.

But still as a sample test code I am referring following program:
Expand|Select|Wrap|Line Numbers
  1. /* deMunck's multilayer model. */
  2. /* 
  3.    See J.C. Demunck and Maria J. Peters,
  4.    "A Fast Method to Compute the Potential 
  5.    in the Multisphere Model", IEEE Trans. 
  6.    Biomed. Eng. , Vo 40. N. 11, November 1993.
  7.    pp 1168-1174
  8.    All Units are MKS, dammit.
  9.  */
  10. #include <time.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <math.h>
  14. #include <malloc.h>
  15. #include <limits.h>
  16. /*#include <values.h>*/
  17. #include "matrixmalloc.h"
  18. #include <unistd.h>
  19. #include <getopt.h>
  20. #define FOUR_PI 12.5664f
  21. #define Pi 3.14159265358979
  22. #define pi Pi
  23. #include <signal.h>
  24.  
  25. int I,J,K;
  26. int start_i=1,start_j=1,start_k=1;
  27. int curr_i,curr_j,curr_k;
  28.  
  29. int minimum_terms=50;
  30.  
  31. int slow=0,singleslice=0,sensorlist=0;
  32. int isotropic =1; 
  33.  
  34. double rad,mono=0.0f;
  35. int filemode; 
  36. double *r, *eps, *eta;
  37. int layers;
  38. double Mrad =0.0f,  Mtan =0.0f ;
  39. double  dx=1.0f,dy=1.0f,dz=1.0f,rbottom=0.0f,rbottom2=0.0f;
  40. double sx=0.0f,sy=0.0f,sz=0.0f;
  41. double tolerance =0.001f; 
  42. double *Rbottom, *Rright; 
  43. double * legendre;
  44. int rbsize; 
  45. void oopsie(int signum) { 
  46.   FILE * disasterfile; 
  47.   fprintf(stderr, "Caught signal %d, while on voxel %d %d %d.",
  48.      signum,curr_i,curr_j,curr_k); 
  49.   disasterfile=fopen("demunck.disaster","w");
  50.   fprintf(disasterfile, "Caught signal %d, while on voxel %d %d %d.",
  51.      signum,curr_i,curr_j,curr_k); 
  52.   fclose(disasterfile); 
  53.   exit(-22); 
  54.  
  55.  
Oct 30 '07 #6
Expand|Select|Wrap|Line Numbers
  1. #if 0
  2. int ijkton(int i, int j, int k){
  3.   return i+I*(j-1)+I*J*(k-1);
  4. }
  5. #endif
  6.  
  7. double nu(int j,int n)
  8. { /* equation 14 */
  9.   return
  10.     isotropic?
  11.     n:
  12.   ((-1+sqrt(1+
  13.         4*n*(n+1)*eta[j]/eps[j]))
  14.    /2);
  15. }
  16.  
  17. void smatrix(int sign, int j, double r_a, double r_b,int n, double out[3][3]) {
  18.   /* equations 30 and 29 */
  19.   double nu_val,nu2;
  20.  
  21.   nu_val=nu(j,n);
  22.   nu2= 2*nu_val+1;
  23.   if (sign == -1) {
  24.     out[1][1] = nu_val*r_a/(nu2*r_b);
  25.     out[1][2] = -r_a/(nu2*eps[j]);
  26.     out[2][1] = -(nu_val+1)*nu_val*eps[j]/(nu2*r_b);
  27.     out[2][2] = (nu_val+1)/nu2;
  28.   }  
  29.   if (sign == 1) {
  30.     out[1][1] = (nu_val+1)/nu2;
  31.     out[1][2] = r_b/(nu2*eps[j]);
  32.     out[2][1] = (nu_val+1)*nu_val*eps[j]/(nu2*r_a);
  33.     out[2][2] = nu_val*r_b/(nu2*r_a);
  34.   }
  35.  
  36. }
  37.  
  38. double beta(int j) {
  39.   return sqrt(eta[j]*eps[j]);
  40. }
  41.  
  42. double alpha(int j ) {
  43.   return sqrt(eta[j]/eps[j]);
  44. }
  45.  
  46. void matrix_prod_2x2(double a[3][3], double b[3][3], double prod[3][3]){
  47.  
  48.   prod[1][1] = a[1][1]*b[1][1]+a[1][2]*b[2][1];
  49.   prod[1][2] = a[1][1]*b[1][2]+a[1][2]*b[2][2];
  50.   prod[2][1] = a[2][1]*b[1][1]+a[2][2]*b[2][1];
  51.   prod[2][2] = a[2][1]*b[1][2]+a[2][2]*b[2][2];
  52.  
  53. }
  54.  
  55. void matrix_prod(double** a, double** b, double** prod){
  56.  
  57.   prod[1][1] = a[1][1]*b[1][1]+a[1][2]*b[2][1];
  58.   prod[1][2] = a[1][1]*b[1][2]+a[1][2]*b[2][2];
  59.   prod[2][1] = a[2][1]*b[1][1]+a[2][2]*b[2][1];
  60.   prod[2][2] = a[2][1]*b[1][2]+a[2][2]*b[2][2];
  61.  
  62. }
  63.  
  64. void clear_2x2 (double **matrix){
  65.  
  66.   free(matrix[1]);
  67.  
  68.   free(matrix);
  69. }
  70.  
  71. void matrix_sum_2x2(double a[3][3], double b[3][3]){
  72.   a[1][1]+=b[1][1];
  73.   a[1][2]+=b[1][2];
  74.   a[2][2]+=b[2][2];
  75.   a[2][1]+=b[2][1];
  76.  
  77. }
  78.  
  79. void copy_2x2 (double a[3][3], double b[3][3]){
  80.   a[1][1]=b[1][1];
  81.   a[1][2]=b[1][2];
  82.   a[2][1]=b[2][1];
  83.   a[2][2]=b[2][2];
  84. }
  85.  
  86. void matrix_scalar_2x2(double a[3][3], double b){
  87.   a[1][1]*=b;
  88.   a[1][2]*=b;
  89.   a[2][1]*=b;
  90.   a[2][2]*=b;
  91. }
  92. double lambda(int j,double nu_){/* equation 33 */
  93.   return pow(r[j+1]/r[j],nu_);
  94. }
  95.  
  96. void u_matrix(int n,int j, double r_a, double r_b, double out[3][3]){
  97.   /* equation 31 */
  98.   double sminus[3][3];
  99.   double splus[3][3];
  100.   double tempscalar,nu_;
  101.  
  102.   if (r_b>0.0f) { 
  103.  
  104.     tempscalar=pow(r_a/r_b,-2*nu(j,n)-2);
  105.  
  106.     smatrix(1,j,r_a,r_b,n,splus);/* r_a r_b*/
  107.     smatrix(-1,j,r_a,r_b,n,sminus);
  108.     matrix_scalar_2x2(sminus,tempscalar);
  109.  
  110.     matrix_sum_2x2(splus,sminus);
  111.     copy_2x2(out,splus);
  112.  
  113.   }else {
  114.     /* the problem for the deep cases lies HERE. */
  115.  
  116.     nu_=nu(layers,n);
  117.     out[1][1]=0.0f; 
  118.     out[2][1]=0.0f;
  119.     out[1][2]=1/(eps[layers]*(1+2*nu_)); 
  120.     out[2][2]=nu_/(r_a*(1+2*nu_)); 
  121.     if (!n) {
  122.       out[1][2]=-1/(r_a*eps[layers]);
  123.       out[2][2]=1/(r_a*r_a);
  124.     }
  125.   }
  126.  
  127. }
  128.  
Oct 30 '07 #7
Expand|Select|Wrap|Line Numbers
  1. double R(int n,double r_o, double r_e,
  2.      int Jo, int Je) {
  3.   /* equation 32 */
  4.   double nu_, nu_lJo, nu_lJe;
  5.   int j,lJe,lJo;
  6.   double lr_o,lr_e;
  7.   double Rout;
  8.   double mat_[3][3]; 
  9.   double mat_a[3][3]; 
  10.   double mat_b[3][3];
  11.   double mat_c[3][3];                    
  12.   double mat_d[3][3];
  13.   /* suspect situations : 
  14.      when there is a border between source and point. 
  15.      R() is symmetric when there aren't any borders. */
  16.  
  17.   if (r_o <= r_e) { 
  18.     lr_o=r_o;
  19.     lr_e=r_e;
  20.     lJe=Je;
  21.     lJo=Jo;
  22.   } else {
  23.     /* modify things for electrode deeper than dipole */
  24.     lr_o=r_e;
  25.     lr_e=r_o;
  26.     lJe=Jo;
  27.     lJo=Je;
  28.   }
  29.   nu_lJo=nu(lJo,n);
  30.   nu_lJe=nu(lJe,n);
  31.  
  32.   if (lJe > 1) { 
  33.     u_matrix(n,1,r[1],r[2],mat_c);
  34.     for (j=2; j<=lJe-1; j++) {
  35.  
  36.       u_matrix(n,j,r[j],r[j+1],mat_);
  37.  
  38.       copy_2x2(mat_d,mat_c);
  39.       matrix_prod_2x2(mat_d,mat_,mat_c);
  40.     }
  41.     u_matrix(n,lJe,r[lJe],lr_e,mat_a);
  42.  
  43.     matrix_prod_2x2(mat_c,mat_a,mat_d);
  44.     Rout= mat_d[2][2];
  45.   } else { 
  46.     if (!lJe) 
  47.       Rout=1.0f;
  48.     else { /* lje==1 */
  49.       u_matrix(n,1,r[1],lr_e,mat_a);
  50.       Rout= mat_a[2][2];
  51.     }
  52.   }
  53.  
  54.   u_matrix(n,lJo,lr_o,r[lJo+1],mat_c);
  55.  
  56.     for (j=lJo+1; j<=layers; j++) {
  57.       copy_2x2(mat_d,mat_c);
  58.       u_matrix(n,j,r[j],r[j+1],mat_);
  59.       matrix_prod_2x2(mat_d,mat_,mat_c);
  60.     }
  61.  
  62.     Rout*=
  63.       mat_c[1][2];
  64.  
  65.     if (n > rbsize) {
  66.       printf("-"); fflush(NULL);
  67.       rbsize +=200;
  68.       Rbottom = (double*)realloc(Rbottom,sizeof(double)*(rbsize+1));
  69.       legendre = (double*)realloc(legendre,sizeof(double)*(rbsize+2));
  70.       for (j=rbsize-200; j <= rbsize; j++)
  71.     Rbottom[j]=0.0f; 
  72.  
  73.     }
  74.     if (Rbottom[n] == 0.0f) {  
  75.       u_matrix(n,1,r[1],r[2],mat_c);
  76.       for (j=2; j<=layers; j++) {
  77.     copy_2x2(mat_d,mat_c);
  78.     u_matrix(n,j,r[j],r[j+1],mat_);
  79.     matrix_prod_2x2(mat_d,mat_,mat_c);
  80.       }
  81.       Rbottom[n] = -mat_c[2][2];
  82.     }
  83.     /* this ought to be very suspect: */
  84.     Rout/=lr_e*lr_e*Rbottom[n];
  85.   //  Rout/=r[1]*r[1]*Rbottom[n];
  86.  
  87.   Rout *=
  88.     pow(lr_o/r[lJo],nu_lJo)/
  89.     pow(lr_e/r[lJe],nu_lJe);
  90.   for (j=lJe; j<lJo; j++) {
  91.     nu_=nu(j,n);
  92.     Rout *=lambda(j,nu_);
  93.  
  94.   }
  95.  
  96.   return Rout;
  97.  
  98. }
  99.  
  100. double Rprime(int n,double r_o, double r_e,
  101.      int Jo, int Je) {
  102.   /* equation 60 */
  103.   int j,lJe,lJo,deep;
  104.   double nu_, nu_lJo, nu_lJe;
  105.   double lr_o,lr_e;
  106.   double Rpr;
  107.   double mat_[3][3]; 
  108.   double mat_a[3][3]; 
  109.   double mat_b[3][3];
  110.   double mat_c[3][3];   
  111.   double mat_d[3][3];
  112.  
  113.  
  114.   if (r_o <= r_e) { 
  115.     deep =0;
  116.     lr_o=r_o;
  117.     lr_e=r_e;
  118.     lJe=Je;
  119.     lJo=Jo;
  120.   } else {
  121.     /* modify things for electrode deeper than dipole */
  122.     deep=1;
  123.     lr_o=r_e;
  124.     lr_e=r_o;
  125.     lJe=Jo;
  126.     lJo=Je;
  127.   }
  128.  
  129.   nu_lJo=nu(lJo,n);
  130.   nu_lJe=nu(lJe,n);
  131.   /* outermost shell down to first of r_e and r_o */
  132.   /* can be automated only for the deep case. */
  133.   if (lJe > 1) { 
  134.     u_matrix(n,1,r[1],r[2],mat_c);
  135.     for (j=1; j<=lJe-1; j++) {
  136.  
  137.       u_matrix(n,j,r[j],r[j+1],mat_);
  138.  
  139.       copy_2x2(mat_d,mat_c);
  140.       matrix_prod_2x2(mat_d,mat_,mat_c);
  141.     }
  142.     u_matrix(n,lJe,r[lJe],lr_e,mat_a);
  143.  
  144.     matrix_prod_2x2(mat_c,mat_a,mat_d);
  145.     Rpr=deep?
  146.       mat_d[2][1]:mat_d[2][2];
  147.   } else { 
  148.     if (!lJe){
  149.  
  150.       Rpr=1.0f; 
  151.     }
  152.     else {
  153.       u_matrix(n,1,r[1],lr_e,mat_a);
  154.       Rpr= deep?
  155.     mat_a[2][1]:mat_a[2][2];/* [2][1] */
  156.     }    
  157.   }
  158.   if (n > rbsize) {
  159.     printf("-"); fflush(NULL);
  160.     rbsize +=100;
  161.     Rbottom = (double*)realloc(Rbottom,sizeof(double)*(rbsize+1));
  162.     Rright = (double*)realloc(Rright,sizeof(double)*(rbsize+1));
  163.     legendre = (double*)realloc(legendre,sizeof(double)*(rbsize+2));
  164.     for (j=rbsize-100; j <= rbsize; j++)
  165.       Rbottom[j]=0.0f; 
  166.  
  167.   }
  168.  
Oct 30 '07 #8
Expand|Select|Wrap|Line Numbers
  1. /* second of r_e and r_o through to the center. */
  2.   /* can be automated only for the shallow case. */
  3.   if (deep || (Rright[n]==0.0f)) {  
  4.     u_matrix(n,lJo,lr_o,r[lJo+1],mat_c);
  5.  
  6.     for (j=lJo+1; j<=layers; j++) {
  7.       copy_2x2(mat_d,mat_c);
  8.       u_matrix(n,j,r[j],r[j+1],mat_);
  9.       matrix_prod_2x2(mat_d,mat_,mat_c);
  10.     }
  11.     if (!deep)
  12.       Rright[n] =mat_c[2][2];
  13.  
  14.     Rpr*=  deep?mat_c[1][2]:mat_c[2][2];/* for deep 1 2 */
  15.   } else 
  16.     Rpr*=Rright[n];
  17.  
  18.   if (Rbottom[n] == 0.0f) {  
  19.     u_matrix(n,1,r[1],r[2],mat_c);
  20.     for (j=2; j<=layers; j++) {
  21.       copy_2x2(mat_d,mat_c);
  22.       u_matrix(n,j,r[j],r[j+1],mat_);
  23.       matrix_prod_2x2(mat_d,mat_,mat_c);
  24.     }
  25.     Rbottom[n] = -mat_c[2][2];
  26.  
  27.   }
  28.   Rpr/=lr_e*lr_e*Rbottom[n]*eps[Jo];
  29.  
  30.  
  31.   Rpr*=pow(lr_o/r[lJo],nu_lJo)/pow(lr_e/r[lJe],nu_lJe);       
  32.   for (j=lJe; j<=lJo-1; j++) {
  33.     nu_=nu(j,n);
  34.     Rpr *=lambda(j,nu_);
  35.   }
  36.  
  37.   return Rpr;
  38.  
  39. }
  40.  
  41.  
  42. int find_Jo(double r_o) { /* see 27*/ 
  43.   int temp=1;
  44.   while (r[temp]>=r_o)
  45.     temp++;
  46.   temp--;
  47.  
  48.   return temp;
  49. }
  50.  
  51. int find_Je(double r_e) {/* see 27*/ 
  52.   int temp=1;
  53.   while (r[temp]>r_e)
  54.     temp++;
  55.   temp--;
  56.  
  57.   return temp;
  58. }
  59.  
  60. #if 1
  61.  
  62. double Smono(double costheta, 
  63.          double r_o, double r_e) { 
  64.   /* equation 4 - monopole! */
  65.   double S,Rn,Sprev; 
  66.   int n,flag;
  67.  
  68.   S=Sprev=0.0f;
  69.   if (r_o<0.0f) 
  70.     return 0.0f;
  71.   legendre[0]=1;
  72.   legendre[1]=costheta; 
  73.   for (n=1,flag=1;flag;n++){
  74.     Sprev=S;
  75.     Rn=R(n,r_o,r_e,find_Jo(r_o),find_Je(r_e));
  76.     if (n>1)
  77.       legendre[n] =
  78.     ((2*n-1)*costheta*legendre[n-1]-
  79.      (n-1)*legendre[n-2])/n;    
  80.     S+=(2*n+1)*Rn*legendre[n];
  81.     if (n>minimum_terms &&(fabs((S-Sprev)/S) < tolerance))
  82.       flag = 0;
  83.     if (!finite(S)) {
  84.  
  85.       return Sprev; 
  86.     }
  87.   }
  88.   return S;
  89.  
  90.  
  91.  
  92. }
  93.  
  94. double S0 (double costheta,
  95.        double r_o, double r_e) { 
  96.   /* equation 57   */
  97.   /* tangential dipoles. */
  98.   double S,Ra,P,F0,Lambda,A,Rn;
  99.   double lp, Sprev;
  100.   int i,n,flag;
  101.   int Jo,Je;
  102.   Jo=find_Jo(r_o);  Je=find_Je(r_e);
  103.   if (!slow && (r_e>r_o) ){
  104.  
  105.     if (isotropic) { 
  106.       Lambda = r_o/r_e; 
  107.     }else { 
  108.       Lambda =
  109.     pow(r_o/r[Jo],alpha(Jo))/
  110.     pow(r_e/r[Je],alpha(Je));
  111.       A =
  112.     pow(r_o/r[Jo],0.5f*(alpha(Jo)-1))/
  113.     pow(r_e/r[Je],0.5f*(alpha(Je)-1)); 
  114.       for (i=Jo-1; i>= Je; i-- ) {
  115.  
  116.     lp = lambda(i,1.0f);
  117.     Lambda *= pow(lp, alpha(i));
  118.     A *= pow(lp,
  119.          0.5f*(alpha(i)-1)
  120.          );
  121.       }
  122.     }
  123.  
  124.     F0 = -A/(r_e*beta(Jo));
  125.     if (Je != Jo)
  126.       for (i=Je ; i<= Jo-1; i++ ) 
  127.     F0 *= 2*beta(i+1)/(beta(i) + beta(i+1));
  128.  
  129.  
  130.     Ra = 1-2*Lambda*costheta + Lambda*Lambda;
  131.     lp = 1.0f;
  132.   }
  133.   S = (slow ||(r_e<r_o))?0.0f: F0*Lambda/(r_o*Ra*sqrt(Ra));
  134.   legendre[0]=1;
  135.   legendre[1]=costheta; 
  136.  
  137.   for (n = flag = 1; flag > 0 ; n++) {
  138.     Sprev = S;
  139.     if (n>1)
  140.       legendre[n] =
  141.     ((2*n-1)*costheta*legendre[n-1]-
  142.      (n-1)*legendre[n-2])/n;
  143.     /* this is how it gets differentiated */
  144.     P = (n*costheta*legendre[n]-n*legendre[n-1])/(costheta*costheta-1);
  145.     Rn = R(n,r_o,r_e,find_Jo(r_o),find_Je(r_e));
  146.  
  147.     if (slow ||(r_e<r_o)) 
  148.       S+= (2*n+1)*Rn*P/r_o;
  149.     else{
  150.       lp *= Lambda;
  151.       S += ((2*n + 1) * Rn - F0*lp)*P/r_o;
  152.     }
  153.     if (n>minimum_terms &&(fabs((S-Sprev)/S) < tolerance))
  154.       flag = 0;
  155.     if (isnan(S)) {
  156.  
  157.       return Sprev; 
  158.     }
  159.   }
  160.   return S;
  161. }
  162.  
  163.  
  164. double S1 (double costheta,double r_o, double r_e) { 
  165.   /* equation 58 */  
  166.   /* radial dipoles */
  167.   double S,F0,F1,Ra,P,Lambda,A,Rn;
  168.   double lp, Sprev;
  169.  
  170.   int i,n,flag;
  171.   int Jo,Je;
  172.   Jo=find_Jo(r_o);  Je=find_Je(r_e);
  173.  
  174.   if (!slow && (r_e>r_o)){
  175.     if (isotropic) { 
  176.       Lambda = r_o/r_e; 
  177.       A=1.0f;
  178.     }else { 
  179.       Lambda =
  180.     pow(r_o/r[Jo],alpha(Jo))/
  181.     pow(r_e/r[Je],alpha(Je));
  182.       A =
  183.     pow(r_o/r[Jo],0.5f*(alpha(Jo)-1))/
  184.     pow(r_e/r[Je],0.5f*(alpha(Je)-1)); 
  185.       for (i=Jo-1; i>= Je; i-- ) {
  186.  
  187.     Lambda *= lambda(i, alpha(i));
  188.     A *= lambda(i,
  189.             0.5f*(alpha(i)-1)
  190.             );
  191.       }
  192.     }
  193.     F0 = -A/(r_e*beta(Jo));
  194.     for (i=Je ; i<= Jo-1; i++ ) {
  195.       F0 *= 2*beta(i+1)/(beta(i) + beta(i+1));
  196.     }
  197.     F1 =
  198.       F0 *
  199.       sqrt(eps[Jo]*eta[Jo]) /(r_o*eps[Jo]);
  200.  
  201.     Ra = 1.0f -2*Lambda*costheta + Lambda*Lambda;
  202.     Ra *=sqrt(Ra);  
  203.     lp = 1.0f;
  204.   }
  205.   S = (slow ||(r_e<r_o)) ?0.0f:F1*Lambda*(costheta-Lambda) /Ra;
  206.  
  207.   legendre[0]=1;
  208.   legendre[1]=costheta; 
  209.   for (n = 1; ; n++) {
  210.     Sprev = S;
  211.  
  212.     Rn = Rprime(n,r_o,r_e,Jo,Je);
  213.  
  214.     if (n>1)
  215.       legendre[n] =
  216.     ((2*n-1)*costheta*legendre[n-1]-
  217.      (n-1)*legendre[n-2])/n;
  218.     if (slow ||(r_e<r_o)) 
  219.       S+= (2*n+1)*Rn*legendre[n];
  220.     else { 
  221.       lp *= Lambda;
  222.       S += ((2*n + 1) * Rn - F1*n*lp)*legendre[n];
  223.     }
  224.     if (isnan(S))
  225.       return Sprev; 
  226.     if (n>minimum_terms && (fabs((S-Sprev)/S) < tolerance))
  227.       break;     
  228.   }
  229.   return S;
  230. }
  231. double psi_function(double r_o, double r_e,
  232.          double costheta, double cosphi,
  233.          double Mrad1, double Mtan1){
  234.  
  235.   double psi=0.0f;
  236.   double Sa,Sb; 
  237.   /* this worked for tangentials on 
  238.      June 1st, with S0 doing tangentials. */
  239.   find_Je(r_e);
  240.   if (mono>0.0f) {
  241.  
  242.     if (Mtan1 != 0.0f){ 
  243.       fprintf(stderr,
  244.           "Can't do tangential monopole pairs yet.\n");
  245.       exit(-22);
  246.     }
  247.     if (Mrad1 != 0.0f){
  248.       Sa=Smono(costheta,r_o,r_e);
  249. #if 0
  250.       Sb=Smono(costheta,r_o-mono*dz,r_e);
  251. #else 
  252.       Sb=0.0f;
  253. #endif
  254.       psi+= Mrad1*(Sa-Sb);
  255.  
  256.     }
  257.   } else {
  258.     if (Mtan1 != 0.0f) 
  259.       psi += Mtan1* cosphi* S0(costheta,r_o,r_e);
  260.     if (Mrad1 != 0.0f)
  261.       psi += Mrad1* S1 (costheta,r_o,r_e);
  262.   }
  263.   return psi/FOUR_PI;
  264. }
  265. #endif
  266.  
Oct 30 '07 #9
Expand|Select|Wrap|Line Numbers
  1. double r_e,r_o;
  2. #define MAXLINE 1024
  3. void calculate_sensors(double mrad ,double mtan,
  4.                char *infilename){
  5.   FILE * infile;
  6.   char line[MAXLINE];
  7.   int numsensors=0,n=0; 
  8.   double x,y,z,az,el,vi;
  9.   infile = fopen(infilename,"r"); 
  10.   if (!infile) {
  11.     fprintf(stderr,"%s not found.\n",infilename); 
  12.     exit(-1); 
  13.   }
  14.   rbsize = 1000; 
  15.   r_o=r[0];
  16.   find_Jo(r_o);
  17.   Rbottom = (double *)malloc(sizeof(double)*(rbsize+1)); 
  18.   Rright = (double *)malloc(sizeof(double)*(rbsize+1)); 
  19.   legendre = (double *)malloc(sizeof(double)*(rbsize+2)); 
  20.   for (n=0; n <= rbsize; n++)
  21.     Rbottom[n]=0.0f; 
  22.  
  23.   if (filemode>1) { 
  24.     if (!fscanf(infile,"%d\n",&numsensors))
  25.       fprintf(stderr,"File lacks correct format.\n");
  26.     for (n=0;n<numsensors;n++) {
  27.       if (!fscanf(infile,"%lf %lf %lf %*f %*f %*f\n",&x,&y,&z))
  28.     fprintf(stderr,"File goof.\n");; 
  29.       /* using the dx,dy,dz variables helps 
  30.      with unit conversions. */
  31.       r_e = sqrt(x*x*dx*dx+y*y*dy*dy+z*z*dz*dz); 
  32.       el=dz*z/r_e;    
  33.       az=dy*y/r_e;
  34.       vi = psi_function(r_o,r_e,el,az,mrad,mtan); 
  35.       printf("%f\n",vi);
  36.     }
  37.   } else { 
  38.     /* if it's a PPI file: */
  39.  
  40.     int ncom,c,i,j,ncol,laten,N_sensors;
  41.     float ftemp;
  42.     /* skip first line*/
  43.     fgets(line,MAXLINE,infile);
  44.  
  45.     /* read number of lines in the header */
  46.     fgets(line,MAXLINE,infile);
  47.     sscanf(line,"%4d%c",&ncom,&c);
  48.  
  49.     /* look for latencies and noise in header */
  50.     laten = 0; /* laten is set to 1 if the next input line 
  51.           will contain the latency values */
  52.     for (j=0; j<ncom ; j++)
  53.       {
  54.     fgets(line,MAXLINE,infile);
  55.       }
  56.  
  57.     /* read number of columns of data */
  58.     fgets(line,MAXLINE,infile);
  59.     sscanf(line,"%4d",&ncol);
  60.     /* measure page size */
  61.     N_sensors = 0;
  62.  
  63.     while (fgets(line,MAXLINE,infile))
  64.       if (strlen(line) > (size_t)10) (N_sensors)++;
  65.  
  66.     rewind(infile);
  67.  
  68.     /* Now skip the header, and read the sensor and amplitude data. */
  69.     for (i=0; i<ncom+3; i++)
  70.       fgets(line,MAXLINE,infile);
  71.  
  72.     for (i=0; i<N_sensors; i++) {
  73.       fscanf(infile, "%*f%*f%*f%*f%*f%*f%");
  74.  
  75.       fscanf(infile, "%lf %lf %lf", &x,&y,&z);
  76.       x+=sx;
  77.       y+=sy;
  78.       z+=sz;
  79.       for (j=0; j<3; j++)
  80.     {
  81.       fscanf(infile, "%*f");
  82.     }
  83.       for (j=0; j<ncol; j++)
  84.     {
  85.       fscanf(infile, "%*f",&ftemp);
  86.     }
  87.  
  88.       r_e = sqrt(x*x*dx*dx+y*y*dy*dy+z*z*dz*dz); 
  89.       el=z*dz/r_e;    
  90.       az=y*dy/r_e;
  91.       vi = psi_function(r_o,r_e,el,az,mrad,mtan); 
  92.       printf("%f\n",vi);
  93.     }
  94.  
  95.   } 
  96.  
  97.   fclose(infile);
  98. }
  99.  
  100.  
  101. void record_volume(
  102.                     double mrad ,double mtan,
  103.                     char *outfilename)
  104. {
  105.   double xc,yc,zc,az,el;
  106.   int kb,dummy;
  107.   double r_oe;
  108.   float temp_float; 
  109.   FILE *surfile;
  110.   surfile= fopen( outfilename,"w");
  111.   printf("Recording the surface.\n");
  112.   rbsize = 1000; 
  113.   Rbottom = (double *)malloc(sizeof(double)*(rbsize+1)); 
  114.   Rright = (double *)malloc(sizeof(double)*(rbsize+1)); 
  115.   legendre = (double *)malloc(sizeof(double)*(rbsize+2)); 
  116.   for (dummy=0; dummy <= rbsize; dummy++)
  117.     Rbottom[dummy]=0.0f; 
  118.  
  119.   r_o=r[0];
  120.   r[0]=-10000.0f;/* trap! */
  121.   find_Jo(r_o);
  122.   dummy=0;
  123.   for (curr_i=start_i,curr_j=start_j,curr_k=start_k;
  124.        curr_k<=K;
  125.        curr_k++) {
  126.     zc=dz*((double)curr_k-(double)(K/2)-sz);
  127.     printf("%d",curr_k%10);
  128.     if (dummy>0)
  129.       printf(".");
  130.     fflush(NULL);
  131.  
  132.     for (;curr_j<=J;curr_j++){
  133.  
  134.       yc=dy*((double)curr_j-(double)(J/2)-sy);
  135.       for (;curr_i<=I;curr_i++){
  136.     xc=dx*((double)curr_i-(double)(I/2)-sx);
  137.  
  138.     r_e=sqrt(xc*xc+yc*yc+zc*zc);    
  139.     //    r_oe = sqrt(xc*xc+yc*yc+(zc-r_o)*(zc-r_o));
  140.     /* we're generating our own volumes now */
  141.     if (/*(voxel_radius >r_o)&&*/
  142.         (r_e<= r[1])) {
  143.       dummy++;
  144.       /* no orientation switches.
  145.          We be standardising for the bakeoff.
  146.          Dipole is always on the slowest changing axis,
  147.          and pointing to the second slowest in the case 
  148.          of tangentials. */
  149.  
  150.       el=zc/r_e;
  151.  
  152.       az=yc/r_e;
  153.  
  154.       temp_float=(float)psi_function(r_o,r_e,el,az,mrad,mtan);
  155.  
  156.     } else 
  157.       temp_float = 0.0f; 
  158.     if (isnan(temp_float))
  159.       temp_float = 0.0f; 
  160.     fwrite(&temp_float, sizeof(float) , 1, surfile);
  161.  
  162.       }
  163.       curr_i=1;
  164.     }
  165.     curr_j=1;
  166.   }
  167.  
  168.   fclose(surfile);
  169.   printf("\n");
  170.  
  171. }
  172. extern char *optarg;
  173. extern int optind, opterr, optopt;
  174.  
  175. int main(int argc, char *argv[])
  176. {
  177.   int i,j,k;
  178.   int surfmode,index,option_index;
  179.   FILE *infile;
  180.  
  181.   char * comma;
  182.   char c;
  183.  
  184.   struct option long_options[] =
  185.   {
  186.     {"I",1,0,'I'},
  187.     {"J",1,0,'J'},
  188.     {"K",1,0,'K'},
  189.     {"filemode",1,0,'f'},
  190.     {"sensorlist",0,0,'F'},
  191.     {"or",1,0,'o'},
  192.     {"orientation",1,0,'o'},
  193.     {"resolution",1,0,'d'},
  194.     {"recenter",1,0,'S'},
  195.     {"dxdydz",1,0,'d'},
  196.     {"layers",1,0,'l'},
  197.     {"eta",1,0,'h'},
  198.     {"eps",1,0,'e'},
  199.     {"radii",1,0,'r'},
  200.     {"Mrad",1,0,'R'},  
  201.     {"Mtan",1,0,'T'},
  202.     {"minimum",1,0,'m'},
  203.     {"Tolerance",1,0,'t'},
  204.     {"i",1,0,'i'},
  205.     {"j",1,0,'j'},
  206.     {"k",1,0,'k'},
  207.     {0, 0, 0, 0}
  208.   };
  209.  
  210.   signal(SIGHUP,oopsie); 
  211.   signal(SIGINT,oopsie); 
  212.  
  213.   layers=4;
  214.  
  215.   I=100;
  216.  
  217.   J=100;
  218.   K=100;
  219.  
  220.   r=fvector(layers+1);
  221.   eps=fvector(layers);
  222.   eta=fvector(layers);
  223.  
  224.  
  225.  
  226.   Mrad=1000;
  227.   Mtan=0;
  228.   filemode=1;
  229.  
  230.   /* Because I am an MKS bigot, the units are as follow: */
  231.   while(1) {
  232.     c = getopt_long (argc, argv, "I:J:K:R:T:r:e:h:f:o:l:d:t:m:S:scFH",
  233.              long_options, &option_index);
  234.     if (c==-1) 
  235.       break; 
  236.     switch(c){
  237.     case 'H':
  238.       fprintf(stderr,"Usage:\n"
  239.           "demunck filename -I I -J J -K K \n"
  240.           "-l (number of layers) -r [radii]\n"
  241.           "-e [radial conductivity] -h [tangential]\n"
  242.           "-R (radial dipole) -T (tangential) \n"
  243.           "-d [resolution] -S [displacement] \n"
  244.           "Bunch of others.\n");
  245.       exit(0);
  246.     case 'm':
  247.       minimum_terms = atoi(optarg);
  248.       break;
  249.     case 'c': 
  250.       singleslice=1;
  251.       break;
  252.     case 's': /* forget the addition-subtraction speedup. */
  253.       slow =1;
  254.       break;
  255.     case 'd': /* resolution of our cube in meters */
  256.       sscanf(optarg,"%lf,%lf,%lf",&dx,&dy,&dz);
  257.       break;
  258.     case 'f': 
  259.       filemode=atoi(optarg);
  260.       break;
  261.     case 'I':   /* number of voxels (for when we generate cubes) */
  262.       I=atoi(optarg);
  263.       break; 
  264.     case 'J':
  265.       J=atoi(optarg);
  266.       break;
  267.     case 'K':
  268.       K=atoi(optarg);
  269.       break; 
  270.     case 'i': /* starting dimensions */
  271.       start_i=atoi(optarg);
  272.       break; 
  273.     case 'j':
  274.       start_j=atoi(optarg);
  275.       break;
  276.     case 'k':
  277.       start_k=atoi(optarg);
  278.       break; 
  279.     case 'o':
  280.       mono=atof(optarg);
  281.       break;
  282.     case 'S':
  283.       sscanf(optarg,"%lf,%lf,%lf",&sx,&sy,&sz);
  284.       break;
  285.  
  286.     case 'l': /* number of spherical layers */
  287.         layers=atoi(optarg);
  288.     r=re_fvector(r,layers+1);
  289.     eps=re_fvector(eps,layers);
  290.     eta=re_fvector(eta,layers);
  291.     break;
  292.     case 'F':
  293.       sensorlist =1; 
  294.       break;
  295.     case 'R':
  296.       Mrad=atof(optarg);/* ampere*meters */
  297.       break;
  298.     case 't': 
  299.       tolerance = atof(optarg);
  300.       break; 
  301.     case 'T':
  302.       Mtan=atof(optarg); /* ampere*meters */
  303.       break;
  304.     case 'r': /* radii, r0 being radius of dipole, r1-N 
  305.          radii of the layers, descending order */
  306.       index=0; 
  307.       comma=optarg;
  308.       while ((index <=layers) && (comma != NULL)) {
  309.     sscanf(comma,"%lf",&r[index]); /* meters */
  310.     comma = (char*)strchr(comma,',');
  311.     if (comma!=NULL) 
  312.       comma++; 
  313.     index++;
  314.       }
  315.       r[layers+1]=0.0f;
  316.       break;
  317.     case 'h': /* tangential conductivity (S/m) */
  318.       index=1; 
  319.       comma=optarg;
  320.       while (comma != NULL) {
  321.     sscanf(comma,"%lf",&eta[index]); /* siemens per meter */
  322.     comma = (char*)strchr(comma,',');
  323.     if (comma!=NULL) 
  324.       comma++; 
  325.  
  326.     index++;
  327.       }
  328.  
  329.       break;
  330.     case 'e':/* radial conductivity (S/m) */
  331.       index=1; 
  332.       comma=optarg;
  333.       while (comma != NULL) {
  334.     sscanf(comma,"%lf",&eps[index]);/* siemens per meter */
  335.     comma =(char*) strchr(comma,',');
  336.     if (comma!=NULL) 
  337.       comma++; 
  338.     index++;
  339.       }
  340.  
  341.     }
  342.   }
  343.   fprintf(stderr,"I %d. ",I);
  344.  
  345.   fprintf(stderr,"J %d. ",J);
  346.  
  347.   fprintf(stderr,"K %d. ",K);
  348.  
  349.   fprintf(stderr," filemode %d\n",filemode);
  350.   fflush(NULL);
  351.   fprintf(stderr,"Mrad: %f Mtan: %f \n",
  352.          Mrad, Mtan);
  353.   for (index=1; index<=layers; index++) { 
  354.     if (eps[index] != eta[index])
  355.       isotropic =0 ;
  356.   }
  357.   fprintf(stderr,"Resolution: %f %f %f\n",dx,dy,dz);
  358.   fprintf(stderr,"radii: ");
  359.   for (i=0; i<=layers+1; i++)
  360.     fprintf(stderr,"%f ",
  361.        r[i]);
  362.   fprintf(stderr,"\neta: ");
  363.   for (i=1; i<=layers; i++)
  364.     fprintf(stderr,"%f ",
  365.        eta[i]);         
  366.   fprintf(stderr,"\neps: ");
  367.   for (i=1; i<=layers; i++)
  368.     fprintf(stderr,"%f ",
  369.        eps[i]);         
  370.   fprintf(stderr,"\n");
  371.   fprintf(stderr,"S %f %f %f\n", sx,sy,sz);
  372.   if (tolerance == 0.0f) {
  373.     fprintf(stderr, "Nonzero tolerance value req'd. \n");
  374.     exit(-1);
  375.   }
  376.  
  377.   if (!sensorlist)
  378.     record_volume(Mrad,Mtan,argv[argc-1]);
  379.   else 
  380.     calculate_sensors(Mrad,Mtan,argv[argc-1]);
  381.  
  382.   return 0; 
  383. }
  384. /*fid=fopen('/var/tmp/homo2.flt','r','ieee-le'); a=fread(fid,inf,'float'); fclose(fid); a=reshape(a,[150 150 150]); 
  385.  pcolor(atan(squeeze(a(:,75,:)))); shading flat
  386.  
  387. */
  388.  
Input to Grammar: Any C file
Output: List of function calls present in C file
Description: Grammer should be able to extract the list of function calls (only the text where function is getting called) used in C file whereever they may present.


-Abhijeet
Oct 30 '07 #10
numberwhun
3,509 Expert Mod 2GB
Ok, that is A LOT of C code. Do you have any Perl code that you have been working on? We will need to see that to help you.

Regards,

Jeff
Oct 30 '07 #11
I am working on perl program csourceparser.pl which is available on CPAN.
This code is also huge one.

-Abhijeet
Oct 30 '07 #12
The following link gives the perl code to parse C file,

Link

This perl code I am currently referring and I want to add grammar to it.
The grammar will give me the list of function calls from C file.

You can take any C file as a sample to test the grammar.


Thank you.


-Abhijeet
Oct 31 '07 #13
numberwhun
3,509 Expert Mod 2GB
The following link gives the perl code to parse C file,

Link

This perl code I am currently referring and I want to add grammar to it.
The grammar will give me the list of function calls from C file.

You can take any C file as a sample to test the grammar.


Thank you.


-Abhijeet
Not to ask this, especially after you posted all of that code, but are you trying to recruit help with your module or are you asking specifically how to do something?

Regards,

Jeff
Oct 31 '07 #14
I want the help in creation of grammar for function calls, because the present perl module gives list of declarations, definations of functions but not the list of function calls.

As the C grammar is complex, many things may come under extraction of function calls from file. so that's why I want help to start with writing grammar for it by cosidering the parse::recdescent approach.


-Abhijeet
Nov 1 '07 #15
Hi Abhijeet
according to me the statement_list subrule in function_defination production matches the function call some where. u need to trace out where it is getting matched,
I am also tracing out the same. Will keep u updated if any new things found.

-Amit
Nov 1 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kangol kangoll | last post by:
hi, i've been trying to figure out how to make visual basic start extracting text at a certain line to when i tell it to stop. I am making trying to make a program where it extracts text from a...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
by: Epetruk | last post by:
Hi, I'm having to modify a PHP script even though I have little knowledge of PHP itself. The script extracts specific strings from an html file, and I need to it extract some further...
19
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with...
1
by: Jason Huang | last post by:
Hi, To make it short, how do we do the data extraction to MSWord using ASP.Net C#? Any help will be appreciated. Jason
1
by: Peter Thorne | last post by:
I am a perl newbie who is trying to write a script to automate a task. I have a large collection of compressed archives (mostly .tar.gz, tar.bz2, tar.Z, .tgz etc). This are stored in a number...
6
by: Robbie Hatley | last post by:
I'm maintaining a software project with 134 C++ files, some of them huge (as much as 10,000 lines each), and very few prototypes. The author's attitude towards prototypes was like this: ...
16
by: EM.Bateman | last post by:
Working on Visual Studio .Net I've implemented a class: #ifndef CONTRIBUTOR_H #define CONTRIBUTOR_H enum Gender {male=1, female, unk}; #include <iostream> #include <iomanip> #include...
4
by: Choi | last post by:
Good morning. I've tried to extract, using libcurl, web pages but it failed. There is no compilation error concerning the class I wrote, but the problems appear when I compile a main method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.