#include "lu.h"
__kernel void pintgr3(__global double *g_u,
                      __global double *g_phi1,
                      __global double *g_phi2,
                      int ibeg,
                      int ifin,
                      int jbeg,
                      int jfin,
                      int ki1,
                      int ki2)
{
  int j, k;

  k = get_global_id(1) + ki1;
  j = get_global_id(0) + jbeg;
  if (k >= ki2 || j >= jfin) return;

  __global double (*u)[ISIZ2/2*2+1][ISIZ1/2*2+1][5] =
    (__global double (*)[ISIZ2/2*2+1][ISIZ1/2*2+1][5])g_u;
  __global double (*phi1)[ISIZ2+2] = (__global double (*)[ISIZ2+2])g_phi1;
  __global double (*phi2)[ISIZ2+2] = (__global double (*)[ISIZ2+2])g_phi2;

  phi1[k][j] = C2*(  u[k][j][ibeg][4]
      - 0.50 * (  u[k][j][ibeg][1] * u[k][j][ibeg][1]
                + u[k][j][ibeg][2] * u[k][j][ibeg][2]
                + u[k][j][ibeg][3] * u[k][j][ibeg][3] )
               / u[k][j][ibeg][0] );

  phi2[k][j] = C2*(  u[k][j][ifin-1][4]
      - 0.50 * (  u[k][j][ifin-1][1] * u[k][j][ifin-1][1]
                + u[k][j][ifin-1][2] * u[k][j][ifin-1][2]
                + u[k][j][ifin-1][3] * u[k][j][ifin-1][3] )
               / u[k][j][ifin-1][0] );
}
