Ejemplo n.º 1
0
static  pdtStr *convStrFunAux(int pc1, int pc2)
{ pdtStr *D;
  int i,ix,iq,nc,i1=pos(pc1),i2=pos(pc2);
  if(i1>=i2) nc=i1*(i1-1)/2+i2-1; else nc=i2*(i2-1)/2+i1-1;
  if(cData && cData[nc])  return cData[nc];
  if(cData==NULL) 
  { cData=malloc(78*sizeof(pdtStr*));
    for(i=0;i<78;i++) if(cData[i]) cData[i]=NULL;
  }

  D=readPdtData(21);
   
  data1=checkdata(pc1);
  data2=checkdata(pc2);
  if(D->x_grid[0]==0)
  {  D->x_grid[0]=D->x_grid[1]/2;
     if(D->x_grid_aux) D->x_grid_aux[0]=pow(D->x_grid_aux[0],0.3);
  }   
  for(iq=0;iq<D->nq;iq++)for(ix=0;ix<D->nx;ix++)
  { 
    q_ =exp(D->q_grid[iq]);
    x0_=D->x_grid[ix];
    D->strfun[D->nx*iq+ix] = simpson(conv_integrand,0.,-log(x0_),1.E-3);
  }

  cData[nc]=D;
  return D;  
}
Ejemplo n.º 2
0
int main (int argc, char* argv[])
{
  /* check that we got an appropriate number of arguments */
  if (argc != 1 && argc != 4) {
    printf("Usage: test_correctness [filesize times sleep_secs]\n");
    return 1;
  }

  /* read parameters from command line, if any */
  if (argc > 1) {
    filesize = (size_t) atol(argv[1]);
    times = atoi(argv[2]);
    seconds = atoi(argv[3]);
  }

  MPI_Init(&argc, &argv);

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &ranks);

  cruise_mount("/tmp",1024,0);

  char name[256];
  sprintf(name, "/tmp/rank.%d", rank);

  /* allocate space for the checkpoint data (make filesize a function of rank for some variation) */
  filesize = filesize + rank;

  /* verify data integrity in file */
  checkdata(name, filesize, times);

  MPI_Finalize();

  return 0;
}
Ejemplo n.º 3
0
double parton_x( int pNum, double  Q)
{
  double x1;
  q_=Q;

  data_=checkdata(pNum); 
  if(data_ == NULL || q_< data_->q_min ) return 0;
  
  x1=simpson(x_integrand,data_->x_min,1.,1.E-4);  
  if(pNum==21) return x1;
  if(abs(pNum)>2) return 2*x1;
  
  data_=checkdata(-pNum);
  if(data_ == NULL) return 0;  
  return x1+simpson(x_integrand,data_->x_min,1.,1.E-4);
}
int main()
{
  int alldone = 0;
  welcome();
  do
  {
    if (checkdata() == 1)
    { resetstatus(); }
    do
    {
      if (checkstatus() == 1)
      {
        if (restart()) 
        { break; }
      }
      displaystatus();
      alldone = continueclipping();
    } 
    while (alldone == 0);
  resetstatus();
  goodbye();
  } 
  while (close() == 0);
  return 0;
}
Ejemplo n.º 5
0
static int Dloadbuffer (lua_State *L) { /** data:loadbuffer(buf) */
  ExifData *data = checkdata(L);
  size_t length;
  const char *buffer = luaL_checklstring(L, 2, &length);

  exif_data_load_data(data, (const unsigned char *)buffer, length);

  return 0;
}
Ejemplo n.º 6
0
static int WritePack(lua_State *L) 
    {
    hostmem_t* hostmem = checkhostmem(L, 1, NULL);
    size_t offset = luaL_checkinteger(L, 2);
    int type = checktype(L, 3);
    size_t size = hostmem->size - offset;
    if(offset >= hostmem->size)
        return luaL_error(L, errstring(ERR_BOUNDARIES));
    checkdata(L, 4, type, hostmem->ptr + offset, size);
    return 0;
    }
