Hi PDL folks: I just wrote a function that I think should be thread-able, but I can't think how. Any ideas welcome.

This function is used to up-sample a weather model grid via linear interpolation. I use the local PP function Dutil::dplinear to do this. It may be better to use other PDL interpolation functions, but I've been using this for years and I know just what it does. Here is its signature:

dplinear (x(n); y(n); in(); [o]out())

It is just a simple interpolation routine which takes $x and $y vectors as input, along with one value in $x-space to interpolate into $y space.

The tricky bit here is that two sorts of threading are necessary:

1) Interpolating a column of input temperatures via the $x and $y input
to dplinear.

2) Threading over all the lat/lon columns in the input temperature grid $t. The tricky bit is that the pressure values are different for each column--this model does not use standard pressure levels, but the pressure
levels at each grid point depend upon the surface pressure.

Any ideas?  Please let me know if this is not clear...

Regards,

  Doug Hunt

--------------------------------------------------------------------------------------
sub upsampleGrid {

  my $lgrid = shift;  # low resolution  (half) pressure grid: lat x lon x 92 
levels
  my $hgrid = shift;  # high resolution (half) pressure grid: lat x lon x 138 
levels
  my $t     = shift;  # temperature grid to upsample: lat x lon x level

  my ($nlat, $nlon, $llvl) = $t->dims; # llvl = 92
  my $hlvl = ($hgrid->dims)[2]; # 138
  my $ht = zeroes($nlat, $nlon, $hlvl); # high resolution output grid

  # This could be sped up with threading, I feel sure...
  for (my $lati=0;$lati<$nlat;$lati++) {
    for (my $loni=0;$loni<$nlon;$loni++) {
      my $x  = $lgrid->(($lati),($loni),:);
      my $y  = $t->(($lati),($loni),:);
      my $in = $hgrid->(($lati),($loni),:);
      $hg(($lati),($loni),:) .= Dutil::dplinear($x, $y, $in);
    }
  }

  return $hg;
}
--------------------------------------------------------------------------------------

[email protected]
Software Engineer
UCAR - COSMIC, Tel. (303) 497-2611

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to