Ejemplo n.º 1
0
/* entry points for broadcasting system events */
void snd_seq_system_broadcast(int client, int port, int type)
{
	struct snd_seq_event ev;
	
	if (setheader(&ev, client, port) < 0)
		return;
	ev.type = type;
	snd_seq_kernel_client_dispatch(sysclient, &ev, 0, 0);
}
Ejemplo n.º 2
0
Archivo: websh.c Proyecto: zhemao/websh
void handle_input(char * url, char * input){
	vector * vec = str_split(input, " ");
	CURL * curl;
	char *com, *path;
	char *data = NULL;
	upload_buffer upbuf;
	
	int perform = 1;
	
	if(vec->length < 2){
		destroy_vector(vec);
		return;
	}
	
	/* init some stuff */
	curl = curl_easy_init();
	com = vector_get(vec, 0);
	str_lower(com);
	
	/* handle specific request types */
	if(strcmp(com, "get")==0){
		prepare_get(curl);
	} else if(strcmp(com, "post")==0){
		data = prepare_post(curl);
	} else if (strcmp(com, "head")==0){
		prepare_head(curl);
	} else if (strcmp(com, "put")==0){
		data = prepare_put(curl, &upbuf);
	} else if(strcmp(com, "delete")==0) {
		prepare_delete(curl);
	} else if (strcmp(com, "setheader")==0){
		perform = 0;
		setheader(vec);
	} else if(strcmp(com, "getheader")==0){
		perform = 0;
		getheader(vec);
	} else if(strcmp(com, "delheader")==0){
		perform = 0;
		delheader(vec);
	} else perform = 0;
	
	if(perform){
		path = vector_get(vec, 1);
		perform_request(curl, url, path);
	}
	
	/* free data if needed */
	if(data != NULL)
		free(data);
	
	destroy_vector(vec);
	curl_easy_cleanup(curl);
}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
  const char *header = "";
  int nonce = 0;
  int c;
  while ((c = getopt (argc, argv, "h:n:")) != -1) {
    switch (c) {
      case 'h':
        header = optarg;
        break;
      case 'n':
        nonce = atoi(optarg);
        break;
    }
  }
  char headernonce[HEADERLEN];
  u32 hdrlen = strlen(header);
  memcpy(headernonce, header, hdrlen);
  memset(headernonce+hdrlen, 0, sizeof(headernonce)-hdrlen);
  ((u32 *)headernonce)[HEADERLEN/sizeof(u32)-1] = htole32(nonce);
  siphash_keys keys;
  setheader(headernonce, sizeof(headernonce), &keys);
  printf("nonce %d k0 k1 k2 k3 %llx %llx %llx %llx\n", nonce, keys.k0, keys.k1, keys.k2, keys.k3);
  printf("Verifying size %d proof for cuckaroo%d(\"%s\",%d)\n",
               PROOFSIZE, EDGEBITS, header, nonce);
  for (int nsols=0; scanf(" Solution") == 0; nsols++) {
    word_t nonces[PROOFSIZE];
    for (int n = 0; n < PROOFSIZE; n++) {
      uint64_t nonce;
      int nscan = scanf(" %" SCNx64, &nonce);
      assert(nscan == 1);
      nonces[n] = nonce;
    }
    int pow_rc = verify(nonces, &keys);
    if (pow_rc == POW_OK) {
      printf("Verified with cyclehash ");
      unsigned char cyclehash[32];
      blake2b((void *)cyclehash, sizeof(cyclehash), (const void *)nonces, sizeof(nonces), 0, 0);
      for (int i=0; i<32; i++)
        printf("%02x", cyclehash[i]);
      printf("\n");
    } else {
      printf("FAILED due to %s\n", errstr[pow_rc]);
    }
  }
  return 0;
}
Ejemplo n.º 4
0
void ESPHttpClient::httpPost(String url, String useragent="", String host="", String contenttype="", int contentlength=0, String connection="")
{
setheader("POST",url);
if(useragent != "")
addHeaderDetails("User-Agent: "+ useragent);
if(host != "")
addHeaderDetails("Host: "+ host);
if(contenttype != "")
addHeaderDetails("Content-Type: "+ contenttype);
if(contentlength != 0)
{
String s =  String(contentlength);
addHeaderDetails("Content-Length: "+ s);
}
if(connection != "")
addHeaderDetails("Connection: "+ connection);
}
Ejemplo n.º 5
0
 cuckoo_ctx(const char* header, nonce_t easy_ness) {
   setheader(&sip_ctx, header);
   easiness = easy_ness;
   cuckoo = (node_t *)calloc(1+SIZE, sizeof(node_t));
   assert(cuckoo != 0);
 }