Ejemplo n.º 7
0
void MainWindow::on_pushButton_clicked()
{
    if (checkdata())
    {
        message = "LOGIN||";
        QString host = ui->ipLine->text();
        QString port = ui->portLine->text();
        client = new QTcpSocket();
        connect(client, SIGNAL(connected()), this, SLOT(send()));
        client->connectToHost(host, port.toInt());
    }
}
Ejemplo n.º 8
0
rsa_keypair_t *rsa_read_public(const uint8_t *data, const size_t len) {
	rsa_keypair_t *out;
	uint32_t bytes_m, bytes_e;
	size_t offs = 0;

	if(checkdata(data, len, 2) == 0) return NULL;
	if((out = emptypublic()) == NULL) return NULL;
	mp_init_multi(out->modulus, out->public, NULL);

	bytes_m = *(data + offs);									offs += INT_SIZE;
	mp_read_unsigned_bin(out->modulus, data + offs, bytes_m);	offs += bytes_m;
	bytes_e = *(data + offs);									offs += INT_SIZE;
	mp_read_unsigned_bin(out->public, data + offs, bytes_e);	offs += bytes_m;

	out->ksize_bytes = bytes_m;

	return out;
}
Ejemplo n.º 9
0
static pdtStr * checkdata(int pc)
{ int pp=pos(pc)-1;
  if(data[pp]) return data[pp]; 
  if(abs(pc) <80) data[pp]= readPdtData(pc);
  else
  { pdtStr * dataAux;
    double a,b;
    int i, ntot;
    data[pp]=readPdtData(3);
    ntot=data[pp]->nq*data[pp]->nx; 
    pc=(pc>0)? pc-80:pc+80;
    dataAux=checkdata(pc);
    if(abs(pc)==1) a=0.221*0.221; else a=1-0.221*0.221;
    b=1-a;
    for(i=0;i<ntot;i++) data[pp]->strfun[i]= a*data[pp]->strfun[i]
                                            +b*dataAux->strfun[i]; 
  }
  return data[pp];
}
Ejemplo n.º 10
0
int EthernetFrame::fillframe(string sourcemac, string desmac, string data, string seedstring)
{
    crcdata.clear();

    int checkresult;
    if (!(checkresult=checkdata(sourcemac, desmac, data, seedstring)))
    {
        ostringstream len,llc;
		//长度字段,将长度转换成网络字节序在转换成01格式
        short temp = data.size() / 8;
        temp = htons(temp);
        len << bitset<16>(temp);
		//填充字段
        llc << std::setw(368) << std::left << std::setfill('0') << data;
		//整个要生成crc校验码的字段
        crcdata = hexstrtobinary(desmac) + hexstrtobinary(sourcemac) + len.str() +llc.str();
        crc.crc8(crcdata,crcgenerater::seedstr2seed(seedstring));
    }
    return checkresult;
}
Ejemplo n.º 11
0
static int Difd (lua_State *L) { /** data:ifd(ifd) */
  ExifData *data = checkdata(L);
  static const char *const ifdnames[] = {
    "0",
    "1",
    "EXIF",
    "GPS",
    "Interoperability",
    NULL
  };
  static const ExifIfd ifds[] = {
    EXIF_IFD_0,
    EXIF_IFD_1,
    EXIF_IFD_EXIF,
    EXIF_IFD_GPS,
    EXIF_IFD_INTEROPERABILITY
  };
  int i = luaL_checkoption(L, 2, NULL, ifdnames);
  pushcontent(L, data->ifd[ifds[i]]);
  return 1;
}
Ejemplo n.º 12
0
/*-----------------------------------------------
|						|
|	 	  getdata()/0			|
|						|
|   This function reads the 1D or 2D data in 	|
|   form disk, manipulates it appropriately,	|
|   and moves the ReRe component to the memory	|
|   allocated for the phasefile data.		|
|						|
+----------------------------------------------*/
static int getdata()
{
   char		dsplymes[20],	/* display mode label		*/
		dmg1[5];
   int		npf1=0,		/* number of points along F1	*/
		npf2=0,		/* number of points along F2	*/
		i,
		r,
		found,
		f1phase,
		f2phase,
		quad2,
		quad4,
		complex_1D=0,
                norm_av,
                norm_dir,
                norm_phase,
                norm_phaseangle,
                norm_dbm,
                rev_av=0,
                rev_dir=0,
                rev_phase=0,
                rev_phaseangle=0,
		nplinear,
		npblock;
   float	*f1phasevec=NULL,	/* F1 phasing vector		*/
		*f2phasevec=NULL;	/* F2 phasing vector		*/
   double	rp_norm,
		lp_norm;
   double	rp_rev,
		lp_rev;
   dpointers	datablock;
   hycmplxhead	*tmpblkhead;


/********************************************
*  Get pointer to data in specified block.  *
********************************************/

   if ( (r = D_getbuf(D_DATAFILE, nblocks, c_buffer, &datablock)) )
   {
      D_error(r);
      return(ERROR);
   }
   else if (checkdata(datablock.head))
   {
      return(ERROR);
   }

/**********************
*  Setup for 2D data  *
**********************/

   quad2 = quad4 = FALSE;
   f1phase = f2phase = FALSE;

   if (d2flag)
   {
/************************************
*  Set the flags for the number of  *
*  quadrants.                       *
************************************/

     quad4 = (datahead.status & S_HYPERCOMPLEX);
     if (!quad4)
        quad2 = (datahead.status & S_COMPLEX);

/********************************************
*  Precalculate phasing vectors for the F1  *
*  and F2 dimensions if necessary.          *
********************************************/

      nplinear = pointsperspec;
      npblock = specperblock * nblocks;
      if (quad4)
      {
         npblock *= 2;
         nplinear /= 2;
      }

      if (revflag)
      {
         npf1 = nplinear;
         npf2 = npblock;
      }
      else
      {
         npf2 = nplinear;
         npf1 = npblock;
      }

      f1phasevec = NULL;	/* initialize pointer */
      f2phasevec = NULL;	/* initialize pointer */

/**********************************************
*  If a phase-sensitive display is requested  *
*  along F1, precalculate the F1 phasing      *
*  vector.                                    *
**********************************************/

      rev_dir = get_direction(REVDIR);
      get_phase_pars(rev_dir,&rp_rev,&lp_rev);
      rev_phase = get_phase_mode(rev_dir);
      rev_phaseangle = get_phaseangle_mode(rev_dir);
      rev_av = get_av_mode(rev_dir);
      f1phase = ( ((rev_phase && nonzerophase(rp_rev, lp_rev)) || rev_phaseangle) &&
                  (quad2 || quad4) &&
		  get_axis_freq(rev_dir) );

      if (f1phase)
      {
         f1phasevec = (float *) (allocateWithId( (unsigned) (sizeof(float)
	 			    * npf1), "getdata" ));
         if (f1phasevec == NULL)
         {
            Werrprintf("Unable to allocate memory for F1 phase buffer");
            return(ERROR);
         }
         else
         {
            phasefunc(f1phasevec, npf1/2, lp_rev, rp_rev);
         }
      }

/**********************************************
*  If a phase-sensitive display is requested  *
*  along F2, precalculate the F2 phasing      *
*  vector.                                    *
**********************************************/

      norm_dir = get_direction(NORMDIR);
      get_phase_pars(norm_dir,&rp_norm,&lp_norm);
      norm_phase = get_phase_mode(norm_dir);
      norm_phaseangle = get_phaseangle_mode(norm_dir);
      norm_av = get_av_mode(norm_dir);
      norm_dbm = get_dbm_mode(norm_dir); /* may not be active?? */
      f2phase = ( (norm_phase || norm_phaseangle) && quad4 && nonzerophase(rp_norm, lp_norm) );
		/* (quad4 || quad2)??  (quad4) only?? */

      if (f2phase)
      {
         f2phasevec = (float *) (allocateWithId( (unsigned) (sizeof(float)
	 			    * npf2), "getdata" ));
         if (f2phasevec == NULL)
         {
            Werrprintf("Unable to allocate memory for F2 phase buffer");
            if (f1phase)
               releaseAllWithId("getdata");
            return(ERROR);
         }
         else
         {
            phasefunc(f2phasevec, npf2/2, lp_norm, rp_norm);
         }
      }
   }
   else
   {
      complex_1D = (datablock.head->status & NP_CMPLX);
      norm_dir = HORIZ;
      norm_phase = get_phase_mode(norm_dir);
      norm_phaseangle = get_phaseangle_mode(norm_dir);
      norm_av = get_av_mode(norm_dir);
      norm_dbm = get_dbm_mode(norm_dir); /* may not be active 2 */
   }

/*************************************
*  Readjust "npf1" and "npf2" to be  *
*  per block.                        *
*************************************/

   if (d2flag)
   {
      if (revflag)
      {
         npf2 /= nblocks;
      }
      else
      {
         npf1 /= nblocks;
      }
   }

/**********************************
*  Construct display mode label.  *
**********************************/

   strcpy(dsplymes, ""); 	/* initialization of string */

   if ( d2flag && (quad2 || quad4) )
   {
      char charval;
      char tmp[10];

      get_display_label(rev_dir,&charval);
      if (rev_phase)
      {
         sprintf(tmp, "PH%c ",charval);
      }
      else if (rev_av)
      {
         sprintf(tmp, "AV%c ",charval);
      }
      else if (rev_phaseangle)
      {
         sprintf(tmp, "PA%c ",charval);
      }
      else
      {
         sprintf(tmp, "PW%c ",charval);
      }

      strcpy(dsplymes, tmp);
   }

   if ( (d2flag && quad4) || ((!d2flag) && complex_1D) )
   {
      char charval;
      char tmp[10];

      get_display_label(norm_dir,&charval);
      if (charval == '\0')
         charval = ' ';
      if (norm_phase)
      {
         sprintf(tmp, "PH%c",charval);
      }
      else if (norm_av)
      {
         sprintf(tmp, "AV%c",charval);
      }
      else if (norm_phaseangle)
      {
         sprintf(tmp, "PA%c",charval);
      }
      else
      {
         sprintf(tmp, "PW%c",charval);
      }

      strcat(dsplymes, tmp);
   }

   disp_status(dsplymes);

/*************************************************
*  Manipulate data depending upon the number of  *
*  2D data quadrants and the desired mode of     *
*  display.					 *
*************************************************/

   if (d2flag)
   {
      if (quad4)
      {

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 phase-sensitive display      *
***********************************/

         if (norm_phase)
         {
            if (rev_phase)
            {

	/*****************************
	*  phase for ReRe component  *
	*****************************/
               if (f1phase && f2phase)
               {
                  blockphase4(datablock.data, c_block.data, f1phasevec,
	  		f2phasevec, nblocks, c_buffer, npf1/2, npf2/2);
               }
               else if (f1phase)
               {
                  blockphase2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
			COMPLEX, TRUE, FALSE);
               }
               else if (f2phase)
               {
                  blockphase2(datablock.data, c_block.data, f2phasevec,
			nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
			REAL, FALSE, FALSE);
               }
               else
               {
                  movmem((char *)datablock.data, (char *)c_block.data,
			(npf1*npf2*sizeof(float))/4, HYPERCOMPLEX,
			4);
               }
            }
            else
            {
               if (f2phase)
               {

	/***************************
	*  rotate ReRe <---> ReIm  *
	*  rotate ImRe <---> ImIm  *
	***************************/
                  if (rev_av)
                  {

	/********************************
	*  S = sqrt(ReRe**2 + ImRe**2)  *
	********************************/
                     blockphsabs4(datablock.data, c_block.data, f2phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, REAL, FALSE);
                  }
                  else if (rev_phaseangle)
                  {
                     blockphaseangle2(datablock.data, c_block.data, f1phasevec,
                           nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
                           COMPLEX, TRUE, FALSE);
                  }
                  else
                  {

	/**************************
	*  S = ReRe**2 + ImRe**2  *
	**************************/
                     blockphspwr4(datablock.data, c_block.data, f2phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, REAL, FALSE);
                  }
               }
               else if (rev_av)	/* no F2 phasing required */
               {

	/********************************
	*  S = sqrt(ReRe**2 + ImRe**2)  *
	********************************/
                  absval2(datablock.data, c_block.data, (npf1*npf2)/4,
                        HYPERCOMPLEX, COMPLEX, REAL, FALSE);
               }
/* else if (rev_phaseangle) {} */
               else			/* no F2 phasing required */
               {

	/**************************
	*  S = ReRe**2 + ImRe**2  *
	**************************/
                  pwrval2(datablock.data, c_block.data, (npf1*npf2)/4,
                        HYPERCOMPLEX, COMPLEX, REAL, FALSE);
               }
            }
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 absolute-value display       *
***********************************/

         else if (norm_av)
         {
            if (rev_phase)
            {
               if (f1phase)
               {

	/********************************
	*  rotate ReRe <---> ImRe       *
	*  rotate ReIm <---> ImIm       *
	*  S = sqrt(ReRe**2 + ReIm**2)  *
	********************************/
                  blockphsabs4(datablock.data, c_block.data, f1phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, COMPLEX, TRUE);
               }
               else
               {

	/********************************
	*  S = sqrt(ReRe**2 + ReIm**2)  *
	********************************/
                  absval2(datablock.data, c_block.data, (npf1*npf2)/4,
			HYPERCOMPLEX, REAL, REAL, FALSE);
               }
            }
            else if (rev_av)
            {

	/****************************************************
	*  S = sqrt(ReRe**2 + ReIm**2 + ImRe**2 + ImIm**2)  *
	****************************************************/
               absval4(datablock.data, c_block.data, npf1*npf2/4);
            }
/* else if (rev_phaseangle) {} */
            else
            {

	/****************************
	*  S1 = ReRe**2 + ImRe**2   *
	*  S2 = ReIm**2 + ImIm**2   *
        *  S = sqrt(S1**2 + S2**2)  *
	****************************/
               blockpwrabs(datablock.data, c_block.data, (npf1*npf2)/4,
				COMPLEX);
            }
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 phaseangle display           *
***********************************/

         else if (norm_phaseangle)
         {
            Werrprintf("Cannot perform hypercomplex phaseangle");
            return(ERROR);
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 power display                *
***********************************/

         else
         {
            if (rev_phase)
            {
               if (f1phase)
               {

	/***************************
	*  rotate ReRe <---> ImRe  *
	*  rotate ReIm <---> ImIm  *
	*  S = ReRe**2 + ReIm**2   *
	***************************/
                  blockphspwr4(datablock.data, c_block.data, f1phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, COMPLEX, TRUE);
               }
               else
               {

	/**************************
	*  S = ReRe**2 + ReIm**2  *
	**************************/
                  pwrval2(datablock.data, c_block.data, (npf1*npf2)/4,
			   HYPERCOMPLEX, REAL, REAL, FALSE);
               }
            }
            else if (rev_av)
            {

	/****************************
	*  S1 = ReRe**2 + ReIm**2   *
	*  S2 = ImRe**2 + ImIm**2   *
        *  S = sqrt(S1**2 + S2**2)  *
	****************************/
               blockpwrabs(datablock.data, c_block.data, (npf1*npf2)/4,
				REAL);
            }
/* else if (rev_phaseangle) {} */
            else
            {

	/**********************************************
	*  S = ReRe**2 + ReIm**2 + ImRe**2 + ImIm**2  *
	*  THIS IS NOT QUITE RIGHT!                   *
	**********************************************/
               pwrval4(datablock.data, c_block.data, npf1*npf2/4);
            }
         }

/**********************************************
*  Set the F1 phase constants into the block  *
*  header of the phasefile data.              *
**********************************************/

         if (rev_phase || rev_phaseangle)
         {
            c_block.head->lpval = lp_rev;
            c_block.head->rpval = rp_rev;
         }
         else
         {
            c_block.head->lpval = 0.0;
            c_block.head->rpval = 0.0;
         }

/***************************************************
*  Locate the block header for the "hypercomplex"  *
*  information.  Then set the F2 phase constants   *
*  into the block header of the phasefile data.    *
***************************************************/

         i = 0;
         found = FALSE;

         while (!found)
         {
            if ( (~(datablock.head + i)->status) & MORE_BLOCKS )
            {
               Werrprintf("Block headers inconsistent with hypercomplex data");
               if (f1phase || f2phase)
                  releaseAllWithId("getdata");
               return(ERROR);
            }

            i += 1;
            found = ( (datablock.head + i)->status & U_HYPERCOMPLEX );
         }

         tmpblkhead = (hycmplxhead *) (c_block.head + i);
         if (norm_phase)
         {
            tmpblkhead->lpval1 = lp_norm;
            tmpblkhead->rpval1 = rp_norm;
         }
         else
         {
            tmpblkhead->lpval1 = 0.0;
            tmpblkhead->rpval1 = 0.0;
         }
      }
      else if (quad2)
      {

/*******************************
*  COMPLEX 2D spectral data:   *
*  F1 display selection        *
*******************************/

         if (rev_phase)
         {

       /***************************
       *  rotate ReRe <---> ImRe  *
       ***************************/
            if (f1phase)
            {
               blockphase2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2, COMPLEX, 1,
			TRUE, FALSE);
            }
            else
            {
               movmem((char *)datablock.data, (char *)c_block.data,
			(npf1*npf2*sizeof(float))/2, COMPLEX, 4);
            }
         }
         else if (rev_phaseangle)
         {
            if (f1phase)
            {
               blockphaseangle2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2, COMPLEX, 1,
			TRUE, FALSE);
            }
            else
            {
               movmem((char *)datablock.data, (char *)c_block.data,
                        (npf1*npf2*sizeof(float))/2, COMPLEX, 4);
            }
         }
         else if (rev_av)
         {

       /********************************
       *  S = sqrt(ReRe**2 + ImRe**2)  *
       ********************************/
            absval2(datablock.data, c_block.data, (npf1*npf2)/2,
			COMPLEX, 1, 1, FALSE);
         }
         else
         {

       /**************************
       *  S = ReRe**2 + ImRe**2  *
       **************************/
            pwrval2(datablock.data, c_block.data, (npf1*npf2)/2,
			COMPLEX, 1, 1, FALSE);
         }

         if (rev_phase || rev_phaseangle)
         {
            c_block.head->lpval = lp_rev;
            c_block.head->rpval = rp_rev;
         }
         else
         {
            c_block.head->lpval = 0.0;
            c_block.head->rpval = 0.0;
         }
      }
      else
      {

/***************************
*  REAL 2D spectral data   *
***************************/

         movmem((char *)datablock.data, (char *)c_block.data,
			npf1*npf2*sizeof(float), REAL, 4);
         c_block.head->lpval = 0.0;
         c_block.head->rpval = 0.0;
      }
   }

/**********************
*  Setup for 1D data  *
**********************/

   else
   {
    if(bph()>0 && complex_1D && (norm_phase || norm_phaseangle)) {
      // don't use lp, rp, because block is individually phased. 
      c_block.head->lpval=getBph1(c_buffer); 
      c_block.head->rpval=getBph0(c_buffer);
      if (norm_phase)
      {
        phase2(datablock.data, c_block.data, fn/2, c_block.head->lpval, c_block.head->rpval);
      }
      else if (norm_phaseangle)
      {
        phaseangle2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE, c_block.head->lpval, c_block.head->rpval);
      }
      P_setreal(CURRENT,"bph1",c_block.head->lpval,0);
      P_setreal(CURRENT,"bph0",c_block.head->rpval,0);
    } else { 
      c_block.head->lpval = 0.0;
      c_block.head->rpval = 0.0;

      if (complex_1D)
      {
         if (norm_phase)
         {
            phase2(datablock.data, c_block.data, fn/2, lp, rp);
            c_block.head->lpval = lp;
            c_block.head->rpval = rp;
         }
         else if (norm_phaseangle)
         {
            phaseangle2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE, lp, rp);
            c_block.head->lpval = lp;
            c_block.head->rpval = rp;
         }
         else if (norm_av)
         {
            absval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         }
         else if (norm_dbm)
         {
            dbmval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         } 
         else
         {
            pwrval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         }
      }
      else
      {
         if (datablock.head->status & S_COMPLEX)
         {
            movmem((char *)datablock.data, (char *)c_block.data,
			(fn/2)*sizeof(float), COMPLEX, 4);
         }
         else
         {
            movmem((char *)datablock.data, (char *)c_block.data,
			(fn/2)*sizeof(float), REAL, 4);
         }
      }
    }
   }

