void GenerateDlg::OnStart(wxCommandEvent& evt)
{
	prjFrame->GenerateStarted();
	EnableOK(0, 0);
	ed->AppendText("---------- Start ----------\r\n");
	canceled = 0;
	paused = 0;

	int sel = rateWnd->GetCurrentSelection();
	if (sel != wxNOT_FOUND)
		updateRate = (long) rateWnd->GetClientData(sel);

	if (!genAuto)
	{
		playFrom = GetTimeValue("IDC_PLAY_FROM");
		playTo  = GetTimeValue("IDC_PLAY_TO");
	}
	if (playSome)
	{
		theProject->StartTime(playFrom);
		theProject->EndTime(playTo);
		startTime = playFrom;
	}
	else
	{
		theProject->StartTime(0);
		theProject->EndTime(0);
		startTime = 0;
	}
	lastTime = 0;
	theProject->PlayMode(playLive);

	lastMsg = "";
	FormatTime("IDC_TIME", startTime);
	tml->Reset();
	lpkMtr->Reset();
	rpkMtr->Reset();
	lftPeak = 0;
	rgtPeak = 0;
	lftMax = 0;
	rgtMax = 0;
	FormatPeak();
	prjGenerate = static_cast<GenerateWindow*>(this);

	theProject->CallbackRate((float)updateRate / 10.0f);
	if (theProject->Start() == 0)
		EnableOK(0, 1);
	else
		EnableOK(1, 0);
}
示例#2
0
int Traj_Gro::readFrame(int fnum, Frame& frm) {
    if (fnum < currentSet_) {
        file_.CloseFile();
        file_.OpenFileRead( fname_ );
        currentSet_ = 0;
    }
    // Position file
    const char* ptr;
    for (int set = currentSet_; set != fnum; set++) {
        ptr = file_.Line(); // Title
        ptr = file_.Line(); // Natoms
        for (int i = 0; i != linesToRead_; i++)
            ptr = file_.Line(); // Atom (and possibly box)
        if (ptr == 0) return 1;
    }
    // Read current frame
    ptr = file_.Line(); // Title
    if (ptr == 0) return 1;
    if (CoordInfo().HasTime())
        frm.SetTime( GetTimeValue(ptr) );
    ptr = file_.Line(); // Natoms TODO check?
    double* Xptr = frm.xAddress();
    if (CoordInfo().HasVel()) {
        double* Vptr = frm.vAddress();
        for (int i = 0; i != natom_; i++, Xptr += 3, Vptr += 3) {
            ptr = file_.Line(); // Atom
            sscanf(ptr, "%*5c%*5c%*5c%*5c%lf %lf %lf %lf %lf %lf",
                   Xptr, Xptr+1, Xptr+2, Vptr, Vptr+1, Vptr+2);
            for (int n = 0; n != 3; n++) {
                Xptr[n] *= 10.0;
                Vptr[n] *= 10.0;
            }
        }
    } else {
        for (int i = 0; i != natom_; i++, Xptr += 3) {
            ptr = file_.Line(); // Atom
            sscanf(ptr, "%*5c%*5c%*5c%*5c%lf %lf %lf", Xptr, Xptr+1, Xptr+2);
            for (int n = 0; n != 3; n++)
                Xptr[n] *= 10.0;
        }
    }
    // Box read
    if (CoordInfo().HasBox()) {
        ptr = file_.Line();
        frm.SetBox( GetBox(ptr) );
    }

    ++currentSet_;
    return 0;
}
示例#3
0
 INT64 CDateTime::DiffWeek(const CDateTime &datetime)
 {
     return (GetTimeValue() - datetime.GetTimeValue())/(86400*7);
 }
示例#4
0
 INT64 CDateTime::DiffDay(const CDateTime &datetime)
 {
     return (GetTimeValue() - datetime.GetTimeValue())/86400;
 }
示例#5
0
 INT64 CDateTime::DiffHour(const CDateTime &datetime)
 {
     return (GetTimeValue() - datetime.GetTimeValue())/3600;
 }
示例#6
0
 INT64 CDateTime::DiffMinute(const CDateTime &datetime)
 {
     return (GetTimeValue() - datetime.GetTimeValue())/60;
 }
示例#7
0
 INT64 CDateTime::DiffSecond(const CDateTime &datetime)
 {
     return GetTimeValue() - datetime.GetTimeValue();
 }
