Exemplo n.º 1
0
//
// idlpgr_CreateImage
//
IDL_VPTR IDL_CDECL idlpgr_CreateImage(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Image *image;
  IDL_MEMINT dim;

  dim = (IDL_MEMINT) sizeof(fc2Image);
  image = (fc2Image *) IDL_MemAlloc(dim, NULL, 0);
  error = fc2CreateImage(image);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could create image",
			 error);

  return IDL_GettmpULong64((IDL_ULONG64) image);
}
Exemplo n.º 2
0
IDL_VPTR readwu(int argc, IDL_VPTR argv[], char *argk) {
  IDL_VPTR filename=NULL;
  static IDL_VARIABLE rv;
  rv.type=IDL_TYP_INT;
  rv.flags=IDL_V_CONST|IDL_V_NULL;
  rv.value.i=-1;

  char *outfile=NULL, buf[256];
  struct stat statbuf;
  int nbytes,nread,nsamples;
  std::string tmpbuf("");
  int i=0,j;

  if (argc != 1) {
    fprintf(stderr,"argc=%d\n",argc);
    fprintf(stderr,"array=readwu(wufile_name)\n");
    return &rv;
  }
  IDL_STRING *infile=NULL;
  if (argv[0]->type != IDL_TYP_STRING) {
    IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"Parameter 1 must be type STRING");
  } else {
    infile=(IDL_STRING *)(&argv[0]->value.s);
  }
  FILE *in=fopen(infile->s,"r");
  if (!in) {
    IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"File not found");
    return &rv;
  } 
  stat(infile->s,&statbuf);
  nbytes=statbuf.st_size;
  fseek(in,0,SEEK_SET);
  tmpbuf.reserve(nbytes);
  // read entire file into a buffer.
  while ((nread=(int)fread(buf,1,sizeof(buf),in))) {
    tmpbuf+=std::string(&(buf[0]),nread);
  }
  // parse the header
  header.parse_xml(tmpbuf);
  // decode the data
  std::vector<unsigned char> datav(
    xml_decode_field<unsigned char>(tmpbuf,"data") 
  );
  tmpbuf.clear();
  nsamples=header.group_info->data_desc.nsamples;
  nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8;
  if (datav.size() < nbytes) {
    fprintf(stderr,"Data size does not match number of samples\n");
    return &rv;
  }
  // convert the data to floating point
  sah_complex *fpdata=(sah_complex *)IDL_MemAlloc(nsamples*sizeof(sah_complex),0,IDL_MSG_RET);
  if (!fpdata) {
    fprintf(stderr,"Unable to allocate memory!\r\n");
    return &rv;
  } 
  bits_to_floats(&(datav[0]),fpdata,nsamples);
  datav.clear();
  IDL_MEMINT dims[]={nsamples};
  return IDL_ImportArray(1,dims,IDL_TYP_COMPLEX,(UCHAR *)fpdata,NULL,NULL);
}