On May 10, 12:25 pm, smurray444 <smurray@gmail.com> wrote:
> Hey guys,
> I'm trying to write some Fortran code to achieve a bilinear
> interpolation upon a grid of dimension 240 values (x) by 120 values
> (y) and where the data is currently at a spatial resolution of 1.5
> degrees... I want the output grid to be at a resolution of 5 minutes.
> How would I go about doing this, and what would the Fortran code look
> like to achieve this?
> Thanks for your time and help,
> Steve
a simple approach:
subroutine grid_bilin(old,ns,new)
real,intent(in):: old(0:,0:) ! old data
integer,intent(in):: ns ! resolution factor (common for x and y)
real,intent(out):: new(0:,0:)
real:: im(0:ns,2) ! interpolation matrix (common for x and y)
integer:: i,j
! prepare interpolation matrix
forall(i=0:ns) im(i,2) = real(i,kind(im))/ns
im(:,1) = 1 - im(:,2)
do j=1,ubound(old,2)
do i=1,ubound(old,1)
new((i-1)*ns:i*ns,(j-1)*ns:j*ns) =
matmul(im,matmul(old(i-1:i,j-1:j),transpose(im)))
end do
end do
end subroutine
(untested, may contain bugs)
which you can call with ns=18 to get your fine resolution.
Note that you will get more that 9 million numbers. a simple piecewise
bilinear interpolation from a regular grid (like this) is so fast that
it is IMHO almost always better to just keep the original data and
interpolate on demand. If you insist on pre-interpolating to a fine
grid, you should at least look at more elaborate tensor product
splines that produce smoother surfaces. See, e.g. numerical recipes in
Fortran, chapter ... uhh ... three?
Jaroslav