Ejemplo n.º 1
0
/*
  nbytes = MG_NET_SENDTO(socket, variable, host, port)

  Sends the raw byte data from the IDL variable on the socket. Returns the
  number of bytes sent or -1 for error. Note: no byteswapping is performed.
*/
static IDL_VPTR IDL_CDECL mg_net_sendto(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i, iNum, iRet;
  struct sockaddr_in sin;
  IDL_VPTR vpTmp;
  char *pbuffer;
  short	port;
  int host, addr_len;

  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];
  port = (short) IDL_LongScalar(argv[3]);
  host = IDL_ULongScalar(argv[2]);

  if (vpTmp->type == IDL_TYP_STRING) {
    vpTmp  = IDL_CvtByte(1, &vpTmp);
  }

  IDL_VarGetData(vpTmp, &iNum, &pbuffer, 1);
  iNum = iNum * IDL_TypeSizeFunc(vpTmp->type);

  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, pbuffer, iNum, 0, (struct sockaddr *) &sin, addr_len);

  if (vpTmp != argv[1]) IDL_Deltmp(vpTmp);

  return(IDL_GettmpLong(iRet));
}
Ejemplo n.º 2
0
/*
  nbytes = MG_NET_SEND(socket, variable [, host] [, port])

  Sends the raw byte data from the IDL variable on the socket. Returns the
  number of bytes sent or -1 for error. Note: no byteswapping is performed.

	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.
*/
static IDL_VPTR IDL_CDECL mg_net_send(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i, iNum, iRet;
  IDL_VPTR vpTmp;
  char *pbuffer;

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

  if (vpTmp->type == IDL_TYP_STRING) {
    vpTmp  = IDL_CvtByte(1, &vpTmp);
  }

  IDL_VarGetData(vpTmp, &iNum, &pbuffer, 1);
  iNum = iNum * IDL_TypeSizeFunc(vpTmp->type);

  iRet = send(net_list[i].socket, pbuffer, iNum, 0);

  if (vpTmp != argv[1]) IDL_Deltmp(vpTmp);

  return(IDL_GettmpLong(iRet));
}
Ejemplo n.º 3
0
//
// idlpgr_GetCameraFromIndex
//
IDL_VPTR IDL_CDECL idlpgr_GetCameraFromIndex(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  int camera;
  fc2PGRGuid guid;
  IDL_VPTR idl_guid;
  IDL_ULONG *pd;
  IDL_MEMINT dim = 4;
  int i;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  camera = (argc == 2) ? (int) IDL_LongScalar(argv[1]) : 0;

  error = fc2GetCameraFromIndex(context, camera, &guid);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not acquire specified camera",
			 error);

  // transfer camera guid to IDL as a vector of ULONG values
  pd = (IDL_ULONG *) 
    IDL_MakeTempVector(IDL_TYP_ULONG, dim, IDL_ARR_INI_NOP, &idl_guid);
  for (i = 0; i < 4; i++)
    pd[i] = guid.value[i];
  
  return idl_guid;
}
Ejemplo n.º 4
0
static IDL_VPTR IDL_CDECL IDL_mg_nc_inq_format(int argc, IDL_VPTR *argv) {
  IDL_VPTR ncid_vptr = argv[0];
  int status, ncid, formatp;
  ncid = IDL_LongScalar(ncid_vptr);
  status = nc_inq_format(ncid, &formatp);
  return IDL_GettmpLong(formatp);
}
Ejemplo n.º 5
0
/*
  socket = MG_NET_CREATEPORT(portnum [, /TCP] [, /UDP])

  Creates a socket listening on the specified port for a new connection. Set
  the TCP keyword to create a TCP/IP port, or set the UDP keyword to create a
  UDP/IP port. By default a TCP port is created.

  For TCP sockets, MG_NET_SELECT returns true for this socket if there is an
  attempt to connect to it (which should be serviced by MG_NET_ACCEPT).

  For UDP sockets, you can both send and receive from this socket.
*/
static IDL_VPTR IDL_CDECL mg_net_createport(int argc, IDL_VPTR argv[], char *argk) {
  SOCKET s;
  struct sockaddr_in sin;
  short	port;
  int err;
  IDL_LONG i;
  
  static IDL_LONG	iUDP,iTCP;
  static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN,
				  { "TCP", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iTCP) },
				  { "UDP", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iUDP) },
				  { NULL }
  };

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc, argv, argk, kw_pars, argv, 1);
  port = (short) IDL_LongScalar(argv[0]);
  IDL_KWCleanup(IDL_KW_CLEAN);

  for(i = 0; i < MAX_SOCKETS; i++) {
    if (net_list[i].iState == NET_UNUSED) break;
  }
  if (i == MAX_SOCKETS) return (IDL_GettmpLong(-2));

  if (iUDP) {
    s = socket(AF_INET, SOCK_DGRAM, 0);
    net_list[i].iType = NET_UDP;
  } else {
    s = socket(AF_INET, SOCK_STREAM, 0);
    net_list[i].iType = NET_TCP;
  }
  if (s == -1) return (IDL_GettmpLong(-1));

  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl(INADDR_ANY);
  sin.sin_port = htons(port);
  err = bind(s,(struct sockaddr *) &sin, sizeof(sin));
  if (err == -1) {
    CLOSE(s);
    return(IDL_GettmpLong(-1));
  }
  if (!iUDP) {
    err = listen(s, 5);
    if (err == -1) {
      CLOSE(s);
      return (IDL_GettmpLong(-1));
    }
    net_list[i].iState = NET_LISTEN;
  } else {
    net_list[i].iState = NET_IO;
  }

  net_list[i].socket = s;

  return(IDL_GettmpLong(i));
}
Ejemplo n.º 6
0
/*
  err = MG_NET_RECVVAR(socket, variable)

  Reads an IDL variable from the socket in the form written by MG_NET_SENDVAR.
  The complete variable is reconstructed. See MG_NET_SENDVAR for more details.
 */
