-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mlee03
authored and
mlee03
committed
May 13, 2024
1 parent
d41c451
commit a17fbbc
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*********************************************************************** | ||
* GNU Lesser General Public License | ||
* | ||
* This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools). | ||
* | ||
* FRE-NCtools is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* FRE-NCtools is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FRE-NCTools. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
**********************************************************************/ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <math.h> | ||
#include "mosaic_util.h" | ||
#include "create_xgrid_utils_acc.h" | ||
#include "constant.h" | ||
|
||
/******************************************************************************* | ||
void get_grid_area(const int *nlon, const int *nlat, const double *lon, const double *lat, const double *area) | ||
return the grid area. | ||
*******************************************************************************/ | ||
void get_grid_area_acc(const int *nlon, const int *nlat, const double *lon, const double *lat, double *area) | ||
{ | ||
int nx, ny, nxp, i, j, n_in; | ||
double x_in[20], y_in[20]; | ||
|
||
nx = *nlon; | ||
ny = *nlat; | ||
nxp = nx + 1; | ||
|
||
for(j=0; j<ny; j++) for(i=0; i < nx; i++) { | ||
x_in[0] = lon[j*nxp+i]; | ||
x_in[1] = lon[j*nxp+i+1]; | ||
x_in[2] = lon[(j+1)*nxp+i+1]; | ||
x_in[3] = lon[(j+1)*nxp+i]; | ||
y_in[0] = lat[j*nxp+i]; | ||
y_in[1] = lat[j*nxp+i+1]; | ||
y_in[2] = lat[(j+1)*nxp+i+1]; | ||
y_in[3] = lat[(j+1)*nxp+i]; | ||
n_in = fix_lon(x_in, y_in, 4, M_PI); | ||
area[j*nx+i] = poly_area(x_in, y_in, n_in); | ||
} | ||
|
||
}; /* get_grid_area */ | ||
|
||
void get_grid_great_circle_area(const int *nlon, const int *nlat, const double *lon, const double *lat, double *area) | ||
{ | ||
int nx, ny, nxp, nyp, i, j, n_in; | ||
int n0, n1, n2, n3; | ||
double x_in[20], y_in[20], z_in[20]; | ||
struct Node *grid=NULL; | ||
double *x=NULL, *y=NULL, *z=NULL; | ||
|
||
|
||
nx = *nlon; | ||
ny = *nlat; | ||
nxp = nx + 1; | ||
nyp = ny + 1; | ||
|
||
x = (double *)malloc(nxp*nyp*sizeof(double)); | ||
y = (double *)malloc(nxp*nyp*sizeof(double)); | ||
z = (double *)malloc(nxp*nyp*sizeof(double)); | ||
|
||
latlon2xyz(nxp*nyp, lon, lat, x, y, z); | ||
|
||
for(j=0; j<ny; j++) for(i=0; i < nx; i++) { | ||
/* clockwise */ | ||
n0 = j*nxp+i; | ||
n1 = (j+1)*nxp+i; | ||
n2 = (j+1)*nxp+i+1; | ||
n3 = j*nxp+i+1; | ||
rewindList(); | ||
grid = getNext(); | ||
addEnd(grid, x[n0], y[n0], z[n0], 0, 0, 0, -1); | ||
addEnd(grid, x[n1], y[n1], z[n1], 0, 0, 0, -1); | ||
addEnd(grid, x[n2], y[n2], z[n2], 0, 0, 0, -1); | ||
addEnd(grid, x[n3], y[n3], z[n3], 0, 0, 0, -1); | ||
area[j*nx+i] = gridArea(grid); | ||
} | ||
|
||
free(x); | ||
free(y); | ||
free(z); | ||
|
||
}; /* get_grid_great_circle_area */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*********************************************************************** | ||
* GNU Lesser General Public License | ||
* | ||
* This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools). | ||
* | ||
* FRE-NCtools is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* FRE-NCtools is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FRE-NCTools. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
**********************************************************************/ | ||
#ifndef CREATE_XGRID_ACC_H_ | ||
#define CREATE_XGRID_ACC_H_ | ||
|
||
#define MV 50 | ||
/* this value is small compare to earth area */ | ||
|
||
void get_grid_area_acc(const int *nlon, const int *nlat, const double *lon, const double *lat, double *area); | ||
|
||
void get_grid_great_circle_area(const int *nlon, const int *nlat, const double *lon, const double *lat, double *area); | ||
|
||
#endif |