Esempio n. 1
0
void OutputData(float *outData)
{
	int c, eV;
	long unsigned int e, eTmp, dim;
	double *tmpFits;
	
	tmpFits = (double*)malloc(nExperiments * sizeof(double));

	dim = nExperiments * nCycles;
	for (c = 0; c < nCycles; c++)
	{
		for (e = 0; e < dim; e += nCycles)
		{
			// Check if this outData row must be included
			if (outData[c + e] != -1 || c == nCycles - 1)
			{
				for (eTmp = 0, eV = 0; eTmp < dim; eTmp += nCycles, eV++)
				{
					if (outData[c + eTmp] != -1)
					{
						tmpFits[eV] = outData[c + eTmp];
					}
					else
					{
						outData[c + eTmp] = tmpFits[eV];
					}
				}
				break;
			}
		}
	}
	WriteOutData(outData);
}
Esempio n. 2
0
static bool Swap16AndWrite(TrackBuf& buf, io::stream& dst)
{
    int i = 0;
    char* data = buf.Beg();
    for( ; i < buf.Size()-1; i += 2 )
        std::swap(data[i], data[i+1]);

    WriteOutData(dst, data, buf, i);
    return true;
}
Esempio n. 3
0
void MastersLoop(int startupflags)
{
  int i;
  double energy;
  long daytime, newtinc;
  Entity et;
  Vector sunpos;
  const ParCommand timestep = DO_TIME_STEP;
  while (plausible && actime < tend)  {
    daytime = ((int)(timeofday*3600.)+actime) % 86400;
    printf("Now at %li seconds = %02li:%02li:%02li  ",
           actime, daytime / 3600, (daytime % 3600)/60, daytime % 60);
    pvm_initsend(PvmDataRaw);
    pvm_pkint((int *)&timestep, 1, 1);
    SendCommand();
    ActualiseValuesInTime(actime);
    for (et = maxentity; et--; )
      CalculateLayerAverage(g[et], pstat, avg+et*nz);
    CalcMeanHydrostaticPressure();
    CheckTimeStep(&tinc, &chemtinc, 0.8);
    if (pressuretype == NONHYDROSTATIC)  {		/* Calc wind acceleration */
      SolveForPressure(tinc);
    }
    CheckTimeStep(&newtinc, &chemtinc, 1.);
    chemtinc = (chemtime <= actime ? chemtinc : 0);
    if (nsubs)  printf("chemtinc = %3ld  ", chemtinc);
    if (newtinc < tinc)  {
      fprintf(stderr, "Warning: Time step had to be changed in the middle of iteration\n");
      tinc = newtinc;
    }
    
    // Call ModuleManager
    McInterface::modmanager.DoCalc(actime+tinc);

    actime += tinc; chemtime += chemtinc;
    if (dumpnow || (dumptime && (actime % dumptime == 0)))  {
      MakeAFullDump();
      dumpnow = 0;
    }
    plausible = IsPlausible(&energy);
    printf("Energy = %lf\n", energy);
    if (!(startupflags & NO_OUTPUT))  {
      WriteOutData(actime, FALSE);
      WriteToDomainFiles(actime);
    }
    if (mailtime)  {
      mailtime = 0;
      MailTheTime();
    }
/*    if (nt != tinc)  {
      tinc = nt;
      printf("Changing \"tinc\"; now %ld seconds\n", tinc);
    } */
  }
}
Esempio n. 4
0
static bool Reconstruct24bitLPCM(TrackBuf& buf, int ncha, io::stream& dst)
{
    int j = 0;
    char* buffer   = buf.Beg();
    char* mybuffer = ReserveSameSize(buf);
    for( ; j < (buf.Size()-6*ncha+1) ; j+=(6*ncha) )
    {
        for( int i=0; i<2*ncha; i++ )
        {
            mybuffer[j+3*i+2]=buffer[j+2*i];
            mybuffer[j+3*i+1]=buffer[j+2*i+1];
            mybuffer[j+3*i]=  buffer[j+4*ncha+i];
        }
    }
    
    WriteOutData(dst, mybuffer, buf, j);
    return true;
}
bool AutomatedTestHarness::FrameUpdate(float fElapsedTime)
{
    if(m_complete) return false;

    // A little dead time between events
    if(--m_accumEventChange > 0) return false;

    // each simulation event smooths over a few frames...
    m_accumTime += fElapsedTime;
    m_accumFrame++;

    // limit step by a fixed time
    if(m_accumFrame < smoothFrames) return false;

    SimulationTestResult r;
    r.instances = m_events[m_currentEvent].instances;
    r.dcType = m_events[m_currentEvent].dcType;
    r.ms = m_accumTime / (float)m_accumFrame;    // average time per frame
    r.frames = m_accumFrame;    // probably wont' use this data
    r.bVaryShaders = m_events[m_currentEvent].bVaryShaders;
    r.bUnifyVSPSCB = m_events[m_currentEvent].bUnifyVSPSCB;
    r.bVTF = m_events[m_currentEvent].bVTF;
    r.threads = m_events[m_currentEvent].threads;
    r.updatethreads = m_events[m_currentEvent].updatethreads;
    m_results.push_back(r);

    m_accumFrame = 0;
    m_accumTime = 0.f;
    m_accumEventChange = eventChangeFrames;

    // Go to the next event
    m_currentEvent++;

    if(m_currentEvent == (int)m_events.size())
    {
        WriteOutData();
        m_complete = true;
        return false;
    }

    return true;
}
Esempio n. 6
0
static bool Reconstruct20bitLPCM(TrackBuf& buf, int ncha, io::stream& dst)
{
#define hi_nib(a)	((a>>4) & 0x0f)
#define lo_nib(a)	(a & 0x0f)

    int j = 0;
    char* buffer   = buf.Beg();
    char* mybuffer = ReserveSameSize(buf);
    for( ; j < (buf.Size()-5*ncha+1) ; j+=(5*ncha) )
    {
        for( int i=0; i<ncha; i++ )
        {
            mybuffer[j+5*i+0] = (hi_nib(buffer[j+4*ncha+i])<<4) + hi_nib(buffer[j+4*i+1]);
            mybuffer[j+5*i+1] = (lo_nib(buffer[j+4*i+1])<<4) + hi_nib(buffer[j+4*i+0]);
            mybuffer[j+5*i+2] = (lo_nib(buffer[j+4*i+0])<<4) + lo_nib(buffer[j+4*ncha+i]);
            mybuffer[j+5*i+3] = buffer[j+4*i+3];
            mybuffer[j+5*i+4] = buffer[j+4*i+2];
        }
    }
    
    WriteOutData(dst, mybuffer, buf, j);
    return true;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
  Entity et;
  int error, startupflags, i;
  char *restartname, name[128];
#ifdef PARALLEL
  const ParCommand end = EXIT;
#endif
  InitVarTable();
#ifdef PARALLEL
  IsMaster();
  if (master) {
    printf("MetPhoMod   Rel. 2.2\n" SYSTEM " parallel Version - " DATE "\n\n");
#else
  printf("MetPhoMod   Rel. 2.2\n" SYSTEM " sequential Version - " DATE "\n\n");
#endif
    if (argc > 1 && (!strcmp(argv[1], "-help") || !strcmp(argv[1], "-h")))  {
      McInterface::modmanager.Init1();
      PrintHelp(argc - 2, argv + 2);
      exit (0);
    }
    if (argc > 1 && !strcmp(argv[1], "-genchem"))  {
      if (argc != 3)  goto instant_help;
      GenerateSpecialChem(argv[2]);
      exit (0);
    }
    startupflags = AnalizeOptions(&argc, argv, &restartname);
    if (argc != 2)  {
instant_help :
      printf("Usage : meteochem [-RESTART restart-file [-REOPEN]] [-noexcpt] [-syntax] \\\n"
             "                  [-nooutput] [-debug] [-sequential] inpfile\n"
             "or    : meteochem (-h | -help) [keyword]\n"
             "or    : meteochem -genchem chemfile\n");
      return (1);
    }
    McInterface::modmanager.Init1();
    if (startupflags & SYNTAX_ONLY)  {
      if (ParseInput(argv[1]))  {
        printf("Errors in Input-File\n");
        return (1);
      }
      else  {
        printf("the input-file seems to be OK!\n");
        return (0);
      }
    }
#ifdef PARALLEL
    if (startupflags & SEQUENTIAL)  {
      parallel = FALSE; master = TRUE;
      leftest = rightest = TRUE;
    }
  }
  if (master)  {
#endif
    if (ParseInput(argv[1]))  {
      fprintf(stderr, "Errors parsing Input-File. I don't start the calculation.\n");
      return (1);
    }
    plausible = TRUE;
    if (!(startupflags & NOEXCPT))  InstallFpeHandler();
    tinc = chemtinc = tincmax;
    actime = chemtime = tstart;
#ifdef PARALLEL
    if (!parallel)  printf("\n\n!!! Using sequential mode !!!\n\n");
    else
      McInterface::modmanager.CheckIfReadyForParallel();
  }
  InitializeWorkers(argv[0], startupflags & DEBUG_WORKERS);
  if (parallel && !master)  {
    if (!(startupflags & NOEXCPT))  InstallFpeHandler();
    McInterface::modmanager.Init1();
    ReadDataFromMaster();
    InitializeData();
    plausible = TRUE;
    tinc = chemtinc = tincmax;
    actime = chemtime = tstart;
  }
  if (parallel && master)  {
    printf("Sending Data to workers...\n");
    SendDataToWorkers();
    InitializeData();
  }
  if (!parallel)
#endif
    InitializeData();
  for (et = maxentity; et--; )
    if (g[et])
      CalculateLayerAverage(g[et], pstat, avg+et*nz);
    else
      memset(avg+et*nz, 0, nz*sizeof(double));
  CalcMeanHydrostaticPressure();
#ifdef PARALLEL
  if (!parallel || !master)  {
#endif
    SetAvgMountains();
    SetBoundary(maxentity);
/*    CalcAllKm();  */
#ifdef PARALLEL
  }
  if (parallel && !master)  {
    if (GetRestartName(name))  {
      if (!(ReadFullDump(name, (startupflags & REOPEN)) && actime <= tend))  {
	printf("Error : Restart-file not found\n");
	plausible = FALSE;
      }
    }
  }
  else  {
    if (parallel)
      SendRestartName((startupflags & RESTART) ? restartname : NULL);
#endif
    if (startupflags & RESTART)  {
      if (!ReadFullDump(restartname, (startupflags & REOPEN)))  {
        printf("Error : Restart-file not found\n");
        return (1);
      }
    }
    else if (startupflags & REOPEN)  {
      printf("Error: -REOPEN can only be used together with -RESTART\n");
      return (1);
    }
#ifdef PARALLEL
  }
  if (master)  {
#endif
    if (!(startupflags & NO_OUTPUT))  {
      printf("Opening output-Files...");
      if (OpenOutputFiles(argv[1], (startupflags & RESTART) && (startupflags & REOPEN)))  {
        printf("\nExecution abortet\n");
        exit (1);
      }
      CreateDomainFiles((startupflags & RESTART) && (startupflags & REOPEN));
    }
    InstallSignalHandler();
    printf("\n");
#ifdef PARALLEL
    if (parallel)  printf("Starting calculation...\n");
  }
#else  
  printf("Starting calculation...\n");
#endif
#if PARALLEL
  if (!parallel || master)  
#endif
    if (!(startupflags & NO_OUTPUT))  {
      WriteOutData(tstart, FALSE);
      WriteToDomainFiles(tstart);
    }
/*  TestChemicals("Start");  */
#if PARALLEL
  if (parallel)
    if (master)  MastersLoop(startupflags);
    else	 WorkersLoop(startupflags);
  else
#endif
    SequentialLoop(startupflags);
  printf("Closing output-Files...\n");
  if (plausible)  printf("Calculation terminated successfully\n\n");
  else  {
    if (!(startupflags & NO_OUTPUT))
      WriteOutData(actime, TRUE);
    printf("Calculation stopped because of inplausibilities!\n\n");
  }
  if (!(startupflags & NO_OUTPUT))  {
    CloseOutputFiles();
    CloseDomainFiles();
  }
#ifdef PARALLEL
  if (parallel)  {
    pvm_initsend(PvmDataRaw);
    pvm_pkint((int *)&end, 1, 1);
    SendCommand();
    pvm_exit();
  }
#endif
  return (0);
}
Esempio n. 8
0
void SequentialLoop(int startupflags)
{
  int i;
  double theta;
  long daytime, newtinc;
  Entity et;
  Vector sunpos;
  while (plausible && actime < tend)  {
    daytime = ((int)(timeofday*3600.)+actime) % 86400;
    printf("Now at %li seconds = %02li:%02li:%02li  ",
           actime, daytime / 3600,
           (daytime % 3600)/60,
           daytime % 60);
    ActualiseValuesInTime(actime);	/* Actualise Border values */
    for (et = maxentity; et--; )
      CalculateLayerAverage(g[et], pstat, avg+et*nz);
    SetAvgMountains();
    CalcMeanHydrostaticPressure();
    InterpolateToFaces();			/* Interpolate wind speeds from center to faces */
    InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC);
    if (tstart == actime)  Continuity();
    CheckTimeStep(&tinc, &chemtinc, 0.8);
    if (pressuretype == NONHYDROSTATIC)
      ApplyBuoyancy(tinc);			/* Calculate Buoyancy */
    if (pressuretype != NOPRESSURE)  {		/* Calc wind acceleration */
      switch (pressuretype)  {			/* Calculate Pressure field */
         case HYDROSTATIC    : CalcHydrostaticPressure(); break;
         case NONHYDROSTATIC : SolveForPressure(tinc); break;
      }
      ApplyPressure(tinc);
    }
    Continuity();				/* Mass conservation */
    InterpolateToCenter(1., pressuretype == NONHYDROSTATIC);
    if (coriolistype != NOCORIOLIS)  ApplyCoriolis(tinc);
    if (filtertype != NO_FILTER)  {
      SetBoundary(WWIND+1);
      switch (filtertype)  {
        case PEPPER_FILTER :
           for (i = nz; i--; )
             for (et = HUMIDITY; et--; )
               ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter);
           break;
        case SHAPIRO_FILTER :
           for (i = nz; i--; )  {
             for (et = HUMIDITY; et--; )
               ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter);
/*             if (turbtype == KEPS_T)  {
               ShapiroFilter(g[TKE]+i*layer, pstat+i*layer, 3, spatialfilter);
               ShapiroFilter(g[EPS]+i*layer, pstat+i*layer, 3, spatialfilter);
             } */
           }
           break;
        case DIFFUSION_FILTER :
           for (i = nz; i--; )
             for (et = HUMIDITY; et--; )
               ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter);
           break;
      }
    }
    SetBoundary(WWIND+1);
    CheckTimeStep(&newtinc, &chemtinc, 1.);
    if (newtinc < tinc)  {
      fprintf(stderr, "Warning: Time step had to be changed in the middle of iteration\n");
      tinc = newtinc;
    }
    chemtinc = (chemtime <= actime ? chemtinc : 0);
    if (nsubs)  printf("chemtinc = %3ld  ", chemtinc);
    if (advection || windadvection)
      switch (advectiontype)  {
        case MPDATA_A : Advect(tinc, chemtinc); break;
        case PPM_A    : PPM_Transport(tinc, chemtinc, smiord); break;
      }
    if (dampinglayer)  DampTop();
    if (groundinterface || shortwaveradiation)  {
      GroundInterface(timeofday + (double)actime / 3600., dayofyear,
		      tinc, &sunpos);
      sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.);
    }
    if (cloudwater)  CloudPhysics();
    if (turbtype == TTTT)  {
      if (groundinterface)
        CalcGroundTurbulence(tinc);
      CalcTransilientTurbulence(tinc);
    }
    else if (turbtype == KEPS_T)  {
      CalcKEpsilon(tinc);
      if (groundinterface)
        CalcGroundTurbulence(tinc);
      CalcKTurb(tinc, chemtinc);
    }
    Emit(tinc);
    Deposit(tinc);
    if (!(radiationtype && shortwaveradiation) &&
	// When using the two-stream module, ChemicalTimeStep
	// must be called from within ShortWaveRadiation!
	nsubs && actime % tchem == 0)  ChemicalTimeStep(tchem, &sunpos);
    SetBoundary(chemtinc ? maxentity : SUBS);
    
    // Call ModuleManager
    McInterface::modmanager.DoCalc(actime+tinc);
/*    TestChemicals("Boundary");  */
    actime += tinc; chemtime += chemtinc;
    if (!(startupflags & NO_OUTPUT))  {
      WriteOutData(actime, FALSE);
      WriteToDomainFiles(actime);
    }
    if (dumpnow || (dumptime && (actime % dumptime == 0)))  {
      MakeAFullDump();
      dumpnow = 0;
    }
    if (mailtime)  {
      mailtime = 0;
      MailTheTime();
    }
    printf("Energy = %lf\n", CalcTopEnergy());
  }
}