testing/icgen/random_verschillende_resoluties_N-GenIC/gadget3_64/run.c
int find_next_outputtime(int ti_curr)
{
  int i, ti, ti_next, iter = 0;
  double next, time;

  DumpFlag = 1;
  ti_next = -1;


  if(All.OutputListOn)
    {
      for(i = 0; i < All.OutputListLength; i++)
	{
	  time = All.OutputListTimes[i];

	  if(time >= All.TimeBegin && time <= All.TimeMax)
	    {
	      if(All.ComovingIntegrationOn)
		ti = (int) (log(time / All.TimeBegin) / All.Timebase_interval);
	      else
		ti = (int) ((time - All.TimeBegin) / All.Timebase_interval);

	      if(ti >= ti_curr)
		{
		  if(ti_next == -1)
		    {
		      ti_next = ti;
		      DumpFlag = All.OutputListFlag[i];
		    }

		  if(ti_next > ti)
		    {
		      ti_next = ti;
		      DumpFlag = All.OutputListFlag[i];
		    }
		}
	    }
	}
    }
  else
    {
      if(All.ComovingIntegrationOn)
	{
	  if(All.TimeBetSnapshot <= 1.0)
	    {
	      printf("TimeBetSnapshot > 1.0 required for your simulation.\n");
	      endrun(13123);
	    }
	}
      else
	{
	  if(All.TimeBetSnapshot <= 0.0)
	    {
	      printf("TimeBetSnapshot > 0.0 required for your simulation.\n");
	      endrun(13123);
	    }
	}

      time = All.TimeOfFirstSnapshot;

      iter = 0;

      while(time < All.TimeBegin)
	{
	  if(All.ComovingIntegrationOn)
	    time *= All.TimeBetSnapshot;
	  else
	    time += All.TimeBetSnapshot;

	  iter++;

	  if(iter > 1000000)
	    {
	      printf("Can't determine next output time.\n");
	      endrun(110);
	    }
	}

      while(time <= All.TimeMax)
	{
	  if(All.ComovingIntegrationOn)
	    ti = (int) (log(time / All.TimeBegin) / All.Timebase_interval);
	  else
	    ti = (int) ((time - All.TimeBegin) / All.Timebase_interval);

	  if(ti >= ti_curr)
	    {
	      ti_next = ti;
	      break;
	    }

	  if(All.ComovingIntegrationOn)
	    time *= All.TimeBetSnapshot;
	  else
	    time += All.TimeBetSnapshot;

	  iter++;

	  if(iter > 1000000)
	    {
	      printf("Can't determine next output time.\n");
	      endrun(111);
	    }
	}
    }


  if(ti_next == -1)
    {
      ti_next = 2 * TIMEBASE;	/* this will prevent any further output */

      if(ThisTask == 0)
	printf("\nThere is no valid time for a further snapshot file.\n");
    }
  else
    {
      if(All.ComovingIntegrationOn)
	next = All.TimeBegin * exp(ti_next * All.Timebase_interval);
      else
	next = All.TimeBegin + ti_next * All.Timebase_interval;

      if(ThisTask == 0)
	printf("\nSetting next time for snapshot file to Time_next= %g  (DumpFlag=%d)\n\n", next, DumpFlag);

    }

  return ti_next;
}
/*! this function returns the next output time that is equal or larger to
 *  ti_curr
 */
