예제 #1
0
vector processZeros(vector data)
{
    bool needProcess = false;
    int start = 0;
    int end = 0;
    for (int i=0; i<data.x; i++)
    {
        end = i - 1;
        if (getv(data, i) != 0 && needProcess)
        {
            needProcess = false;
            for (int j=end; j>=start; j--)
            {
                setv(data, j, getv(data, i));
            }
        }
        else if (getv(data, i) == 0 && !needProcess)
        {
            start = i;
            needProcess = true;
        }
    }
    if (needProcess)
    {
        end++;
        for (int i=start; i<=end; i++)
        {
            setv(data, i, getv(data, start-1));
        }
    }
    return data;
}
예제 #2
0
/*
 * Re-markout segment by relative limit of segment max value
 */
Points relativeAlignSement(Points points, vector data, int relativeLimit, double scaleFactor)
{
    int pointIndex = points.pointsCount - 1;
    qDebug() << "relativeAlignSement" << LOG_DATA;
    uint32_t startPosition = points.pointsOffset[pointIndex] / scaleFactor;
    uint32_t stopPosition = startPosition + points.pointsLenght[pointIndex] / scaleFactor;

    qDebug() << "startPosition: " << startPosition << LOG_DATA;
    qDebug() << "stopPosition: " << stopPosition << LOG_DATA;

    // Look for max value
    double maxValue = 0.0;
    for (int i = startPosition; i<=stopPosition; i++)
    {
        double value = getv(data, i);
        if (maxValue < value)
            maxValue = value;
    }
    qDebug() << "maxValue: " << maxValue << LOG_DATA;

    // Calculate new absolute limit
    double limit = maxValue * relativeLimit / 100.0;
    qDebug() << "limit: " << limit << LOG_DATA;

    // Recalculate start segments border
    uint32_t newSegmentOffset = -1;
    for (uint32_t i = startPosition; i<=stopPosition || newSegmentOffset == -1; i++)
    {
        double value = getv(data, i);
        if (value > limit)
        {
            newSegmentOffset = i;
            break;
        }
    }

    // Recalculate stop segments border
    uint32_t newSegmentLenght = -1;
    for (uint32_t i = stopPosition; i>=startPosition || newSegmentLenght == -1; i--)
    {
        double value = getv(data, i);
        if (value > limit)
        {
            newSegmentLenght = i - newSegmentOffset;
            break;
        }
    }

    qDebug() << "pointsOffset: " << points.pointsOffset[pointIndex] << LOG_DATA;
    qDebug() << "pointsLenght: " << points.pointsLenght[pointIndex] << LOG_DATA;
    points.pointsOffset[pointIndex] = newSegmentOffset * scaleFactor;
    points.pointsLenght[pointIndex] = newSegmentLenght * scaleFactor;
    qDebug() << "pointsOffset: " << points.pointsOffset[pointIndex] << LOG_DATA;
    qDebug() << "pointsLenght: " << points.pointsLenght[pointIndex] << LOG_DATA;

    return points;
}
예제 #3
0
파일: Ans.cpp 프로젝트: niyuzheno1/CODES
pdd inser(int li1,int li2)
{
  double dk = a[li1].X-a[li2].X;
  double db = a[li2].Y-a[li1].Y;
  double x = db/dk; 
  return MP(x,getv(li1,x));
}
예제 #4
0
파일: Par.hpp 프로젝트: hust220/nsp
	pars_t getv(K &&s, V && ...pars) const {
		if (_pars.count(s)) {
			return _pars.at(s);
		}
		else {
			return getv(pars...);
		}
	}
예제 #5
0
const char *getMainArg(PCStr(where),PCStr(name)){
	const char *val;
	if( MAIN_argv ){
		if( val = getv(MAIN_argv,name) )
			return val;
	}
	return getenv(name);
}
예제 #6
0
파일: tabcell.c 프로젝트: brayc0/nlfetdb
static Any
getIf(Any cell, Name method, Any def)	/* can be optimised further */
{ Any rval;

  if ( hasGetMethodObject(cell, method) &&
       (rval = getv(cell, method, 0, NULL)) )
    answer(rval);

  answer(def);
}
예제 #7
0
static Any
getExecuteObtain(Obtain obt)
{ Any receiver;
  Name selector;
  Any rval = FAIL;
  void *savedcontext;

  if ( notNil(obt->context) &&
       TheCallbackFunctions.setHostContext )
  { savedcontext =
	(*TheCallbackFunctions.setHostContext)(obt->context);
  } else
    savedcontext = NIL;

  if ( !(receiver = expandCodeArgument(obt->receiver)) )
    goto out;
  if ( !(selector = checkSelector(obt->selector)) )
    goto out;

  if ( isNil(obt->arguments) )
  { rval = getv(receiver, selector, 0, NULL);
  } else
  { int n;
    int argc = valInt(obt->arguments->size);
    ArgVector(argv, argc);
    Any *elms = obt->arguments->elements;

    for(n = 0; n < argc; n++)
    { if ( !(argv[n] = expandCodeArgument(elms[n])) )
	goto out;
    }

    rval = getv(receiver, selector, argc, argv);
  }

out:
  if ( notNil(savedcontext) )
    (*TheCallbackFunctions.setHostContext)(savedcontext);

  return rval;
}
예제 #8
0
bool validateMask(vector mask)
{
    bool valid = false;
    for (int i=0; i<mask.x; i++)
    {
        if (getv(mask, i) == 1)
        {
            valid = true;
        }
    }
    return valid;
}
예제 #9
0
static void
sv_index_replace0(void)
{
	svindex i;
	t( sv_indexinit(&i) == 0 );

	uint32_t key = 7;
	svv *h = st_svv(&st_r.g, NULL, 0, 0, key);
	svv *n = st_svv(&st_r.g, NULL, 1, 0, key);

	t( sv_indexset(&i, &st_r.r, h) == 0 );
	t( sv_indexset(&i, &st_r.r, n) == 0 );

	svv *keyv = st_svv(&st_r.g, &st_r.gc, 0, 0, key);

	svv *p = getv(&i, &st_r.r, 0, keyv);
	t( p == h );

	p = getv(&i, &st_r.r, 1, keyv);
	t( p == n );
	t( h->next == NULL );

	sv_indexfree(&i, &st_r.r);
}
예제 #10
0
파일: tc.os.c 프로젝트: tcsh-org/tcsh
/*ARGSUSED*/
void
dover(Char **v, struct command *c)
{
    Char *p;

    setname(short2str(*v++));
    if (!*v) {
	if (!(p = tgetenv(STRSYSTYPE)))
	    stderror(ERR_NAME | ERR_STRING,
		     CGETS(23, 29, "System type is not set"));
	xprintf("%S\n", p);
    }
    else {
	tsetenv(STRSYSTYPE, getv(*v) ? STRbsd43 : STRsys53);
	dohash(NULL, NULL);
    }
}
예제 #11
0
/*
 * Get new relative limit of segment max value
 */