示例#8
0
 INT64 CDateTime::operator - (const CDateTime &datetime)
 {
     return GetTimeValue() - datetime.GetTimeValue();
 }
示例#9
0
QTime RDRecording::endTime() const
{
  return GetTimeValue("END_TIME");
}
示例#10
0
 CDateTime & CDateTime::DecSecond(UINT32 second)
 {
     time_t tmp = GetTimeValue() - second;
     SetTimeValue(tmp);
     return *this;
 }
示例#11
0
 CDateTime & CDateTime::DecMinute(UINT32 minute)
 {
     time_t tmp = GetTimeValue() - minute*60;
     SetTimeValue(tmp);
     return *this;
 }
示例#12
0
 CDateTime & CDateTime::DecHour(UINT32 hour)
 {
     time_t tmp = GetTimeValue() - hour*3600;
     SetTimeValue(tmp);
     return *this;
 }
示例#13
0
 CDateTime & CDateTime::DecDay(UINT32 day)
 {
     time_t tmp = GetTimeValue() - day*86400;
     SetTimeValue(tmp); 
     return *this;
 }
示例#14
0
int Traj_Gro::setupTrajin(FileName const& fnameIn, Topology* trajParm)
{
    float fXYZ[9];
    fname_ = fnameIn; // TODO SetupRead for BufferedLine
    // Open file for reading
    if (file_.OpenFileRead( fname_ )) return TRAJIN_ERR;
    // Read the title. May contain time value, 't= <time>'
    const char* ptr = file_.Line();
    if (ptr == 0) {
        mprinterr("Error: Reading title.\n");
        return TRAJIN_ERR;
    }
    std::string title( ptr );
    RemoveTrailingWhitespace(title);
    mprintf("DBG: Title: %s\n", title.c_str());
    bool hasTime = true;
    // TODO Is it OK to assume there will never be a negative time value?
    double timeVal = GetTimeValue( ptr );
    if (timeVal < 0.0) hasTime = false;
    mprintf("DBG: Timeval= %g HasTime= %i\n", timeVal, (int)hasTime);
    // Read number of atoms
    ptr = file_.Line();
    if (ptr == 0) return TRAJIN_ERR;
    natom_ = atoi(ptr);
    if (natom_ < 1) {
        mprinterr("Error: Reading number of atoms.\n");
        return TRAJIN_ERR;
    }
    if (natom_ != trajParm->Natom()) {
        mprinterr("Error: Number of atoms %i does not match associated parm %s (%i)\n",
                  natom_, trajParm->c_str(), trajParm->Natom());
        return TRAJIN_ERR;
    }
    // Read first atom to see if there are velocities
    ptr = file_.Line();
    int nread = sscanf(ptr, "%*5c%*5c%*5c%*5c%f %f %f %f %f %f",
                       fXYZ, fXYZ+1, fXYZ+2, fXYZ+3, fXYZ+4, fXYZ+5);
    bool hasV = false;
    if (nread == 6)
        hasV = true;
    else if (nread != 3) {
        mprinterr("Error: Reading first atom, expected 3 or 6 coordinates, got %i\n", nread);
        return TRAJIN_ERR;
    }
    // Read past the rest of the atoms
    for (int i = 1; i != natom_; i++)
        if (file_.Line() == 0) {
            mprinterr("Error: Reading atom %i of first frame.\n", i+1);
            return TRAJIN_ERR;
        }
    // Attempt to read box line
    // v1(x) v2(y) v3(z) [v1(y) v1(z) v2(x) v2(z) v3(x) v3(y)]
    ptr = file_.Line();
    Box groBox;
    if (ptr != 0)
        groBox = GetBox( ptr );
    // Set trajectory information. No temperature info.
    SetCoordInfo( CoordinateInfo(groBox, hasV, false, hasTime) );
    SetTitle( title );
    // Check for multiple frames. If nothing was read above, 1 frame, no box. If
    // box info was read but nothing more can be read, 1 frame. Otherwise there
    // are more frames.
    bool hasMultipleFrames = false;
    if (ptr != 0) {
        if (groBox.Type() == Box::NOBOX) // Assume another title read.
            hasMultipleFrames = true;
        else {
            ptr = file_.Line(); // Read line after box info
            if (ptr != 0)
                hasMultipleFrames = true;
        }
    }
    // Set up some info for performing blank reads.
    linesToRead_ = natom_;
    if (groBox.Type() != Box::NOBOX)
        linesToRead_ += 1;
    int nframes = 1;
    if (hasMultipleFrames) {
        // Since there is no guarantee that each frame is the same size we cannot
        // just seek. Blank reads for as many times as possible. Should currently
        // be positioned at the title line of the next frame.
        while (ptr != 0 ) {
            ptr = file_.Line(); // Natoms
            int Nat = atoi(ptr);
            if (Nat != natom_) {
                mprinterr("Error: Frame %i # atoms (%i) does not match first frame (%i).\n"
                          "Error: Only reading %i frames.\n", nframes+1, Nat, natom_, nframes);
                break;
            }
            for (int i = 0; i != linesToRead_; i++)
                ptr = file_.Line();
            if (ptr == 0) break;
            nframes++;
            ptr = file_.Line(); // Next title or EOF
        }
    }
    file_.CloseFile();
    return nframes;
}
示例#15
0
 CDateTime & CDateTime::DecWeek(UINT32 week)
 {
     time_t tmp = GetTimeValue() - week*86400*7;
     SetTimeValue(tmp);
     return *this;
 }
