Beispiel #1
0
// MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
//                                    const char *user, const char *passwd,
//                                    const char *db, unsigned int port,
//                                    const char *unix_socket,
//                                    unsigned long clientflag);
static IDL_VPTR IDL_mg_mysql_real_connect(int argc, IDL_VPTR *argv) {
    MYSQL *mysql = mysql_real_connect((MYSQL *) argv[0]->value.ptrint,
                                      IDL_VarGetString(argv[1]),
                                      IDL_VarGetString(argv[2]),
                                      IDL_VarGetString(argv[3]),
                                      argv[4]->value.str.slen == 0 ? NULL : IDL_VarGetString(argv[4]),
                                      IDL_ULongScalar(argv[5]),
                                      argv[6]->value.str.slen == 0 ? NULL : IDL_VarGetString(argv[6]),
                                      IDL_ULong64Scalar(argv[7]));
    return IDL_GettmpMEMINT((IDL_MEMINT) mysql);
}
Beispiel #2
0
static IDL_VPTR IDL_CDECL IDL_mg_nc_isncdf(int argc, IDL_VPTR *argv) {
  IDL_VPTR cptr_filename = argv[0];
  int status, ncidp;
  IDL_ENSURE_STRING(cptr_filename);
  status = nc_open(IDL_VarGetString(cptr_filename), 0, &ncidp);
  return IDL_GettmpByte(status == NC_ENOTNC ? 0 : 1);
}
Beispiel #3
0
IDL_VPTR pgsql_query(int argc, IDL_VPTR *argv, char *argk)
{

    IDL_VPTR queryVptr;
    char *query;
    char *connect_info;

    IDL_VPTR resultVptr;

    int async = 1;

    int status;


    (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, 
            (IDL_VPTR *) 0, 1, &kw);


    if (kw.nrows_there)
        IDL_StoreScalarZero(kw.nrows, IDL_TYP_ULONG64);

    /* Check number of input parameters */
    if (pgsql_query_nparams(argc) < 1)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO, 
                "-Syntax: result=pgsql_query(query, nrows=, connect_info=, file=, /append, /nointerrupt, /verbose, status=)\nIf there are results for the query, a structure is returned.  Otherwise the result is -1");
        return(IDL_GettmpInt(-1));
    }

    /* Get the input query */
    queryVptr = argv[0];
    query = IDL_VarGetString(queryVptr);



    /* The user may have input connection information */
    if (kw.connect_info_there)
        connect_info=IDL_STRING_STR(&kw.connect_info);
    else
        connect_info="";

    /* Should we query asynchronously?  This would allow cancel through ^C */
    if (kw.nointerrupt_there)
        if (kw.nointerrupt) 
            async = 0;

    if (async) 
        status = pgsql_query_send_async(query, connect_info, &resultVptr);
    else 
        status = pgsql_query_send(query, connect_info, &resultVptr);

    setStatus(status);

    IDL_KW_FREE;
    if (status == MYPG_SUCCESS)
        return(resultVptr);
    else
        return(IDL_GettmpInt(-1));
}
/**
 * Hide a layer.
 *
 * @param[in] [1]
 *            The name of the layer to hide.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @rsof
 * @usage print,hide_layer("raster.tif")
 * @endusage
 */
