1 | /*\file Exp2Kml.c
|
---|
2 | *\brief: exp to kml file conversion mex module.
|
---|
3 | */
|
---|
4 | #include "./Exp2Kml.h"
|
---|
5 |
|
---|
6 | void Exp2KmlUsage(void){/*{{{*/
|
---|
7 | _printf0_("Exp2Kml - exp to kml file conversion module:\n");
|
---|
8 | _printf0_("\n");
|
---|
9 | _printf0_(" This module converts a file from exp to kml format.\n");
|
---|
10 | _printf0_("\n");
|
---|
11 | _printf0_(" Usage:\n");
|
---|
12 | _printf0_(" [ret]=Exp2Kml(filexp,filkml,sgn,'param name',param,...);\n");
|
---|
13 | _printf0_("\n");
|
---|
14 | _printf0_(" filexp file name of exp file to be read (char)\n");
|
---|
15 | _printf0_(" filkml file name of kml file to be written (char)\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_(" holes flag for treatment of multiple profiles (char, optional, 'yes' for holes))\n");
|
---|
21 | _printf0_("\n");
|
---|
22 | _printf0_(" ret return code (non-zero for warning)\n");
|
---|
23 | _printf0_("\n");
|
---|
24 | _printf0_(" Examples:\n");
|
---|
25 | _printf0_(" [ret]=Exp2Kml('file.exp','file.kml', 1);\n");
|
---|
26 | _printf0_(" [ret]=Exp2Kml('file.exp','file.kml', 1,'central_meridian',45,'standard_parallel',70,'holes','yes');\n");
|
---|
27 | _printf0_(" [ret]=Exp2Kml('file.exp','file.kml',-1,'central_meridian', 0,'standard_parallel',71,'holes','yes');\n");
|
---|
28 | _printf0_("\n");
|
---|
29 | }/*}}}*/
|
---|
30 | WRAPPER(Exp2Kml_python){
|
---|
31 |
|
---|
32 | int i,verbose=1;
|
---|
33 |
|
---|
34 | /*input: */
|
---|
35 | char *filexp=NULL,*filkml=NULL;
|
---|
36 | int sgn;
|
---|
37 |
|
---|
38 | Options* options=NULL;
|
---|
39 | char *choles=NULL;
|
---|
40 | bool holes=false;
|
---|
41 | double cm=0.,sp=0.;
|
---|
42 |
|
---|
43 | /* output: */
|
---|
44 | int iret=0;
|
---|
45 |
|
---|
46 | /*Boot module: */
|
---|
47 | MODULEBOOT();
|
---|
48 |
|
---|
49 | /*checks on arguments on the matlab side: */
|
---|
50 | if (nlhs > NLHS) {
|
---|
51 | Exp2KmlUsage(); _error_("Exp2Kml usage error");
|
---|
52 | }
|
---|
53 | if (nrhs < NRHS) {
|
---|
54 | Exp2KmlUsage(); _error_("Exp2Kml usage error");
|
---|
55 | }
|
---|
56 |
|
---|
57 | /*Input datasets: */
|
---|
58 | FetchData(&filexp,EXP_IN);
|
---|
59 | FetchData(&filkml,KML_IN);
|
---|
60 | FetchData(&sgn,SGN_IN);
|
---|
61 | FetchData(&options,NRHS,nrhs,prhs);
|
---|
62 |
|
---|
63 | options->Get(&choles,"holes",(char*)"no");
|
---|
64 | if (!strncmp(choles,"y",1) || !strncmp(choles,"on",2)) holes=true;
|
---|
65 |
|
---|
66 | /* defaults are in Xy2lldef, so don't duplicate them here, and only use user values if both have been specified */
|
---|
67 | if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
|
---|
68 | options->Get(&cm,"central_meridian");
|
---|
69 | if (verbose) _printf_(" cm=" << cm << "\n");
|
---|
70 | options->Get(&sp,"standard_parallel");
|
---|
71 | if (verbose) _printf_(" sp=" << sp << "\n");
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*some checks*/
|
---|
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 | /* Run core computations: */
|
---|
80 | if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
|
---|
81 | iret=Exp2Kmlx(filexp,filkml,sgn,cm,sp,holes);
|
---|
82 | else
|
---|
83 | iret=Exp2Kmlx(filexp,filkml,sgn,holes);
|
---|
84 |
|
---|
85 | /*Write data: */
|
---|
86 | WriteData(RET_OUT,iret);
|
---|
87 |
|
---|
88 | /*Clean-up*/
|
---|
89 | xDelete<char>(choles);
|
---|
90 | xDelete<char>(filkml);
|
---|
91 | xDelete<char>(filexp);
|
---|
92 | delete options;
|
---|
93 |
|
---|
94 | /*end module: */
|
---|
95 | MODULEEND();
|
---|
96 | }
|
---|