예제 #1
0
bool HDFWalkerInputManager::put(xmlNodePtr cur)
{
  //reference revision number
  HDFVersion start_version(0,4);
  //current node
  int pid=myComm->rank();
  string froot("0"), cfile("0");
  //string  target("e"), collect("no");
  int anode=-1, nblocks=1, nprocs=1;
  HDFVersion in_version(0,1); //set to be old version
  OhmmsAttributeSet pAttrib;
  pAttrib.add(cfile,"href");
  pAttrib.add(cfile,"file");
  pAttrib.add(froot,"fileroot");
  pAttrib.add(anode,"node");
  pAttrib.add(nprocs,"nprocs");
  //pAttrib.add(collect,"collected");
  pAttrib.add(in_version,"version");
  pAttrib.put(cur);
  bool success=false;
  if(in_version>=start_version)
  {
    HDFWalkerInput_0_4 win(targetW,myComm,in_version);
    success= win.put(cur);
    cfile=win.FileName;
  }
  else
  {
    //missing version or old file
    if(froot[0] != '0')//use nprocs
    {
      anode=pid;
      if(nprocs==1)
        cfile=froot;
      else
      {
        char *h5name=new char[froot.size()+10];
        sprintf(h5name,"%s.p%03d",froot.c_str(),pid);
        cfile=h5name;
        delete [] h5name;
      }
    }
    int pid_target= (anode<0)? pid:anode;
    if(pid_target == pid && cfile[0] != '0')
    {
      HDFWalkerInput_0_0 win(targetW,cfile);
      success= win.put(cur);
    }
  }
  if(success)
    CurrentFileRoot = cfile;
  return success;
}
예제 #2
0
파일: mrflsh4.c 프로젝트: FlexCOS/code
void fasinh(_MIPD_ flash x,flash y)
{ /* calculate y=asinh(x) */
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    copy(x,y);
    if (mr_mip->ERNUM || size(y)==0) return;

    MR_IN(66)
    fmul(_MIPP_ y,y,mr_mip->w11);
    fincr(_MIPP_ mr_mip->w11,1,1,mr_mip->w11);
    froot(_MIPP_ mr_mip->w11,2,mr_mip->w11);
    fadd(_MIPP_ y,mr_mip->w11,y);
    flog(_MIPP_ y,y);
    MR_OUT
}
예제 #3
0
void facosh(_MIPD_ flash x,flash y)
{ /* calculate y=acosh(x) */
#ifndef MR_GENERIC_MT
    miracl *mr_mip=get_mip();
#endif
    copy(x,y);
    if (mr_mip->ERNUM) return;

    MR_IN(62)
    fmul(_MIPP_ y,y,mr_mip->w11);
    fincr(_MIPP_ mr_mip->w11,(-1),1,mr_mip->w11);
    froot(_MIPP_ mr_mip->w11,2,mr_mip->w11);
    fadd(_MIPP_ y,mr_mip->w11,y);
    flog(_MIPP_ y,y);
    MR_OUT
}
예제 #4
0
파일: lregex.cpp 프로젝트: mynlp/lilfes
/**
  * @predicate	= regex_match(+REGEX, +OPTIONS, +TARGET, -RESULT) 
  * @desc	= Get partial strings matched the regular exoression.
  * @param	= +REGEX/ string : regular expression
  * @param	= +OPTIONS/ list : list of options
  * @param	= +TARGET/ string : target string
  * @param	= -RESULT/ list : The first element is the whole matched string .The following elements is parts of matched expression(enclosed with parenthesis).
  * @note	= The folowing options can be used.
  * @note	= <UL>
  * @note	= <LI>"ICASE" : Not case-sensitive
  * @note	= <LI>"i" : same as "ICASE" 
  * @note	= <LI>"GLOBAL" : global matching (see example)
  * @note	= <LI>"g" : same as "GLOBAL" 
  * @note	= <LI>"NEWLINE" : use character of linefeed as segmentation
  * @note	= <LI>"NOTBOL" : If appointed "NEWLINE","^" does not match linefeed.
  * @note	= <LI>"NOTEOL" : If appointed "NEWLINE","$" does not match linefeed.</LI></UL>
  * @example	= 
  > ?- regex_match("(a)+", ["i"], "aAbbaaa",X).
  X: < "aA", "a" >
  > ?- regex_match("(a)+", ["i", "g"], "aAbbaaa",X).
  X: < "aA", "aaa" > 
  * @end_example

  * @jdesc	= 正規表現にマッチする部分文字列を返します. 
  * @jparam	= +REGEX/ string : 正規表現
  * @jparam	= +OPTIONS/ list : オプションのリスト.
  * @jparam	= +TARGET/ string : 対象の文字列
  * @jparam	= -RESULT/ list : 第1要素にマッチした文字列全体,第2要素以降にマッチした部分表現(かっこで囲まれた部分)が入ります. 
  * @jnote	= 以下のオプションを指定できます. 
  * @jnote	= <UL>
  * @jnote	= <LI>"ICASE" : 大文字/小文字を区別しない. 
  * @jnote	= <LI>"i" : "ICASE" と同じ. 
  * @jnote	= <LI>"GLOBAL" : グローバルマッチング(使用例を参照). 
  * @jnote	= <LI>"g" : "GLOBAL" と同じ. 
  * @jnote	= <LI>"NEWLINE" : 改行文字を文の区切りとする. 
  * @jnote	= <LI>"NOTBOL" : "NEWLINE" が指定されたとき,"^" が改行にマッチしない. 
  * @jnote	= <LI>"NOTEOL" : "NEWLINE" が指定されたとき,"$" が改行にマッチしない. </LI></UL>
  * @jexample	=
  > ?- regex_match("(a)+", ["i"], "aAbbaaa",X).
  X: < "aA", "a" >
  > ?- regex_match("(a)+", ["i", "g"], "aAbbaaa",X).
  X: < "aA", "aaa" > 
  * @end_jexample
*/
bool regex_match_4( machine& m, FSP arg1, FSP arg2, FSP arg3, FSP arg4 ) {

  if ( ! arg1.IsString() ) {
    RUNERR("1st argument of 'regex_match/4' must be a regular expression pattern");
    return false;
  }
  if ( ! arg3.IsString() ) {
    RUNERR("3rd argument of 'regex_match/4' must be a target string");
    return false;
  }

  try {

    LiLFeSRegEx regex( arg1.ReadString() );
    regex.addFlags( arg2 );
    regex.compile();
    const string& target( arg3.ReadString() );

    if ( ! regex.exec( target ) ) {
      return false;
    }

    FSP f( m );
    FSP froot( m, f.GetAddress() );
    for ( size_t i = 0; i < regex.numSubstr(); ++i ) {
      FSP g( m, regex.getSubstr( i ).c_str() );
      f.Follow( hd ).Unify( g );
      f = f.Follow( tl );
    }
    f.Coerce( nil );

    if ( ! arg4.Unify( froot ) ) {
      return false;
    }
    return true;

  } catch ( LiLFeSRegExError e ) {
    RUNERR( e.message() );
    return false;
  }
}
예제 #5
0
int main()
{ /* Brents example program */
    flash x,pi;
    miracl *mip=mirsys(-35,0);
    x=mirvar(0);
    pi=mirvar(0);
    mip->RPOINT=ON;
    printf("Calculating pi..\n");
    fpi(pi);
    cotnum(pi,stdout); /* output pi */
    printf("Calculating exp(pi*(163/9)^0.5)\n");
    fconv(163,9,x);
    froot(x,2,x);
    fmul(x,pi,x);
    fexp(x,x);
    cotnum(x,stdout);
    printf("Calculating exp(pi*(163)^0.5)\n");
    fpower(x,3,x);
    cotnum(x,stdout);
    return 0;
}
예제 #6
0
bool ExtractSingleWmo(std::string& fname)
{
    // Copy files from archive

    char szLocalFile[1024];
    const char * plain_name = GetPlainName(fname.c_str());
    sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
    FixNameCase(szLocalFile,strlen(szLocalFile));

    if (FileExists(szLocalFile))
        return true;

    int p = 0;
    // Select root wmo files
    char const* rchr = strrchr(plain_name, '_');
    if (rchr != NULL)
    {
        char cpy[4];
        memcpy(cpy, rchr, 4);
        for (int i = 0; i < 4; ++i)
        {
            int m = cpy[i];
            if (isdigit(m))
                p++;
        }
    }

    if (p == 3)
        return true;

    bool file_ok = true;
    std::cout << "Extracting " << fname << std::endl;
    WMORoot froot(fname);
    if(!froot.open())
    {
        printf("Couldn't open RootWmo!!!\n");
        return true;
    }
    FILE *output = fopen(szLocalFile,"wb");
    if(!output)
    {
        printf("couldn't open %s for writing!\n", szLocalFile);
        return false;
    }
    froot.ConvertToVMAPRootWmo(output);
    int Wmo_nVertices = 0;
    //printf("root has %d groups\n", froot->nGroups);
    if (froot.nGroups !=0)
    {
        for (uint32 i = 0; i < froot.nGroups; ++i)
        {
            char temp[1024];
            strcpy(temp, fname.c_str());
            temp[fname.length()-4] = 0;
            char groupFileName[1024];
            sprintf(groupFileName, "%s_%03u.wmo", temp, i);
            //printf("Trying to open groupfile %s\n",groupFileName);

            std::string s = groupFileName;
            WMOGroup fgroup(s);
            if(!fgroup.open())
            {
                printf("Could not open all Group file for: %s\n", plain_name);
                file_ok = false;
                break;
            }

            Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
        }
    }

    fseek(output, 8, SEEK_SET); // store the correct no of vertices
    fwrite(&Wmo_nVertices,sizeof(int),1,output);
    fclose(output);

    // Delete the extracted file in the case of an error
    if (!file_ok)
        remove(szLocalFile);
    return true;
}
예제 #7
0
static BOOL act(int p,int q)
{ /* act on selected key */
    int k,n,c;
    aprint(PRESSED,4+5*p,6+3*q,keys[q][p]);
    switch(p+7*q)
    {
    case 0:  if (degrees) fmul(x,radeg,x);
             if (hyp) fsinh(x,x);
             else     fsin(x,x);
             newx=TRUE;
             break;
    case 1:  if (degrees) fmul(x,radeg,x);
             if (hyp) fcosh(x,x);
             else     fcos(x,x);
             newx=TRUE;
             break;
    case 2:  if (degrees) fmul(x,radeg,x);
             if (hyp) ftanh(x,x);
             else     ftan(x,x);
             newx=TRUE;
             break;
    case 3:  if (lgbase>0)
             {
                 n=size(x);
                 if (abs(n)<MR_TOOBIG)
                 {
                     convert(lgbase,x);
                     if (n<0) frecip(x,x);
                     fpower(x,abs(n),x);
                     newx=TRUE;
                     break;
                 }
                 if (lgbase==2)  fmul(x,loge2,x);
                 if (lgbase==10) fmul(x,loge10,x);
             }
             fexp(x,x);
             newx=TRUE;
             break;
    case 4:  mip->RPOINT=!mip->RPOINT;
             newx=TRUE;
             break;
    case 5:  clrall();
             newx=TRUE;
             break;
    case 6:  return TRUE;
    case 7:  if (hyp) fasinh(x,x);
             else     fasin(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 8:  if (hyp) facosh(x,x);
             else     facos(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 9:  if (hyp) fatanh(x,x);
             else     fatan(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 10: flog(x,x);
             if (lgbase==2)  fdiv(x,loge2,x);
             if (lgbase==10) fdiv(x,loge10,x);
             newx=TRUE;
             break;
    case 11: newx=TRUE;
             k=3;
             forever
             {
                 aprint(INVER,2+stptr[k],2,settings[k][option[k]]);
                 curser(2+stptr[k],2);
                 c=arrow(gethit());
                 if (c==1)
                 {
                     if (option[k]==nops[k]) option[k]=0;
                     else option[k]+=1;
                     continue;
                 }
                 aprint(STATCOL,2+stptr[k],2,settings[k][option[k]]);
                 if (c==0 || c==2) break;
                 if (c==4 && k>0) k--;
                 if (c==3 && k<3) k++;
             }
             setopts();
             break;
    case 12: chekit(7);
             break;
    case 13: result=FALSE;
             if (ipt==0) break;
             ipt--;
             mybuff[ipt]='\0';
             if (ipt==0) clr();
             just(mybuff);
             cinstr(x,mybuff);
             newx=TRUE;
             break;
    case 14: if (!next('7')) putchar(BELL);
             break;
    case 15: if (!next('8')) putchar(BELL);
             break;
    case 16: if (!next('9')) putchar(BELL);
             break;
    case 17: chekit(6);
             break;
    case 18: chekit(5);
             break;
    case 19: chekit(4);
             break;
    case 20: copy(m,x);
             newx=TRUE;
             break;
    case 21: if (!next('4')) putchar(BELL);
             break;
    case 22: if (!next('5')) putchar(BELL);
             break;
    case 23: if (!next('6')) putchar(BELL);
             break;
    case 24: fmul(x,x,x);
             newx=TRUE;
             break;
    case 25: froot(x,2,x);
             newx=TRUE;
             break;
    case 26: chekit(3);
             break;
    case 27: brkt=0;
             chekit(0);
             flag=OFF;
             fadd(m,x,m);
             newx=TRUE;
             break;
    case 28: if (!next('1')) putchar(BELL);
             break;
    case 29: if (!next('2')) putchar(BELL);
             break;
    case 30: if (!next('3')) putchar(BELL);
             break;
    case 31: frecip(x,x);
             newx=TRUE;
             break;
    case 32: fpi(x);
             newx=TRUE;
             break;
    case 33: chekit(2);
             break;
    case 34: negify(x,x);
             newx=TRUE;
             break;
    case 35: if (!next('0')) putchar(BELL);
             break;
    case 36: if (!next('/')) putchar(BELL);
             break;
    case 37: if (!next('.')) putchar(BELL);
             break;
    case 38: if (ipt>0)
             {
                 putchar(BELL);
                 result=FALSE;
             }
             else
             {
                 zero(x);
                 brkt+=1;
                 newx=TRUE;
             }
             break;
    case 39: if (brkt>0)
             {
                 chekit(0);
                 brkt-=1;
             }
             else
             {
                 putchar(BELL);
                 result=FALSE;
             }
             break;
    case 40: chekit(1);
             break;
    case 41: brkt=0;
             equals(0);
             flag=OFF;
             break;
    }
    return FALSE;
}
예제 #8
0
파일: plotxy.cpp 프로젝트: LANLhakel/FESTR
int main(int argc, char **argv)
{
    if (argc != 2)
    {
        print_usage();
        exit(EXIT_FAILURE);
    }

    std::string froot(argv[1]);
    size_t k(froot.find_first_of("-"));
    bool detector(k != std::string::npos);
    std::string dname;
    if (detector) dname = froot.substr(0, k);
    std::string fname_in(froot + ".txt");
    std::string fname_out(froot + ".dat");
    std::ifstream infile(fname_in.c_str());
    if (!infile.is_open())
    {
        std::cerr << "Error: file " << fname_in << " is not open." << std::endl;
        exit(EXIT_FAILURE);
    }

    std::string fgrid;
    if (detector)
        fgrid = dname + "-hv_grid.txt";
    else // e.g., a Database table file
        fgrid = "hv_grid.txt";
    std::ifstream hv_grid(fgrid.c_str());
    if (!hv_grid.is_open())
    {
        std::cerr << "Error: file " << fgrid << " is not open." << std::endl;
        exit(EXIT_FAILURE);
    }

    std::ofstream outfile(fname_out.c_str());
    if (!outfile.is_open())
    {
        std::cerr << "Error: file " << fname_out << " is not open." << std::endl;
        exit(EXIT_FAILURE);
    }

    utils::find_word(infile, "data");
    std::string s, units;
    while (true)
    {
        infile >> s;
        if (s == "in") break;
    }
    infile >> units;
    outfile << "# hv in eV\n# data in " << units << std::endl;

    utils::find_line(hv_grid, "Number of grid points:");
    size_t nhv;
    hv_grid >> nhv;

    utils::find_line(hv_grid, "Grid points:");
    size_t ihv, j;
    double x, y;
    for (ihv = 0; ihv < nhv; ++ihv)
    {
        hv_grid >> j >> x;
        infile >> y;
        outfile << utils::double_to_string(x) << " "
                << utils::double_to_string(y) << std::endl;
    }
    hv_grid.close();
    hv_grid.clear();
    infile.close();
    infile.clear();
    outfile.close();
    outfile.clear();

    return EXIT_SUCCESS;
}
예제 #9
0
bool ExtractSingleWmo(std::string& fname)
{
    // Copy files from archive

    char szLocalFile[1024];
    const char * plain_name = GetPlainName(fname.c_str());
    sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
    FixNameCase(szLocalFile, strlen(szLocalFile));
    FixNameSpaces(szLocalFile, strlen(szLocalFile));

    if (FileExists(szLocalFile))
        return true;

    int p = 0;
    // Select root wmo files
    char const* rchr = strrchr(plain_name, '_');
    if (rchr != NULL)
    {
        char cpy[4];
        memcpy(cpy, rchr, 4);
        for (int i = 0; i < 4; ++i)
        {
            int m = cpy[i];
            if (isdigit(m))
                p++;
        }
    }

    if (p == 3)
        return true;

    bool file_ok = true;
    printf("Extracting %s\n", fname.c_str());
    WMORoot froot(fname);
    if(!froot.open())
    {
        printf("Couldn't open RootWmo!!!\n");
        return true;
    }
    FILE *output = fopen(szLocalFile,"wb");
    if(!output)
    {
        printf("couldn't open %s for writing!\n", szLocalFile);
        return false;
    }
    froot.ConvertToVMAPRootWmo(output);
    int Wmo_nVertices = 0;
    //printf("root has %d groups\n", froot->nGroups);
    for (std::size_t i = 0; i < froot.groupFileDataIDs.size(); ++i)
    {
        std::string s = Trinity::StringFormat("FILE%08X.xxx", froot.groupFileDataIDs[i]);
        WMOGroup fgroup(s);
        if(!fgroup.open())
        {
            printf("Could not open all Group file for: %s\n", plain_name);
            file_ok = false;
            break;
        }

        Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
    }

    fseek(output, 8, SEEK_SET); // store the correct no of vertices
    fwrite(&Wmo_nVertices,sizeof(int),1,output);
    fclose(output);

    // Delete the extracted file in the case of an error
    if (!file_ok)
        remove(szLocalFile);
    return true;
}
예제 #10
0
bool ExtractSingleWmo(std::string& fname)
{
    // Copy files from archive
    std::string originalName = fname;

    char szLocalFile[1024];
    char* plain_name = GetPlainName(&fname[0]);
    FixNameCase(plain_name, strlen(plain_name));
    FixNameSpaces(plain_name, strlen(plain_name));
    sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);

    if (FileExists(szLocalFile))
        return true;

    int p = 0;
    // Select root wmo files
    char const* rchr = strrchr(plain_name, '_');
    if (rchr != NULL)
    {
        char cpy[4];
        memcpy(cpy, rchr, 4);
        for (int i = 0; i < 4; ++i)
        {
            int m = cpy[i];
            if (isdigit(m))
                p++;
        }
    }

    if (p == 3)
        return true;

    bool file_ok = true;
    printf("Extracting %s\n", originalName.c_str());
    WMORoot froot(originalName);
    if (!froot.open())
    {
        printf("Couldn't open RootWmo!!!\n");
        return true;
    }
    FILE *output = fopen(szLocalFile,"wb");
    if(!output)
    {
        printf("couldn't open %s for writing!\n", szLocalFile);
        return false;
    }
    froot.ConvertToVMAPRootWmo(output);
    WMODoodadData& doodads = WmoDoodads[plain_name];
    std::swap(doodads, froot.DoodadData);
    int Wmo_nVertices = 0;
    //printf("root has %d groups\n", froot->nGroups);
    for (std::size_t i = 0; i < froot.groupFileDataIDs.size(); ++i)
    {
        std::string s = Trinity::StringFormat("FILE%08X.xxx", froot.groupFileDataIDs[i]);
        WMOGroup fgroup(s);
        if (!fgroup.open(&froot))
        {
            printf("Could not open all Group file for: %s\n", plain_name);
            file_ok = false;
            break;
        }

        Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, preciseVectorData);
        for (uint16 groupReference : fgroup.DoodadReferences)
        {
            if (groupReference >= doodads.Spawns.size())
                continue;

            uint32 doodadNameIndex = doodads.Spawns[groupReference].NameIndex;
            if (froot.ValidDoodadNames.find(doodadNameIndex) == froot.ValidDoodadNames.end())
                continue;

            doodads.References.insert(groupReference);
        }
    }

    fseek(output, 8, SEEK_SET); // store the correct no of vertices
    fwrite(&Wmo_nVertices,sizeof(int),1,output);
    fclose(output);

    // Delete the extracted file in the case of an error
    if (!file_ok)
        remove(szLocalFile);
    return true;
}