示例#16
0
文件: main.c 项目: bochf/testing
/* ========================================================================= */
int run_as_sender(struct optbase *ob)
{
   /* This used to be char junkbuf[0]; but the compiler complained. junkbuf
      is a pointer to the top of the auto variables. The point is to have
      a pointer to some data - but nothing of particular value. */
   int junk;
   char *junkbuf = (char *)&junk;


   struct roundtrip *rt;

   struct pc_comm *pcomm = NULL;
   int go; /* Used multiple times for "event loops" */
   char child_message[80];

   char mirror_address[MAX_VALUE_SIZE];
   char mirror_protocol[MAX_VALUE_SIZE];
   char mirror_port[MAX_VALUE_SIZE];

   unsigned long multiplier;
   unsigned short optimal_block;

   unsigned long run_seconds;

   char sink_address[MAX_VALUE_SIZE];
   char sink_protocol[MAX_VALUE_SIZE];
   char sink_port[MAX_VALUE_SIZE];

   time_t time_started;  /* Really about reporting. */
   time_t time_now;      /* The most recent time.   */
   time_t time_stop;


   /* Do some basic validation of the expected values */
   if ( IsInvalidOption(ob, "MIRROR_ADDRESS", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_ADDRESS option is missing or invalid.\n");
      return(1);
   }
      
   if ( IsInvalidOption(ob, "MIRROR_PROTOCOL", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_PROTOCOL option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "MIRROR_PORT", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_PORT option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "RETURN_MULTIPLIER", IVO_NNNUMERIC) )
   {
      ErrorMessage("ERROR: RETURN_MULTIPLIER option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "OPTIMAL_BLOCK", IVO_EXISTS) )
   {
      optimal_block = DEFAULT_OPTIMAL_BLOCK;
   }
   else
   {
      if ( GetUSValue(ob, &optimal_block, "OPTIMAL_BLOCK", 0, 65535) )
      {
         ErrorMessage("ERROR: Problems parsing OPTIMAL_BLOCK value.\n");
         return(1);
      }
   }

   if ( IsInvalidOption(ob, "RUN_FOR", IVO_EXISTS) )
   {
      run_seconds = 0;
   }
   else
   {
      if ( GetTimeValue(ob, &run_seconds, "RUN_FOR", 0, ULONG_MAX) )
      {
         ErrorMessage("ERROR: Problems parsing RUN_FOR value.\n");
         return(1);
      }
   }

   if ( GetULValue(ob, &multiplier, "RETURN_MULTIPLIER", 0, ULONG_MAX) )
   {
      ErrorMessage("ERROR: Problems parsing RETURN_MULTIPLIER value.\n");
      return(1);
   }

   if ( multiplier > 0 )
   {
      /* This *could* be derived - it should not be *required* */
      if ( IsInvalidOption(ob, "SINK_ADDRESS", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_ADDRESS option is missing or invalid.\n");
         return(1);
      }

      if ( IsInvalidOption(ob, "SINK_PORT", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_PORT option is missing or invalid.\n");
         return(1);
      }
         
      if ( IsInvalidOption(ob, "SINK_PROTOCOL", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_PROTOCOL option is missing or invalid.\n");
         return(1);
      }
   }
      
   if ( GetStrValue(ob, mirror_address, "MIRROR_ADDRESS", 4, MAX_VALUE_SIZE) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_ADDRESS value.\n");
      return(1);
   }

   if ( GetSTRValue(ob, mirror_protocol, "MIRROR_PROTOCOL", 2, 4) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_PROTOCOL value.\n");
      return(1);
   }

   if ( GetStrValue(ob, mirror_port, "MIRROR_PORT", 2, 5) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_PORT value.\n");
      return(1);
   }

   if ( multiplier > 0 )
   {
      if ( GetStrValue(ob, sink_address, "SINK_ADDRESS", 4, MAX_VALUE_SIZE) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_ADDRESS value.\n");
         return(1);
      }
      
      if ( GetSTRValue(ob, sink_protocol, "SINK_PROTOCOL", 2, 4) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_PROTOCOL value.\n");
         return(1);
      }
         
      if ( GetStrValue(ob, sink_port, "SINK_PORT", 2, 5) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_PORT value.\n");
         return(1);
      }
   }

   ReportStart("netmirror", NULL, "A module to bounce packets across the network.");

   /* Register signal handlers */
   /*
   signal(SIGTERM, capture_signal);
   signal(SIGQUIT, capture_signal);
   signal(SIGINT, capture_signal);
   signal(SIGHUP, NULL);
   */

   if ( NULL == ( rt = InitRoundTrip() ) )
      return(1);

   if ( InitSender(rt, mirror_address, mirror_protocol, mirror_port) )
      return(1);
   
   if ( InitReceiver(rt, sink_address, sink_protocol, sink_port, multiplier) )
      return(1);

   DebugMessage("Round trip multiplier is %lu.\n", multiplier);
   DebugMessage("Run time (in seconds) is: %lu.\n", run_seconds);

   if ( multiplier > 0 )
   {
      if (NULL == (pcomm = LaunchAsSink("ADDR", "PROTO", "PORT")))
         return(1);
   }
   
   /* Check for message from the sink (if we started it). */
   if (pcomm)
   {
      if(CheckForChildMessages(pcomm->outof, 250, child_message) > 0)
         VerboseMessage("Sink: %s\n", child_message);
      /* A sink is present */
   }


   rt->opt_block = optimal_block;
   rt->run_seconds = run_seconds;

   /* Start up the sender and send the opening packets */
   if(StartSender(rt))
      return(1);


   /* Take time here - use it or not */
   time(&time_started);
   time_stop = time_started + run_seconds;

   /* Send packets - handle sink messages */
   go = 1;
   while(go)
   {
      //DebugMessage("Sending data...");
      send(rt->sd, junkbuf, optimal_block, 0);
      //DebugMessage("Done.\n");

      /* NOTE: This is an oppurtunity to put a delay in the sender. It
               can be done here with the CheckForChildMessages() API.
               In cases where there is no sink, then that code will not
               run, so some other blocking mechanisim might be required
               to insert the (optional) delay. */
      if (pcomm)
      {
         /* A sink is present */
         if(CheckForChildMessages(pcomm->outof, 0, child_message) > 0)
            VerboseMessage("Sink: %s\n", child_message);
      }
      
      /* Now time becomes conditional */
      if ( run_seconds > 0 )
      {
         time(&time_now);

         if ( time_now >= time_stop )
            go = 0;
      }
   }

   DebugMessage("Shutting down the connection...");
   close(rt->sd); /* An actual shutdown() is not relevant. */
   DebugMessage("Done.\n");

   /* There should be a several second pause between shutting down
      outbound traffic and sending the stop to the sink. */

   DebugMessage("Sending stop to sink process");
   go = 3;
   while(go)
   {
      DebugMessage(".");
      sleep(1);
      go--;
   }
   SendStopSink(pcomm->into);
   DebugMessage("Done.\n");
      
   go = 10; 
   while ( go )
   {
      if(CheckForChildMessages(pcomm->outof, 500, child_message) > 0)
      {
         if ( child_message[0] == '.' )
         {
            VerboseMessage("Sink exited. Sender exiting now.\n");
            return(0);
         }
      }

      go--;
   }

   ErrorMessage("ERROR: Sink process never exited. Sender exiting.\n");
   return(1);
}
示例#17
0
QTime RDRecording::startTime() const
{
  return GetTimeValue("START_TIME");
}