this function returns the next output time that is equal or larger to
ti_curr
this function returns the next output time that is equal or larger to ti_curr
int find_next_outputtime(int ti_curr)
{
  int i, ti, ti_next, iter = 0;
  double next, time;
  DumpFlag = 1;
  ti_next = -1;
  if(All.OutputListOn)
    {
      for(i = 0; i < All.OutputListLength; i++)
	{
	  time = All.OutputListTimes[i];
	  if(time >= All.TimeBegin && time <= All.TimeMax)
	    {
	      if(All.ComovingIntegrationOn)
		ti = (int) (log(time / All.TimeBegin) / All.Timebase_interval);
	      else
		ti = (int) ((time - All.TimeBegin) / All.Timebase_interval);
	      if(ti >= ti_curr)
		{
		  if(ti_next == -1)
		    {
		      ti_next = ti;
		      DumpFlag = All.OutputListFlag[i];
		    }
		  if(ti_next > ti)
		    {
		      ti_next = ti;
		      DumpFlag = All.OutputListFlag[i];
		    }
		}
	    }
	}
    }
  else
    {
      if(All.ComovingIntegrationOn)
	{
	  if(All.TimeBetSnapshot <= 1.0)
	    {
	      printf("TimeBetSnapshot > 1.0 required for your simulation.\n");
	      endrun(13123);
	    }
	}
      else
	{
	  if(All.TimeBetSnapshot <= 0.0)
	    {
	      printf("TimeBetSnapshot > 0.0 required for your simulation.\n");
	      endrun(13123);
	    }
	}
      time = All.TimeOfFirstSnapshot;
      iter = 0;
      while(time < All.TimeBegin)
	{
	  if(All.ComovingIntegrationOn)
	    time *= All.TimeBetSnapshot;
	  else
	    time += All.TimeBetSnapshot;
	  iter++;
	  if(iter > 1000000)
	    {
	      printf("Can't determine next output time.\n");
	      endrun(110);
	    }
	}
      while(time <= All.TimeMax)
	{
	  if(All.ComovingIntegrationOn)
	    ti = (int) (log(time / All.TimeBegin) / All.Timebase_interval);
	  else
	    ti = (int) ((time - All.TimeBegin) / All.Timebase_interval);
	  if(ti >= ti_curr)
	    {
	      ti_next = ti;
	      break;
	    }
	  if(All.ComovingIntegrationOn)
	    time *= All.TimeBetSnapshot;
	  else
	    time += All.TimeBetSnapshot;
	  iter++;
	  if(iter > 1000000)
	    {
	      printf("Can't determine next output time.\n");
	      endrun(111);
	    }
	}
    }
  if(ti_next == -1)
    {
      ti_next = 2 * TIMEBASE;	
      if(ThisTask == 0)
	printf("\nThere is no valid time for a further snapshot file.\n");
    }
  else
    {
      if(All.ComovingIntegrationOn)
	next = All.TimeBegin * exp(ti_next * All.Timebase_interval);
      else
	next = All.TimeBegin + ti_next * All.Timebase_interval;
      if(ThisTask == 0)
	printf("\nSetting next time for snapshot file to Time_next= %g  (DumpFlag=%d)\n\n", next, DumpFlag);
    }
  return ti_next;
}
int find_next_outputtime ( int ti_curr ) { int i , ti , ti_next , iter = 0 ; double next , time ; DumpFlag = 1 ; ti_next = -1 ; if ( All . OutputListOn ) { for ( i = 0 ; i < All . OutputListLength ; i ++ ) { time = All . OutputListTimes [ i ] ; if ( time >= All . TimeBegin && time <= All . TimeMax ) { if ( All . ComovingIntegrationOn ) ti = ( int ) ( log ( time / All . TimeBegin ) / All . Timebase_interval ) ; else ti = ( int ) ( ( time - All . TimeBegin ) / All . Timebase_interval ) ; if ( ti >= ti_curr ) { if ( ti_next == -1 ) { ti_next = ti ; DumpFlag = All . OutputListFlag [ i ] ; } if ( ti_next > ti ) { ti_next = ti ; DumpFlag = All . OutputListFlag [ i ] ; } } } } } else { if ( All . ComovingIntegrationOn ) { if ( All . TimeBetSnapshot <= 1.0 ) { printf ( " \n " ) ; endrun ( 13123 ) ; } } else { if ( All . TimeBetSnapshot <= 0.0 ) { printf ( " \n " ) ; endrun ( 13123 ) ; } } time = All . TimeOfFirstSnapshot ; iter = 0 ; while ( time < All . TimeBegin ) { if ( All . ComovingIntegrationOn ) time *= All . TimeBetSnapshot ; else time += All . TimeBetSnapshot ; iter ++ ; if ( iter > 1000000 ) { printf ( " \n " ) ; endrun ( 110 ) ; } } while ( time <= All . TimeMax ) { if ( All . ComovingIntegrationOn ) ti = ( int ) ( log ( time / All . TimeBegin ) / All . Timebase_interval ) ; else ti = ( int ) ( ( time - All . TimeBegin ) / All . Timebase_interval ) ; if ( ti >= ti_curr ) { ti_next = ti ; break ; } if ( All . ComovingIntegrationOn ) time *= All . TimeBetSnapshot ; else time += All . TimeBetSnapshot ; iter ++ ; if ( iter > 1000000 ) { printf ( " \n " ) ; endrun ( 111 ) ; } } } if ( ti_next == -1 ) { ti_next = 2 * TIMEBASE ; if ( ThisTask == 0 ) printf ( " \n \n " ) ; } else { if ( All . ComovingIntegrationOn ) next = All . TimeBegin * exp ( ti_next * All . Timebase_interval ) ; else next = All . TimeBegin + ti_next * All . Timebase_interval ; if ( ThisTask == 0 ) printf ( " \n \n \n " , next , DumpFlag ) ; } return ti_next ; }
this function returns the next output time that is equal or larger to
  ti_curr
this function returns the next output time that is equal or larger to ti_curr
/* this will prevent any further output */