PIPS
average_power.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
+ Include dependency graph for average_power.c:

Go to the source code of this file.

Data Structures

struct  Cplfloat
 

Functions

void average_power (int Nth, int Nrg, int Nv, Cplfloat ptrin[Nth][Nrg][Nv], Cplfloat Pow[Nth])
 
int main (int argc, char *argv[])
 

Function Documentation

◆ average_power()

void average_power ( int  Nth,
int  Nrg,
int  Nv,
Cplfloat  ptrin[Nth][Nrg][Nv],
Cplfloat  Pow[Nth] 
)

Definition at line 11 of file average_power.c.

11  {
12 
13  float PP;
14  int th, v, rg;
15 
16  for (th=0; th<Nth; th++) {
17  PP=0.;
18  for (rg=0; rg<Nrg; rg++) {
19  for (v=0; v<Nv; v++) {
20  PP += ptrin[th][rg][v].re *ptrin[th][rg][v].re
21  +ptrin[th][rg][v].im *ptrin[th][rg][v].im;
22  }
23  }
24  Pow[th].re= (float)(PP/((float)(Nv*Nrg)));
25  Pow[th].im= 0.;
26  }
27 }
float im
Definition: average_power.c:8
float re
Definition: average_power.c:7

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

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

only print with bad precision for validation

Definition at line 29 of file average_power.c.

30 {
31  int i,j,k;
32  int th,rg,v;
33  th=256,rg=256,v=256;
34  {
35  Cplfloat (*in)[th][rg][v], (*pow)[th];
36  in = malloc(th * rg * v *sizeof(Cplfloat));
37  if (!in)
38  err(1, "in = malloc(%zu)", th *rg*v* sizeof(Cplfloat));
39  for (i=0; i<th; i++) {
40  for (j=0; j<rg; j++) {
41  for (k=0;k<v;k++) {
42  (*in)[i][j][k].re = i*j*k;
43  (*in)[i][j][k].re = i*j+k;
44  }
45  }
46  }
47  pow = malloc(th * sizeof(Cplfloat));
48  if (!pow)
49  err(1, "malloc(%zu)", th * sizeof(Cplfloat));
50  average_power(th,rg,v,*in,*pow);
51  /* only print with bad precision for validation */
52  for(i=0;i<th;i++)
53  printf("-%d-%d-\n", ((int)(*pow)[i].re)/10, ((int)(*pow)[i].im)/10);
54  }
55  return 0;
56 }
void average_power(int Nth, int Nrg, int Nv, Cplfloat ptrin[Nth][Nrg][Nv], Cplfloat Pow[Nth])
Definition: average_power.c:11
void * malloc(YYSIZE_T)
int printf()

References average_power(), malloc(), and printf().

+ Here is the call graph for this function: