/* Copyright (c) 1984-98 by The MathWorks, Inc. */
/*
* hdfgd.c --- support file for HDF.MEX
*
* This module supports the HDF-EOS GD interface. The only public
* function is hdfGD(), which is called by mexFunction().
* hdfGD looks at the second input argument to determine which
* private function should get control.
*
*/
/* $Revision: 1.8 $ $Date: 1998/08/06 21:17:21 $ */
static char rcsid[] = "$Id: hdfgd.c,v 1.8 1998/08/06 21:17:21 clay Exp $";
#include <string.h>
#include <math.h>
/* Main HDF library header file */
#include "hdf.h"
/* MATLAB API header file */
#include "mex.h"
/* HDFMEX utility functions */
#include "hdfutils.h"
/* HDF-EOS header file */
#include "HdfEosDef.h"
#define NUM_PROJ_PARMS 16
#define BUFLEN 128
/*
* GetProjParm
*
* Purpose: Fill in projection parameter vector from MATLAB array.
*
* Inputs: inStr --- MATLAB array; should be NUM_PROJ_PARMS-element array
* Outputs: proj_parm[NUM_PROJ_PARMS] --- projection parameters
* Return: none
*/
static
void GetProjParm(const mxArray *array, float64 proj_parm[NUM_PROJ_PARMS])
{
double *pr;
int k;
int num_elements = mxGetNumberOfElements(array);
if (! mxIsDouble(array) || (num_elements > NUM_PROJ_PARMS))
{
mexErrMsgTxt("Invalid projection parameter vector.");
}
pr = mxGetPr(array);
for (k = 0; k < num_elements; k++)
{
proj_parm[k] = pr[k];
}
for (k = num_elements; k < NUM_PROJ_PARMS; k++)
{
proj_parm[k] = 0;
}
}
/*
* GetProjCode
*
* Purpose: Given MATLAB string array, return HDF-EOS projection code
*
* Inputs: inStr --- MATLAB string array
* Outputs: none
* Return: HDF-EOS projection code; errors out if none found
*/
static
int32 GetProjCode(const mxArray *inStr)
{
static struct
{
char *longStr;
char *shortStr;
int32 code;
}
projCodes[] =
{
{"gctp_geo", "geo", GCTP_GEO},
{"gctp_utm", "utm", GCTP_UTM},
{"gctp_lamcc", "lamcc", GCTP_LAMCC},
{"gctp_ps", "ps", GCTP_PS},
{"gctp_polyc", "polyc", GCTP_POLYC},
{"gctp_tm", "tm", GCTP_TM},
{"gctp_lamaz", "lamaz", GCTP_LAMAZ},
{"gctp_hom", "hom", GCTP_HOM},
{"gctp_som", "som", GCTP_SOM},
{"gctp_good", "good", GCTP_GOOD},
{"gctp_isinus", "isinus", GCTP_ISINUS}
};
static int numCodes = sizeof(projCodes) / sizeof(*projCodes);
char buffer[BUFLEN];
int32 projCode;
int k = 0;
bool codeFound = false;
if (!mxIsChar(inStr))
{
mexErrMsgTxt("Projection code must be a string.");
}
mxGetString(inStr, buffer, BUFLEN);
for (k = 0; k < numCodes; k++)
{
if ((haStrcmpi(buffer, projCodes[k].longStr) == 0) ||
(haStrcmpi(buffer, projCodes[k].shortStr) == 0))
{
projCode = projCodes[k].code;
codeFound = true;
break;
}
}
if (! codeFound)
{
mexErrMsgTxt("Invalid projection code.");
}
return(projCode);
}
/*
* GetOriginCode
*
* Purpose: Given MATLAB string array, return HDF-EOS origin code
*
* Inputs: inStr --- MATLAB string array
* Outputs: none
* Return: HDF-EOS origin code; errors out if none found
*/
static
int32 GetOriginCode(const mxArray *inStr)
{
static struct
{
char *longStr;
char *shortStr;
int32 code;
}
originCodes[] =
{
{"hdfe_gd_ul", "ul", HDFE_GD_UL},
{"hdfe_gd_ur", "ur", HDFE_GD_UR},
{"hdfe_gd_ll", "ll", HDFE_GD_LL},
{"hdfe_gd_lr", "lr", HDFE_GD_LR}
};
static int numCodes = sizeof(originCodes) / sizeof(*originCodes);
char buffer[BUFLEN];
int32 originCode;
int k = 0;
bool codeFound = false;
if (!mxIsChar(inStr))
{
mexErrMsgTxt("Origin code must be a string.");
}
mxGetString(inStr, buffer, BUFLEN);
for (k = 0; k < numCodes; k++)
{
if ((haStrcmpi(buffer, originCodes[k].longStr) == 0) ||
(haStrcmpi(buffer, originCodes[k].shortStr) == 0))
{
originCode = originCodes[k].code;
codeFound = true;
break;
}
}
if (! codeFound)
{
mexErrMsgTxt("Invalid origin code.");
}
return(originCode);
}
int32 GetEntryCode(const mxArray *inStr)
{
static struct
{
char *longStr;
char *shortStr;
int32 code;
}
entryCodes[] =
{
{"hdfe_nentdim", "nentdim", HDFE_NENTDIM},
{"hdfe_nentdfld", "nentdfld", HDFE_NENTDFLD}
};
static int numCodes = sizeof(entryCodes) / sizeof(*entryCodes);
char buffer[BUFLEN];
int32 entryCode;
int k = 0;
bool codeFound = false;
if (!mxIsChar(inStr))
{
mexErrMsgTxt("Entry code must be a string.");
}
mxGetString(inStr, buffer, BUFLEN);
for (k = 0; k < numCodes; k++)
{
if ((haStrcmpi(buffer, entryCodes[k].longStr) == 0) ||
(haStrcmpi(buffer, entryCodes[k].shortStr) == 0))
{
entryCode = entryCodes[k].code;
codeFound = true;
break;
}
}
if (! codeFound)
{
mexErrMsgTxt("Invalid entry code.");
}
return(entryCode);
}
int32 GetPixReg(const mxArray *inStr)
{
static struct
{
char *longStr;
char *shortStr;
int32 code;
}
codes[] =
{
{"hdfe_center", "center", HDFE_CENTER},
{"hdfe_corner", "corner", HDFE_CORNER}
};
static int numCodes = sizeof(codes) / sizeof(*codes);
char buffer[BUFLEN];
int32 code;
int k = 0;
bool codeFound = false;
if (!mxIsChar(inStr))
{
mexErrMsgTxt("Registration code must be a string.");
}
mxGetString(inStr, buffer, BUFLEN);
for (k = 0; k < numCodes; k++)
{
if ((haStrcmpi(buffer, codes[k].longStr) == 0) ||
(haStrcmpi(buffer, codes[k].shortStr) == 0))
{
code = codes[k].code;
codeFound = true;
break;
}
}
if (! codeFound)
{
mexErrMsgTxt("Invalid registration code.");
}
return(code);
}
int32 GetTileCode(const mxArray *inStr)
{
static struct
{
char *longStr;
char *shortStr;
int32 code;
}
codes[] =
{
{"hdfe_tile", "tile", HDFE_TILE},
{"hdfe_notile", "notile", HDFE_NOTILE}
};
static int numCodes = sizeof(codes) / sizeof(*codes);
char buffer[BUFLEN];
int32 code;
int k = 0;
bool codeFound = false;
if (!mxIsChar(inStr))
{
mexErrMsgTxt("Tile code must be a string.");
}
mxGetString(inStr, buffer, BUFLEN);
for (k = 0; k < numCodes; k++)
{
if ((haStrcmpi(buffer, codes[k].longStr) == 0) ||
(haStrcmpi(buffer, codes[k].shortStr) == 0))
{
code = codes[k].code;
codeFound = true;
break;
}
}
if (! codeFound)
{
mexErrMsgTxt("Invalid tile code.");
}
return(code);
}
/*
* GetCompressionStringFromCode
*
* Purpose: Return an mxArray containing the string corresponding to the
* given compression code.
*
* Inputs: int32 compcode
*
* Outputs: none
*
* Returns: mxArray compressionString
*/
static
mxArray *GetCompressionStringFromCode(int32 compcode)
{
mxArray *compstring;
if (compcode == HDFE_COMP_RLE)
compstring = mxCreateString("rle");
else if (compcode ==