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