Beispiel #1
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 #3
0
//
// idlPvAttrStringSet
//
// Set the value of a string attribute
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN attribute name
// argv[3]: IN attribute value
int idlPvAttrStringSet (int argc, char *argv[])
{
  unsigned long n;
  unsigned long err;
  IDL_STRING *name;
  IDL_STRING *value;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  name = (IDL_STRING *) argv[2];
  value = (IDL_STRING *) argv[3];

  CHECKINDEX(n);

  err = PvAttrStringSet(camera[n],
			(const char *) IDL_STRING_STR(name),
			(const char *) IDL_STRING_STR(value));

  return idlPvErrCode(err);
}
/**
 * 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);
}
/**
 * Get the name of the layer in a given position in the layer list.
 *
 * @param[in] INDEX @opt
 *            The 0 based index of the layer. Defaults to the top most layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return The name of the layer.
 * @usage print,get_layer_name(2, WINDOW="Window 1")
 * @endusage
 */
IDL_VPTR get_layer_name(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
      int indexExists;
      IDL_LONG index;
   } 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,
      {"INDEX", IDL_TYP_LONG, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(indexExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(index))},
      {"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;
   int index = -1;
   std::string name;

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

   if (argc < 0)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "Invalid arguments");
      return IDL_StrToSTRING("");
   }
   Layer* pLayer = IdlFunctions::getLayerByIndex(windowName, index);
   if (pLayer != NULL)
   {
      name =  pLayer->getName();
   }
   return IDL_StrToSTRING(const_cast<char*>(name.c_str()));
}
Beispiel #6
0
void ridl_closenotebook(void) {
  char *ts = ridl_currenttimestamp();
  switch(ridl_logging_format) {
    case 0:
      fprintf(notebook_fp, "    <p class=\"date\">Notebook produced by rIDL %s with IDL %s on %s.</p>", 
              RIDL_VERSION, IDL_STRING_STR(&IDL_SysvVersion.release), ts);
  
      fprintf(notebook_fp, "  </body>\n");  
      fprintf(notebook_fp, "</html>\n");
      break;
    case 1:
      if (ridl_new_codeblock) {
        ridl_new_codeblock = 0;
      } else {
        fprintf(notebook_fp, "\n");
      }
      fprintf(notebook_fp, "Notebook produced by rIDL %s with IDL %s on %s.\n",
              RIDL_VERSION, IDL_STRING_STR(&IDL_SysvVersion.release), ts);
      break;
  }
  free(ts);
  fclose(notebook_fp);
}
Beispiel #7
0
//
// idlPvCommandRun
//
// Run a command.  A command is an attribute that executes a function
// when written.
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN command name
int idlPvCommandRun (int argc, char * argv[])
{
  unsigned long n;
  unsigned long err;
  IDL_STRING * name;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  name = (IDL_STRING *) argv[2];

  CHECKINDEX(n);

  err = PvCommandRun(camera[n], IDL_STRING_STR(name));

  return idlPvErrCode(err);
}
Beispiel #8
0
//
// idlPvAttrIsAvailable
//
// Determine if the attribute is available for a specified camera
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN index of camera
// argv[2]: IN name of attribute
int idlPvAttrIsAvailable (int argc, char *argv[])
{
  unsigned long n;
  IDL_STRING *attribute;
  unsigned long err;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  attribute = (IDL_STRING *) argv[2];

  CHECKINDEX(n);

  err = PvAttrIsAvailable(camera[n],
			  IDL_STRING_STR(attribute));

  return idlPvErrCode(err);
}
Beispiel #9
0
int pgsql_write_file(PGresult *res)
{

    int nFields;
    long long nTuples;
    int field;
    long long row;

    char *file;
    FILE *OFILEPTR;

    file = IDL_STRING_STR(&kw.file);
    nFields = PQnfields(res);
    nTuples = PQntuples(res);

    /* Are we creating new or appending? */
    if ( (kw.append_there) && (kw.append != 0) )
        OFILEPTR = fopen(file, "a");
    else
        OFILEPTR = fopen(file, "w");

    if (!OFILEPTR)
    {
        pgsql_query_error("Could not open file",file);
        return(MYPG_WRITE_FAILURE);
    }

    /* Loop through and write everything to file, tab-separated */
    for (row=0; row<nTuples; row++)
        for (field=0;field<nFields;field++)
        {
            fprintf(OFILEPTR,"%s", PQgetvalue(res, row, field) );
            /* If last field print a new line, else a tab*/
            if (field == nFields-1)
                fprintf(OFILEPTR,"\n");
            else
                fprintf(OFILEPTR,"\t");
        }
    fclose(OFILEPTR);

    /* No matter what there are no results */
    return(MYPG_NO_RESULT);

}
Beispiel #10
0
//
// idlPvAttrInfo
//
// Get data type and access mode information for an attribute
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN attribute name
// argv[3]: OUT data type
// argv[4]: OUT flags
int idlPvAttrInfo (int argc, char *argv[])
{
  unsigned long n;
  IDL_STRING * name;
  tPvAttributeInfo info;
  unsigned long err;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  name = (IDL_STRING *) argv[2];

  CHECKINDEX(n);

  err = PvAttrInfo(camera[n], IDL_STRING_STR(name), &info);

  *(IDL_ULONG *) argv[3] = (IDL_ULONG) info.Datatype;
  *(IDL_ULONG *) argv[4] = (IDL_ULONG) info.Flags;

  return idlPvErrCode(err);
}
Beispiel #11
0
/*
  host = MG_NET_NAME2HOST(name)

  Converts the ASCII host name into an unsigned long host value. If name is
  not specified, the local host name is used.
*/
static IDL_VPTR IDL_CDECL mg_net_name2host(int argc, IDL_VPTR argv[], char *argk) {
  struct hostent *hp;
  char *pName, host_name[256];

  if (argc == 0) {
    if (gethostname(host_name, 256) == -1) {
      host_name[0] = '\0';
    }
    pName = host_name;
  } else {
    IDL_ENSURE_STRING(argv[0]);
    IDL_ENSURE_SCALAR(argv[0]);
    pName = IDL_STRING_STR(&(argv[0]->value.str));
  }

  hp = gethostbyname(pName);
  if (!hp) return(IDL_GettmpLong(0));

  return(IDL_GettmpULong(((struct in_addr *) (hp->h_addr))->s_addr));
}
/**
 * Get the number of layers in a window.
 *
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return The number of layers in the window.
 * @usage num_layers = get_num_layers()
 * @endusage
 */
