source: issm/trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.cpp@ 13651

Last change on this file since 13651 was 13250, checked in by Mathieu Morlighem, 12 years ago

CHG: getting rid of xfree

File size: 3.3 KB
Line 
1/*\file Exp2Kml.c
2 *\brief: exp to kml file conversion mex module.
3 */
4#include "./Exp2Kml.h"
5
6void Exp2KmlUsage(void){/*{{{*/
7 _pprintLine_("Exp2Kml - exp to kml file conversion module:");
8 _pprintLine_("");
9 _pprintLine_(" This module converts a file from exp to kml format.");
10 _pprintLine_("");
11 _pprintLine_(" Usage:");
12 _pprintLine_(" [ret]=Exp2Kml(filexp,filkml,sgn,'param name',param,...);");
13 _pprintLine_("");
14 _pprintLine_(" filexp file name of exp file to be read (char)");
15 _pprintLine_(" filkml file name of kml file to be written (char)");
16 _pprintLine_(" sgn sign for hemisphere (double, +1 (north) or -1 (south))");
17 _pprintLine_("");
18 _pprintLine_(" central_meridian central meridian (double, optional, but must specify with sp)");
19 _pprintLine_(" standard_parallel standard parallel (double, optional, but must specify with cm)");
20 _pprintLine_(" holes flag for treatment of multiple profiles (char, optional, 'yes' for holes))");
21 _pprintLine_("");
22 _pprintLine_(" ret return code (non-zero for warning)");
23 _pprintLine_("");
24 _pprintLine_(" Examples:");
25 _pprintLine_(" [ret]=Exp2Kml('file.exp','file.kml', 1);");
26 _pprintLine_(" [ret]=Exp2Kml('file.exp','file.kml', 1,'central_meridian',45,'standard_parallel',70,'holes','yes');");
27 _pprintLine_(" [ret]=Exp2Kml('file.exp','file.kml',-1,'central_meridian', 0,'standard_parallel',71,'holes','yes');");
28 _pprintLine_("");
29}/*}}}*/
30WRAPPER(Exp2Kml){
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) _printLine_(" cm=" << cm);
70 options->Get(&sp,"standard_parallel");
71 if (verbose) _printLine_(" sp=" << sp);
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}
Note: See TracBrowser for help on using the repository browser.