source: MML/trunk/machine/SOLEIL/common/naff/nafflib/example.c @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.3 KB
Line 
1/*
2 *  Hello World for the CodeWarrior
3 *  ï¿œ 1997-1998 Metrowerks Corp.
4 *
5 *  Questions and comments to:
6 *       <mailto:support@metrowerks.com>
7 *       <http://www.metrowerks.com/>
8 */
9
10#include "modnaff.h"
11#include "complexe.h"
12double pi=M_PI; /* ajout Laurent sinon pi non trouve */
13
14int main(void)
15{
16    int i, iCpt;
17    const int ndata=9996; /* multiple of 6 */
18   
19 g_NAFVariable.DTOUR=2*pi;   /* size of a "cadran" */
20 g_NAFVariable.XH=1;         /* step */
21 g_NAFVariable.T0=0;         /* time t0 */
22 g_NAFVariable.NTERM=10;     /* max term to find */
23 g_NAFVariable.KTABS=ndata;  /* number of data : must be a multiple of 6 */
24 g_NAFVariable.m_pListFen=NULL; /*no window*/
25 g_NAFVariable.TFS=NULL;    /* will contain frequency */
26 g_NAFVariable.ZAMP=NULL;   /* will contain amplitude */
27 g_NAFVariable.ZTABS=NULL;  /* will contain data to analyze */
28
29 /*internal use in naf */
30 g_NAFVariable.NERROR=0;
31 g_NAFVariable.ICPLX=1;
32 g_NAFVariable.IPRT=-1; /*0*/
33 g_NAFVariable.NFPRT=stdout; /*NULL;*/
34 g_NAFVariable.NFS=0;
35 g_NAFVariable.IW=1;
36 g_NAFVariable.ISEC=1;
37 g_NAFVariable.EPSM=0; 
38 g_NAFVariable.UNIANG=0;
39 g_NAFVariable.FREFON=0;
40 g_NAFVariable.ZALP=NULL; 
41 g_NAFVariable.m_iNbLineToIgnore=1; /*unused*/
42 g_NAFVariable.m_dneps=1.E100;
43 g_NAFVariable.m_bFSTAB=FALSE; /*unused*/
44 /*end of interl use in naf */
45 
46 
47    naf_initnaf();
48   
49    /*remplit les donnees initiales*/
50    for(i=0;i<ndata;i++)
51    {
52     g_NAFVariable.ZTABS[i].reel=2.E0+0.1*cos(pi*i)+0.00125*cos(pi/3*i);
53     g_NAFVariable.ZTABS[i].imag=2.E0+0.1*sin(pi*i)+0.00125*sin(pi/3*i);
54     fprintf(stdout,"%2d = % .15f % .15f\n",i,g_NAFVariable.ZTABS[i].reel
55     ,g_NAFVariable.ZTABS[i].imag);
56    }
57   
58    /*analyse en frequence*/
59    /* recherche de 5 termes */
60    printf("cte=%g\n",fabs(g_NAFVariable.FREFON)/g_NAFVariable.m_dneps);
61    naf_mftnaf(5,fabs(g_NAFVariable.FREFON)/g_NAFVariable.m_dneps);
62
63   /* affichage des resultats */
64
65   printf("NFS=%d\n",g_NAFVariable.NFS);
66   for(iCpt=1;iCpt<=g_NAFVariable.NFS; iCpt++)
67   {
68    printf("AMPL=% .15E+i*% .15E abs(AMPL)=% .15E arg(AMPL)=% .15E FREQ=% .15E\n",
69           g_NAFVariable.ZAMP[iCpt].reel,g_NAFVariable.ZAMP[iCpt].imag, 
70           i_compl_module(g_NAFVariable.ZAMP[iCpt]), 
71           i_compl_angle(g_NAFVariable.ZAMP[iCpt]),
72           g_NAFVariable.TFS[iCpt]);
73   }
74    /*liberation de la memoire*/
75        naf_cleannaf();
76        return 0;
77}
78
Note: See TracBrowser for help on using the repository browser.