IDL_VPTR hide_layer(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   IDL_VPTR idlPtr;
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
   } KW_RESULT;

   //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the
   //name of the keyword, followed by the type, the mask(which should be 1),
   //flags, a boolean whether the value was populated and finally the value itself
   static IDL_KW_PAR kw_pars[] = {
      IDL_KW_FAST_SCAN,
      {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))},
      {NULL}
   };

   IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1);

   std::string windowName;
   std::string layerName;

   if (kw->windowExists)
   {
      windowName = IDL_STRING_STR(&kw->windowName);
   }
   bool bSuccess = false;
   if (argc < 1)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "function takes a layer name as a parameter with "
         "'window' as an optional keyword.");
      return IDL_StrToSTRING("failure");
   }
   //the layer name as a parameter
   layerName = IDL_VarGetString(pArgv[0]);
   SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName));
   if (pView != NULL)
   {
      Layer* pLayer = IdlFunctions::getLayerByName(windowName, layerName, false);
      if (pLayer != NULL)
      {
         pView->hideLayer(pLayer);
         bSuccess = true;
      }
   }
   if (bSuccess)
   {
      idlPtr = IDL_StrToSTRING("success");
   }
   else
   {
      idlPtr = IDL_StrToSTRING("failure");
   }
   return idlPtr;
}
Beispiel #5
0
// MYSQL_RES *mysql_list_dbs(MYSQL *mysql, const char *wild)
static IDL_VPTR IDL_mg_mysql_list_dbs(int argc, IDL_VPTR *argv) {
    char *wildcard = NULL;
    if (argc > 1) {
        if (argv[1]->type == IDL_TYP_STRING) {
            wildcard = IDL_VarGetString(argv[1]);
        }
    }
    MYSQL_RES *result = mysql_list_dbs((MYSQL *)argv[0]->value.ptrint,
                                       wildcard);
    return IDL_GettmpMEMINT((IDL_MEMINT) result);
}
/**
 * Get the current position of a layer in the layer list.
 *
 * @param[in] [1]
 *            The name of the layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return The 0 based position of the layer in the layer list.
 * @usage idx = get_layer_position("data.tif")
 * @endusage
 */
