mask_region.c File Reference

Mask region in a variable given latitude and longitude coordinates. More...

#include <utils.h>
Include dependency graph for mask_region.c:

Go to the source code of this file.

Functions

void mask_region (double *buffer, double missing_value, double *lon, double *lat, double minlon, double maxlon, double minlat, double maxlat, int nlon, int nlat, int ndim)
 Mask region in a variable given latitude and longitude coordinates.

Detailed Description

Mask region in a variable given latitude and longitude coordinates.

Definition in file mask_region.c.


Function Documentation

void mask_region ( double *  buffer,
double  missing_value,
double *  lon,
double *  lat,
double  minlon,
double  maxlon,
double  minlat,
double  maxlat,
int  nlon,
int  nlat,
int  ndim 
)

Mask region in a variable given latitude and longitude coordinates.

Parameters:
[out] buffer 3D buffer
[in] missing_value Missing value
[in] lon Longitude array
[in] lat Latitude array
[in] minlon Subdomain bounds: minimum longitude
[in] maxlon Subdomain bounds: maximum longitude
[in] minlat Subdomain bounds: minimum latitude
[in] maxlat Subdomain bounds: maximum latitude
[in] nlon Longitude dimension length
[in] nlat Latitude dimension length
[in] ndim Third dimension length

Definition at line 59 of file mask_region.c.

Referenced by wt_learning().

00061                                           {
00076   int i; /* Loop counter */
00077   int j; /* Loop counter */
00078   int t; /* Time loop counter */
00079   double curlon; /* Current longitude */
00080   double curlat; /* Current latitude */
00081 
00082   (void) printf("%s: Masking domain. Longitudes: %lf %lf. Latitudes: %lf %lf.\n", __FILE__, minlon, maxlon, minlat, maxlat);
00083 
00084   /* Loop over all gridpoints */
00085 
00086   /* Loop over latitudes */
00087   for (j=0; j<nlat; j++) {
00088     /* Loop over longitudes */
00089     for (i=0; i<nlon; i++) {
00090       /* Adjust longitude to span -180 to +180 */
00091       if (lon[i] > 180.0)
00092         curlon = lon[i] - 360.0;
00093       else
00094         curlon = lon[i+j*nlon];
00095       curlat = lat[i+j*nlon];
00096       /* Mask only gridpoints within bounds */
00097       if (curlon >= minlon && curlon <= maxlon && curlat >= minlat && curlat <= maxlat) {
00098         /* Loop over last dimension to assign missing value for this gridpoint */
00099         for (t=0; t<ndim; t++)
00100           buffer[i+j*nlon+t*nlon*nlat] = missing_value;
00101       }
00102     }
00103   }
00104 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1