IDL_VPTR get_num_layers(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;
   int layers = 0;

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

   SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName));
   if (pView != NULL)
   {
      LayerList* pList = pView->getLayerList();
      if (pList != NULL)
      {
         layers = pList->getNumLayers();
      }
   }
   return IDL_GettmpInt(layers);
}
Beispiel #13
0
//
// idlPvAttrStringGet
//
// Get the value of a string attribute
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN attribute name
// argv[3]: OUT attribute value
int idlPvAttrStringGet (int argc, char *argv[])
{
  unsigned long n;
  unsigned long err;
  IDL_STRING *name;
  IDL_STRING *value;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  name = (IDL_STRING *) argv[2];
  value = (IDL_STRING *) argv[3];

  CHECKINDEX(n);

  err = PvAttrStringGet(camera[n],
			(const char *) IDL_STRING_STR(name),
			buffer, STRBUFFERSIZE, (unsigned long *) NULL);

  IDL_StrStore(value, buffer);
		      
  return idlPvErrCode(err);
}
Beispiel #14
0
//
// idlPvAttrFloat32Range
//
// Get the range of value of a Float32 attribute
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN attribute name
// argv[3]: OUT attribute range minumum
// argv[4]: OUT attribute range maximum
int idlPvAttrFloat32Range (int argc, char *argv[])
{
  unsigned long n;
  unsigned long err;
  IDL_STRING *name;
  float *vmin;
  float *vmax;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  name = (IDL_STRING *) argv[2];
  vmin = (float *) argv[3];
  vmax = (float *) argv[4];

  CHECKINDEX(n);

  err = PvAttrRangeFloat32(camera[n],
			   (const char *) IDL_STRING_STR(name),
			   (tPvFloat32 *) vmin, (tPvFloat32 *) vmax);

  return idlPvErrCode(err);
}
Beispiel #15
0
int32 OldFitIDLInxClose(int argc,char *argv[]) {

  int n;
  struct RadarIDLParm *idlprm;
  struct RadarParm prm;
  int32 irec;
  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  irec=*((int32 *) argv[2]);

  memset(&prm,0,sizeof(struct RadarParm));

  /* load up the data structures */

  prm.revision.major=idlprm->revision.major;
  prm.revision.minor=idlprm->revision.minor;
  prm.cp=idlprm->cp;
  prm.stid=idlprm->stid;
  prm.time.yr=idlprm->time.yr;
  prm.time.mo=idlprm->time.mo;
  prm.time.dy=idlprm->time.dy;
  prm.time.hr=idlprm->time.hr;
  prm.time.mt=idlprm->time.mt;
  prm.time.sc=idlprm->time.sc;
  prm.time.us=idlprm->time.us;
  prm.txpow=idlprm->txpow;
  prm.nave=idlprm->nave;
  prm.atten=idlprm->atten;
  prm.lagfr=idlprm->lagfr;
  prm.smsep=idlprm->smsep;
  prm.ercod=idlprm->ercod;
  prm.stat.agc=idlprm->stat.agc;
  prm.stat.lopwr=idlprm->stat.lopwr;
  prm.noise.search=idlprm->noise.search;
  prm.noise.mean=idlprm->noise.mean;
  prm.channel=idlprm->channel;
  prm.bmnum=idlprm->bmnum;
  prm.scan=idlprm->scan;
  prm.rxrise=idlprm->rxrise;
  prm.intt.sc=idlprm->intt.sc;
  prm.intt.us=idlprm->intt.us;
  prm.txpl=idlprm->txpl;
  prm.mpinc=idlprm->mpinc;
  prm.mppul=idlprm->mppul;
  prm.mplgs=idlprm->mplgs;
  prm.nrang=idlprm->nrang;
  prm.frang=idlprm->frang;
  prm.rsep=idlprm->rsep;
  prm.xcf=idlprm->xcf;
  prm.tfreq=idlprm->tfreq;
  prm.offset=idlprm->offset;
  prm.mxpwr=idlprm->mxpwr;
  prm.lvmax=idlprm->lvmax;

  for (n=0;n<prm.mppul;n++) prm.pulse[n]=idlprm->pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    prm.lag[n][0]=idlprm->lag[n];
    prm.lag[n][1]=idlprm->lag[LAG_SIZE+n];
  }

  if (strlen(IDL_STRING_STR(&idlprm->combf)) !=0) 
    strncpy(prm.combf,IDL_STRING_STR(&idlprm->combf),COMBF_SIZE);

 
  s=OldFitInxFclose(fp,&prm,irec);
  
  return s;

}
Beispiel #16
0
/*
  err = MG_NET_SENDVAR(socket, variable [, host] [, port])

  Sends a complete IDL variable to a socket for reading by MG_NET_RECVVAR. The
  variable must be one of the basic types, but strings and arrays are sent
  with array dimensions and lengths intact.

	When sending data from a UDP socket, you must specify the remote host and
	port arguments where host is the value returned from the MG_NET_NAME2HOST
	function.

  Note: This is the easiest way to send a complete variable from one IDL to
  another. The receiver will byteswap the data if necessary. One should be
  careful not to mix calls to MG_NET_SEND/RECV and MG_NET_SENDVAR/RECVVAR as
  the latter send formatted information. You can use the two calls on the same
  socket as long as they are paired.
*/
static IDL_VPTR IDL_CDECL mg_net_sendvar(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i;
  i_var	var;
  int host, addr_len;
  short	port;
  IDL_LONG iRet;
  IDL_VPTR vpTmp;
  char *pbuffer;
  struct sockaddr_in sin;

  i = IDL_LongScalar(argv[0]);
  if ((i < 0) || (i >= MAX_SOCKETS)) return (IDL_GettmpLong(-1));
  if (net_list[i].iState != NET_IO) return (IDL_GettmpLong(-1));
  IDL_ENSURE_SIMPLE(argv[1]);
  vpTmp = argv[1];

  if (net_list[i].iType == NET_UDP) {
    if (argc == 4) {
      host = IDL_ULongScalar(argv[2]);
      port = (short) IDL_LongScalar(argv[3]);
    } else {
      IDL_MessageFromBlock(msg_block,
			   MG_NET_ERROR,
			   IDL_MSG_RET,
			   "This UDP socket requires the destination HOST and PORT arguments.");
    }
  }

  var.token = TOKEN;
  var.type = vpTmp->type;
  if ((var.type == IDL_TYP_STRUCT) ||
      (var.type == IDL_TYP_PTR) ||
      (var.type == IDL_TYP_OBJREF) ||
      (var.type == IDL_TYP_UNDEF)) {
    IDL_MessageFromBlock(msg_block,
			 MG_NET_BADTYPE,
			 IDL_MSG_LONGJMP,
			 IDL_TypeNameFunc(var.type));
  }

  if (vpTmp->type == IDL_TYP_STRING) {
    if (vpTmp->flags & IDL_V_ARR) return (IDL_GettmpLong(-1));
    pbuffer = IDL_STRING_STR(&(vpTmp->value.str));
    var.ndims = 0;
    var.len = vpTmp->value.str.slen + 1;
    var.nelts = var.len;
  } else if (vpTmp->flags & IDL_V_ARR) {
    pbuffer = vpTmp->value.arr->data;
    var.ndims = vpTmp->value.arr->n_dim;
    var.len = vpTmp->value.arr->arr_len;
    var.nelts = vpTmp->value.arr->n_elts;
    memcpy(var.dims, vpTmp->value.arr->dim, IDL_MAX_ARRAY_DIM * sizeof(IDL_LONG));
  } else {
    pbuffer = &(vpTmp->value.c);
    var.ndims = 0;
    var.len = IDL_TypeSizeFunc(var.type);
    var.nelts = 1;
  }

  /* send native, recvvar swaps if needed */
  if (net_list[i].iType == NET_UDP) {
    sin.sin_addr.s_addr = host;
    sin.sin_family = AF_INET;
    sin.sin_port = htons(port);
    addr_len = sizeof(struct sockaddr_in);

    iRet = sendto(net_list[i].socket, (char *) &var, sizeof(i_var), 0,
		  (struct sockaddr *) &sin, addr_len);
    if (iRet == -1) return(IDL_GettmpLong(iRet));

    iRet = sendto(net_list[i].socket, pbuffer, var.len, 0,
		  (struct sockaddr *) &sin, addr_len);
  } else {
    iRet = send(net_list[i].socket,(char *) &var, sizeof(i_var), 0);
    if (iRet == -1) return (IDL_GettmpLong(iRet));
    
    iRet = send(net_list[i].socket, pbuffer, var.len, 0);
  }

  return(IDL_GettmpLong(1));
}
Beispiel #17
0
void getobjectdetails( IDL_VPTR var, void *data, char *taglist[],
                       char hdstype[], int *numtags,
                       int *ndims, int dims[], int *elt_len, int *status ) {

    UCHAR idltype;     /* Type of variable */
    int i;             /* counter */
    int *vardim;
    IDL_VPTR tmpvar;
    IDL_LONG offset;
    char *dimptr;
    char *tok;

    if ( *status != SAI__OK ) return;
    /* Type */
    idltype = var->type;
    strcpy(hdstype, gethdstype( idltype ));

    if ( var->flags & IDL_V_STRUCT ) {
        /* Structure */
        *numtags = IDL_StructNumTags( var->value.s.sdef );
        *elt_len = var->value.s.arr->elt_len;
        if ( var->value.s.arr->n_elts == 1 )
            *ndims = 0;
        else
            *ndims = (int)var->value.s.arr->n_dim;
        vardim = (int *)var->value.s.arr->dim;
        for ( i=0; i<*ndims; i++ ) dims[i] = vardim[i];

        if ( !strcmp( *taglist, "HDSSTRUCTYPE" ) ) {
            /* Get the tag info */
            offset = IDL_StructTagInfoByIndex(
                         var->value.s.sdef, 0, IDL_MSG_LONGJMP, &tmpvar );
            strcpy( hdstype, IDL_STRING_STR((IDL_STRING *)data+offset) );
        }

        /* If it's an array structure -    */
        if ( dimptr=strpbrk(hdstype,"(") ) {
            /*    terminate hdstype at the (   */
            *dimptr++ = '\0';
            /*    and get the array dimensions */
            for ( i=0; tok=strtok(i?NULL:dimptr,",)"); i++ ) {
                dims[i] = atoi(tok);
            }
        }
        *ndims = i;

    } else if ( var->flags & IDL_V_ARR ) {
        /* Primitive Array */
        *numtags = 0;;
        *ndims = (int)var->value.arr->n_dim;
        vardim = (int *)var->value.s.arr->dim;
        for ( i=0; i<*ndims; i++ ) dims[i] = vardim[i];

    } else {
        /* Primitive scalar */
        *numtags = 0;
        *ndims = 0;
    }

    /*    if it's IDL_STRING find the largest string size */
    if ( idltype == 7 ) {
        strcat(hdstype,"*");
        i = getidlstringsize(var,(IDL_STRING *)data);
        sprintf(hdstype+6,"%d",i);
    }

    return;
}
/**
 * Get the names of all the data elements which are children of the primary raster element.
 *
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return An array of data element names or the string "failure" if an error occurred.
 * @usage names = get_data_element_names()
 * @endusage
 */