IDL_VPTR get_layer_position(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
   } KW_RESULT;

   //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the
   //name of the keyword, followed by the type, the mask(which should be 1),
   //flags, a boolean whether the value was populated and finally the value itself
   static IDL_KW_PAR kw_pars[] = {
      IDL_KW_FAST_SCAN,
      {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))},
      {NULL}
   };

   IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1);

   std::string windowName;
   std::string name;
   int index = -1;

   if (kw->windowExists)
   {
      windowName = IDL_STRING_STR(&kw->windowName);
   }

   if (argc < 1)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "get_layer_position takes a layer name as a parameter with a "
         "window as an optional keyword to specify a non current window.");
   }
   else
   {
      //layer name passed in as a parameter
      name = IDL_VarGetString(pArgv[0]);
      SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName));
      if (pView != NULL)
      {
         Layer* pLayer = IdlFunctions::getLayerByName(windowName, name, false);
         if (pLayer != NULL)
         {
            index = pView->getLayerDisplayIndex(pLayer);
         }
      }
   }
   return IDL_GettmpInt(index);
}
Beispiel #7
0
static void IDL_CDECL IDL_mg_tout_push(int argc, IDL_VPTR *argv) {
  if (diverting) {
    IDL_ToutPop();
  } else diverting = 1;

  if (argc > 0) {
    IDL_ENSURE_STRING(argv[0]);
    outf_fp = fopen(IDL_VarGetString(argv[0]), "w");
    IDL_ToutPush(mg_tout_outf_file);
  } else {
    outf_buffer_loc = 0;
    outf_buffer_size = OUTF_BUFFER_BLOCKSIZE;
    outf_buffer = (char *) malloc(OUTF_BUFFER_BLOCKSIZE);
    IDL_ToutPush(mg_tout_outf_buffer);
  }

}
Beispiel #8
0
// int mysql_options(MYSQL *mysql, enum mysql_option option, const char *arg)
static IDL_VPTR IDL_mg_mysql_options(int argc, IDL_VPTR *argv) {
    char *value;
    switch (argv[2]->type) {
    case IDL_TYP_BYTE:
        value = (char *) &argv[2]->value.c;
        break;
    case IDL_TYP_ULONG:
        value = (char *) &argv[2]->value.ul;
        break;
    case IDL_TYP_STRING:
        value = IDL_VarGetString(argv[2]);
        break;
    }
    int status = mysql_options((MYSQL *)argv[0]->value.ptrint,
                               IDL_ULongScalar(argv[1]),
                               value);
    return IDL_GettmpLong(status);
}
Beispiel #9
0
static void IDL_CDECL IDL_mg_print(int argc, IDL_VPTR *argv, char *argk) {
  int nargs;
  char *format, *cformat;
  IDL_VPTR origFormat, vcformat;

  typedef struct {
    IDL_KW_RESULT_FIRST_FIELD;
    IDL_VPTR format;
    int format_present;
  } KW_RESULT;

  static IDL_KW_PAR kw_pars[] = {
    { "FORMAT", IDL_TYP_STRING, 1, IDL_KW_VIN,
      IDL_KW_OFFSETOF(format_present), IDL_KW_OFFSETOF(format) },
    { NULL }
  };

  KW_RESULT kw;

  nargs = IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw);

  if (kw.format_present) {
    origFormat = argv[argc - 1];
    format = IDL_VarGetString(origFormat);
    cformat = (char *) calloc(strlen(format) + 5 + 1, sizeof(char));
    sprintf(cformat, "(%%\"%s\")", format);
    vcformat = IDL_StrToSTRING(cformat);
    argv[argc - 1] = vcformat;
  }

  IDL_Print(argc, argv, argk);

  if (kw.format_present) {
    argv[argc - 1] = origFormat;
    IDL_Deltmp(vcformat);
    free(cformat);
  }

  IDL_KW_FREE;
}
Beispiel #10
0
/**
   Launch editor in $EDITOR environment variable on the given filename.

   @param[in] filename file to launch editor on
*/
void ridl_launcheditor(char *filename) {
  int result;
  IDL_VPTR ridl_editfile;
  char *launchCmdFormat, *launchCmd, *compileCmdFormat, *compileCmd;

  launchCmdFormat = "_ridl_editfile = ridl_launcheditor('%s')";
  launchCmd = (char *)malloc(strlen(filename) + strlen(launchCmdFormat) + 1);
  sprintf(launchCmd, launchCmdFormat, filename);

  result = IDL_ExecuteStr(launchCmd);
  free(launchCmd);

  if (auto_compile) {
    compileCmdFormat = ".compile %s";
    compileCmd = (char *)malloc(strlen(filename) + strlen(compileCmdFormat) + 1);
    ridl_editfile = IDL_FindNamedVariable("_ridl_editfile", 0);
    sprintf(compileCmd, compileCmdFormat, IDL_VarGetString(ridl_editfile));

    result = IDL_ExecuteStr(compileCmd);
    free(compileCmd);
  }

  result = IDL_ExecuteStr("delvar, _ridl_editfile");
}
/**
 * Get the data element name of a specified layer.
 *
 * @param[in] [1] @opt
 *            The name of the layer. Defaults to the top most layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @param[in] DATASET @opt
 *            If \p [1] is not specified and this flag it set, get the
 *            data set name of the top most raster layer.
 * @return The name of the data element.
 * @usage print,get_data_name(/DATASET)
 * @endusage
 */
