source: issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.cpp@ 12517

Last change on this file since 12517 was 12517, checked in by Mathieu Morlighem, 13 years ago

no more printf

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