1 | /*\file Ll2xy.c
|
---|
2 | *\brief: lat/long to x/y coordinate mex module.
|
---|
3 | */
|
---|
4 | #include "./Ll2xy.h"
|
---|
5 |
|
---|
6 | void Ll2xyUsage(void){/*{{{*/
|
---|
7 | _printf0_("Ll2xy - lat/long to x/y coordinate transformation module:\n");
|
---|
8 | _printf0_("\n");
|
---|
9 | _printf0_(" This module transforms lat/long to x/y coordinates.\n");
|
---|
10 | _printf0_("\n");
|
---|
11 | _printf0_(" Usage:\n");
|
---|
12 | _printf0_(" [x,y]=Ll2xy(lat,lon,sgn,'param name',param,...);\n");
|
---|
13 | _printf0_("\n");
|
---|
14 | _printf0_(" lat latitude coordinates (double vector)\n");
|
---|
15 | _printf0_(" lon longitude coordinates (double vector)\n");
|
---|
16 | _printf0_(" sgn sign for hemisphere (double, +1 (north) or -1 (south))\n");
|
---|
17 | _printf0_("\n");
|
---|
18 | _printf0_(" central_meridian central meridian (double, optional, but must specify with sp)\n");
|
---|
19 | _printf0_(" standard_parallel standard parallel (double, optional, but must specify with cm)\n");
|
---|
20 | _printf0_("\n");
|
---|
21 | _printf0_(" x x coordinates (double vector)\n");
|
---|
22 | _printf0_(" y y coordinates (double vector)\n");
|
---|
23 | _printf0_("\n");
|
---|
24 | _printf0_(" Examples:\n");
|
---|
25 | _printf0_(" [x,y]=Ll2xy(lat,lon, 1);\n");
|
---|
26 | _printf0_(" [x,y]=Ll2xy(lat,lon, 1,'central_meridian',45,'standard_parallel',70);\n");
|
---|
27 | _printf0_(" [x,y]=Ll2xy(lat,lon,-1,'central_meridian', 0,'standard_parallel',71);\n");
|
---|
28 | _printf0_("\n");
|
---|
29 | }/*}}}*/
|
---|
30 | WRAPPER(Ll2xy){
|
---|
31 |
|
---|
32 | int i,verbose=1;
|
---|
33 |
|
---|
34 | /*input: */
|
---|
35 | double *lat=NULL,*lon=NULL;
|
---|
36 | int nlat,nlon,ncoord;
|
---|
37 | int sgn;
|
---|
38 |
|
---|
39 | Options* options=NULL;
|
---|
40 | double cm=0.,sp=0.;
|
---|
41 |
|
---|
42 | /* output: */
|
---|
43 | double *x=NULL,*y=NULL;
|
---|
44 | int iret=0;
|
---|
45 |
|
---|
46 | /*Boot module: */
|
---|
47 | MODULEBOOT();
|
---|
48 |
|
---|
49 | /*checks on arguments on the matlab side: */
|
---|
50 | if (nlhs > NLHS) {
|
---|
51 | Ll2xyUsage(); _error_("Ll2xy usage error");
|
---|
52 | }
|
---|
53 | if (nrhs < NRHS) {
|
---|
54 | Ll2xyUsage(); _error_("Ll2xy usage error");
|
---|
55 | }
|
---|
56 |
|
---|
57 | /*Input datasets: */
|
---|
58 | FetchData(&lat,&nlat,LAT_IN);
|
---|
59 | FetchData(&lon,&nlon,LON_IN);
|
---|
60 | FetchData(&sgn,SGN_IN);
|
---|
61 | FetchData(&options,NRHS,nrhs,prhs);
|
---|
62 |
|
---|
63 | /* defaults are in Ll2xydef, so don't duplicate them here, and only use user values if both have been specified */
|
---|
64 | if(options->GetOption("central_meridian") || options->GetOption("standard_parallel")){
|
---|
65 | options->Get(&cm,"central_meridian");
|
---|
66 | if (verbose) _printf_(" cm=" << cm << "\n");
|
---|
67 | options->Get(&sp,"standard_parallel");
|
---|
68 | if (verbose) _printf_(" sp=" << sp << "\n");
|
---|
69 | }
|
---|
70 |
|
---|
71 | /*some checks*/
|
---|
72 | if (verbose) _printf_("Checking inputs:\n");
|
---|
73 | if (nlat != nlon){_error_("Must have same number of lat[" << nlat << "] and lon[" << nlon << "] coordinates.");}
|
---|
74 | else ncoord=nlat;
|
---|
75 | if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=" << sgn << " must be +1 (north) or -1 (south).");
|
---|
76 | if (fabs(cm) > 180.) _error_("Central meridian cm=" << cm << " must be between -180 (west) and +180 (east) degrees.");
|
---|
77 | if (sp < 0. || sp > 90.) _error_("Standard parallel sp=" << sp << " must be between 0 and 90 degrees (in specified hemisphere).");
|
---|
78 |
|
---|
79 | x=(double*)mxMalloc(ncoord*sizeof(double));
|
---|
80 | y=(double*)mxMalloc(ncoord*sizeof(double));
|
---|
81 |
|
---|
82 | /* Run core computations: */
|
---|
83 | if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
|
---|
84 | iret=Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp);
|
---|
85 | else
|
---|
86 | iret=Ll2xyx(x,y,lat,lon,ncoord,sgn);
|
---|
87 |
|
---|
88 | /*Write data: */
|
---|
89 | WriteData(X_OUT,x,ncoord);
|
---|
90 | WriteData(Y_OUT,y,ncoord);
|
---|
91 |
|
---|
92 | /*Clean-up*/
|
---|
93 | delete options;
|
---|
94 |
|
---|
95 | /*end module: */
|
---|
96 | MODULEEND();
|
---|
97 | }
|
---|