Пример #1
0
    void ProcessData(const T *Values,
                     typename ValueArray::size_type Size,
                     FnWriter pfnWriter,
                     FnReader pfnReader)
    {
        ValueArray InValues(Size);

        {
            wxFileOutputStream FileOutput( wxT("mytext.dat") );
            wxDataOutputStream DataOutput( FileOutput );

            (DataOutput.*pfnWriter)(Values, Size);
        }

        {
            wxFileInputStream FileInput( wxT("mytext.dat") );
            wxDataInputStream DataInput( FileInput );

            (DataInput.*pfnReader)(&*InValues.begin(), InValues.size());
        }

        m_ok = true;
        for (typename ValueArray::size_type idx=0; idx!=Size; ++idx) {
            if (InValues[idx]!=Values[idx]) {
                m_ok = false;
                break;
            }
        }
    }
Пример #2
0
int main(int argc, char* argv[]) {
	if (argc > 1) {
		FileInput(argv, argc);
	} else {
		NowInput();
	}
	printf("<退出!>\n");
	return EXIT_SUCCESS;
}
int Read_Trial(std::string File) {
    std::string New = "";
    while (New == "") {
        std::ifstream FileInput(File);
        getline(FileInput,New);
        FileInput.close();
    }
    return atoi(New.c_str());
}
bool Sync_Check(std::string File, std::string Message) {
    std::string New;
    std::ifstream FileInput (File);
    getline(FileInput,New);
    FileInput.close();
    if(New == Message)
        return true;
    return false;
}
std::string DirectionalReader(std::string File, std::string Previous) {
    std::string New;
    std::ifstream FileInput (File);
    getline(FileInput,New);
    FileInput.close();
    if (New != Previous && New.length() > 0)
        return New;
    else
        return "No Update";

}
bool Sync_Wait(std::string File, std::string Message, std::string Check, SDL_Event event) {
    std::string New;
    while(New != Message) {
        std::ifstream FileInput (File);
        getline(FileInput,New);
        FileInput.close();
        if (EventDetection(event) == SDL_SCANCODE_Q || New == Check)
            return false;
    }
    return true;
}
Пример #7
0
static
T TestRW(const T &Value)
{
    T InValue;

    {
        wxFileOutputStream FileOutput( wxT("mytext.dat") );
        wxDataOutputStream DataOutput( FileOutput );

        DataOutput << Value;
    }

    {
        wxFileInputStream FileInput( wxT("mytext.dat") );
        wxDataInputStream DataInput( FileInput );

        DataInput >> InValue;
    }

    return InValue;
}
Пример #8
0
/* open the file and parse its contents
*/
int ParseConfigFileEnc( TidyDocImpl* doc, ctmbstr file, ctmbstr charenc )
{
    uint opterrs = doc->optionErrors;
    tmbstr fname = (tmbstr) ExpandTilde( file );
    TidyConfigImpl* cfg = &doc->config;
    FILE* fin = fopen( fname, "r" );
    int enc = CharEncodingId( charenc );

    if ( fin == NULL || enc < 0 )
    {
        FileError( doc, fname, TidyConfig );
        return -1;
    }
    else
    {
        tchar c;
        cfg->cfgIn = FileInput( doc, fin, enc );
        c = FirstChar( cfg );
       
        for ( c = SkipWhite(cfg); c != EndOfStream; c = NextProperty(cfg) )
        {
            uint ix = 0;
            tmbchar name[ TIDY_MAX_NAME ] = {0};

            /* // or # start a comment */
            if ( c == '/' || c == '#' )
                continue;

            while ( ix < sizeof(name)-1 && c != '\n' && c != EndOfStream && c != ':' )
            {
                name[ ix++ ] = (tmbchar) c;  /* Option names all ASCII */
                c = AdvanceChar( cfg );
            }

            if ( c == ':' )
            {
                const TidyOptionImpl* option = lookupOption( name );
                c = AdvanceChar( cfg );
                if ( option )
                    option->parser( doc, option );
                else
                {
                    if (NULL != doc->pOptCallback)
                    {
                        TidyConfigImpl* cfg = &doc->config;
                        tmbchar buf[8192];
                        uint i = 0;
                        tchar delim = 0;
                        Bool waswhite = yes;

                        tchar c = SkipWhite( cfg );

                        if ( c == '"' || c == '\'' )
                        {
                            delim = c;
                            c = AdvanceChar( cfg );
                        }

                        while ( i < sizeof(buf)-2 && c != EndOfStream && c != '\r' && c != '\n' )
                        {
                            if ( delim && c == delim )
                                break;

                            if ( IsWhite(c) )
                            {
                                if ( waswhite )
                                {
                                    c = AdvanceChar( cfg );
                                    continue;
                                }
                                c = ' ';
                            }
                            else
                                waswhite = no;

                            buf[i++] = (tmbchar) c;
                            c = AdvanceChar( cfg );
                        }
                        buf[i] = '\0';
                        if (no == (*doc->pOptCallback)( name, buf ))
                            ReportUnknownOption( doc, name );
                    }
                    else
                        ReportUnknownOption( doc, name );
                }
            }
        }

        fclose( fin );
        MemFree( (void *)cfg->cfgIn->source.sourceData ); /* fix for bug #810259 */
        freeStreamIn( cfg->cfgIn );
        cfg->cfgIn = NULL;
    }

    if ( fname != (tmbstr) file )
        MemFree( fname );

    AdjustConfig( doc );

    /* any new config errors? If so, return warning status. */
    return (doc->optionErrors > opterrs ? 1 : 0); 
}
Пример #9
0
int main(){

  PARTICLE *p,*pn;
  p=malloc(sizeof(PARTICLE)); //need to allocate memory to pointer
  pn=malloc(sizeof(PARTICLE));
  FILE *fp;

	double dDelta,t,tmax;
  double CnPreFac, CtPreFac, dLnEpsN, dLnEpsT, dLnEpsNsq, dLnEpsTsq, a;;
  int i;
  int nSteps,iStep=0;
  int iOutFreq;
  int bOverlap=0;
  char achOutFile[20];

  //Need to initialize dKn for each particle
  p->dKn = 1.06e-15;
  p->dKt = 2.*p->dKn/7.;
  p->dEpsN = 0.8;
  p->dEpsT = 0.8;
  p->dMuS = 0.4;
  
  pn->dKn = p->dKn;
  pn->dKt = p->dKt;
  pn->dEpsN = p->dEpsN;
  pn->dEpsT = p->dEpsT;
  pn->dMuS = p->dMuS;
  
  dDelta=1.47e-10;
  nSteps = 40000;
  iOutFreq = nSteps / 50;
  t=0;
  tmax=dDelta * nSteps;
 
 
  const double pi_sq = M_PI*M_PI;
  static int bCnCtPreFacCalculated = 0; /* since dEpsN and dEpsT are identical for all particles in sim */

  if (!bCnCtPreFacCalculated) {
    /* damping term: normal */
    dLnEpsN = log(p->dEpsN);
    dLnEpsNsq = dLnEpsN*dLnEpsN;
    a = pi_sq + dLnEpsNsq;
    CnPreFac = -sign(dLnEpsN)*sqrt(dLnEpsNsq*p->dKn/a);
    CnPreFac += CnPreFac;

    /* damping term: tangential */
    dLnEpsT = log(p->dEpsT);
    dLnEpsTsq = dLnEpsT*dLnEpsT;
    a = pi_sq + dLnEpsTsq;
    CtPreFac = -sign(dLnEpsT)*sqrt(dLnEpsTsq*p->dKt/a);
    CtPreFac += CtPreFac;
    bCnCtPreFacCalculated = 1;
    }

  /*Take input from FILE here - Initialization*/
  FileInput(p, pn);

  
  /*Simulation loop here*/
  while (t<tmax){
  
    /* Output to file Here*/
    if ((t == 0) || (iStep % iOutFreq == 0)){
      /*Define File Name based on time step*/
      sprintf(achOutFile,"ss.%09d.bt",iStep);
      /*Output function*/
		  FileOutput(p, pn, achOutFile);
    }
    /* Output-Function Ends Here*/
    

    /* LeapFrog */
    for (i=0;i<3;i++){
      p->v[i]=p->v[i]+(0.5*dDelta*p->a[i]); //kick
      pn->v[i]=pn->v[i]+(0.5*dDelta*pn->a[i]);
    }

    for (i=0;i<3;i++){
  	  p->r[i]=p->r[i]+(dDelta*p->v[i]); //drift
  	  pn->r[i]=pn->r[i]+(dDelta*pn->v[i]); //
    }

    //Overlap Test
        bOverlap = bOverlapTest(p,pn);
    if (bOverlap){
      DoDEM(p, pn, dDelta, CnPreFac, CtPreFac);
      printf("%d\n",bOverlap);
    }
    else{
      vecZero(p->a); //Is this correct?
      vecZero(pn->a);
    }
    
    for (i=0;i<3;i++){
      p->v[i]=p->v[i]+(0.5*dDelta*p->a[i]); //kick
      pn->v[i]=pn->v[i]+(0.5*dDelta*pn->a[i]);
    }
    /* LeapFrog ENDS*/


    t+=dDelta;
    iStep++;
  }
  
  return 0;
}