IDL_VPTR get_data_element_names(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;
   bool bSuccess = false;
   IDL_VPTR idlPtr;
   unsigned int total = 0;
   IDL_STRING* pStrarr = NULL;

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

   SpatialDataWindow* pWindow = NULL;
   if (windowName.empty())
   {
      pWindow = dynamic_cast<SpatialDataWindow*>(Service<DesktopServices>()->getCurrentWorkspaceWindow());
   }
   else
   {
      pWindow = dynamic_cast<SpatialDataWindow*>(
         Service<DesktopServices>()->getWindow(windowName, SPATIAL_DATA_WINDOW));
   }
   if (pWindow != NULL)
   {
      SpatialDataView* pView = pWindow->getSpatialDataView();
      if (pView != NULL)
      {
         LayerList* pList = pView->getLayerList();
         if (pList != NULL)
         {
            RasterElement* pElement = pList->getPrimaryRasterElement();
            if (pElement != NULL)
            {
               std::vector<std::string> names = Service<ModelServices>()->getElementNames(pElement, "");
               total = names.size();
               if (total > 0)
               {
                  pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total * sizeof(IDL_STRING)));
                  for (unsigned int i=0; i < total; ++i)
                  {
                     IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str()));
                  }
                  bSuccess = true;
               }
            }
         }
      }
   }
   else if (windowName == "all")
   {
      std::vector<std::string> names = Service<ModelServices>()->getElementNames("RasterElement");
      total = names.size();
      if (total > 0)
      {
         pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total* sizeof(IDL_STRING)));
         for (unsigned int i=0; i < total; ++i)
         {
            IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str()));
         }
         bSuccess = true;
      }
   }
   if (!bSuccess)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "No elements matched.");
      return IDL_StrToSTRING("failure");
   }
   IDL_MEMINT dims[] = {total};
   idlPtr = IDL_ImportArray(1, dims, IDL_TYP_STRING, reinterpret_cast<UCHAR*>(pStrarr),
      reinterpret_cast<IDL_ARRAY_FREE_CB>(free), NULL);
   return idlPtr;
}
/**
 * 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 #20
0
/**
   Registered to be called when the !prompt changes.

   @param[in] prompt string to change prompt to
*/
void ridl_changeprompt(IDL_STRING *prompt) {
  ridl_prompt = IDL_STRING_STR(prompt);
  ridl_updateprompt();
}
Beispiel #21
0
IDL_VPTR hds2idl( int argc, IDL_VPTR argv[] ) {
/*
** Declare variables
*/
IDL_VPTR hds_name;       /* IDL_VPTR to name of the HDS object to be read */
IDL_VPTR var;            /* Variable pointer to IDL object */
IDL_VARIABLE temp;       /* Temporary storage for primitive scalar variable */
IDL_StructDefPtr sdef;   /* Structure definition of sub-structure */
IDL_STRING *objname;     /* Pointer to object name as IDL string */
HDSLoc *objloc = NULL;   /* Locator of file */

int status;             /* Starlink status */

char type[DAT__SZTYP+1];/* HDS type of component */
UCHAR idltype;          /* IDl type of component */
int ndims;              /* Number of dimensions of object */
int dims[DAT__MXDIM];   /* Dimensions of object HDS style */
IDL_LONG idldims[DAT__MXDIM];/* Dimensions of object IDL style */
int i;                  /* loop index */
int fstat;              /* Final status (before emsEload) */
int isstruct;           /* Whether object is structure */
void *tdata;            /* Pointer to data area of IDL variable or array */

char param[EMS__SZPAR+1]; /* Error message parameter name */
int parlen;             /* Length of error message parameter name */
char opstr[EMS__SZMSG+1]; /* Error message */
int oplen;              /* Length of error message */

IDL_LONG one[IDL_MAX_ARRAY_DIM]={1};

/* Start Error context */
   status = SAI__OK;
   emsMark();

/* Check that the correct number of arguments were passed in */
   if(argc != 1) {

   /* Print an error message and return */
      status = SAI__ERROR;
      emsRep( " ", "hds2idl: Incorrect number of arguments", &status );

   } else {
   /* Extract the arguments to comprehensible names */
      hds_name = argv[0];
      objname = &hds_name->value.str;

   /* Open the HDS object */
      getcomp( IDL_STRING_STR(objname), "READ", &objloc, &status );

   /* Check for structure or primitive */
      datStruc( objloc, &isstruct, &status );
      if (status == SAI__OK) {
         if ( isstruct ) {
         /* Create a structure */
            sdef = idlstructdef( objloc, &status );

         /* Create a temporary variable */
            if ( status == SAI__OK ) {
               (void *)IDL_MakeTempStruct( sdef, 1, one, &var, TRUE );
               idlstructfill( objloc, var->value.s, &status );
            }

         } else {
         /* Object is primitive */
            datType( objloc, type, &status );
            idltype = getidltype( type );
            datShape( objloc, DAT__MXDIM, dims, &ndims, &status );
            if ( status == SAI__OK ) {
               if (ndims) {
               /* Get dimensions IDL style */
                  for (i=0;i<ndims;i++) idldims[i] = (IDL_LONG)dims[i];
               /* Object is primitive array */
                  tdata = IDL_MakeTempArray( (int)idltype, ndims, idldims,
                    IDL_BARR_INI_ZERO , &var );

               } else {
               /* Object is primitive scalar */
                  var = &temp;
                  var->type = idltype;
                  var->flags = 0;
                  tdata = &var->value;
               }

               idlprimfill( objloc, var, tdata, &status );
            }

         }

      /* Annul the object (and close the file) */
         datAnnul( &objloc, &status );
      }
   }

   if ( status != SAI__OK ) {
   /*  Report any error messages             */
   /*  Adding Starlink-style !! and ! prefix */
      fstat = status;
      while ( status != SAI__OK ) {
         emsEload(
            param, &parlen, opstr, &oplen, &status );
         if ( status != SAI__OK )
            IDL_Message( IDL_M_NAMED_GENERIC, IDL_MSG_INFO, opstr );
      }

   /*  Set to return undefined variable */
      var = IDL_Gettmp();

   /*  and close error context */
      emsRlse();
   }

/*  That's it, return to the calling routine */
   return var;
}
Beispiel #22
0
int32 OldFitIDLWrite(int argc,char *argv[]) {

  int n;
  struct RadarIDLParm *idlprm;
  struct FitIDLData *idlfit;
  struct RadarParm prm;
  struct FitData fit;

  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  if (unit !=-1) { /* a real file */
    /* Make sure that the "STDIO" keyword was used to
     * open the file in IDL.
     */

    s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
    if (s==FALSE) return -1;

    /* Get information about the file */

    IDL_FileStat(unit,&stat);
 
    /* Find the file pointer */

    fp=stat.fptr; 
  
    if (fp==NULL) return -1;

    fflush(fp);

  } else fp=NULL; /* dummy routine */

  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  idlfit=(struct FitIDLData *) argv[2];
  
  memset(&prm,0,sizeof(struct RadarParm));
  memset(&fit,0,sizeof(struct FitData));

  /* load up the data structures */

  prm.revision.major=idlprm->revision.major;
  prm.revision.minor=idlprm->revision.minor;
  prm.cp=idlprm->cp;
  prm.stid=idlprm->stid;
  prm.time.yr=idlprm->time.yr;
  prm.time.mo=idlprm->time.mo;
  prm.time.dy=idlprm->time.dy;
  prm.time.hr=idlprm->time.hr;
  prm.time.mt=idlprm->time.mt;
  prm.time.sc=idlprm->time.sc;
  prm.time.us=idlprm->time.us;
  prm.txpow=idlprm->txpow;
  prm.nave=idlprm->nave;
  prm.atten=idlprm->atten;
  prm.lagfr=idlprm->lagfr;
  prm.smsep=idlprm->smsep;
  prm.ercod=idlprm->ercod;
  prm.stat.agc=idlprm->stat.agc;
  prm.stat.lopwr=idlprm->stat.lopwr;
  prm.noise.search=idlprm->noise.search;
  prm.noise.mean=idlprm->noise.mean;
  prm.channel=idlprm->channel;
  prm.bmnum=idlprm->bmnum;
  prm.scan=idlprm->scan;
  prm.rxrise=idlprm->rxrise;
  prm.intt.sc=idlprm->intt.sc;
  prm.intt.us=idlprm->intt.us;
  prm.txpl=idlprm->txpl;
  prm.mpinc=idlprm->mpinc;
  prm.mppul=idlprm->mppul;
  prm.mplgs=idlprm->mplgs;
  prm.nrang=idlprm->nrang;
  prm.frang=idlprm->frang;
  prm.rsep=idlprm->rsep;
  prm.xcf=idlprm->xcf;
  prm.tfreq=idlprm->tfreq;
  prm.offset=idlprm->offset;
  prm.mxpwr=idlprm->mxpwr;
  prm.lvmax=idlprm->lvmax;

  for (n=0;n<prm.mppul;n++) prm.pulse[n]=idlprm->pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    prm.lag[n][0]=idlprm->lag[n];
    prm.lag[n][1]=idlprm->lag[LAG_SIZE+n];
  }

  if (strlen(IDL_STRING_STR(&idlprm->combf)) !=0) 
    strncpy(prm.combf,IDL_STRING_STR(&idlprm->combf),COMBF_SIZE);


  fit.revision.major=idlfit->revision.major;
  fit.revision.minor=idlfit->revision.minor;
  fit.noise.skynoise=idlfit->noise.sky;
  fit.noise.lag0=idlfit->noise.lag0;
  fit.noise.vel=idlfit->noise.vel;

  for (n=0;n<prm.nrang;n++) {
    fit.rng[n].p_0=idlfit->pwr0[n];
    fit.rng[n].nump=idlfit->nlag[n];
    fit.rng[n].qflg=idlfit->qflg[n];
    fit.rng[n].gsct=idlfit->gflg[n];
    fit.rng[n].p_l=idlfit->p_l[n];
    fit.rng[n].p_l_err=idlfit->p_l_e[n];
    fit.rng[n].p_s=idlfit->p_s[n];
    fit.rng[n].p_s_err=idlfit->p_s_e[n];
    fit.rng[n].v=idlfit->v[n];
    fit.rng[n].v_err=idlfit->v_e[n];
    fit.rng[n].w_l=idlfit->w_l[n];
    fit.rng[n].w_l_err=idlfit->w_l_e[n];
    fit.rng[n].w_s=idlfit->w_s[n];
    fit.rng[n].w_s_err=idlfit->w_s_e[n];
    fit.rng[n].sdev_l=idlfit->sd_l[n];
    fit.rng[n].sdev_s=idlfit->sd_s[n];
    fit.rng[n].sdev_phi=idlfit->sd_phi[n];
    if (prm.xcf !=0) {
      fit.elv[n].low=idlfit->elv_low[n];
      fit.elv[n].normal=idlfit->elv[n];
      fit.elv[n].high=idlfit->elv_high[n];
      fit.xrng[n].qflg=idlfit->x_qflg[n];
      fit.xrng[n].gsct=idlfit->x_gflg[n];
      fit.xrng[n].p_l=idlfit->x_p_l[n];
      fit.xrng[n].p_l_err=idlfit->x_p_l_e[n];
      fit.xrng[n].p_s=idlfit->x_p_s[n];
      fit.xrng[n].p_s_err=idlfit->x_p_s_e[n];
      fit.xrng[n].v=idlfit->x_v[n];
      fit.xrng[n].v_err=idlfit->x_v_e[n];
      fit.xrng[n].w_l=idlfit->x_w_l[n];
      fit.xrng[n].w_l_err=idlfit->x_w_l_e[n];
      fit.xrng[n].w_s=idlfit->x_w_s[n];
      fit.xrng[n].w_s_err=idlfit->x_w_s_e[n];
      fit.xrng[n].sdev_l=idlfit->x_sd_l[n];
      fit.xrng[n].sdev_s=idlfit->x_sd_s[n];
      fit.xrng[n].sdev_phi=idlfit->x_sd_phi[n];
      fit.xrng[n].phi0=idlfit->phi0[n];
      fit.xrng[n].phi0_err=idlfit->phi0_e[n];
    }
  }
  
  s=OldFitFwrite(fp,&prm,&fit,NULL);
  
  return s;

}