double getRelativeLimitForSement(uint32_t startPosition, uint32_t stopPosition, vector data, int relativeLimit)
{
    // Look for max value
    double maxValue = 0.0;
    double minValue = 1.0;
    for (int i = startPosition; i<=stopPosition; i++)
    {
        double value = getv(data, i);
        if (maxValue < value)
            maxValue = value;
        if (minValue > value)
            minValue = value;
    }
    qDebug() << "maxValue: " << maxValue << LOG_DATA;
    qDebug() << "minValue: " << minValue << LOG_DATA;

    // Calculate new absolute limit
    double limit = minValue + ((maxValue - minValue) * relativeLimit / 100.0);

    return limit;
}
예제 #12
0
파일: Ans.cpp 프로젝트: niyuzheno1/CODES
int main(int argc, char *argv[])
{
    setIO("sample");
    n = gi;
    for(int i = 1;i<=n;++i) a[i].Y = gi,sou[i] = i;
    for(int i = 1;i<=n;++i) a[i].X = gi;
    sort(sou+1,sou+1+n,cmp2);
    sort(a+1,a+n+1,cmp1);
    stk[++top] = 1;
    for(int i = 2;i<=n;++i)
    {
      if(dblcmp(a[stk[top]].X-a[i].X) == 0) continue;
      while(top)
      {
       pdd pu = inser(stk[top],i);
       if(pu.X<0) --top;
       else if(top >= 2 && pu.Y<getv(stk[top-1],pu.X)) --top;
       else break;
      }
      stk[++top] = i;
    }
    for(int i = 1;i<=top;++i)
    {
     int x = stk[i];
     for(int j = x;j<=n;++j)
      if(dblcmp(a[j].X - a[x].X) != 0 || dblcmp(a[j].Y - a[x].Y) != 0)
       break;
      else
       ans.pb(sou[j]);
    }
    sort(ans.begin(),ans.end());
    printf("%d\n",ans.size());
    for(int i = 0;i<ans.size()-1;++i)
     printf("%d ",ans[i]);
    printf("%d\n",ans[ans.size()-1]);
    closeIO();
    return EXIT_SUCCESS;
}
예제 #13
0
파일: iostream.c 프로젝트: brayc0/nlfetdb
static ssize_t
Sread_object(void *handle, char *buf, size_t size)
{ OpenObject h = handle;
  Any argv[2];
  CharArray sub;
  int chread;
  size_t advance;

  if ( isFreedObj(h->object) )
  { errno = EIO;
    return -1;
  }

  if ( h->encoding == ENC_WCHAR )
  { advance = size/sizeof(wchar_t);
  } else if ( h->encoding == ENC_OCTET )
  { advance = size;
  } else
  { assert(0);
    errno = EIO;
    return -1;
  }

  argv[0] = toInt(h->point);
  argv[1] = toInt(advance);

  if ( (sub = getv(h->object, NAME_readAsFile, 2, argv)) &&
       instanceOfObject(sub, ClassCharArray) )
  { String s = &sub->data;

    assert(s->size <= advance);

    if ( h->encoding == ENC_WCHAR )
    { if ( isstrA(s) )
      { charW *dest = (charW*)buf;
	const charA *f = s->s_textA;
	const charA *e = &f[s->size];

	while(f<e)
	  *dest++ = *f++;
      } else
      { memcpy(buf, s->s_textW, s->size*sizeof(charW));
      }
      chread = s->size * sizeof(wchar_t);
    } else
    { if ( isstrA(s) )
      { memcpy(buf, s->s_textA, s->size);
      } else
      { errno = EIO;
	chread = -1;
      }
      chread = s->size;
    }

    h->point += s->size;
  } else
  { errno = EIO;
    chread = -1;
  }

  return chread;
}
예제 #14
0
GraphData * ProcWave2Data(QString fname)
{
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    QFile file(fname);
    file.open(QIODevice::ReadOnly);
    WaveFile * waveFile = waveOpenHFile(file.handle());
    qDebug() << "waveOpenFile" << LOG_DATA;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "chunkDataSize" << LOG_DATA;
    short int bits = littleEndianBytesToUInt16(waveFile->formatChunk->significantBitsPerSample);
    qDebug() << "significantBitsPerSample" << LOG_DATA;

    vector wave = sptk_v2v(waveFile->dataChunk->waveformData, size, bits);
    qDebug() << "wave" << LOG_DATA;

    vector frame = sptk_frame(wave, sptk_settings->frame);
    qDebug() << "frame" << LOG_DATA;

    vector intensive = vector_intensive(frame, sptk_settings->frame->leng, sptk_settings->frame->shift);
    qDebug() << "intensive" << LOG_DATA;

    vector window = sptk_window(frame, sptk_settings->window);
    qDebug() << "window" << LOG_DATA;

    vector lpc = sptk_lpc(frame, sptk_settings->lpc);
    qDebug() << "lpc" << LOG_DATA;

    vector spec = sptk_spec(lpc, sptk_settings->spec);
    qDebug() << "spec " << maxv(spec) << LOG_DATA;

    vector spec_proc;
    if (sptk_settings->spec->proc == 0){
        spec_proc = vector_pow_log(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_log" << LOG_DATA;
    } else if (sptk_settings->spec->proc == 1){
        spec_proc = vector_pow_exp(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_exp" << LOG_DATA;
    }
    qDebug() << "spec_proc " << maxv(spec_proc) << LOG_DATA;

    vector pitch = processZeros(sptk_pitch_spec(wave, sptk_settings->pitch, intensive.x));
    qDebug() << "pitch" << LOG_DATA;

    vector mask = getFileMask(waveFile, wave, pitch.x);
    qDebug() << "mask" << LOG_DATA;

    vector pitch_cutted = processZeros(vector_cut_by_mask(pitch, mask));
    qDebug() << "pitch_cutted" << LOG_DATA;
    double pitch_min = getv(pitch_cutted, minv(pitch_cutted));
    double pitch_max = getv(pitch_cutted, maxv(pitch_cutted));

    vector intensive_cutted = vector_cut_by_mask(intensive, mask);
    qDebug() << "intensive_cutted" << LOG_DATA;

    vector inverted_mask = vector_invert_mask(mask);
    qDebug() << "inverted_mask" << LOG_DATA;

    vector pitch_interpolate = vector_interpolate_by_mask(
                pitch_cutted,
                inverted_mask,
                0,
                sptk_settings->plotF0->interpolation_type
                );
    qDebug() << "pitch_interpolate" << LOG_DATA;

    vector intensive_interpolate = vector_interpolate_by_mask(
                intensive_cutted,
                inverted_mask,
                0,
                sptk_settings->plotEnergy->interpolation_type
                );
    qDebug() << "intensive_interpolate" << LOG_DATA;

    vector pitch_mid = vector_smooth_mid(pitch_interpolate, sptk_settings->plotF0->frame);
    qDebug() << "pitch_mid" << LOG_DATA;

    vector intensive_mid = vector_smooth_lin(intensive_interpolate, sptk_settings->plotEnergy->frame);
    qDebug() << "intensive_mid" << LOG_DATA;

    vector norm_wave = normalizev(wave, 0.0, 1.0);

    MaskData md_p = getLabelsFromFile(waveFile, MARK_PRE_NUCLEUS);
    MaskData md_n = getLabelsFromFile(waveFile, MARK_NUCLEUS);
    MaskData md_t = getLabelsFromFile(waveFile, MARK_POST_NUCLEUS);

    vector p_mask = readMaskFromFile(waveFile, wave.x, MARK_PRE_NUCLEUS);
    qDebug() << "p_mask" << LOG_DATA;

    vector n_mask = readMaskFromFile(waveFile, wave.x, MARK_NUCLEUS);
    qDebug() << "n_mask" << LOG_DATA;

    vector t_mask = readMaskFromFile(waveFile, wave.x, MARK_POST_NUCLEUS);
    qDebug() << "t_mask" << LOG_DATA;

    vector p_wave = zero_to_nan(vector_cut_by_mask(norm_wave, p_mask));
    qDebug() << "p_mask" << LOG_DATA;

    vector n_wave = zero_to_nan(vector_cut_by_mask(norm_wave, n_mask));
    qDebug() << "n_mask" << LOG_DATA;

    vector t_wave = zero_to_nan(vector_cut_by_mask(norm_wave, t_mask));
    qDebug() << "t_mask" << LOG_DATA;

    vector pnt_mask = onesv(norm_wave.x);
    for (int i=0; i<p_mask.x && i<n_mask.x && i<t_mask.x && i<norm_wave.x; i++) {
        if (getv(p_mask, i) == 1 || getv(n_mask, i) == 1 || getv(t_mask, i) == 1)
        {
            setv(pnt_mask, i, 0);
        } else {
            setv(pnt_mask, i, 1);
        }
    }

    vector display_wave = zero_to_nan(vector_cut_by_mask(norm_wave, pnt_mask));

    freev(frame);
    freev(window);
    freev(lpc);
    freev(pitch_cutted);
    freev(intensive_cutted);
    freev(inverted_mask);
    freev(pitch_interpolate);
    freev(intensive_interpolate);
    freev(wave);
    qDebug() << "freev" << LOG_DATA;

    file.close();
    waveCloseFile(waveFile);
    qDebug() << "waveCloseFile" << LOG_DATA;

    GraphData * data = new GraphData();

    data->d_full_wave = norm_wave;
    data->d_wave = display_wave;
    data->d_p_wave = p_wave;
    data->d_n_wave = n_wave;
    data->d_t_wave = t_wave;
    data->d_pitch_original = pitch;
    data->d_pitch = pitch_mid;
    data->pitch_max = pitch_max;
    data->pitch_min = pitch_min;
    data->d_intensive_original = intensive;
    data->d_intensive = intensive_mid;
    data->d_spec_proc = spec_proc;
    data->d_spec = spec;
    data->d_mask = mask;
    data->p_mask = p_mask;
    data->n_mask = n_mask;
    data->t_mask = t_mask;
    data->pnt_mask = pnt_mask;

    data->md_p = md_p;
    data->md_t = md_t;
    data->md_n = md_n;

    return data;
}
예제 #15
0
static void advance(struct rnc_source *sp) {
  sp->cur=!sp->cur;
  for(;;) {
    NXT(sp).line=sp->line; NXT(sp).col=sp->col;
    if(newline(sp->v)||whitespace(sp->v)) {getv(sp); continue;}
    switch(sp->v) {
    case -1: NXT(sp).sym=SYM_EOF; return;
    case '#':
      getv(sp);
      if(sp->v=='#') {
	int i=0;
	for(;;) {
	  do getv(sp); while(sp->v=='#');
	  if(whitespace(sp->v)) getv(sp);
	  for(;;) {
	    if(i+U_MAXLEN>NXT(sp).slen) realloc_s(&NXT(sp),2*(i+U_MAXLEN));
	    if(newline(sp->v)) {
	      do getv(sp); while(whitespace(sp->v));
	      if(sp->v=='#') {getv(sp);
		if(sp->v=='#') {NXT(sp).s[i++]='\n'; break;}
		skip_comment(sp);
	      }
	      NXT(sp).s[i]=0; NXT(sp).sym=SYM_DOCUMENTATION; return;
	    } else i+=u_put(NXT(sp).s+i,sp->v);
	    getv(sp);
	  }
	}
      } else {skip_comment(sp); continue;}
    case '=': getv(sp); NXT(sp).sym=SYM_ASGN; return;
    case ',': getv(sp); NXT(sp).sym=SYM_GROUP; return;
    case '|': getv(sp);
      if(sp->v=='=') {
	getv(sp); NXT(sp).sym=SYM_ASGN_CHOICE; return;
      } NXT(sp).sym=SYM_CHOICE; return;
    case '&': getv(sp);
      if(sp->v=='=') {getv(sp); NXT(sp).sym=SYM_ASGN_ILEAVE;} else NXT(sp).sym=SYM_ILEAVE; return;
    case '?': getv(sp); NXT(sp).sym=SYM_OPTIONAL; return;
    case '*': getv(sp); NXT(sp).sym=SYM_ZERO_OR_MORE; return; /* SYM_ANY_NAME */
    case '+': getv(sp); NXT(sp).sym=SYM_ONE_OR_MORE; return;
    case '-': getv(sp); NXT(sp).sym=SYM_EXCEPT; return;
    case '~': getv(sp); NXT(sp).sym=SYM_CONCAT; return;	
    case '(': getv(sp); NXT(sp).sym=SYM_LPAR; return;
    case ')': getv(sp); NXT(sp).sym=SYM_RPAR; return;
    case '{': getv(sp); NXT(sp).sym=SYM_LCUR; return;
    case '}': getv(sp); NXT(sp).sym=SYM_RCUR; return;
    case '[': getv(sp); NXT(sp).sym=SYM_LSQU; return;
    case ']': getv(sp); NXT(sp).sym=SYM_RSQU; return;
    case '>': getv(sp);
      if(sp->v!='>') error(0,sp,RNC_ER_LEXP,sp->fn,sp->line,sp->col,'>');
      getv(sp); NXT(sp).sym=SYM_FOLLOW_ANNOTATION; return;
    case '"': case '\'':
      { int q=sp->v;
	int triple=0;
	int i=0;
	getv(sp);
	if(sp->v==q) {getv(sp);
	  if(sp->v==q) { /* triply quoted string */
	    triple=1; getv(sp);
	  } else {
	    NXT(sp).s[0]='\0'; NXT(sp).sym=SYM_LITERAL; return;
	  }
	}
	for(;;) {
	  if(sp->v==q) {
	    if(triple) {
	      if(i>=2 && NXT(sp).s[i-2]==q && NXT(sp).s[i-1]==q) {
		NXT(sp).s[i-2]='\0'; break;
	      } else i+=u_put(NXT(sp).s+i,sp->v);
	    } else {NXT(sp).s[i]='\0'; break;}
	  } else if(sp->v<=0) {
	    if(sp->v==-1 || !triple) {
	      error(0,sp,RNC_ER_LLIT,sp->fn,sp->line,sp->col);
	      NXT(sp).s[i]='\0'; break;
	    } else NXT(sp).s[i++]='\n';
	  } else i+=u_put(NXT(sp).s+i,sp->v);
	  getv(sp);
	  if(i+U_MAXLEN>NXT(sp).slen) realloc_s(&NXT(sp),2*(i+U_MAXLEN));
	}
	getv(sp); NXT(sp).sym=SYM_LITERAL; return;
      }
    default:
      { int escaped=0,prefixed=0;
	if(sp->v=='\\') {escaped=1; getv(sp);}
	if(name_start(sp->v)) {
	  int i=0;
	  for(;;) {
	    i+=u_put(NXT(sp).s+i,sp->v);
	    if(i+U_MAXLEN>NXT(sp).slen) realloc_s(&NXT(sp),2*(i+U_MAXLEN));
	    getv(sp);
	    if(!name_char(sp->v)) {NXT(sp).s[i]='\0'; break;}
	    if(sp->v==':') prefixed=1;
	  }
	  if(!(escaped||prefixed)) {
	    int kwd;
	    if((kwd=s_tab(NXT(sp).s,kwdtab,NKWD))!=NKWD) {
	      NXT(sp).sym=kwd;
	      return;
	    }
	  }
	  if(prefixed) {
	    if(NXT(sp).s[i-1]==':'&&sp->v=='*') {
	      getv(sp); NXT(sp).s[i-1]='\0';
	      NXT(sp).sym=SYM_NSNAME;
	    } else NXT(sp).sym=SYM_QNAME;
	  } else NXT(sp).sym=SYM_IDENT;
	  return;
	} else {
	  error(0,sp,RNC_ER_LILL,sp->fn,sp->line,sp->col,sp->v);
	  getv(sp);
	  continue;
	}
      }	
    }
  }
}
예제 #16
0
int
main(int argc, char *argv[])
{
  struct QOP_MDWF_State *mdwf_state = NULL;
  QMP_thread_level_t qt = QMP_THREAD_SINGLE;
  int status = 1;
  int vx[4];
  int i;

  if (QMP_init_msg_passing(&argc, &argv, qt, &qt) != QMP_SUCCESS) {
    fprintf(stderr, "QMP_init() failed\n");
    return 1;
  }

  for (i = 0; i < NELEM(b5); i++) {
    b5[i] = 0.1 * i * (NELEM(b5) - i);
    c5[i] = 0.1 * i * i * (NELEM(b5) - i);
  }

  self = QMP_get_node_number();
  primary = QMP_is_primary_node();
  for (i = 0; i < argc; i++)
    zprint("arg[%d]=%s", i, argv[i]);
  if (argc != 14) {
    zprint("14 arguments expected, found %d", argc);
    QMP_finalize_msg_passing();
    return 1;
  }

  for (i = 0; i < 4; i++) {
    mynetwork[i] = atoi(argv[i+1]);
    mylocal[i] = atoi(argv[i+5]);
    vx[i] = atoi(argv[i+10]);
    mylattice[i] = mylocal[i] * mynetwork[i];
  }
  mylocal[4] = mylattice[4] = atoi(argv[9]);

  zshowv4("network", mynetwork);
  zshowv5("local lattice", mylocal);
  zshowv5("lattice", mylattice);

  getv(mynode, 0, 4, vx);

  xshowv("node", mynode);

  if (QOP_MDWF_init(&mdwf_state,
		    mylattice, mynetwork, mynode, primary,
		    getsub, NULL)) {
    zprint("MDWF_init() failed");
    goto end;
  }

  zprint("MDWF_init() done");

  dump_state(mdwf_state);

  QOP_MDWF_fini(&mdwf_state);

  status = 0;
 end:
  QMP_finalize_msg_passing();
  return status;
}
예제 #17
0
int
main(int argc, char *argv[])
{
  struct QOP_MDWF_State *mdwf_state = NULL;
  struct QOP_MDWF_Parameters *mdwf_params = NULL;
  QMP_thread_level_t qt = QMP_THREAD_SINGLE;
  int status = 1;
  int i;

  if (QMP_init_msg_passing(&argc, &argv, qt, &qt) != QMP_SUCCESS) {
    fprintf(stderr, "QMP_init() failed\n");
    return 1;
  }

  for (i = 0; i < NELEM(b5); i++) {
    b5[i] = 0.1 * i * (NELEM(b5) - i);
    c5[i] = 0.1 * i * i * (NELEM(b5) - i);
  }

  self = QMP_get_node_number();
  primary = QMP_is_primary_node();
  if (argc != 7) {
    zprint("7 arguments expected, found %d", argc);
    zprint("usage: localheat Lx Ly Lz Lt Ls time");
    QMP_finalize_msg_passing();
    return 1;
  }

  for (i = 0; i < 4; i++) {
    mynetwork[i] = 1;
    mylocal[i] = atoi(argv[i+1]);
    mylattice[i] = mylocal[i] * mynetwork[i];
  }
  mylocal[4] = mylattice[4] = atoi(argv[5]);
  total_sec = atoi(argv[6]);

  zshowv4("network", mynetwork);
  zshowv5("local lattice", mylocal);
  zshowv5("lattice", mylattice);
  zprint("total requested runtime %.0f sec", total_sec);

#if 0
  if (QMP_declare_logical_topology(mynetwork, 4) != QMP_SUCCESS) {
    zprint("declare_logical_top failed");
    goto end;
  }

  getv(mynode, 0, QMP_get_logical_number_of_dimensions(),
       QMP_get_logical_coordinates());
#else
  { int i;
    for (i = 0; i < 4; i++)
       mynode[i] = 0;
  }
#endif

  if (QOP_MDWF_init(&mdwf_state,
		    mylattice, mynetwork, mynode, primary,
		    getsub, NULL)) {
    zprint("MDWF_init() failed");
    goto end;
  }

  zprint("MDWF_init() done");

  if (QOP_MDWF_set_generic(&mdwf_params, mdwf_state, b5, c5, 0.123, 0.05)) {
    zprint("MDW_set_generic() failed");
    goto end;
  }
  zprint("MDWF_set_generic() done");

  if (do_run(mdwf_state, mdwf_params)) {
    zprint("float test failed");
    goto end;
  }

  QOP_MDWF_fini(&mdwf_state);

  zprint("Heater test finished");
  status = 0;
 end:
  QMP_finalize_msg_passing();
  return status;
}
예제 #18
0
static void exp3g(int n0, cgraph ** c)
{
    int       n1, n2, n4, n5;
    int       e04, e05, e45;
    cgraph * cg=*c;

    /* expand 3G vertex (see figure) - 08/01/90  */
    /* 14/03/99: Check tadpole before expanding */

#  if (CDEBLEV > DEBLEV)
    fprintf(stderr,".......Exp3G........\n");
#  endif

    n1 = findl(1,n0,cg);
    if (istadpole(n0,cg) || istadpole(n1,cg))
    {
        cg->sgn=0;
        cg->gl = 0;
        cg->vl[n0-1].vt = zv;
        cg->vl[n1-1].vt = zv;
#     if (CDEBLEV > DEBLEV)
        wrcg(cg);
#     endif
        return;
    }
    n1 = findl(1,n0,cg);      /*      v0            v4  v5     */
    n2 = findl(2,n0,cg);      /*  v1..*...v2    v1..*-<-*..v2  */
    /*      :              \ /       */
    n4 = getv(cg);            /*      :      ->       *v0      */
    e45 = ++(cg->en);         /*      :               :        */
    e04 = ++(cg->en);         /*      v3              v3       */
    cg->vl[n4-1].vt = qg;
    if (cg->vl[n1-1].vt == g3)
        rev3g(cg->vl[n0-1].e[0],&cg->vl[n1-1]);
    cg->vl[n4-1].e[0] = cg->vl[n1-1].e[0];
    cg->vl[n4-1].e[1] = e45;
    cg->vl[n4-1].e[2] = e04;
    n5 = getv(cg);
    e05 = ++(cg->en);
    cg->vl[n5-1].vt = qg;
    if (cg->vl[n2-1].vt == g3)
        rev3g(cg->vl[n0-1].e[1],&cg->vl[n2-1]);
    cg->vl[n5-1].e[0] = cg->vl[n2-1].e[0];
    cg->vl[n5-1].e[1] = e05;
    cg->vl[n5-1].e[2] = e45;
    rev3g(cg->vl[n0-1].e[2],&cg->vl[n0-1]);
    cg->vl[n0-1].vt = qg;
    cg->vl[n0-1].e[1] = e04;
    cg->vl[n0-1].e[2] = e05;
    cg->sgn*=-1;
    cg->pow2++;

    cg=addcg(c);   /*  Second term  */
    cg->vl[n0-1].e[1] = e05;
    cg->vl[n0-1].e[2] = e04;
    cg->vl[n4-1].e[1] = e04;
    cg->vl[n4-1].e[2] = e45;
    cg->vl[n5-1].e[1] = e45;
    cg->vl[n5-1].e[2] = e05;
    cg->sgn*=-1;

#  if (CDEBLEV > DEBLEV)
    wrcg(cg);
    wrcg(cg->next);
    fprintf(stderr,".......end Exp3G........\n");
#  endif
}  /* Exp3G */
예제 #19
0
파일: sh.sem.c 프로젝트: lukem/tcsh
/*VARARGS 1*/
void
execute(struct command *t, volatile int wanttty, int *pipein, int *pipeout,
    int do_glob)
{
    int    forked = 0;
    const struct biltins * volatile bifunc;
    pid_t pid = 0;
    int     pv[2];
    sigset_t set;
    static sigset_t csigset;
#ifdef VFORK
    static int onosigchld = 0;
#endif /* VFORK */
    static int nosigchld = 0;

    (void) &wanttty;
    (void) &forked;
    (void) &bifunc;

    if (t == 0) 
	return;

#ifdef WINNT_NATIVE
    {
        if ((varval(STRNTslowexec) == STRNULL) &&
            !t->t_dcdr && !t->t_dcar && !t->t_dflg && !didfds &&
            (intty || intact) && (t->t_dtyp == NODE_COMMAND) &&
	    !isbfunc(t)) {
	    if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
		(void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1);
	    Dfix(t);
            if (nt_try_fast_exec(t) == 0)
                return;
        }
    }
#endif /* WINNT_NATIVE */

    /*
     * Ed [email protected] & Dominic [email protected]
     * Sat Feb 25 03:13:11 PST 1995
     * try implicit cd if we have a 1 word command 
     */
    if (implicit_cd && (intty || intact) && t->t_dcom && t->t_dcom[0] &&
	 t->t_dcom[0][0] && (blklen(t->t_dcom) == 1) && !noexec) {
	Char *sCName;
	struct stat stbuf;
	char *pathname;

	sCName = dollar(t->t_dcom[0]);
	if (sCName != NULL && sCName[0] == '~') {
	    struct Strbuf buf = Strbuf_INIT;
	    const Char *name_end;

	    for (name_end = sCName + 1; *name_end != '\0' && *name_end != '/';
		 name_end++)
		continue;
	    if (name_end != sCName + 1) {
		Char *name, *home;

		name = Strnsave(sCName + 1, name_end - (sCName + 1));
		home = gethdir(name);
		if (home != NULL) {
		    Strbuf_append(&buf, home);
		    xfree(home);
		} else
		    Strbuf_append(&buf, name);
		xfree(name);
	    } else
		Strbuf_append(&buf, varval(STRhome));
	    Strbuf_append(&buf, name_end);
	    xfree(sCName);
	    sCName = Strbuf_finish(&buf);
	}

	pathname = short2str(sCName);
	xfree(sCName);
	/* if this is a dir, tack a "cd" on as the first arg */
	if (pathname != NULL &&
	    ((stat(pathname, &stbuf) != -1 && S_ISDIR(stbuf.st_mode))
#ifdef WINNT_NATIVE
	     || (pathname[0] && pathname[1] == ':' && pathname[2] == '\0')
#endif /* WINNT_NATIVE */
	     )) {
	    Char *vCD[2];
	    Char **ot_dcom = t->t_dcom;
	
	    vCD[0] = Strsave(STRcd);
	    vCD[1] = NULL;
	    t->t_dcom = blkspl(vCD, ot_dcom);
	    xfree(ot_dcom);
	    if (implicit_cd > 1) {
		blkpr(t->t_dcom);
		xputchar( '\n' );
	    }
	}
    }

    /*
     * From: Michael Schroeder <*****@*****.**>
     * Don't check for wantty > 0...
     */
    if (t->t_dflg & F_AMPERSAND)
	wanttty = 0;
    switch (t->t_dtyp) {

    case NODE_COMMAND:
	if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
	    memmove(t->t_dcom[0], t->t_dcom[0] + 1,
		    (Strlen(t->t_dcom[0] + 1) + 1) * sizeof (*t->t_dcom[0]));
	if ((t->t_dflg & F_REPEAT) == 0)
	    Dfix(t);		/* $ " ' \ */
	if (t->t_dcom[0] == 0) {
	    return;
	}
	/*FALLTHROUGH*/

    case NODE_PAREN:
#ifdef BACKPIPE
	if (t->t_dflg & F_PIPEIN)
	    mypipe(pipein);
#else /* !BACKPIPE */
	if (t->t_dflg & F_PIPEOUT)
	    mypipe(pipeout);
#endif /* BACKPIPE */
	/*
	 * Must do << early so parent will know where input pointer should be.
	 * If noexec then this is all we do.
	 */
	if (t->t_dflg & F_READ) {
	    xclose(0);
	    heredoc(t->t_dlef);
	    if (noexec)
		xclose(0);
	}

	setcopy(STRstatus, STR0, VAR_READWRITE);

	/*
	 * This mess is the necessary kludge to handle the prefix builtins:
	 * nice, nohup, time.  These commands can also be used by themselves,
	 * and this is not handled here. This will also work when loops are
	 * parsed.
	 */
	while (t->t_dtyp == NODE_COMMAND)
	    if (eq(t->t_dcom[0], STRnice)) {
		if (t->t_dcom[1]) {
		    if (strchr("+-", t->t_dcom[1][0])) {
			if (t->t_dcom[2]) {
			    setname("nice");
			    t->t_nice = (unsigned char)getn(t->t_dcom[1]);
			    lshift(t->t_dcom, 2);
			    t->t_dflg |= F_NICE;
			}
			else
			    break;
		    }
		    else {
			t->t_nice = 4;
			lshift(t->t_dcom, 1);
			t->t_dflg |= F_NICE;
		    }
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRnohup)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_NOHUP;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRhup)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_HUP;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRtime)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_TIME;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
#ifdef F_VER
	    else if (eq(t->t_dcom[0], STRver))
		if (t->t_dcom[1] && t->t_dcom[2]) {
		    setname("ver");
		    t->t_systype = getv(t->t_dcom[1]);
		    lshift(t->t_dcom, 2);
		    t->t_dflg |= F_VER;
		}
		else
		    break;
#endif  /* F_VER */
	    else
		break;

	/* is it a command */
	if (t->t_dtyp == NODE_COMMAND) {
	    /*
	     * Check if we have a builtin function and remember which one.
	     */
	    bifunc = isbfunc(t);
 	    if (noexec) {
		/*
		 * Continue for builtins that are part of the scripting language
		 */
		if (bifunc == NULL)
		    break;
		if (bifunc->bfunct != (bfunc_t)dobreak	&&
		    bifunc->bfunct != (bfunc_t)docontin	&&
		    bifunc->bfunct != (bfunc_t)doelse	&&
		    bifunc->bfunct != (bfunc_t)doend	&&
		    bifunc->bfunct != (bfunc_t)doforeach&&
		    bifunc->bfunct != (bfunc_t)dogoto	&&
		    bifunc->bfunct != (bfunc_t)doif	&&
		    bifunc->bfunct != (bfunc_t)dorepeat	&&
		    bifunc->bfunct != (bfunc_t)doswbrk	&&
		    bifunc->bfunct != (bfunc_t)doswitch	&&
		    bifunc->bfunct != (bfunc_t)dowhile	&&
		    bifunc->bfunct != (bfunc_t)dozip)
		    break;
	    }
	}
	else {			/* not a command */
	    bifunc = NULL;
	    if (noexec)
		break;
	}

	/* 
	 * GrP Executing a command - run jobcmd hook
	 * Don't run for builtins
	 * Don't run if we're not in a tty
	 * Don't run if we're not really executing 
	 */
	/*
	 * CR  -  Charles Ross Aug 2005
	 * added "isoutatty".
	 * The new behavior is that the jobcmd won't be executed
	 * if stdout (SHOUT) isnt attached to a tty.. IE when
	 * redirecting, or using backquotes etc..
	 */
	if (t->t_dtyp == NODE_COMMAND && !bifunc && !noexec && intty && isoutatty) {
	    Char *cmd = unparse(t);

	    cleanup_push(cmd, xfree);
	    job_cmd(cmd);
	    cleanup_until(cmd);
	}
	   
	/*
	 * We fork only if we are timed, or are not the end of a parenthesized
	 * list and not a simple builtin function. Simple meaning one that is
	 * not pipedout, niced, nohupped, or &'d. It would be nice(?) to not
	 * fork in some of these cases.
	 */
#ifdef BACKPIPE
	/*
	 * Can't have NOFORK for the tail of a pipe - because it is not the
	 * last command spawned (even if it is at the end of a parenthesised
	 * list).
	 */
	if (t->t_dflg & F_PIPEIN)
	    t->t_dflg &= ~(F_NOFORK);
#else
	/*
	 * "command | builtin" may cause major misbehaviour as noted in
	 * in the BUGS file entry
	 * Subject: Redirected input to built-in functions misbehaves badly
	 * forking when the builtin is the end of the pipe corrects the
	 * problem.
	 */
	if (bifunc && (t->t_dflg & F_PIPEIN))
	    t->t_dflg &= ~(F_NOFORK);
#endif /* BACKPIPE */
	/*
	 * Prevent forking cd, pushd, popd, chdir cause this will cause the
	 * shell not to change dir! (XXX: but only for nice?)
	 */
	if (bifunc && (bifunc->bfunct == (bfunc_t)dochngd ||
		       bifunc->bfunct == (bfunc_t)dopushd ||
		       bifunc->bfunct == (bfunc_t)dopopd))
	    t->t_dflg &= ~(F_NICE);

	if (((t->t_dflg & F_TIME) || ((t->t_dflg & F_NOFORK) == 0 &&
	     (!bifunc || t->t_dflg &
	      (F_PIPEOUT | F_AMPERSAND | F_NICE | F_NOHUP | F_HUP)))) ||
	/*
	 * We have to fork for eval too.
	 */
	    (bifunc && (t->t_dflg & F_PIPEIN) != 0 &&
	     bifunc->bfunct == (bfunc_t)doeval)) {
#ifdef VFORK
	    if (t->t_dtyp == NODE_PAREN ||
		t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc)
#endif /* VFORK */
	    {
		forked++;
		/*
		 * We need to block SIGCHLD here, so that if the process does
		 * not die before we can set the process group
		 */
		if (wanttty >= 0 && !nosigchld) {
		    sigemptyset(&set);
		    sigaddset(&set, SIGCHLD);
		    (void)sigprocmask(SIG_BLOCK, &set, &csigset);

		    nosigchld = 1;
		}

		pid = pfork(t, wanttty);
		if (pid == 0 && nosigchld) {
		    sigprocmask(SIG_SETMASK, &csigset, NULL);
		    nosigchld = 0;
		}
		else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
		    backpid = pid;
	    }

#ifdef VFORK
	    else {
		int     ochild, osetintr, ohaderr, odidfds;
		int     oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
		int     oisoutatty, oisdiagatty;
		sigset_t oset, ocsigset;
# ifndef CLOSE_ON_EXEC
		int     odidcch;
# endif  /* !CLOSE_ON_EXEC */

		/*
		 * Prepare for the vfork by saving everything that the child
		 * corrupts before it exec's. Note that in some signal
		 * implementations which keep the signal info in user space
		 * (e.g. Sun's) it will also be necessary to save and restore
		 * the current sigvec's for the signals the child touches
		 * before it exec's.
		 */

		/*
		 * Sooooo true... If this is a Sun, save the sigvec's. (Skip
		 * Gilbrech - 11/22/87)
		 */
# ifdef SAVESIGVEC
		struct sigaction savesv[NSIGSAVED];
		sigset_t savesm;

# endif /* SAVESIGVEC */
		if (wanttty >= 0 && !nosigchld && !noexec) {
		    sigemptyset(&set);
		    sigaddset(&set, SIGCHLD);
		    (void)sigprocmask(SIG_BLOCK, &set, &csigset);
		    nosigchld = 1;
		}
		sigemptyset(&set);
		sigaddset(&set, SIGCHLD);
		sigaddset(&set, SIGINT);
		(void)sigprocmask(SIG_BLOCK, &set, &oset);
		ochild = child;
		osetintr = setintr;
		ohaderr = haderr;
		odidfds = didfds;
# ifndef CLOSE_ON_EXEC
		odidcch = didcch;
# endif /* !CLOSE_ON_EXEC */
		oSHIN = SHIN;
		oSHOUT = SHOUT;
		oSHDIAG = SHDIAG;
		oOLDSTD = OLDSTD;
		otpgrp = tpgrp;
		oisoutatty = isoutatty;
		oisdiagatty = isdiagatty;
		ocsigset = csigset;
		onosigchld = nosigchld;
		Vsav = Vdp = 0;
		Vexpath = 0;
		Vt = 0;
# ifdef SAVESIGVEC
		savesigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		if (use_fork)
		    pid = fork();
		else
		    pid = vfork();

		if (pid < 0) {
# ifdef SAVESIGVEC
		    restoresigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		    sigprocmask(SIG_SETMASK, &oset, NULL);
		    stderror(ERR_NOPROC);
		}
		forked++;
		if (pid) {	/* parent */
# ifdef SAVESIGVEC
		    restoresigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		    child = ochild;
		    setintr = osetintr;
		    haderr = ohaderr;
		    didfds = odidfds;
		    SHIN = oSHIN;
# ifndef CLOSE_ON_EXEC
		    didcch = odidcch;
# endif /* !CLOSE_ON_EXEC */
		    SHOUT = oSHOUT;
		    SHDIAG = oSHDIAG;
		    OLDSTD = oOLDSTD;
		    tpgrp = otpgrp;
		    isoutatty = oisoutatty;
		    isdiagatty = oisdiagatty;
		    csigset = ocsigset;
		    nosigchld = onosigchld;

		    xfree(Vsav);
		    Vsav = 0;
		    xfree(Vdp);
		    Vdp = 0;
		    xfree(Vexpath);
		    Vexpath = 0;
		    blk_cleanup(Vt);
		    Vt = 0;
		    /* this is from pfork() */
		    palloc(pid, t);
		    sigprocmask(SIG_SETMASK, &oset, NULL);
		}
		else {		/* child */
		    /* this is from pfork() */
		    pid_t pgrp;
		    int    ignint = 0;
		    if (nosigchld) {
			sigprocmask(SIG_SETMASK, &csigset, NULL);
			nosigchld = 0;
		    }

		    if (setintr)
			ignint = (tpgrp == -1 && (t->t_dflg & F_NOINTERRUPT))
				|| (gointr && eq(gointr, STRminus));
		    pgrp = pcurrjob ? pcurrjob->p_jobid : getpid();
		    child++;
		    if (setintr) {
			setintr = 0;
/*
 * casts made right for SunOS 4.0 by Douglas C. Schmidt
 * <*****@*****.**>
 * (thanks! -- PWP)
 *
 * ignint ifs cleaned by Johan Widen <[email protected]>
 * (thanks again)
 */
			if (ignint) {
			    (void) signal(SIGINT, SIG_IGN);
			    (void) signal(SIGQUIT, SIG_IGN);
			}
			else {
			    (void) signal(SIGINT, vffree);
			    (void) signal(SIGQUIT, SIG_DFL);
			}
# ifdef BSDJOBS
			if (wanttty >= 0) {
			    (void) signal(SIGTSTP, SIG_DFL);
			    (void) signal(SIGTTIN, SIG_DFL);
			    (void) signal(SIGTTOU, SIG_DFL);
			}
# endif /* BSDJOBS */

			sigaction(SIGTERM, &parterm, NULL);
		    }
		    else if (tpgrp == -1 &&
			     (t->t_dflg & F_NOINTERRUPT)) {
			(void) signal(SIGINT, SIG_IGN);
			(void) signal(SIGQUIT, SIG_IGN);
		    }

		    pgetty(wanttty, pgrp);

		    if (t->t_dflg & F_NOHUP)
			(void) signal(SIGHUP, SIG_IGN);
		    if (t->t_dflg & F_HUP)
			(void) signal(SIGHUP, SIG_DFL);
		    if (t->t_dflg & F_NICE) {
			int nval = SIGN_EXTEND_CHAR(t->t_nice);
# if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
			if (setpriority(PRIO_PROCESS, 0, nval) == -1 && errno)
				stderror(ERR_SYSTEM, "setpriority",
				    strerror(errno));
# else /* !HAVE_SETPRIORITY || !PRIO_PROCESS */
			(void) nice(nval);
# endif /* HAVE_SETPRIORITY && PRIO_PROCESS */
		    }
# ifdef F_VER
		    if (t->t_dflg & F_VER) {
			tsetenv(STRSYSTYPE, t->t_systype ? STRbsd43 : STRsys53);
			dohash(NULL, NULL);
		    }
# endif /* F_VER */
		}

	    }
#endif /* VFORK */
	}
	if (pid != 0) {
	    /*
	     * It would be better if we could wait for the whole job when we
	     * knew the last process had been started.  Pwait, in fact, does
	     * wait for the whole job anyway, but this test doesn't really
	     * express our intentions.
	     */
#ifdef BACKPIPE
	    if (didfds == 0 && t->t_dflg & F_PIPEOUT) {
		xclose(pipeout[0]);
		xclose(pipeout[1]);
	    }
	    if ((t->t_dflg & F_PIPEIN) != 0)
		break;
#else /* !BACKPIPE */
	    if (didfds == 0 && t->t_dflg & F_PIPEIN) {
		xclose(pipein[0]);
		xclose(pipein[1]);
	    }
	    if ((t->t_dflg & F_PIPEOUT) != 0)
		break;
#endif /* BACKPIPE */

	    if (nosigchld) {
		sigprocmask(SIG_SETMASK, &csigset, NULL);
		nosigchld = 0;
	    }
	    if ((t->t_dflg & F_AMPERSAND) == 0)
		pwait();
	    break;
	}

	doio(t, pipein, pipeout);
#ifdef BACKPIPE
	if (t->t_dflg & F_PIPEIN) {
	    xclose(pipein[0]);
	    xclose(pipein[1]);
	}
#else /* !BACKPIPE */
	if (t->t_dflg & F_PIPEOUT) {
	    xclose(pipeout[0]);
	    xclose(pipeout[1]);
	}
#endif /* BACKPIPE */
	/*
	 * Perform a builtin function. If we are not forked, arrange for
	 * possible stopping
	 */
	if (bifunc) {
	    if (forked) {
		func(t, bifunc);
		exitstat();
	    } else {
		jmp_buf_t oldexit;
		int ohaderr = haderr;

		getexit(oldexit);
		if (setexit() == 0)
		    func(t, bifunc);
		resexit(oldexit);
		haderr = ohaderr;

		if (adrof(STRprintexitvalue)) {
		    int rv = getn(varval(STRstatus));
		    if (rv != 0)
			xprintf(CGETS(17, 2, "Exit %d\n"), rv);
		}
	    }
	    break;
	}
	if (t->t_dtyp != NODE_PAREN) {
	    doexec(t, do_glob);
	    /* NOTREACHED */
	}
	/*
	 * For () commands must put new 0,1,2 in FSH* and recurse
	 */
	if ((OLDSTD = dcopy(0, FOLDSTD)) >= 0)
	    (void)close_on_exec(OLDSTD, 1);
	if ((SHOUT = dcopy(1, FSHOUT)) >= 0) {
	    (void)close_on_exec(SHOUT, 1);
	    isoutatty = isatty(SHOUT);
	}
	if ((SHDIAG = dcopy(2, FSHDIAG)) >= 0) {
	    (void)close_on_exec(SHDIAG, 1);
	    isdiagatty = isatty(SHDIAG);
    	}
	xclose(SHIN);
	SHIN = -1;
#ifndef CLOSE_ON_EXEC
	didcch = 0;
#else
	(void) close_on_exec(FSHOUT, 1);
	(void) close_on_exec(FSHDIAG, 1);
	(void) close_on_exec(FOLDSTD, 1);
#endif /* !CLOSE_ON_EXEC */
	didfds = 0;
	wanttty = -1;
	t->t_dspr->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	execute(t->t_dspr, wanttty, NULL, NULL, do_glob);
	exitstat();

    case NODE_PIPE:
#ifdef BACKPIPE
	t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
	    (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcdr, wanttty, pv, pipeout, do_glob);
	t->t_dcar->t_dflg |= F_PIPEOUT | (t->t_dflg &
	    (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcar, wanttty, pipein, pv, do_glob);
#else /* !BACKPIPE */
	t->t_dcar->t_dflg |= F_PIPEOUT | (t->t_dflg &
	    (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcar, wanttty, pipein, pv, do_glob);
	t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
	    (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcdr, wanttty, pv, pipeout, do_glob);
#endif /* BACKPIPE */
	break;

    case NODE_LIST:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcar, wanttty, NULL, NULL, do_glob);
	    /*
	     * In strange case of A&B make a new job after A
	     */
	    if (t->t_dcar->t_dflg & F_AMPERSAND && t->t_dcdr &&
		(t->t_dcdr->t_dflg & F_AMPERSAND) == 0)
		pendjob();
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcdr, wanttty, NULL, NULL, do_glob);
	}
	break;

    case NODE_OR:
    case NODE_AND:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcar, wanttty, NULL, NULL, do_glob);
	    if ((getn(varval(STRstatus)) == 0) !=
		(t->t_dtyp == NODE_AND)) {
		return;
	    }
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcdr, wanttty, NULL, NULL, do_glob);
	}
	break;

    default:
	break;
    }
    /*
     * Fall through for all breaks from switch
     * 
     * If there will be no more executions of this command, flush all file
     * descriptors. Places that turn on the F_REPEAT bit are responsible for
     * doing donefds after the last re-execution
     */
    if (didfds && !(t->t_dflg & F_REPEAT))
	donefds();
}
예제 #20
0
WaveFile * markOutFileByA0Integral(SimpleGraphData *data)
{
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    WaveFile * waveFile = data->file_data;
    qDebug() << "waveOpenHFile" << LOG_DATA;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "file size " << size << LOG_DATA;

    vector intensive = data_get_intensive_norm(data);
    qDebug() << "intensive " << intensive.x << LOG_DATA;

    vector intensive_smooth = data_get_intensive_smooth(data);
    qDebug() << "intensive_smooth " << intensive_smooth.x << LOG_DATA;

    double scaleFactor = 1.0 * size / CHAR_BIT_RECORD / intensive.x;
    qDebug() << "scaleFactor " << scaleFactor << LOG_DATA;

    double intensiveAbsLimit = sptk_settings->dp->markoutA0IntA0abs / 100.0;
    qDebug() << "intensiveAbsLimit " << intensiveAbsLimit << LOG_DATA;

    int segmentLimit = sptk_settings->dp->segmentsMinLength * RECORD_FREQ * CHAR_BIT_RECORD / 1000 / scaleFactor;
    qDebug() << "segmentLimit " << segmentLimit << LOG_DATA;

    Points points;

    uint8_t gotIt = 0;
    double intensive_value = 0.0;
    double smooth_value = 0.0;
    uint32_t startPosition = 0;
    uint32_t stopPosition = 0;
    for (uint32_t i=0; i<intensive.x; i++)
    {
        intensive_value = getv(intensive, i);
        smooth_value = getv(intensive_smooth, i);
        if (gotIt == 0 && intensive_value > smooth_value && intensive_value > intensiveAbsLimit)
        {
            gotIt = 1;
            startPosition = i;
        } else if (gotIt == 1 && (intensive_value <= smooth_value || intensive_value <= intensiveAbsLimit))
        {
            gotIt = 0;
            stopPosition = i;

            if (segmentLimit < (stopPosition - startPosition))
            {
                points.pointsCount++;
                points = addOffset(points, scaleFactor * startPosition);
                points = addLenght(points, scaleFactor * (stopPosition - startPosition));
                points = addLabel(points, points.pointsCount);
            }
        }
    }

    if (gotIt == 1)
    {
        if (segmentLimit < (intensive.x - 1 - startPosition))
        {
            points.pointsCount++;
            points = addOffset(points, scaleFactor * startPosition);
            points = addLenght(points, scaleFactor * (intensive.x - 1 - startPosition));
            points = addLabel(points, points.pointsCount);
        }
    }

    int waveDataSize = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    char* waveData = (char*) malloc(waveDataSize);
    memcpy(waveData, waveFile->dataChunk->waveformData, waveDataSize);

    qDebug() << "waveData " << waveData << LOG_DATA;
    qDebug() << "waveDataSize " << waveDataSize << LOG_DATA;
    qDebug() << "NUMBER_OF_CHANNELS " << NUMBER_OF_CHANNELS << LOG_DATA;
    qDebug() << "RECORD_FREQ " << RECORD_FREQ << LOG_DATA;
    qDebug() << "SIGNIFICANT_BITS_PER_SAMPLE " << SIGNIFICANT_BITS_PER_SAMPLE << LOG_DATA;
    qDebug() << "pointsCount " << points.pointsCount << LOG_DATA;
    qDebug() << "pointsOffset " << points.pointsOffset << LOG_DATA;
    qDebug() << "pointsLenght " << points.pointsLenght << LOG_DATA;
    qDebug() << "pointsLabel " << points.pointsLabels << LOG_DATA;

    return makeWaveFileFromRawData(
                waveData,
                waveDataSize,
                NUMBER_OF_CHANNELS,
                RECORD_FREQ,
                SIGNIFICANT_BITS_PER_SAMPLE,
                points.pointsCount,
                points.pointsOffset,
                points.pointsLenght,
                points.pointsLabels
    );
}
예제 #21
0
Points getPoints(int dataSize, vector data, double scaleFactor, double limit, int relativeLimit = DEFAULT_RELATIVE)
{
    Points points;

    uint8_t gotIt = 0;
    uint32_t lenght = 0;

    double initialLimit = limit;

    int useRelative = 0;
    if (relativeLimit != DEFAULT_RELATIVE)
        useRelative = 1;
    int isRelative = 0;
    int offset = 0;
    uint32_t startRelativePosition = 0;
    uint32_t stopRelativePosition = 0;
    for (uint32_t i=0; i<dataSize; i++)
    {
        double value = getv(data, i);
        // Found segment end

        if (((value < limit ||  i==(dataSize-1)) && gotIt == 1)
                || (useRelative && isRelative && i > stopRelativePosition))
        {
            qDebug() << "found end: " << i << " relative " << isRelative << limit << LOG_DATA;

            // Add point if don't use relative or it's 2nd-gen segmant
            if ((!useRelative || isRelative) && gotIt == 1)
            {
                points.pointsCount++;
                points = addOffset(points, scaleFactor * offset);
                points = addLenght(points, scaleFactor * lenght);
                points = addLabel(points, points.pointsCount);
            }

            gotIt = 0;

            // Calculate relative limit for 1st-gen segment
            if (useRelative && !isRelative)
            {
                stopRelativePosition = i;
                isRelative = 1;
                limit = getRelativeLimitForSement(startRelativePosition, stopRelativePosition, data, relativeLimit);
                qDebug() << "limit relative: " << limit << LOG_DATA;
                i = startRelativePosition;
            }

            // Finish scan for 1st-gen segment, go find next one
            if (useRelative && isRelative && i > stopRelativePosition)
            {
                isRelative = 0;
                startRelativePosition = i;
                stopRelativePosition = i;
                limit = initialLimit;
                qDebug() << "limit original: " << limit << LOG_DATA;
            }
        }
        //  It's segment, go on
        if (value > limit && gotIt == 1)
        {
            lenght++;
        }
        // Found segment start
        if (value > limit && gotIt == 0)
        {
            qDebug() << "found start: " << i << " relative " << isRelative << limit << LOG_DATA;
            if (useRelative && !isRelative)
                startRelativePosition = i;
            gotIt = 1;
            lenght = 0;
            offset = i;
        }
    }

    qDebug() << "pointsOffset size " << points.pointsCount << LOG_DATA;

    return points;
}
예제 #22
0
void deriveNSfractions(bool data, int mode, bool bjet = false)
{
  if (mode==0) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1);
    return;
  }
  if (mode==2) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(0.7);
    return;
  }
  if (mode==4) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1.3);
    return;
  }

  TString fnpp;
  if (bjet)
    fnpp = data ? "dtppjpf" : "mcppbfa";
  else
    fnpp = data ? "dtppjpf" : "mcppqcd";
  auto filepp = config.getfile_djt(fnpp);

  seth(1,0,PI);
  auto hppNS = geth("hppNS");
  auto hppAS = geth("hppAS");

  Fill(filepp,[&] (dict &d) {
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hppNS->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hppAS->Fill(d["dphi21"],d["weight"]);
  });

  float a_pp = hppNS->Integral()/hppAS->Integral();
  cout<<"a_pp "<<a_pp<<endl;


  TString fnPbPb;
  if (bjet)
    fnPbPb = data ? "dtPbbjt" : "mcPbbfa";
  else
    fnPbPb = data ? "dtPbjcl" : "mcPbqcd";
  auto file = config.getfile_djt(fnPbPb);
  vector<TString> histn;
  for (unsigned i=0;i<binbounds.size()-1;i++)
    histn.push_back(Form("PbPb%d%d",binbounds[i],binbounds[i+1]));
  setv(histn);

  auto hPbPbNS = getv("hPbPbNS");
  auto hPbPbAS = getv("hPbPbAS");

  auto hPbPbNSsig = getv("hPbPbNSsig");

  Fill(file,[&] (dict &d) {
    int b = getbin(d["bin"]);
    float w = d["weight"];
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;  
    if (bjet && d["pairCode21"]==0) w*=processweight((int)d["bProdCode"]);
    if (!data && d["pthat"]<50) return;  
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hPbPbNS[b]->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hPbPbAS[b]->Fill(d["dphi21"],d["weight"]);

    if (!data && d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13 && (d["subid2"]==0 && d["refpt2"]>20))
      hPbPbNSsig[b]->Fill(d["dphi21"],d["weight"]);

  });

  vector<double> binmean;
  vector<double> nsfractrue;
  vector<double> nsfracest;

  for (unsigned i=0;i<binbounds.size()-1;i++) {
    float a_PbPb = hPbPbNS[i]->Integral()/hPbPbAS[i]->Integral();
    float x = (1-a_pp/a_PbPb)/(1-a_pp);
    NSfrac.push_back(mode==1 ? x : -1);// = old stupid adding of the signal : 2-x);
    // cout<<binbounds[i]<<" - "<<binbounds[i+1]<<" = "<<NSfrac[i]<<endl;

    nsfractrue.push_back(1-hPbPbNSsig[i]->Integral()/hPbPbNS[i]->Integral());
    nsfracest.push_back(NSfrac[NSfrac.size()-1]);
    binmean.push_back((binbounds[i]+binbounds[i+1])/2);
  }

  auto c = getc();
  TGraph *g = new TGraph(binbounds.size()-1,&binmean[0],&nsfractrue[0]);
  g->Draw();
  SavePlot(c,bjet ? "bjetfractionofNS" : "incfractionofNS");

  auto c2 = getc();
  TGraph *g2 = new TGraph(binbounds.size()-1,&binmean[0],&nsfracest[0]);
  g2->Draw();
  SavePlot(c2,bjet ? "bjetfractionofNSdata" : "incfractionofNSdata");



///////////////////////////// DATA:
// bin<20 : 0.93
// bin>=20 && bin<60 : 0.84
// bin>=60 : 0.39
////////////////////////////


}