Ejemplo n.º 6
0
/* Before using setheader_, use setsiginfo to set the contents of the signal
   information structures. */
INTEGER setheader_(char *record, INTEGER *nsig)
{
    return (setheader(fcstring(record), sinfo, (unsigned int)(*nsig)));
}
Ejemplo n.º 7
0
/*-----------------------------------------------
|						|
|		    lpcmd()			|
|						|
|  This function performs 1D LP on a single	|
|  or arrayed FID data set. A new fid file      |
|  is write to argv[1] or curexpdir/lp.fid      |
|  if not specified.                            |
|						|
+----------------------------------------------*/
int lpcmd(int argc, char *argv[], int retc, char *retv[])
{
  char		filepath[MAXPATHL];
  int		status,
		res,
		cblock,
		lastcblock,
		blocksdone,
		lsfidx,
		fidnum = 0,
		arg_no,
		npx,
		npadj,
		ftflag,
		noreal,
		element_no,
		lastfid,
		first,
		last,
		step,
		i,
		ctcount,
		realt2data;
  float		*outp;
  dpointers	inblock;
  dpointers	outblock;
  dfilehead	fidhead,
		datahead,
		phasehead;
  lpstruct	parLPinfo;
  ftparInfo	ftpar;
  char		newfidpath[MAXPATHL];

  Wturnoff_buttons();
  ftpar.procstatus = (CMPLX_t2|LP_F2PROC);

/************************************
*  Initialize all parameterizeable  *
*  variables                        *
************************************/

  arg_no = first = step = element_no = 1;
  ftpar.nblocks = MAXINT;
  last = MAXINT;

  noreal = ftflag = TRUE;
  ftpar.t2dc = -1;
  ftpar.zeroflag = FALSE;
  ftpar.sspar.lfsflag = ftpar.sspar.zfsflag = FALSE;
  ftpar.dspar.dsflag = FALSE;
  ftpar.dspar.fileflag = FALSE;
  ftpar.dspar.newpath[0] = '\0';
  ftpar.ftarg.useFtargs = 0;
 
  // default newfidpath
  sprintf(newfidpath,"%s/lp.fid",curexpdir);

/*********************************
*  Parse STRING arguments first  *
*********************************/

  while ( (argc > arg_no) && (noreal = !isReal(argv[arg_no])) )
  {
     if(strcmp(argv[arg_no],"rlp") == 0) { // e.g., lp('/tmp/lp.fid')
       ftpar.procstatus = (REAL_t2|LP_F2PROC);
     } else if(argv[arg_no][0] == '/') { // e.g., lp('/tmp/lp.fid')
        strcpy(newfidpath,argv[arg_no]);
     } else {
        sprintf(newfidpath,"%s/%s",curexpdir,argv[arg_no]);
     }
     arg_no++;
  }
  if(strcmp(newfidpath+strlen(newfidpath)-4,".fid") != 0 &&
     strcmp(newfidpath+strlen(newfidpath)-5,".fid/") != 0) strcat(newfidpath,".fid");
  
/******************************
*  Initialize data files and  *
*  FT parameters.             *
******************************/

  if ( i_ft(argc, argv, (S_DATA | S_FLOAT),
            0, 0, &ftpar, &fidhead, &datahead, &phasehead) )
  {
      disp_status("        ");
      ABORT;
  }
  
  if ( (res = D_getbuf(D_USERFILE, fidhead.nblocks,  0, &inblock)) ) { 
    ctcount=1;
  } else ctcount = inblock.head->ctcount; 

  if(ctcount<1) ctcount=1;

  if (ftpar.t2dc == -1)
  {
      ftpar.t2dc = (fidhead.status & S_DDR) ? FALSE : TRUE;
  }
  disp_current_seq();

  ftpar.cf = first;

     specIndex = first;		/* tells interactive programs
				   that new data exist */
/***************************************************
*  np0  =  total number of points in the fid       *
*  npx  =  used number of points in the fid        *
*                                                  *
*  Adjust "npx" and "lsfidx".                      *
***************************************************/

  lsfidx = ftpar.lsfid0;

    npx = ftpar.np0;
    npadj = npx - lsfidx;     /* adjusted number of FID data points */

  if (lsfidx < 0)
  {
     if (npx < 2)
     {
        Werrprintf("lsfid is too large in magnitude");
        ABORT;
     }
  }
  else
  {
     if (lsfidx >= npx)
     {
        Werrprintf("lsfid is too large in magnitude");
        ABORT;
     }
  }

  realt2data = (ftpar.procstatus & REAL_t2);
  fpointmult = getfpmult(S_NP, fidhead.status & S_DDR);

  // note, limit for forward LP is npadj (5th arg)
  if ( setlppar(&parLPinfo, S_NP, ftpar.procstatus, npadj/2, MAXINT,
		  LPALLOC, "ft2d") )
  {
     disp_status("        ");
     releaseAllWithId("ft2d");
     Wsetgraphicsdisplay("");		/* TRY THIS!  SF */
     ABORT;
  }

  if (parLPinfo.sizeLP)
  {
     int	maxlpnp,
		nptmp;

     if (realt2data)
     {
        Werrprintf("LP analysis is not supported for real t2 data");
        releaseAllWithId("ft2d");
        disp_status("        ");
        ABORT;
     }

     maxlpnp = npadj;

     for (i = 0; i < parLPinfo.sizeLP; i++)
     {
        lpparams = *(parLPinfo.parLP + i);

        if (lpparams.status & FORWARD)
        {
           nptmp = 2*(lpparams.startextpt + lpparams.ncextpt - 1);
           if (nptmp > maxlpnp)
              maxlpnp = nptmp;
        }
     }

     npadj = maxlpnp;
  }

/**************************
*  Start loop over FIDs.  *
**************************/

  lastfid = ftpar.ni0 * ftpar.ni1 * ftpar.arraydim;
     if (lastfid > ftpar.nblocks)
        lastfid = ftpar.nblocks;
     if (first > lastfid)
     {
        last = lastfid;
     }

  D_trash(D_DATAFILE);
  if(access(newfidpath,F_OK) != 0) {
   if(mkdir(newfidpath,0777)) {
     Winfoprintf("cannot create %s",newfidpath);
     ABORT;
   }
  }

  status = (S_DATA | S_FLOAT | S_COMPLEX | ftpar.D_cmplx);

  // now write out fid to newfidpath
  strcpy(filepath,newfidpath); 
  strcat(filepath,"/fid");
  
  datahead.status = fidhead.status;
  datahead.vers_id = fidhead.vers_id;
  datahead.nbheaders = fidhead.nbheaders;
  datahead.nblocks = fidhead.nblocks;
  datahead.ntraces = 1;
  datahead.np = npadj; 
  datahead.ebytes = fidhead.ebytes;
  datahead.tbytes = npadj*fidhead.ebytes;
  datahead.bbytes = datahead.tbytes + sizeof(dblockhead);;
   
  if (D_newhead(D_DATAFILE, filepath, &datahead) )
  {
     Werrprintf("cannot open file %s", filepath);
     ABORT;
  }

/***********************************************
*  Necessary until I can devise a function to  *
*  read only the FID block header in order to  *
*  determine if FID data exists in that block. *
***********************************************/

  blocksdone = FALSE;
  lastcblock = ftpar.nblocks;

  cblock = 0;

  while ((cblock < lastcblock) && (!blocksdone))
  {
     DPRINT1("block %d\n", cblock);
     if ( (res = D_allocbuf(D_DATAFILE, cblock, &outblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_status("        ");
        ABORT;
     }
     
     outblock.head->ctcount = ctcount;  /* default setting */
     outblock.head->scale = 0;    /* default setting */

       outp = (float *)outblock.data;

/**********************************************************
*  Start filling at the start of the output data buffer.  *
*  This facilitates the automatic array-like processing   *
*  of 'cf' and 'nf' in 1D.                                *
**********************************************************/

        fidnum = cblock;
     
     if (interuption)
     {
        releaseAllWithId("ft2d");
        D_trash(D_PHASFILE);
        D_trash(D_DATAFILE);
        disp_status("        ");
        ABORT;
     }

     if ((cblock + 1) == first)
     {
        if ( ! ((cblock+1) & 15) )
           disp_index(cblock + 1);
        if ( getfid(fidnum, outp, &ftpar, &fidhead, &lastfid) )
	{

	   Werrprintf("Unable to get FID data");
           releaseAllWithId("ft2d");
	   disp_index(0);
           disp_status("        ");
           ABORT;
        }

	if (lastfid == 0)
	{
           releaseAllWithId("ft2d");
	   disp_index(0);
	   disp_status("        ");
           ABORT;
        }
        else if (cblock == lastfid)
	{
           status = 0;
           blocksdone = TRUE;
           if (last == MAXINT)
           {
              last = cblock;
           }
	}
        else
        {
           if (parLPinfo.sizeLP)
           {
              for (i = 0; i < parLPinfo.sizeLP; i++)
              {
                 lpparams = *(parLPinfo.parLP + i);
                 disp_status(lpparams.label);

                 if (lpz(fidnum, outp, (npx - lsfidx)/2, lpparams))
                 {
                    Werrprintf("LP analysis failed");
                    releaseAllWithId("ft2d");
                    disp_index(0);
                    disp_status("       ");
                    ABORT;
                 }
              }
           }

           if (fpointmult != 1.0)
           {
              *outp *= fpointmult;
              *(outp + 1) *= fpointmult;
           }

           //zerofill(outp + npadj, ftpar.fn0 - npadj);

           last = cblock + 1;
        }

        // multiply outp by ctcount
        outp = (float *)outblock.data;
        outp += npadj;
        for(i = 0; i < npadj; i++)
	  *(--outp) *= ctcount;
       
        setheader(&outblock, status, 0, cblock+1,
			ftpar.hypercomplex);
        first += step;
     }
     else
     {
        setheader(&outblock, 0, 0, cblock, ftpar.hypercomplex);
     }

     if ( (res = D_markupdated(D_DATAFILE, cblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     if ( (res = D_release(D_DATAFILE, cblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     cblock++;
     if (!blocksdone)
        blocksdone = (first > lastcblock);
  }

  if ( (last != ftpar.nblocks) && (last != MAXINT) )
  {
     if ( (res = D_gethead(D_DATAFILE, &datahead)) )
     {
        D_error(res);
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     datahead.nblocks = last;
     if ( (res = D_updatehead(D_DATAFILE, &datahead)) )
     {
        D_error(res);
        disp_index(0);
        disp_status("        ");
        ABORT;
     }
  }

  releasevarlist();
  releaseAllWithId("ft2d");
  disp_index(0);
  disp_status("    ");
  D_close(D_USERFILE);
  D_flush(D_DATAFILE);
  D_trash(D_DATAFILE);
  D_trash(D_PHASFILE);

  // save procpar
  strcpy(filepath,newfidpath); 
  strcat(filepath,"/procpar");
  if(npx == npadj) {
     saveProcpar(filepath);
  } else {
     
     double sw,at, oldat;
     P_getreal(PROCESSED,"at", &oldat, 1);
     P_setreal(PROCESSED,"np",(double)npadj,1);
     if(!P_getreal(PROCESSED,"sw",&sw,1) && sw > 0) {
        at = npadj/(2*sw);
        P_setreal(PROCESSED,"at",at,1);	
     }  
     saveProcpar(filepath);
     P_setreal(PROCESSED,"np",(double)npx,1);
     P_setreal(PROCESSED,"at",oldat,1);
  }

  RETURN;
}
Ejemplo n.º 8
0
main(int argc, char **argv)
{
    char buf[80], *ifname, *record = NULL;
    double sps, wgain;
    int bitspersample, bytespersecond, framelen, i, nsig, tag, wres;
    long flen, len, wnsamp;
    static WFDB_Siginfo *s;

    /* Interpret the command line. */
    pname = prog_name(argv[0]);
    for (i = 1; i < argc; i++) {
	if (*argv[i] == '-') switch (*(argv[i]+1)) {
	  case 'h':	/* help requested */
	    help();
	    exit(1);
	    break;
	  case 'i':	/* input file name follows */
	    if (++i >= argc) {
		(void)fprintf(stderr,
		      "%s: name of wav-format input file must follow -i\n",
			      pname);
		exit(1);
	    }
	    ifname = argv[i];
	    if (strlen(ifname)<5 || strcmp(".wav", ifname+strlen(ifname)-4)) {
		(void)fprintf(stderr,
			      "%s: name of input file must end in '.wav'\n",
			      pname);
		exit(1);
	    }
	    break;
	  case 'r':
	    if (++i >= argc) {
		(void)fprintf(stderr,
			      "%s: record name must follow -r\n", pname);
		exit(1);
	    }
	    record = argv[i];
	    break;
	  default:
	    (void)fprintf(stderr, "%s: unrecognized option %s\n", pname,
			  argv[i]);
	    exit(1);
	}
	else {
	    (void)fprintf(stderr, "%s: unrecognized argument %s\n", pname,
			  argv[i]);
	    exit(1);
	}
    }

    /* Check that required arguments are present and valid. */
    if (ifname == NULL) {
	help();
	exit(1);
    }

    /* If the record name was not specified, generate it from ifname. */
    if (record == NULL) {
	record = malloc(strlen(ifname));
	strncpy(record, ifname, strlen(ifname)-4);
	record[strlen(ifname)-3] = '\0';
    }

    /* Open the input file. */
    if ((ifile = fopen(ifname, "rb")) == NULL) {
	fprintf(stderr, "%s: can't open %s\n", pname, ifname);
	exit(2);
    }
 
    /* Determine the size of the input file. */
    fseek(ifile, 0L, SEEK_END);
    flen = ftell(ifile);
    fseek(ifile, 0L, SEEK_SET);
   
    /* Read and check the header chunk. */
    if (fread(buf, 1, 4, ifile) != 4 ||
	strncmp(buf, "RIFF", 4)) {
	fprintf(stderr, "%s: %s is not a .wav-format file\n", pname, ifname);
	exit(3);
    }
    len = in32() + 8;
    if (len != flen) {
	fprintf(stderr,
	  "%s: header chunk of %s has incorrect length (%ld, should be %ld)\n",
		pname, ifname, len, flen);
	exit(3);
    }
    if (fread(buf, 1, 4, ifile) != 4 ||
	strncmp(buf, "WAVE", 4)) {
	fprintf(stderr, "%s: %s is not a .wav-format file\n", pname, ifname);
	exit(3);
    }

    /* Read and check the format chunk. */
    if (fread(buf, 1, 4, ifile) != 4 ||
	strncmp(buf, "fmt ", 4)) {
	fprintf(stderr, "%s: format chunk missing or corrupt in %s\n",
		pname, ifname);
	exit(3);
    }
    len = in32();
    tag = in16();
    if (len != 16 || tag != 1) {
	fprintf(stderr, "%s: unsupported format %d in %s\n", 
		pname, tag, ifname);
	exit(3);
    }
    nsig = in16();
    sps = in32();
    bytespersecond = in32();
    framelen = in16();
    bitspersample = in16();
    if (bitspersample <= 8) {
	wres = 8;
	wgain = 12.5;
    }
    else if (bitspersample <= 16) {
	wres = 16;
	wgain = 6400;
    }
    else {
	fprintf(stderr, "%s: unsupported resolution (%d bits/sample) in %s\n",
		pname, bitspersample, ifname);
	exit(3);
    }
    if (framelen != nsig * wres / 8) {
	fprintf(stderr, "%s: format chunk of %s has incorrect frame length\n",
		pname, ifname);
	exit(3);
    }

    /* Read and check the beginning of the data chunk. */
    if (fread(buf, 1, 4, ifile) != 4 ||
	strncmp(buf, "data", 4)) {
	fprintf(stderr, "%s: data chunk missing or corrupt in %s\n",
		pname, ifname);
	exit(3);
    }
    len = in32();
    wnsamp = len / framelen;

    if ((s = malloc(nsig * sizeof(WFDB_Siginfo))) == NULL) {
	(void)fprintf(stderr, "%s: insufficient memory\n", pname);
	exit(2);
    }

    for (i = 0; i < nsig; i++) {
	s[i].fname = ifname;
	s[i].desc = NULL;
	s[i].units = NULL;
	s[i].gain = wgain;
	s[i].initval = 0;
	s[i].group = 0;
	s[i].fmt = (wres == 16) ? 16 : 80;
	s[i].spf = 1;
	s[i].bsize = 0;
	s[i].adcres = wres;
	s[i].adczero = (wres == 16) ? 0 : 128;
	s[i].baseline = s[i].adczero;
	s[i].nsamp = wnsamp;
	s[i].cksum = 0;
	wfdbsetstart(i, 44L);
    }
    setsampfreq(sps);

    if (setheader(record, s, nsig))
	exit(4);

    /* Clean up. */
    wfdbquit();

    exit(0);
}
Ejemplo n.º 9
0
/*-----------------------------------------------
|                                               |
|               get_one_fid()/3                 |
|                                               |
|    This function returns a pointer to the     |
|    requested FID in a 1D, arrayed, or 2D      |
|    experiment.                                |
|                                               |
+----------------------------------------------*/
float *get_one_fid(int curfid, int *np, dpointers *c_block, int dcflag)
{
  char          filepath[MAXPATHL],
                dcrmv[4];
  int           res,
                lastfid,
                force_getfid,
                headok;
  float         *fidptr;
  int           cftemp;
  int           cttemp;
  double        tmp;
  vInfo         info;
  ftparInfo	ftpar;
  dfilehead	fidhead,
		phasehead;
 
 
  force_getfid = (*np < 0);
  if (force_getfid)
     *np = -(*np);
  acqflag = FALSE;
  ftpar.np0 = *np;
  ftpar.fn0 = *np;
  ftpar.hypercomplex = FALSE;	/* ==> will not work for hypercomplex
				   2D interferograms */
  D_allrelease();
 
  if ( (res = D_gethead(D_PHASFILE, &phasehead)) )
  {
     if (res == D_NOTOPEN)
     {
        if ( (res = D_getfilepath(D_PHASFILE, filepath, curexpdir)) )
        {
           D_error(res);
           return(NULL);
        }

        res = D_open(D_PHASFILE, filepath, &phasehead); /* open the file */
     }
 
     if (res)
     {
        if ( new_phasefile(&phasehead, 0, 0, 0, 0, 0, ftpar.hypercomplex) )
           return(NULL);
     }
  }
 
  cftemp = 1;
  if (!P_getreal(CURRENT, "cf", &tmp, 1))
  {
     if (!P_getVarInfo(CURRENT, "cf", &info))
     {
        if (info.active)
           cftemp = (int) tmp;
     }
  }
  cttemp = 0;
  if (!P_getreal(PROCESSED, "ct", &tmp, 1))
     cttemp = (int) (tmp + 0.5);

  ls_ph_fid("lsfid", &(ftpar.lsfid0), "phfid", &(ftpar.phfid0), "lsfrq",
		&(ftpar.lsfrq0));
  headok = ( (phasehead.status == (S_DATA|S_FLOAT|S_COMPLEX)) &&
            (phasehead.ntraces == 1) && (phasehead.np == ftpar.np0) );
 
  if (headok)
  { /* if phase file does contain fid data, open the file */
     res = D_getbuf(D_PHASFILE, phasehead.nblocks, curfid, c_block);
 
     if (!res)
     {
        if ( (c_block->head->status == (S_DATA|S_FLOAT|S_COMPLEX)) &&
             (c_block->head->rpval == (float) (ftpar.phfid0)) &&
             (c_block->head->lpval == (float) (ftpar.lsfid0/2)) &&
             (c_block->head->lvl   == (float) (cftemp)) &&
             (c_block->head->tlt   == (float) (cttemp)) &&
             !force_getfid )
        {
           long_event();
           return((float *)c_block->data);
        }
     }
  }
 
/********************************************
*  If phasefile does not contain FID data,  *
*  open phasefile with the data handler.    *
********************************************/

  ftpar.zeroflag = FALSE;
  ftpar.arraydim = dim1count();
  lastfid = ftpar.arraydim;
  ftpar.fn0 = ftpar.np0;
  if ( i_fid(&fidhead, &ftpar) )   /* open fid file with data handler */
     return(NULL);
  if (ftpar.fn0 != ftpar.np0)
     headok = 0;

  *np = ftpar.np0;
  ftpar.fn0 = ftpar.np0;
 
  if (!headok)
  {
     if (new_phasefile(&phasehead, 0, ftpar.arraydim, 2*ftpar.np0, 1,
                    (S_DATA|S_FLOAT|S_COMPLEX), ftpar.hypercomplex))
     {
        return(NULL);
     }
  }
 
  if ( (res = D_allocbuf(D_PHASFILE, curfid, c_block)) )
  {
     D_error(res);
     return(NULL);
  }
 
  fidptr = (float *)c_block->data;
 
  /*******************************************
  *   provision for baseline offset removal  *
  *   using numbers reported by noise check  *
  *******************************************/

  ftpar.offset_flag = FALSE;
  if (!P_getstring(CURRENT,"dcrmv",dcrmv,1,4))
  {
    if (dcrmv[0] == 'y')
    {
      ftpar.offset_flag = TRUE;
    }
  }
  ftpar.t2dc = dcflag;
     
  if ( getfid(curfid, fidptr, &ftpar, &fidhead, &lastfid) ||
        (lastfid <= curfid) )
  {
     return(NULL);
  }
 
  if (ftpar.lsfid0 > 0)
     zerofill(fidptr + ftpar.np0 - ftpar.lsfid0, ftpar.lsfid0);
 
  D_close(D_USERFILE);
  setheader(c_block, (S_DATA|S_FLOAT|S_COMPLEX), NP_PHMODE, curfid,
                ftpar.hypercomplex);
  c_block->head->rpval = (float) (ftpar.phfid0);
  c_block->head->lpval = (float) (ftpar.lsfid0/2);
  c_block->head->lvl   = (float) (ftpar.cf);
  c_block->head->tlt   = (float) (ftpar.dspar.ctcount);
 
  if ( ftpar.cf != cftemp)
  {  /* cf is misset or inactive - just set it = 1 */
     Werrprintf("cf = %d is inconsistent with data",cftemp);
     P_setreal(CURRENT,  "cf", 1.0, 0);
     P_setreal(PROCESSED,"cf", 1.0, 0);
  }
  if ( (res = D_markupdated(D_PHASFILE, curfid)) )
  {
     D_error(res);
     return(NULL);
  }
 
  return(fidptr);
}
Ejemplo n.º 10
0
/*  blocknum    DATA block number to store converted data    */
static int convertblock(int *curfid, int blocknum, int *lastfid, int fidincr,
                ftparInfo *ftpar, dfilehead *fidhead, int nf_firstfid)
{
  int                   status,
                        res,
                        outfile,
                        npadj,
			fidnum,
			zfnumber;
  register int          fidcnt;
  register float        *outp;
  dpointers             outblock;
 
 
  outfile = D_DATAFILE;
 
/****************************************
*  Block "blocknum+nblocks" is used in  *
*  D_DATAFILE to transpose data.        *
****************************************/
 
  if ( (res = D_allocbuf(outfile, blocknum + ftpar->nblocks, &outblock)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  outp = (float *)outblock.data;
/*************************************************
*  Start filling at the beginning of the output  *
*  data buffer.                                  *
*                                                *
*  np0 = the number of actual points in the FID  *
*  fn0 = the number of actual points in the      *
*        converted file                          *
*************************************************/
 
  npadj = ( (ftpar->lsfid0 < 0) ? ftpar->np0 : (ftpar->np0 - ftpar->lsfid0) );
  if (npadj > ftpar->fn0)
     npadj = ftpar->fn0;
  zfnumber = ftpar->fn0 - npadj;
 
/*********************************************
*  DF2D of NF-arrayed 2D data will not work  *
*  at this time.                             *
*********************************************/
  *lastfid = *curfid + ftpar->sperblock0*fidincr;
  for (fidcnt = *curfid; fidcnt < *lastfid; fidcnt += fidincr)
  {
     fidnum = ( (ftpar->D_dimname & S_NF) ? nf_firstfid : fidcnt );
     if ( getfid(fidnum, outp, ftpar, fidhead, lastfid) )
        return(ERROR);
 
     if (*lastfid == 0)
        return(ERROR);
 
     if (fidcnt < (*lastfid))
     {
        if (zfnumber > 0)
           zerofill(outp + npadj, zfnumber);
        scalefid(outp,npadj);
	if (ftpar->D_dimname & S_NF)
           ftpar->cf += ftpar->cfstep;/* increment cf for NF processing */
     }
     outp += ftpar->fn0;
  }
 
  fidnum = fidcnt;
  for (fidcnt = *lastfid + fidincr; fidcnt < *curfid + ftpar->sperblock0*fidincr;
       fidcnt += fidincr)
  {
     zerofill(outp, ftpar->fn0);
     outp += ftpar->fn0;
  }
  *curfid = fidnum;
  status = (S_DATA|S_FLOAT|S_COMPLEX);
     
  setheader(&outblock, status, ftpar->D_dsplymode, blocknum,
                ftpar->hypercomplex);
  if ( (res = D_markupdated(outfile, blocknum + ftpar->nblocks)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  if ( (res = D_release(outfile, blocknum + ftpar->nblocks)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  return(COMPLETE);
}