/*************************************
*  Set status word for block header  *
*  of phasefile.                     *
*************************************/

   c_block.head->status = (S_DATA|S_SPEC|S_FLOAT);

/*********************************** 
*  Set mode word for block header  * 
*  of phasefile.                   * 
***********************************/

   c_block.head->mode = get_mode(HORIZ);
   if (d2flag)
      c_block.head->mode |= get_mode(VERT);

/***************************************
*  Set additional words in main block  *
*  header of phasefile.                *
***************************************/

   c_block.head->scale = 0;
   c_block.head->ctcount = 0;
   c_block.head->index = (short)c_buffer;
   c_block.head->lvl = 0.0;
   c_block.head->tlt = 0.0;

/************************************************
*  Set status word in previous block header of  *
*  phasefile to indicate the presence of a      *
*  following block header.                      *
************************************************/

   if (d2flag)
   {
      i = 0;
      while ((datablock.head + i)->status & MORE_BLOCKS)
      {
         (c_block.head + i)->status |= MORE_BLOCKS;
         i += 1;
         if ((datablock.head + i)->status & U_HYPERCOMPLEX)
            (c_block.head + i)->status |= U_HYPERCOMPLEX;
      }
   }


/******************************************
*  Release this DATAFILE buffer with the  *
*  data handler routines.                 *
******************************************/

   if ( (r = D_release(D_DATAFILE, c_buffer)) )
   {
      D_error(r);
      if (f1phase || f2phase)
         releaseAllWithId("getdata");
      return(ERROR);
   }

   if (P_copyvar(CURRENT, PROCESSED, "dmg", "dmg"))
   {
      Werrprintf("dmg:  cannot copy from 'current' to 'processed' tree\n");
      if (f1phase || f2phase)
         releaseAllWithId("getdata");
      return(ERROR);
   }

   if (d2flag)
   {
      if (!P_getstring(CURRENT, "dmg1", dmg1, 1, 5))
      {
         if (P_copyvar(CURRENT, PROCESSED, "dmg1", "dmg1"))
         {
            Werrprintf("dmg1: cannot copy from 'current' to 'processed' tree");
            if (f1phase || f2phase) 
               releaseAllWithId("getdata");
            return(ERROR);
         }
      }
   }

   if (f1phase || f2phase)
      releaseAllWithId("getdata");
   if (!Bnmr)
      disp_status("                 ");
   return(COMPLETE);
}
Ejemplo n.º 13
0
/**
* Read in DARP data.
@param Instance instance name
*/
void CDar::input(char *Instance)
{
	//CError error;
	ifstream	 fin;
	int i, i_dummy, ei, li, j, nc, k, type;
	float x, y;
	int demand_able, demand_disabled;
	char code[CON_MAXNSTRCODE];
	float st, rt;
	float distance, time;
	int n_entries;
	int tot_capacity;
	char sep;
	double scalef = 10000;
	int n_origin, n_destination;
	int fixed, i_paired_request;

	// Open the log file
	snprintf(buf, sizeof(buf), "%s//%s_dar_input.csv", INPUTDIR, Instance);
	fin.open(buf, ios::out);
	if (!fin.is_open()){
		snprintf(buf, sizeof(buf), "File opening %s", buf);
		error.fatal(buf, __FUNCTION__);
		goto END;
	}

	// SECTION 1
	// #requests, #depots, #vehicles
	fin >> nof.requests >> sep >> nof.depots >> sep >> nof.vehicles >> sep;

	// Check dimensions
	nof.nodes = 2 * nof.requests + nof.depots;
	nof.vehicle_types = 1;
	if (!checkdata())
		error.fatal("Maxinum code dimensions reached", __FUNCTION__);

	// Indices
	ind.first_depot = 2 * nof.requests + 1;
	ind.last_request = 2 * nof.requests;
	ind.first_delivery = nof.requests + 1;

	// SECTION 2
	for (k = 0; k < nof.vehicles; k++){
		// code, 	# seated capacity, # standing capacity, 	# seated capacity(disabled), # total passengers of the vehicle,	earliest time,	latest time, 	origin, 	destination
		fin >> v_vehicles[k].code >> sep >> v_vehicles[k].seated_capacity >> sep >> v_vehicles[k].standing_capacity >> sep >>
			v_vehicles[k].seated_disabled >> sep >> v_vehicles[k].total_passengers >> sep >>
			v_vehicles[k].v_slots_tw[k].e_time >> sep >> v_vehicles[k].v_slots_tw[k].l_time >> sep >> n_origin >> sep >>
			n_destination >> sep;
		v_vehicles[k].nof_slots_tw = 1;
		v_vehicles[k].node_origin = n_origin + 1;
		v_vehicles[k].node_destination = n_destination + 1;


		// Define type of capacity constraints
		// case a)
		//			Vehicle [seated_capacity+standing_capacity, seated_disabled]
		//			Customers: ABLE [x,0], DISABLED [k,x], ABLE+DISABLED [x,x] (request is DISABLED)

		// cases b) and c)
		//			Vehicle [seated_capacity, standing_capacity]
		//			Customers: ABLE [x,0], DISABLED [k,x], ABLE+DISABLED [x,x] (request is DISABLED)

		//				
		tot_capacity = v_vehicles[k].seated_capacity + v_vehicles[k].standing_capacity + v_vehicles[k].seated_disabled;
		if (tot_capacity == v_vehicles[k].total_passengers)
		{
			nof.dimensions = 2;
			v_vehicles[k].type_ccons = A;
			v_vehicles[k].v_capacities[k] = float(v_vehicles[k].seated_capacity + v_vehicles[k].standing_capacity);
			v_vehicles[k].v_capacities[1] = float(v_vehicles[k].seated_disabled);
		}
		else
		{
			nof.dimensions = 2;
			v_vehicles[k].type_ccons = B;
			v_vehicles[k].v_capacities[k] = (float)v_vehicles[k].seated_capacity;
			v_vehicles[k].v_capacities[1] = (float)v_vehicles[k].standing_capacity;
		}
		for (j = 1; j <= nof.nodes; j++)
			v_vehicles[k].v_objection_nodes[j] = 0;
		v_vehicles[k].type = 0;
	}

	// Vehicle type
	strcpy(v_vehicle_types[0].code, "");

	// SECTION 3
	// node number,	code, coordinate x,	coordinate y, earliest time, latest time,	service time, ride time, demand_able, demand_disabled, fixed, paired_request
	for (i = 1; i <= 2 * nof.requests; i++)
	{
		fin >> i_dummy >> sep >> code >> sep >> x >> sep >> y >> sep >> ei >> sep >> li >> sep >> st >> sep >> rt >> sep >> demand_able >> 
			sep >> demand_disabled >> sep >> fixed >> sep >> i_paired_request >> sep;
		//
		i_paired_request++; // request start from 1, input from 0
		// Define nodes
		strcpy(v_nodes[i].code, code);
		v_nodes[i].latitude = y / scalef;
		v_nodes[i].longitude = x / scalef;
		v_nodes[i].max_w_time = 0;
		v_nodes[i].s_time[0] = (int)st;
		v_nodes[i].tw.e_time = ei;
		v_nodes[i].tw.l_time = li;
		v_nodes[i].ride_time = (int)rt;
		v_nodes[i].priority = 0;
		if (i <= nof.requests){
			v_nodes[i].type = PICKUP;
			if (demand_able > 0 && demand_disabled == 0)
			{
				v_nodes[i].demand[0] = (float)demand_able;	// ABLE: index 0
				v_nodes[i].demand[1] = 0;
			}
			if (demand_able == 0 && demand_disabled > 0)
			{
				v_nodes[i].demand[1] = (float)demand_disabled;	// DISABLE: index 1
				v_nodes[i].demand[0] = 0;
			}
			if (demand_able > 0 && demand_disabled > 0)
			{
				v_nodes[i].demand[0] = (float)demand_able;	// ABLE: index 0
				v_nodes[i].demand[1] = (float)demand_disabled;		// DISABLED: index 1
			}
		}
		else{
			v_nodes[i].type = DELIVERY;
			v_nodes[i].demand[0] = -v_nodes[i - nof.requests].demand[0];
			v_nodes[i].demand[1] = -v_nodes[i - nof.requests].demand[1];
			v_nodes[i].priority = 0;
		}
		// v_nodes[i].demand; to be defined during the feasibility
		// Define the request
		if (i <= nof.requests){
			j = i - 1;
			strcpy(v_requests[j].code, code);
			v_requests[j].priority = 0;
			v_requests[j].ride_limit = (int)rt;
			v_requests[j].v_s_times_pickup[0] = st;
			v_requests[j].v_s_times_delivery[0] = st;
			v_requests[j].tw.e_time = ei;
			v_requests[j].tw.l_time = li;
			if (fixed==0)
				v_requests[j].fixed = false;
			else
				v_requests[j].fixed = true;
			v_requests[j].i_paired_request = i_paired_request;
			if (demand_able > 0 && demand_disabled == 0)
			{
				v_requests[j].type = ABLE;
				v_requests[j].demand[0] = (float)demand_able;
				v_requests[j].demand[1] = 0;
			}
			if (demand_able == 0 && demand_disabled > 0)
			{
				v_requests[j].type = DISABLED;
				v_requests[j].demand[1] = (float)demand_disabled;
				v_requests[j].demand[0] = 0;
			}
			if (demand_able > 0 && demand_disabled > 0)
			{
				v_requests[j].type = DISABLED;
				v_requests[j].demand[0] = (float)demand_able;
				v_requests[j].demand[1] = (float)demand_disabled;
			}
			for (k = 0; k < nof.vehicles; k++)
				v_requests[j].v_objection_vehicles[k] = 0;
			for (k = 0; k <= nof.requests; k++)
				v_requests[j].v_objection_requests[k] = 0;
		}
	}
	// SECTION 4
	// node number,	code, type
	nc = 0;
	for (i = 2 * nof.requests + 1; i <= nof.nodes; i++)
	{
		fin >> i_dummy >> sep >> code >> sep >> x >> sep >> y >> sep >> type >> sep;
		if (type == 0) v_depots[nc].type = VEHICLE_DEPOT;
		if (type == 1) v_depots[nc].type = PARKING_AREA;
		v_depots[nc].parking_capacity = 0;
		v_depots[nc].tw.e_time = 0;
		v_depots[nc].tw.l_time = 0;
		strcpy(v_depots[nc].code, code);
		// Define nodes
		strcpy(v_nodes[i].code, code);
		v_nodes[i].latitude		= y / scalef;
		v_nodes[i].longitude		= x / scalef;
		v_nodes[i].max_w_time	= 0;
		v_nodes[i].s_time[0]		= 0;
		v_nodes[i].tw.e_time		= 0;
		v_nodes[i].tw.l_time		= 0;
		v_nodes[i].ride_time		= 0;
		v_nodes[i].type			= v_depots[nc].type;
		v_nodes[i].priority		= 0;
	}
	// SECTION 5
	n_entries = (2 * nof.requests + nof.depots)*(2 * nof.requests + nof.depots) - (2 * nof.requests + nof.depots);
	for (k = 1; k <= n_entries; k++){
		fin >> i >> sep >> j >> sep >> distance >> sep >> time >> sep;
		m_dist[i + 1][j + 1][0] = distance;
		m_time[i + 1][j + 1][0] = time;
	}

	// Additional data
	cons_max_wtime_stops = 15 * 60;

	// Instance loaded
	flg_instance_loaded = true;
	//
END:;
	fin.close();
}
Ejemplo n.º 14
0
 void gamlr(int *famid, // 1 gaus, 2 bin, 3 pois
            int *n_in, // nobs 
            int *p_in, // nvar
            int *N_in, // length of nonzero x entries
            int *xi_in, // length-l row ids for nonzero x
            int *xp_in, // length-p+1 pointers to each column start
            double *xv_in, // nonzero x entry values
            double *y_in, // length-n y
            int *prexx, // indicator for pre-calc xx
            double *xxv_in, // dense columns of upper tri for xx
            double *eta, // length-n fixed shifts (assumed zero for gaussian)
            double *varweight, // length-p weights
            double *obsweight, // length-n weights
            int *standardize, // whether to scale penalty by sd(x_j)
            int *nlam, // length of the path
            double *delta, // path stepsize
            double *penscale,  // gamma in the GL paper
            double *thresh,  // cd convergence
            int *maxit, // cd max iterations 
            double *lambda, // output lambda
            double *deviance, // output deviance
            double *df, // output df
            double *alpha,  // output intercepts
            double *beta, // output coefficients
            int *exits, // exit status.  0 is normal
            int *verb) // talk? 
 {
  dirty = 1; // flag to say the function has been called
  // time stamp for periodic R interaction
  time_t itime = time(NULL);  

  /** Build global variables **/
  fam = *famid;
  n = *n_in;
  p = *p_in;
  nd = (double) n;
  pd = (double) p;
  N = *N_in;
  W = varweight;
  V = obsweight;

  E = eta;
  Y = y_in;
  xi = xi_in;
  xp = xp_in;
  xv = xv_in;

  doxx = *prexx;
  xxv = xxv_in;
  H = new_dvec(p);

  checkdata(*standardize);

  A=0.0;
  B = new_dzero(p);
  G = new_dzero(p);
  ag0 = new_dzero(p);
  gam = *penscale;

  npass = itertotal = 0;


  // some local variables
  double Lold, NLLHD, Lsat;
  int s;

  // family dependent settings
  switch( fam )
  {
    case 2:
      nllhd = &bin_nllhd;
      reweight = &bin_reweight;
      A = log(ybar/(1-ybar));
      Lsat = 0.0;
      break;
    case 3:
      nllhd = &po_nllhd;
      reweight = &po_reweight;
      A = log(ybar);
      // nonzero saturated deviance
      Lsat = ysum;
      for(int i=0; i<n; i++)
        if(Y[i]!=0) Lsat += -Y[i]*log(Y[i]);
      break;
    default: 
      fam = 1; // if it wasn't already
      nllhd = &lin_nllhd;
      A = (ysum - sum_dvec(eta,n))/nd;
      Lsat=0.0;
  }
  if(fam!=1){
    Z = new_dvec(n);
    vxbar = new_dvec(p);
    vxz = new_dvec(p);
  }
  else{ 
    Z = Y;
    vxz = new_dzero(p);
    if(V[0]!=0){
      vxbar = new_dvec(p);
      vstats();
    }
    else{
      vxbar = xbar; 
      vsum = nd;
      for(int j=0; j<p; j++)
        for(int i=xp[j]; i<xp[j+1]; i++)
            vxz[j] += xv[i]*Z[xi[i]]; 
    }
  }

  l1pen = INFINITY;
  Lold = INFINITY;
  NLLHD =  nllhd(n, A, E, Y);

  if(*verb)
    speak("*** n=%d observations and p=%d covariates ***\n", n,p);

  // move along the path
  for(s=0; s<*nlam; s++){

    // deflate the penalty
    if(s>0)
      lambda[s] = lambda[s-1]*(*delta);
    l1pen = lambda[s]*nd;

    // run descent
    exits[s] = cdsolve(*thresh,*maxit);

    // update parameters and objective
    itertotal += npass;
    Lold = NLLHD;
    NLLHD =  nllhd(n, A, E, Y);
    deviance[s] = 2.0*(NLLHD - Lsat);
    df[s] = dof(s, lambda, NLLHD);
    alpha[s] = A;
    copy_dvec(&beta[s*p],B,p);

    if(s==0) *thresh *= deviance[0]; // relativism
    
    // gamma lasso updating
    for(int j=0; j<p; j++) 
      if(isfinite(gam)){
        if( (W[j]>0.0) & isfinite(W[j]) )
          W[j] = 1.0/(1.0+gam*fabs(B[j]));
      } else if(B[j]!=0.0){
        W[j] = 0.0;
      }

    // verbalize
    if(*verb) 
      speak("segment %d: lambda = %.4g, dev = %.4g, npass = %d\n", 
          s+1, lambda[s], deviance[s], npass);

    // exit checks
    if(deviance[s]<0.0){
      exits[s] = 1;
      shout("Warning: negative deviance.  ");
    }
    if(df[s] >= nd){
      exits[s] = 1;
      shout("Warning: saturated model.  "); 
    }
    if(exits[s]){
      shout("Finishing path early.\n");
      *nlam = s; break; }

    itime = interact(itime); 
  }

  *maxit = itertotal;
  gamlr_cleanup();
}
Ejemplo n.º 15
0
double parton_alpha(double q){return  interAlpha(q,checkdata(21));}
Ejemplo n.º 16
0
static int Dgetmnotedata (lua_State *L) { /** data.mnotedata */
  ExifData *data = checkdata(L);
  pushmnote_data(L, exif_data_get_mnote_data(data));
  return 1;
}
Ejemplo n.º 17
0
static int Difds (lua_State *L) { /** data:ifds() */
  ExifData *data = checkdata(L);
  lua_newtable(L);
  exif_data_foreach_content(data, contentfunc, (void *)L);
  return 1;
}
Ejemplo n.º 18
0
static int Dfix (lua_State *L) { /** data:fix() */
  ExifData *data = checkdata(L);
  exif_data_fix(data);
  return 0;
}
Ejemplo n.º 19
0
int		checkfile(char *buffer)
{
	checkdata(buffer);
	checklines(buffer);
	return (0);
}
Ejemplo n.º 20
0
void udpthread::run()
{
    QByteArray temp;
    temp.resize(4);
    temp.fill(0x00, 4);
    int i = 0;
    unsigned short broad = 0;
    unsigned short channel = 0;
    unsigned short parameter = 0;
    unsigned int index = 0;
    unsigned short cmd = 0;
    while(flag) {
        /* 设备信息 */
        temp[1] = 0x10;
        temp[3] = 0x11;
        i = recv_data.indexOf(temp);
        if (i > 0 && checkdata(recv_data.mid(i - 2, 136))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            emit broadinfo(broad, recv_data.mid(i + 4, 128));
            recv_data.remove(0, i + 134);
        }
        /* 配置信息 */
        temp[1] = 0x11;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp);
        if (i > 0 && checkdata(recv_data.mid(i - 2, 8))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            emit configinfo(broad);
            recv_data.remove(0, i + 6);
        }
        /* adc通道实时信息 */
        temp[1] = 0x14;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp.mid(0, 2));
        if (i > 0 && checkdata(recv_data.mid(i - 2, 525))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            channel = (recv_data[i + 2] << 8) | recv_data[i + 3];
            index = (recv_data[i + 4] << 24) | (recv_data[i + 5] << 16) |
                    (recv_data[i + 6] << 8) | recv_data[i + 7];
            emit adcdata(broad, channel, index, recv_data.mid(i + 8, 512));
            recv_data.remove(0, i + 523);
        }
        /* sd卡信息 */
        temp[1] = 0x13;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp.mid(0, 2));
        if (i > 0 && checkdata(recv_data.mid(i - 2, 525))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            parameter = (recv_data[i + 2] << 8) | recv_data[i + 3];
            index = (recv_data[i + 4] << 24) | (recv_data[i + 5] << 16) |
                    (recv_data[i + 6] << 8) | recv_data[i + 7];
            emit sddata(broad, parameter, index, recv_data.mid(i + 8, 512));
            recv_data.remove(0, i + 523);
        }
        /* 固件下载起始应答 */
        temp[1] = 0x20;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp);
        if (i > 0 && checkdata(recv_data.mid(i - 2, 18))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            emit fireware_write_start_ack(broad);
            recv_data.remove(0, i + 16);
        }
        /* 固件下载请求下一个包 */
        temp[1] = 0x21;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp);
        if (i > 0 && checkdata(recv_data.mid(i - 2, 15))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            index = (recv_data[i + 4] << 40) | (recv_data[i + 5] << 32) |
                    (recv_data[i + 6] << 24) | (recv_data[i + 7] << 16) |
                    (recv_data[i + 8] << 8) | (recv_data[i + 9]);
            emit fireware_next_package_request(broad, index);
            recv_data.remove(0, i + 13);
        }
        /* 固件下载重新请求包 */
        temp[1] = 0x22;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp);
        if (i > 0 && checkdata(recv_data.mid(i - 2, 15))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            index = (recv_data[i + 4] << 40) | (recv_data[i + 5] << 32) |
                    (recv_data[i + 6] << 24) | (recv_data[i + 7] << 16) |
                    (recv_data[i + 8] << 8) | (recv_data[i + 9]);
            emit fireware_repeat_package_request(broad, index);
            recv_data.remove(0, i + 13);
        }
        /* 错误信息 */
        temp[1] = 0x50;
        temp[3] = 0x00;
        i = recv_data.indexOf(temp.mid(0, 2));
        if (i > 0 && checkdata(recv_data.mid(i - 2, 8))) {
            broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
            parameter = (recv_data[i + 2] << 8) | recv_data[i + 3];
            emit error(broad, cmd);
            recv_data.remove(0, i + 6);
        }
    }
    quit();
}