00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <math.h>
00012 #include "interp.c"
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 void synop2pole(int ns, int sinlat, double *image, int *imgDims,
00024 double *map, int *mapDims,
00025 double *lons, double *lats, double latLim)
00026 {
00027
00028 int nx = imgDims[0], ny = imgDims[1];
00029 int xsz = mapDims[0], ysz = mapDims[1];
00030
00031
00032
00033 double xc = (nx - 1.) / 2.0;
00034 double yc = (ny - 1.) / 2.0;
00035
00036
00037
00038 double rLim = cos(latLim) / (1 + sin(fabs(latLim)));
00039 double rx = xc / rLim, ry = yc / rLim;
00040
00041
00042
00043 double x0, y0;
00044 double r, th;
00045 double lon, lat;
00046 double ind_lon, ind_lat;
00047
00048 for (int row = 0; row < ny; row++) {
00049 for (int col = 0; col < nx; col++) {
00050
00051
00052
00053 x0 = (col - xc) / rx;
00054 y0 = (row - yc) / ry;
00055 r = sqrt(x0 * x0 + y0 * y0);
00056 th = atan2(y0, x0);
00057 lon = th;
00058 lat = M_PI / 2.0 - atan(r) * 2.0;
00059 if (ns) lat = -lat;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 ind_lon = get_index(0, xsz, lons, lon);
00072 ind_lat = get_index(sinlat, ysz, lats, lat);
00073
00074
00075
00076 image[row * nx + col] = linintd(map, xsz, ysz, ind_lon, ind_lat);
00077
00078 }
00079 }
00080
00081
00082
00083 return;
00084 }
00085
00086 void pole2synop(int ns, int sinlat, double *image, int *imgDims,
00087 double *map, int *mapDims,
00088 double *lons, double *lats, double latLim)
00089 {
00090
00091 int nx = imgDims[0], ny = imgDims[1];
00092 int xsz = mapDims[0], ysz = mapDims[1];
00093
00094
00095
00096 double xc = (imgDims[0] - 1.) / 2.0;
00097 double yc = (imgDims[1] - 1.) / 2.0;
00098
00099
00100
00101 double rLim = cos(latLim) / (1 + sin(fabs(latLim)));
00102 double rx = xc / rLim, ry = yc / rLim;
00103
00104
00105
00106
00107
00108 int row0, row1;
00109 if (ns) {
00110 row0 = 0;
00111 row1 = ceil(get_index(sinlat, ysz, lats, -fabs(latLim)));
00112 } else {
00113 row0 = floor(get_index(sinlat, ysz, lats, fabs(latLim)));
00114 row1 = ysz - 1;
00115 }
00116
00117
00118
00119
00120 double x0, y0;
00121 double x, y;
00122 double r, th;
00123 double lon, lat;
00124
00125 for (int row = row0; row <= row1; row++) {
00126 for (int col = 0; col < xsz; col++) {
00127
00128 lon = lons[col];
00129 lat = lats[row];
00130
00131
00132
00133 r = cos(lat) / (1 + sin(fabs(lat)));
00134 th = lon;
00135 x0 = r * cos(th);
00136 y0 = r * sin(th);
00137 x = x0 * rx + xc;
00138 y = y0 * ry + yc;
00139
00140
00141
00142 map[row * xsz + col] = linintd(image, nx, ny, x, y);
00143
00144 }
00145 }
00146
00147
00148
00149 return;
00150 }