a = -1.0;
b = +1.0;
c = 10.0;
d = 14.0;
w = 4;
h = 3;

fprintf ( 1, '\n' );
fprintf ( 1, '  (I,J) -> (X01,Y01)\n' );
fprintf ( 1, '\n' );

for i = 1 : h
  for j = 1 : w
    xc01 = ( 2 * j - 1 ) / 2 / w;
    yc01 = ( 2 * i - 1 ) / 2 / h;
    fprintf ( '  %d  %d  %f  %f\n', i, j, xc01, yc01 );
  end
end

fprintf ( 1, '\n' );
fprintf ( 1, '  (I,J) -> (XC,YC)\n' );
fprintf ( 1, '\n' );

for i = 1 : h
  for j = 1 : w
    xc01 = ( 2 * j - 1 ) / 2 / w;
    yc01 = ( 2 * i - 1 ) / 2 / h;
    xc = a + ( b - a ) * xc01;
    yc = c + ( d - c ) * yc01;
    fprintf ( '  %d  %d  %f  %f\n', i, j, xc, yc );
  end
end

fprintf ( 1, '\n' );
fprintf ( 1, '  (I,J) -> K\n' );
fprintf ( 1, '\n' );

for i = 1 : h
  for j = 1 : w
    k = ( i - 1 ) * w + j;
    fprintf ( '  %d  %d  %d\n', i, j, k );
  end
end

fprintf ( 1, '\n' );
fprintf ( 1, '  K --> (I,J)\n' );
fprintf ( 1, '\n' );

for k = 1 : h * w
  i = floor ( ( k - 1 ) / w ) + 1;
  j = mod ( k - 1, w ) + 1;
  fprintf ( '  %d  %d  %d\n', k, i, j );
end

fprintf ( 1, '\n' );
fprintf ( 1, '  K --> (XC01,YC01)\n' );
fprintf ( 1, '\n' );

for k = 1 : h * w
  i = floor ( ( k - 1 ) / w ) + 1;
  j = mod ( k - 1, w ) + 1;
  xc01 = ( 2 * j - 1 ) / 2 / w;
  yc01 = ( 2 * i - 1 ) / 2 / h;
  fprintf ( '  %d  %f  %f\n', k, xc01, yc01 );
end

fprintf ( 1, '\n' );
fprintf ( 1, '  K --> (XC,YC)\n' );
fprintf ( 1, '\n' );

for k = 1 : h * w
  i = floor ( ( k - 1 ) / w ) + 1;
  j = mod ( k - 1, w ) + 1;
  xc01 = ( 2 * j - 1 ) / 2 / w;
  yc01 = ( 2 * i - 1 ) / 2 / h;
  xc = a + ( b - a ) * xc01;
  yc = c + ( d - c ) * yc01;
  fprintf ( '  %d  %f  %f\n', k, xc, yc );
end

fprintf ( 1, '\n' );
fprintf ( 1, '  (XC,YC) -> (I,J)\n' );
fprintf ( 1, '\n' );

for i = 1 : h
  for j = 1 : w
    xc = a + ( 2 * j - 1 ) * ( b - a ) / w / 2.0;
    yc = c + ( 2 * i - 1 ) * ( d - c ) / h / 2.0;
    x01 = ( xc - a ) / ( b - a );
    y01 = ( yc - c ) / ( d - c );
    i = round ( ( 2 * h * y01 + 1 ) / 2 );
    j = round ( ( 2 * w * x01 + 1 ) / 2 );
    fprintf ( '  %f  %f  %d  %d\n', xc, yc, i, j  );
  end
end

fprintf ( 1, '\n' );
fprintf ( 1, '  (XC,YC) -> K\n' );
fprintf ( 1, '\n' );

for i = 1 : h
  for j = 1 : w
    xc = a + ( 2 * j - 1 ) * ( b - a ) / w / 2.0;
    yc = c + ( 2 * i - 1 ) * ( d - c ) / h / 2.0;
    x01 = ( xc - a ) / ( b - a );
    y01 = ( yc - c ) / ( d - c );
    i = round ( ( 2 * h * y01 + 1 ) / 2 );
    j = round ( ( 2 * w * x01 + 1 ) / 2 );
    k = (i-1)*w+j;
    fprintf ( '  %f  %f  %d\n', xc, yc, k  );
  end
end