IDL_VPTR get_data_name(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
      int datasetExists;
      IDL_LONG dataset;
   } KW_RESULT;

   //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the
   //name of the keyword, followed by the type, the mask(which should be 1),
   //flags, a boolean whether the value was populated and finally the value itself
   static IDL_KW_PAR kw_pars[] = {
      IDL_KW_FAST_SCAN,
      {"DATASET", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(datasetExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(dataset))},
      {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))},
      {NULL}
   };

   IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1);
   std::string windowName;
   std::string layerName;
   std::string name;

   if (kw->windowExists)
   {
      windowName = IDL_STRING_STR(&kw->windowName);
   }

   //retrieve the layer name passed in as a parameter
   if (argc >= 1)
   {
      layerName = IDL_VarGetString(pArgv[0]);
   }
   //get the layer
   bool datasets = false;
   if (kw->datasetExists)
   {
      if (kw->dataset != 0)
      {
         datasets = true;
      }
   }
   Layer* pLayer = IdlFunctions::getLayerByName(windowName, layerName, datasets);
   if (pLayer != NULL)
   {
      //get the spectral element of the layer and return its name
      DataElement* pElement = pLayer->getDataElement();
      if (pElement != NULL)
      {
         name = pElement->getName();
      }
   }
   else
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "the layer name passed into get_data_name "
         "was invalid.");
      return IDL_StrToSTRING("");
   }

   return IDL_StrToSTRING(const_cast<char*>(name.c_str()));
}
Beispiel #12
0
// int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
//                              unsigned long length);
static IDL_VPTR IDL_mg_mysql_real_query(int argc, IDL_VPTR *argv) {
    int status = mysql_real_query((MYSQL *)argv[0]->value.ptrint,
                                  IDL_VarGetString(argv[1]),
                                  IDL_ULong64Scalar(argv[2]));
    return IDL_GettmpLong(status);
}
Beispiel #13
0
// int mysql_select_db(MYSQL *mysql, const char *db)
static IDL_VPTR IDL_mg_mysql_select_db(int argc, IDL_VPTR *argv) {
    int status = mysql_select_db((MYSQL *) argv[0]->value.ptrint,
                                 IDL_VarGetString(argv[1]));
    return IDL_GettmpLong(status);
}
Beispiel #14
0
void p3d_idlWriteRaw(int argc, IDL_VPTR argv[], char* argk) {

	typedef struct {
		IDL_KW_RESULT_FIRST_FIELD; // Must be first entry in structure
		IDL_LONG endian;
		IDL_LONG sign;
	} KW_RESULT;

	// Alphabetical order is crucial:
	static IDL_KW_PAR kw_pars[] = {
		IDL_KW_FAST_SCAN,
		{ "BIG_ENDIAN", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, (char*) IDL_KW_OFFSETOF(endian)},
		{ "UNSIGNED", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, (char*) IDL_KW_OFFSETOF(sign)},
		{ NULL}
	};

	KW_RESULT kw;
	IDL_VPTR idl_in_rev;

	char* filename;
	int err_code;

	int little_endian;
	int is_signed;

	unsigned char* in_rev8;
	unsigned short* in_rev16;
	unsigned int* in_rev32;
	float* in_rev32f;


	// Process keywords:
	IDL_KWProcessByOffset(argc, argv, argk, kw_pars, (IDL_VPTR *) 0, 1, &kw);

	little_endian = (kw.endian == 0) ? P3D_TRUE : P3D_FALSE;
	is_signed = (kw.sign == 0) ? P3D_TRUE : P3D_FALSE;

	// Get input data in IDL format:
	idl_in_rev = argv[0];

	IDL_ENSURE_SIMPLE(idl_in_rev);
	IDL_ENSURE_ARRAY(idl_in_rev);


	if (argv[1]->type == IDL_TYP_STRING)
		filename = IDL_VarGetString(argv[1]);
	else
		_p3d_idlPrintNamedError("Input argument FILENAME must be a string.");


	// Check if user wants to write a 8-bit or 16-bit format image:
	if (idl_in_rev->type == IDL_TYP_BYTE) {
		// Extract input in C format
		in_rev8 = (unsigned char *) idl_in_rev->value.arr->data;


		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {
			// Call Pore3D:
			err_code = p3dWriteRaw8(
				in_rev8,
				filename,
				(int) (idl_in_rev->value.arr->dim[0]),
				(int) (idl_in_rev->value.arr->dim[1]),
				1,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw8(
				in_rev8,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}
	} else if (idl_in_rev->type == IDL_TYP_UINT) {
		// Extract input in C format
		in_rev16 = (unsigned short *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw16(
				in_rev16,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw16(
				in_rev16,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");

		} else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix."); 
		}
	} else if (idl_in_rev->type == IDL_TYP_ULONG) {
		// Extract input in C format
		in_rev32 = (unsigned int *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw32(
				in_rev32,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw32(
				in_rev32,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		}
		else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}	
	} else if (idl_in_rev->type == IDL_TYP_FLOAT) {
		// Extract input in C format
		in_rev32f = (float *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw32f(
				in_rev32f,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw32f(
				in_rev32f,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		}
		else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}

	} else {
		_p3d_idlPrintNamedError("Input argument IMAGE must be a BYTE, UINT, ULONG or FLOAT matrix.");
	}


	// Free keywords resources:
	IDL_KW_FREE;
}