static IDL_VPTR IDL_CDECL mg_net_recvvar(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i, iRet;
  IDL_LONG swab = 0;
  i_var var;
  IDL_VPTR vpTmp;
  char *pbuffer;

  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_EXCLUDE_EXPR(argv[1]);

  /* read the header */
  iRet = recv_packet(net_list[i].socket, &var,sizeof(i_var));
  if (iRet == -1) return (IDL_GettmpLong(-1));
  if (var.token == SWAPTOKEN) {
    mg_byteswap(&var, sizeof(i_var), sizeof(IDL_LONG));
    swab = 1;
  }
  if (var.token != TOKEN) return (IDL_GettmpLong(-1));

  /* allocate the variable */
  if (var.type == IDL_TYP_STRING) {
    vpTmp = IDL_StrToSTRING("");
    IDL_StrEnsureLength(&(vpTmp->value.str), var.len);
    vpTmp->value.str.slen = var.len - 1;
    pbuffer = vpTmp->value.str.s;
    memset(pbuffer, 0x20, var.len-1);
    pbuffer[var.len] = '\0';
    IDL_VarCopy(vpTmp, argv[1]);
  } else if (var.ndims != 0) {
    pbuffer = IDL_MakeTempArray(var.type, var.ndims, var.dims, IDL_BARR_INI_NOP, &vpTmp);
    IDL_VarCopy(vpTmp, argv[1]);
  } else {
    vpTmp = IDL_GettmpLong(0);
    IDL_VarCopy(vpTmp, argv[1]);
    IDL_StoreScalarZero(argv[1], var.type);
    pbuffer = &(argv[1]->value.c);
  }

  /* read the data */
  iRet = recv_packet(net_list[i].socket, pbuffer, var.len);
  if (iRet == -1) return (IDL_GettmpLong(-1));
  if (swab) {
    int	swapsize = var.len / var.nelts;
    if ((var.type == IDL_TYP_COMPLEX)
	|| (var.type == IDL_TYP_DCOMPLEX)) {
      swapsize /= 2;
    }
    mg_byteswap(pbuffer, var.len, swapsize);
  }

  return (IDL_GettmpLong(1));
}
Ejemplo n.º 7
0
void pvcam_set_gain(int argc, IDL_VPTR argv[], char *argk)
{
    /* Parameter Variables */
    int16 hcam;                         /* A pointer to the camera's handle. */
    int16 gain;
    char error = 0;

    /* Point parameter variables to the actual IDL values. */
    hcam = (int16)IDL_LongScalar(argv[0]);
    gain = (int16)IDL_LongScalar(argv[1]);
    error = !ccd_set_gain(hcam, gain);

    /* Handling the error keyword */
    KW_RESULT kw;
    argc = IDL_KWProcessByOffset(argc,argv,argk,kw_pars,(IDL_VPTR *)0,1,&kw);
    if (kw.iError) {
        IDL_StoreScalar(kw.iError, IDL_TYP_BYTE, (IDL_ALLTYPES*) &error);
    }
    IDL_KW_FREE;
}
Ejemplo n.º 8
0
/*
  err = MG_NET_CLOSE(socket)

  Close and free the socket in question.
*/
static IDL_VPTR IDL_CDECL mg_net_close(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i;

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

  shutdown(net_list[i].socket,2);
  CLOSE(net_list[i].socket);

  net_list[i].iState = NET_UNUSED;

  return (IDL_GettmpLong(0));
}
Ejemplo n.º 9
0
static IDL_VPTR IDLOldRawWriteHeader(int argc,IDL_VPTR *argv) {
  int s=0;
  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct RadarIDLParm *iprm=NULL;
  struct RawIDLData *iraw=NULL;
  FILE *fp;

  char vstring[256];

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_STRUCTURE(argv[2]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);

  /* Find the file pointer */

  fp=stat.fptr;

  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct RadarIDLParm *) argv[1]->value.s.arr->data;
  iraw=(struct RawIDLData *) argv[2]->value.s.arr->data;

  sprintf(vstring,"%d.%.3d",(int) iraw->revision.major,
	                    (int) iraw->revision.minor);
  s=OldRawHeaderFwrite(fp,"rawwrite",vstring,iraw->thr,"IDL output");

  return (IDL_GettmpLong(s));
}
Ejemplo n.º 10
0
static IDL_VPTR IDLOldCnvMapOpen(int argc,IDL_VPTR *argv,char *argk) {
  
  IDL_VARIABLE unit;
  IDL_VPTR fargv[2]; 

  
  IDL_VPTR outargv[1];
  static IDL_LONG iread;
  static IDL_LONG iwrite;
  static IDL_LONG iupdate;
  int access=0;

  static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN,
			       {"READ",IDL_TYP_LONG,1,
                                IDL_KW_ZERO,0,
                                IDL_CHARA(iread)},
			       {"WRITE",IDL_TYP_LONG,1,
                                IDL_KW_ZERO,0,
                                IDL_CHARA(iwrite)},
         	               {"UPDATE",IDL_TYP_LONG,1,
                                IDL_KW_ZERO,0,
                                IDL_CHARA(iwrite)},
				 {NULL}};

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1);

  IDL_ENSURE_STRING(outargv[0]);

  unit.type=IDL_TYP_LONG;
  unit.flags=0;

  fargv[0]=&unit;
  fargv[1]=outargv[0];
  
  IDL_FileGetUnit(1,fargv);  

  if (iread !=0) access=access | IDL_OPEN_R;
  if (iwrite !=0) access=access | IDL_OPEN_W;
  if (iupdate !=0) access=access | IDL_OPEN_APND;

  if (access==0) access=IDL_OPEN_R;

  IDL_FileOpen(2,fargv,NULL,access,IDL_F_STDIO,1,0);

  IDL_KWCleanup(IDL_KW_CLEAN);
  
  return IDL_GettmpLong(IDL_LongScalar(&unit));
}
Ejemplo n.º 11
0
//
// idlpgr_GetPropertyInfo
//
// Get information about property
//
// Reference: FlyCapture2Defs_C.h
//
IDL_VPTR IDL_CDECL idlpgr_GetPropertyInfo(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2PropertyInfo info;
  static IDL_MEMINT one = 1;
  static IDL_MEMINT r[] = {1, 8};
  static IDL_MEMINT s[] = {1, MAX_STRING_LENGTH};
  IDL_VPTR idl_info;
  IDL_StructDefPtr sdef;
  char *pd;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  info.type = (fc2PropertyType) IDL_LongScalar(argv[1]);

  error = fc2GetPropertyInfo(context, &info);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not get requested property information",
			 error);

  static IDL_STRUCT_TAG_DEF tags[] = {
    { "TYPE",             0, (void *) IDL_TYP_LONG },
    { "PRESENT",          0, (void *) IDL_TYP_LONG },
    { "AUTOSUPPORTED",    0, (void *) IDL_TYP_LONG },
    { "MANUALSUPPORTED",  0, (void *) IDL_TYP_LONG },
    { "ONOFFSUPPORTED",   0, (void *) IDL_TYP_LONG },
    { "ONEPUSHSUPPORTED", 0, (void *) IDL_TYP_LONG },
    { "ABSVALSUPPORTED",  0, (void *) IDL_TYP_LONG },
    { "READOUTSUPPORTED", 0, (void *) IDL_TYP_LONG },
    { "MIN",              0, (void *) IDL_TYP_ULONG },
    { "MAX",              0, (void *) IDL_TYP_ULONG },
    { "ABSMIN",           0, (void *) IDL_TYP_FLOAT },
    { "ABSMAX",           0, (void *) IDL_TYP_FLOAT },
    { "PUNITS",           s, (void *) IDL_TYP_BYTE },
    { "PUNITABBR",        s, (void *) IDL_TYP_BYTE },
    { "RESERVED",         r, (void *) IDL_TYP_ULONG },
    { 0 }
  };

  sdef = IDL_MakeStruct("fc2PropertyInfo", tags);
  pd = IDL_MakeTempStruct(sdef, 1, &one, &idl_info, TRUE);
  memcpy(pd, (char *) &info, sizeof(fc2PropertyInfo));

  return idl_info;
}
Ejemplo n.º 12
0
//
// idlpgr_GetProperty
//
// Read property values from camera
//
// Reference: FlyCapture2Defs_C.h
//
IDL_VPTR IDL_CDECL idlpgr_GetProperty(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2Property property;
  static IDL_MEMINT r[] = {1, 8};
  static IDL_MEMINT one = 1;
  IDL_VPTR idl_property;
  IDL_StructDefPtr sdef;
  char *pd;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  property.type = (fc2PropertyType) IDL_LongScalar(argv[1]);

  error = fc2GetProperty(context, &property);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not get requested property",
			 error);
  
  static IDL_STRUCT_TAG_DEF tags[] = {
    { "TYPE",           0, (void *) IDL_TYP_LONG },
    { "PRESENT",        0, (void *) IDL_TYP_LONG },
    { "ABSCONTROL",     0, (void *) IDL_TYP_LONG },
    { "ONEPUSH",        0, (void *) IDL_TYP_LONG },
    { "ONOFF",          0, (void *) IDL_TYP_LONG },
    { "AUTOMANUALMODE", 0, (void *) IDL_TYP_LONG },
    { "VALUEA",         0, (void *) IDL_TYP_ULONG },
    { "VALUEB",         0, (void *) IDL_TYP_ULONG },
    { "ABSVALUE",       0, (void *) IDL_TYP_FLOAT },
    { "RESERVED",       r, (void *) IDL_TYP_ULONG },
    { 0 }
  };
  sdef = IDL_MakeStruct("fc2Property", tags);
  pd = IDL_MakeTempStruct(sdef, 1, &one, &idl_property, TRUE);
  memcpy(pd, (char *) &property, sizeof(fc2Property));

  return idl_property;
}
Ejemplo n.º 13
0
/*
  socket = MG_NET_ACCEPT(socket [, BUFFER=size] [, /NODELAY])

  Accepts a requested TCP/IP connection and returns a socket on which I/O can
  be performed. The BUFFER keyword can be used to set the socket buffer size.
  For high-performance TCP/IP networks (e.g. gigE), higher bandwidth can be
  achived by setting the buffer size to several megabytes. Setting the NODELAY
  keyword disables the Nagle algorithm for the socket (appropriate for
  applications with large numbers of small packets).

	Only valid for TCP based sockets.  Will return -1 if called for a UDP
	socket.
*/
static IDL_VPTR IDL_CDECL mg_net_accept(int argc, IDL_VPTR inargv[], char *argk) {
  IDL_LONG i, j;
  struct sockaddr_in peer_addr;
  int	addr_len;
  SOCKET s;
  IDL_VPTR argv[1];

  static IDL_LONG	iBuffer, iNoDelay;
  static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN,
				  { "BUFFER", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iBuffer) },
				  { "NODELAY", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iNoDelay) },
				  { NULL }
  };

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc, inargv, argk, kw_pars, argv, 1);
  j = IDL_LongScalar(argv[0]);
  IDL_KWCleanup(IDL_KW_CLEAN);
  
  if ((j < 0) || (j >= MAX_SOCKETS)) return (IDL_GettmpLong(-1));
  if (net_list[j].iState != NET_LISTEN) return (IDL_GettmpLong(-1));
  
  for(i = 0; i < MAX_SOCKETS; i++) {
    if (net_list[i].iState == NET_UNUSED) break;
  }
  if (i == MAX_SOCKETS) return(IDL_GettmpLong(-2));

  addr_len = sizeof(struct sockaddr_in);
  s = accept(net_list[j].socket, (struct sockaddr *)&peer_addr, &addr_len);
  if (s == -1) return (IDL_GettmpLong(-1));

  if (iBuffer) rebuffer_socket(s, iBuffer);
  if (iNoDelay) nodelay_socket(s, 1);
  net_list[i].iState = NET_IO;
  net_list[i].socket = s;

  return(IDL_GettmpLong(i));
}
Ejemplo n.º 14
0
/*
  nbytes = MG_NET_RECV(socket, variable [, MAXIMUM_BYTES=b])

  Reads the raw data available on the socket and returns a BYTE array in
  variable. The maximum number of bytes to read can be specified by the
  MAXIMUM_BYTES keyword. The default is to read all the data available on the
  socket. Note: no byteswapping is performed.
*/
static IDL_VPTR IDL_CDECL mg_net_recv(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i, iRet, err;
  int len;
  IDL_VPTR vpPlainArgs[2], vpTmp;
  char *pbuffer;

  static IDL_LONG	iMax;
  static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN,
				  { "MAXIMUM_BYTES", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iMax) },
				  { NULL }
  };

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc, argv, argk, kw_pars, vpPlainArgs, 1);

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

  err = IOCTL(net_list[i].socket, FIONREAD, &len);
  if (err != 0) {
    iRet = -1;
    goto err;
  }
  if (iMax) len = IDL_MIN(iMax, len);

  pbuffer = (char *) IDL_MakeTempVector(IDL_TYP_BYTE, len, IDL_ARR_INI_NOP, &vpTmp);
  IDL_VarCopy(vpTmp, vpPlainArgs[1]);

  iRet = recv(net_list[i].socket, pbuffer, len, 0);

 err:
  IDL_KWCleanup(IDL_KW_CLEAN);

  return(IDL_GettmpLong(iRet));
}
Ejemplo n.º 15
0
static IDL_VPTR IDLOldCnvMapSeek(int argc,IDL_VPTR *argv,char *argk) {

  struct OldCnvMapIDLInx *ifptr;

  int s=0,n;
  struct RfileIndex *finx=NULL;
  static IDL_VPTR vatme;
  double atme=0;

  int outargc=0;
  IDL_VPTR outargv[8];
  static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN,
			       {"ATME",IDL_TYP_UNDEF,1,
                                IDL_KW_OUT | IDL_KW_ZERO,0,
                                IDL_CHARA(vatme)},
				 {NULL}};


  IDL_LONG unit=0,yr=0,mo=0,dy=0,hr=0,mt=0,sc=0;
  IDL_FILE_STAT stat;

  FILE *fp=NULL;

  IDL_KWCleanup(IDL_KW_MARK);
  outargc=IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1);


  IDL_ENSURE_SCALAR(outargv[0]);
  IDL_ENSURE_SCALAR(outargv[1]);
  IDL_ENSURE_SCALAR(outargv[2]);
  IDL_ENSURE_SCALAR(outargv[3]);
  IDL_ENSURE_SCALAR(outargv[4]);
  IDL_ENSURE_SCALAR(outargv[5]);
  IDL_ENSURE_SCALAR(outargv[6]);

  if (outargc>7) IDL_ENSURE_ARRAY(outargv[7]);

  unit=IDL_LongScalar(outargv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  yr=IDL_LongScalar(outargv[1]);
  mo=IDL_LongScalar(outargv[2]);
  dy=IDL_LongScalar(outargv[3]);
  hr=IDL_LongScalar(outargv[4]);
  mt=IDL_LongScalar(outargv[5]);
  sc=IDL_LongScalar(outargv[6]);

  /* test for existence of index */

  if (outargc>7) {
    /* decode index here */
    finx=malloc(sizeof(struct RfileIndex));
    if (finx==NULL) {
      s=-1;
      return (IDL_GettmpLong(s));
    }
    finx->num=outargv[7]->value.s.arr->n_elts;
    finx->time.start=malloc(sizeof(double)*finx->num);
    if (finx->time.start==NULL) {
      s=-1;
      free(finx);
      return (IDL_GettmpLong(s));
    } 
    finx->time.end=malloc(sizeof(double)*finx->num);
    if (finx->time.end==NULL) {
      s=-1;
      free(finx->time.start);
      free(finx);
      return (IDL_GettmpLong(s));
    } 

    finx->offset=malloc(sizeof(int)*finx->num);
    if (finx->offset==NULL) {
      s=-1;
      free(finx->time.start);
      free(finx->time.end);
      free(finx);
      return (IDL_GettmpLong(s));
    } 
    for (n=0;n<finx->num;n++) {
      ifptr=(struct OldCnvMapIDLInx *) (outargv[7]->value.s.arr->data+
                                    n*outargv[7]->value.s.arr->elt_len);
      finx->time.start[n]=ifptr->st_time;
      finx->time.end[n]=ifptr->ed_time;
      finx->offset[n]=ifptr->offset;
    }
    finx->st_time=finx->time.start[0];
    finx->ed_time=finx->time.end[finx->num-1];

  }


  s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,sc,finx,&atme);

  if (vatme) IDL_StoreScalar(vatme,IDL_TYP_DOUBLE,(IDL_ALLTYPES *) &atme);
 
  if (finx !=NULL) {
    free(finx->time.start);
    free(finx->time.end);
    free(finx->offset);
    free(finx);
  }
   
  IDL_KWCleanup(IDL_KW_CLEAN);
  return (IDL_GettmpLong(s));


}
Ejemplo n.º 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));
}
Ejemplo n.º 17
0
/*
  err = MG_NET_QUERY(socket [, AVAILABLE_BYTES=a] [, IS_LISTENER=l]
                     [, LOCAL_HOST=lh] [, LOCAL_PORT=lp]
                     [, REMOTE_HOST=rh] [, REMOTE_PORT=rp])

  Returns various information about the socket in question.

  AVAILABLE_BYTES: number of bytes available for reading.
  REMOTE_HOST: host number of the remote host the socket is connected to.
  IS_LISTENER: true if the socket was created using MG_NET_CREATEPORT()
*/
static IDL_VPTR IDL_CDECL mg_net_query(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i;
  IDL_VPTR vpPlainArgs[1],vpTmp;
  struct sockaddr_in peer_addr;
  int addr_len, err;
  IDL_LONG iRet = 0;

  static IDL_VPTR	vpRHost, vpAvail, vpListen, vpLPort, vpRPort, vpLHost;
  static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN,
				  { "AVAILABLE_BYTES", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpAvail) },
				  { "IS_LISTENER", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpListen) },
				  { "LOCAL_HOST", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpLHost) },
				  { "LOCAL_PORT", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpLPort) },
				  { "REMOTE_HOST", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpRHost) },
				  { "REMOTE_PORT", IDL_TYP_UNDEF, 1, IDL_KW_OUT | IDL_KW_ZERO, 0, IDL_CHARA(vpRPort) },
				  { NULL}
  };

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc, argv, argk, kw_pars, vpPlainArgs, 1);

  i = IDL_LongScalar(vpPlainArgs[0]);
  if ((i < 0) || (i >= MAX_SOCKETS)) {
    IDL_KWCleanup(IDL_KW_CLEAN);
    return(IDL_GettmpLong(-1));
  }

  if (vpRHost || vpRPort) {
    addr_len = sizeof(struct sockaddr_in);
    err = getpeername(net_list[i].socket,
		      (struct sockaddr *) &peer_addr, &addr_len);
    if (err != 0) {
      iRet = -1;
    } else {
      if (vpRHost) {
	vpTmp = IDL_GettmpULong(peer_addr.sin_addr.s_addr);
	IDL_VarCopy(vpTmp, vpRHost);
      }
      if (vpRPort) {
	vpTmp = IDL_GettmpLong((long) ntohs(peer_addr.sin_port));
	IDL_VarCopy(vpTmp, vpRPort);
      }
    }
  }
  if (vpAvail) {
    int len;
    err = IOCTL(net_list[i].socket, FIONREAD, &len);
    if (err != 0) {
      iRet = -1;
    } else {
      vpTmp = IDL_GettmpULong(len);
      IDL_VarCopy(vpTmp, vpAvail);
    }
  }
  if (vpListen) {
    vpTmp = IDL_GettmpLong(net_list[i].iState == NET_LISTEN);
    IDL_VarCopy(vpTmp, vpListen);
  }
  if (vpLPort || vpLHost) {
    addr_len = sizeof(struct  sockaddr_in);
    err = getsockname(net_list[i].socket,
		      (struct sockaddr *) &peer_addr, &addr_len);
    if (err != 0) {
      iRet = -1;
    } else {
      if (vpLHost) {
        vpTmp = IDL_GettmpULong(peer_addr.sin_addr.s_addr);
        IDL_VarCopy(vpTmp, vpLHost);
      }
      if (vpLPort) {
        vpTmp = IDL_GettmpLong((long) ntohs(peer_addr.sin_port));
        IDL_VarCopy(vpTmp, vpLPort);
      }
    }
  }

  IDL_KWCleanup(IDL_KW_CLEAN);

  return(IDL_GettmpLong(iRet));
}
Ejemplo n.º 18
0
static IDL_VPTR IDLOldGridRead(int argc,IDL_VPTR *argv) {

  int s=0;


  IDL_VPTR vprm=NULL,vstvec=NULL,vgvec=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;


  struct GridData *grd=NULL;
  struct GridIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL; 

  FILE *fp=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);


  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);
   
  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 

  grd=GridMake(); 

  s=OldGridFread(fp,grd);

  if (s==-1) {
    GridFree(grd);
    return (IDL_GettmpLong(s));
  }

  iprm=IDLMakeGridPrm(&vprm);
  if (grd->stnum !=0) istvec=IDLMakeGridStVec(grd->stnum,&vstvec);
  if (grd->vcnum !=0) igvec=IDLMakeGridGVec(grd->vcnum,&vgvec);

  /* copy the data here */
   
  IDLCopyGridPrmToIDL(grd,iprm);
  if (istvec !=NULL) IDLCopyGridStVecToIDL(grd,grd->stnum,
                                    vstvec->value.s.arr->elt_len,istvec);
  if (igvec !=NULL) IDLCopyGridGVecToIDL(grd,grd->vcnum,
                                    vgvec->value.s.arr->elt_len,igvec);


  
  GridFree(grd);

  IDL_VarCopy(vprm,argv[1]);  
  if (vstvec !=NULL) IDL_VarCopy(vstvec,argv[2]);
  if (vgvec !=NULL) IDL_VarCopy(vgvec,argv[3]);

  return (IDL_GettmpLong(s));

}
Ejemplo n.º 19
0
static IDL_VPTR IDLOldGridWrite(int argc,IDL_VPTR *argv) {

  int s=0;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct GridData *grd=NULL;
  struct GridIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
 
  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_ARRAY(argv[2]);
  IDL_ENSURE_ARRAY(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct GridIDLPrm *) argv[1]->value.s.arr->data;
  if (argv[2]->type==IDL_TYP_STRUCT) 
     istvec=(struct GridIDLStVec *) argv[2]->value.s.arr->data;
  if (argv[3]->type==IDL_TYP_STRUCT) 
     igvec=(struct GridIDLGVec *) argv[3]->value.s.arr->data;


  grd=GridMake(); 

  IDLCopyGridPrmFromIDL(iprm,grd);
  if (istvec !=NULL)  IDLCopyGridStVecFromIDL(istvec,iprm->stnum,
                        argv[2]->value.s.arr->elt_len,grd);
  else grd->stnum=0;

  if (igvec !=NULL) IDLCopyGridGVecFromIDL(igvec,iprm->vcnum,
       argv[3]->value.s.arr->elt_len,grd);
  else grd->vcnum=0;

  s=OldGridFwrite(fp,grd);

  GridFree(grd);

  return (IDL_GettmpLong(s));


}
Ejemplo n.º 20
0
static IDL_VPTR IDLOldRawSeek(int argc,IDL_VPTR *argv,char *argk) {

  IDL_FILE_STAT stat;
  struct OldRawIDLFp *irawfp;
  struct OldRawFp rawfp;
  int s=0;
  static IDL_VPTR vatme;
  double atme=0;

  IDL_VPTR outargv[8];
  static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN,
			       {"ATME",IDL_TYP_UNDEF,1,
                                IDL_KW_OUT | IDL_KW_ZERO,0,
                                IDL_CHARA(vatme)},
				 {NULL}};


  IDL_LONG yr=0,mo=0,dy=0,hr=0,mt=0,sc=0;
  FILE *ffp=NULL,*ifp=NULL;

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1);

  IDL_ENSURE_STRUCTURE(outargv[0]);
  IDL_ENSURE_SCALAR(outargv[1]);
  IDL_ENSURE_SCALAR(outargv[2]);
  IDL_ENSURE_SCALAR(outargv[3]);
  IDL_ENSURE_SCALAR(outargv[4]);
  IDL_ENSURE_SCALAR(outargv[5]);
  IDL_ENSURE_SCALAR(outargv[6]);

  yr=IDL_LongScalar(outargv[1]);
  mo=IDL_LongScalar(outargv[2]);
  dy=IDL_LongScalar(outargv[3]);
  hr=IDL_LongScalar(outargv[4]);
  mt=IDL_LongScalar(outargv[5]);
  sc=IDL_LongScalar(outargv[6]);

  irawfp=(struct OldRawIDLFp *) outargv[0]->value.s.arr->data;
  
  s=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  IDL_FileFlushUnit(irawfp->rawunit);
  IDL_FileStat(irawfp->rawunit,&stat);
 

  ffp=stat.fptr;
  
  if (ffp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 
  if (irawfp->inxunit !=-1) {
    IDL_FileFlushUnit(irawfp->inxunit);
    IDL_FileStat(irawfp->inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  rawfp.rawfp=fileno(ffp);
  if (ifp !=NULL) rawfp.inxfp=fileno(ifp);
  else rawfp.inxfp=-1;

  OldRawIDLToRawFp(irawfp,&rawfp);

  s=OldRawSeek(&rawfp,yr,mo,dy,hr,mt,sc,&atme);

  OldRawRawFpToIDL(&rawfp,irawfp);


  if (vatme) IDL_StoreScalar(vatme,IDL_TYP_DOUBLE,(IDL_ALLTYPES *) &atme);
 
  IDL_KWCleanup(IDL_KW_CLEAN);
  return (IDL_GettmpLong(s));
}
Ejemplo n.º 21
0
/*
  socket = MG_NET_CONNECT(host, port [, BUFFER=size] [, LOCAL_PORT=lp]
                          [, /NODELAY] [, /TCP] [, /UDP])

  Connect to a TCP socket listener on some specified host and port. The
  returned socket can be used for I/O after the server "accepts" the
  connection.

	The BUFFER keyword can be used to set the socket buffer size. For
	high-performance TCP/IP networks (e.g. gigE), higher bandwidth can be
	achieved by setting the buffer size to several megabytes. Setting the
	NODELAY keyword disables the Nagle algorithm for the socket (appropriate for
	applications with large numbers of small packets).

  Set the UDP keyword to create a UDP port with the peer address set to the
  provided host and port value. Data can then be sent using the MG_NET_SEND
  function which is somehwhat more efficient than the MG_NET_SENDTO function.
  This is useful if you will be sending data to primarily one host/port.

  MG_NET_CONNECT only creates TCP based sockets.
*/
static IDL_VPTR IDL_CDECL mg_net_connect(int argc, IDL_VPTR inargv[], char *argk) {
  SOCKET s;
  struct sockaddr_in sin;
  int	addr_len,err;
  short	port;
  int	host;
  IDL_LONG i;
  IDL_VPTR argv[2];

  static IDL_LONG	iBuffer,iNoDelay,iUDP,iTCP, iLocPort;
  static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN,
				  { "BUFFER", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iBuffer) },
				  { "LOCAL_PORT", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iLocPort) },
				  { "NODELAY", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iNoDelay) },
				  { "TCP", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iTCP) },
				  { "UDP", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, IDL_CHARA(iUDP) },
				  { NULL }
  };

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc,inargv,argk,kw_pars,argv,1);
  host = IDL_ULongScalar(argv[0]);
  port = (short) IDL_LongScalar(argv[1]);
  IDL_KWCleanup(IDL_KW_CLEAN);

  for (i = 0; i < MAX_SOCKETS; i++) {
    if (net_list[i].iState == NET_UNUSED) break;
  }
  if (i == MAX_SOCKETS) return (IDL_GettmpLong(-2));

  if (iUDP) {
    s = socket(AF_INET,SOCK_DGRAM, 0);
    net_list[i].iType = NET_UDP_PEER;
  } else {
    s = socket(AF_INET, SOCK_STREAM, 0);
    if (iBuffer) rebuffer_socket(s, iBuffer);
    if (iNoDelay) nodelay_socket(s, 1);
    net_list[i].iType = NET_TCP;
  }
  if (s == -1) return (IDL_GettmpLong(-2));

  if (iLocPort) {
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = htonl(INADDR_ANY);
    sin.sin_port = htons((short)iLocPort);
    err=bind(s,(struct sockaddr *)&sin, sizeof(sin));
    if (err == -1) {
      CLOSE(s);
      return(IDL_GettmpLong(-2));
    }
  }

  sin.sin_addr.s_addr = host;
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port);
  addr_len = sizeof(struct sockaddr_in);
  err = connect(s, (struct sockaddr *)&sin, addr_len);
  if (err == -1) {
    CLOSE(s);
    return (IDL_GettmpLong(-1));
  }

  net_list[i].iState = NET_IO;
  net_list[i].socket = s;

  return (IDL_GettmpLong(i));
}
Ejemplo n.º 22
0
static IDL_VPTR IDLOldRawWrite(int argc,IDL_VPTR *argv) {
  int s=0;
  IDL_LONG unit=0,recnum;
  IDL_FILE_STAT stat;

  struct RadarIDLParm *iprm=NULL;
  struct RawIDLData *iraw=NULL;

  struct RadarParm *prm=NULL;
  struct RawData *raw=NULL;

  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_STRUCTURE(argv[2]);
  IDL_ENSURE_SCALAR(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);

  unit=IDL_LongScalar(argv[0]);
  recnum=IDL_LongScalar(argv[3]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }


  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);

  /* Find the file pointer */

  fp=stat.fptr;

  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct RadarIDLParm *) argv[1]->value.s.arr->data;
  iraw=(struct RawIDLData *) argv[2]->value.s.arr->data;

  prm=RadarParmMake();
  raw=RawMake();

  IDLCopyRadarParmFromIDL(iprm,prm);
  IDLCopyRawDataFromIDL(prm->nrang,prm->mplgs,prm->xcf,iraw,raw);

  s=OldRawFwrite(fp,"rawwrite",prm,raw,recnum,NULL);

  RadarParmFree(prm);
  RawFree(raw);



  return (IDL_GettmpLong(s));
}
Ejemplo n.º 23
0
static IDL_VPTR IDLOldCnvMapWrite(int argc,IDL_VPTR *argv) {

  int s=0;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct CnvMapData *map=NULL;
  struct GridData *grd=NULL;

  struct CnvMapIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
  struct GridIDLGVec *imvec=NULL;
  struct CnvMapIDLBnd *ibnd=NULL;
  double *icoef=NULL; 

  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_ARRAY(argv[2]);
  IDL_ENSURE_ARRAY(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct CnvMapIDLPrm *) argv[1]->value.s.arr->data;
  if (argv[2]->type==IDL_TYP_STRUCT) 
     istvec=(struct GridIDLStVec *) argv[2]->value.s.arr->data;
  if (argv[3]->type==IDL_TYP_STRUCT) 
     igvec=(struct GridIDLGVec *) argv[3]->value.s.arr->data;
  if (argv[4]->type==IDL_TYP_STRUCT)
     imvec=(struct GridIDLGVec *) argv[4]->value.s.arr->data;
  if (argv[5]->type==IDL_TYP_DOUBLE) 
     icoef=(double *) argv[5]->value.s.arr->data;
  if (argv[6]->type==IDL_TYP_STRUCT) 
     ibnd=(struct CnvMapIDLBnd *) argv[6]->value.s.arr->data;

  map=CnvMapMake(); 
  grd=GridMake();

  IDLCopyCnvMapPrmFromIDL(iprm,map,grd);
  if (istvec !=NULL)  IDLCopyGridStVecFromIDL(istvec,iprm->stnum,
                        argv[2]->value.s.arr->elt_len,grd);
  else grd->stnum=0;

  if (igvec !=NULL) IDLCopyGridGVecFromIDL(igvec,iprm->vcnum,
       argv[3]->value.s.arr->elt_len,grd);
  else grd->vcnum=0;

  if (imvec !=NULL) IDLCopyCnvMapGVecFromIDL(imvec,
                        iprm->modnum,argv[4]->value.s.arr->elt_len,map);
  else map->num_model=0;

  if (ibnd !=NULL) IDLCopyCnvMapBndFromIDL(ibnd,
                        iprm->bndnum,argv[6]->value.s.arr->elt_len,map);
  else map->num_bnd=0;

  if (icoef !=NULL) {
    int n=0;
    map->coef=malloc(sizeof(double)*map->num_coef*4);
    for (n=0;n<map->num_coef;n++) {
      map->coef[4*n]=icoef[n];
      map->coef[4*n+1]= icoef[map->num_coef+n];
      map->coef[4*n+2]=icoef[2*map->num_coef+n];
      map->coef[4*n+3]=icoef[3*map->num_coef+n];
    }
  } else map->num_coef=0;


  s=OldCnvMapFwrite(fp,map,grd);

  CnvMapFree(map);
  GridFree(grd);

  return (IDL_GettmpLong(s));


}
Ejemplo n.º 24
0
static IDL_VPTR IDLOldRawOpen(int argc,IDL_VPTR *argv) {

  IDL_VPTR vrawfp;  
  struct OldRawIDLFp *irawfp;
  struct OldRawFp *rawfp;
  void *s;
  int st;

  static IDL_MEMINT hdim[]={1,80};
  static IDL_MEMINT ddim[]={1,32};
  static IDL_MEMINT edim[]={1,256};

  static IDL_STRUCT_TAG_DEF trawfp[]={
    {"RAWUNIT",0,(void *) IDL_TYP_LONG},
    {"INXUNIT",0,(void *) IDL_TYP_LONG},
    {"RAW_RECL",0,(void *) IDL_TYP_LONG},
    {"INX_RECL",0,(void *) IDL_TYP_LONG},
    {"BLEN",0,(void *) IDL_TYP_LONG},
    {"INX_SREC",0,(void *) IDL_TYP_LONG},
    {"INX_EREC",0,(void *) IDL_TYP_LONG},
    {"CTIME",0,(void *) IDL_TYP_DOUBLE},
    {"STIME",0,(void *) IDL_TYP_DOUBLE},
    {"ETIME",0,(void *) IDL_TYP_DOUBLE},
    {"TIME",0,(void *) IDL_TYP_LONG},
    {"HEADER",hdim,(void *) IDL_TYP_BYTE},
    {"DATE",ddim,(void *) IDL_TYP_BYTE},
    {"EXTRA",edim,(void *) IDL_TYP_BYTE},
    {"MAJOR_REV",0,(void *) IDL_TYP_BYTE},
    {"MINOR_REV",0,(void *) IDL_TYP_BYTE},
    {"RAWREAD",0,(void *) IDL_TYP_LONG},
    {"BNUM",0,(void *) IDL_TYP_LONG},
    0};

  static IDL_MEMINT ilDims[IDL_MAX_ARRAY_DIM];

  IDL_VARIABLE unit;
  IDL_VPTR fargv[2];
  IDL_FILE_STAT stat;


  int ffd=-1,ifd=-1;

  IDL_ENSURE_STRING(argv[0]);
  if (argc>1) IDL_ENSURE_STRING(argv[1]);
  
  s=IDL_MakeStruct("RAWFP",trawfp);
  ilDims[0]=1;
  irawfp=(struct OldRawIDLFp *) IDL_MakeTempStruct(s,1,ilDims,&vrawfp,TRUE);

  unit.type=IDL_TYP_LONG;
  unit.flags=0;

  fargv[0]=&unit;
  fargv[1]=argv[0];

  IDL_FileGetUnit(1,fargv);
  IDL_FileOpen(2,fargv,NULL,IDL_OPEN_R,IDL_F_STDIO,1,0);
  irawfp->rawunit=IDL_LongScalar(&unit);
  irawfp->inxunit=-1;

  st=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);

  if (st==FALSE) {
    st=0;
    IDL_Deltmp(vrawfp);
    return (IDL_GettmpLong(st));
  }
  
  if (argc>1) {
    fargv[1]=argv[1];
    IDL_FileGetUnit(1,fargv);
    IDL_FileOpen(2,fargv,NULL,IDL_OPEN_R,IDL_F_STDIO,1,0);
    irawfp->inxunit=IDL_LongScalar(&unit); 
    st=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);
    if (st==FALSE) { /* free unit for index but continue */
      IDL_FileFreeUnit(1,argv);
      irawfp->inxunit=-1;
    }
  }
 

  IDL_FileStat(irawfp->rawunit,&stat);
  ffd=fileno(stat.fptr);

  if (irawfp->inxunit !=-1) {
    IDL_FileStat(irawfp->inxunit,&stat);
    ifd=fileno(stat.fptr);
  }

  rawfp=OldRawOpenFd(ffd,ifd);
  OldRawRawFpToIDL(rawfp,irawfp);

  free(rawfp);
  
  return vrawfp;
}
Ejemplo n.º 25
0
static IDL_VPTR IDLOldCnvMapRead(int argc,IDL_VPTR *argv) {

  int s=0;


  IDL_VPTR vprm=NULL,vstvec=NULL,vgvec=NULL,vmvec=NULL,vcoef=NULL,vbnd=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;


  struct CnvMapData *map=NULL;
  struct GridData *grd=NULL;

  struct CnvMapIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
  struct GridIDLGVec *imvec=NULL;
  struct CnvMapIDLBnd *ibnd=NULL;
  double *icoef=NULL; 

  IDL_MEMINT cdim[2];

  FILE *fp=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[4]);
  IDL_EXCLUDE_EXPR(argv[5]);
  IDL_EXCLUDE_EXPR(argv[6]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 

  map=CnvMapMake(); 
  grd=GridMake();

  s=OldCnvMapFread(fp,map,grd);

  if (s==-1) {
    CnvMapFree(map);
    GridFree(grd);
    return (IDL_GettmpLong(s));
  }

  iprm=IDLMakeCnvMapPrm(&vprm);
  if (grd->stnum !=0) istvec=IDLMakeGridStVec(grd->stnum,&vstvec);
  if (grd->vcnum !=0) igvec=IDLMakeGridGVec(grd->vcnum,&vgvec);
  if (map->num_model !=0) imvec=IDLMakeGridGVec(map->num_model,&vmvec);
  if (map->num_bnd !=0) ibnd=IDLMakeCnvMapBnd(map->num_bnd,&vbnd);
  if (map->num_coef !=0) {
    int n=0;
    cdim[1]=4;
    cdim[0]=map->num_coef;
    icoef=(double *) 
      IDL_MakeTempArray(IDL_TYP_DOUBLE,2,cdim,IDL_ARR_INI_ZERO,&vcoef);
   
      for (n=0;n<map->num_coef;n++) {
       icoef[n]=map->coef[4*n];
       icoef[map->num_coef+n]=map->coef[4*n+1];
       icoef[2*map->num_coef+n]=map->coef[4*n+2];
       icoef[3*map->num_coef+n]=map->coef[4*n+3];
      }

  }

  /* copy the data here */
   
  IDLCopyCnvMapPrmToIDL(map,grd,iprm);
  if (istvec !=NULL) IDLCopyGridStVecToIDL(grd,grd->stnum,
                                    vstvec->value.s.arr->elt_len,istvec);
  if (igvec !=NULL) IDLCopyGridGVecToIDL(grd,grd->vcnum,
                                    vgvec->value.s.arr->elt_len,igvec);
  if (imvec !=NULL) IDLCopyCnvMapGVecToIDL(map,map->num_model,
                                           vmvec->value.s.arr->elt_len,imvec);
  if (ibnd !=NULL) IDLCopyCnvMapBndToIDL(map,map->num_bnd,
                                         vbnd->value.s.arr->elt_len,ibnd);

  CnvMapFree(map);
  GridFree(grd);

  IDL_VarCopy(vprm,argv[1]);  
  if (vstvec !=NULL) IDL_VarCopy(vstvec,argv[2]);
  if (vgvec !=NULL) IDL_VarCopy(vgvec,argv[3]);
  if (vmvec !=NULL) IDL_VarCopy(vmvec,argv[4]);
  if (vcoef !=NULL) IDL_VarCopy(vcoef,argv[5]);
  if (vbnd !=NULL) IDL_VarCopy(vbnd,argv[6]);


  return (IDL_GettmpLong(s));

}
Ejemplo n.º 26
0
static IDL_VPTR IDLOldCnvMapLoadInx(int argc,IDL_VPTR *argv) {

  int s=0,n;

  IDL_VPTR vinx=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  FILE *fp=NULL;

  struct OldCnvMapIDLInx *ifptr=NULL;
  struct RfileIndex *finx=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

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

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 
  finx=RfileLoadIndex(fp);

  if (finx==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  ifptr=IDLMakeOldCnvMapInx(finx->num,&vinx);
  
  for (n=0;n<finx->num;n++) {
    ifptr[n].st_time=finx->time.start[n];
    ifptr[n].ed_time=finx->time.end[n];
    ifptr[n].offset=finx->offset[n];
  }
  
  free(finx->time.start);
  free(finx->time.end);
  free(finx->offset);
  free(finx);

  IDL_VarCopy(vinx,argv[1]); 
   
  return (IDL_GettmpLong(s));
}