override protected int PassDepart(int pass)
        {
            int pout = Math.Max(0, RNG.Bin(pass, PassOut.getRate(Time.Now())));

            TotalOut += pout;
            return(pout);
        }
        public Station(string name, TimeDistr inrate, TimeDistr outrate, TimeDistr indens, int pass,
                       double driveavg, double drivevar, string datafolder, Simulation sim)
        {
            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Initialising station " + name);
                if (Simulation.WAIT)
                {
                    Console.ReadLine();
                }
            }
            Name           = name;
            Spaces         = new Tram[1];
            lastpassupdate = 0;
            PassWaiting    = 0;
            lastDeparture  = 0;
            TotalIn        = 0;
            TotalOut       = 0;
            DriveAvg       = driveavg;
            DriveVar       = drivevar;
            Sim            = sim;


            //reformulate distributions for incoming passengers to something sensible
            int[]    times      = indens.getTimes();
            double[] passengers = new double[times.Length];
            for (int i = 0; i < passengers.Length; i++)
            {
//                if (Simulation.EXPLICIT) Console.WriteLine("Calculating passengers at time " + times[i].ToString());
                passengers[i] = Convert.ToDouble(pass) * inrate.getRate(times[i]) * indens.getRate(times[i]);
//                if (Simulation.EXPLICIT) Console.WriteLine("Passengers from time " + times[i].ToString() + " : " + passengers[i].ToString());
            }
            PassArrival = new TimeDistr(times, passengers);

            PassArrival.WriteToFile(datafolder + Name + "PassDistr.csv");

            PassOut = outrate;

            logPassengersWaiting = new StreamWriter(datafolder + Name + "PassWaiting.csv");
            logPassengersWaiting.WriteLine("Time , Passengers waiting, passengers in tram");
            logInterDepartureTime = new StreamWriter(datafolder + Name + "IntDepTime.csv");
            logInterDepartureTime.WriteLine("Time , time since last Departure");
            logTramsWaiting = new StreamWriter(datafolder + Name + "TramsWaiting.csv");
            logTramsWaiting.WriteLine("Time , trams waiting , trams at station");
            logWaitingtime = new StreamWriter(datafolder + Name + "WaitingTime.csv");
            logWaitingtime.WriteLine("Time , passengers already waiting , time last departure , new passengers , time since last passenger update , passengers waiting after loading");
            logDwelltime = new StreamWriter(datafolder + name + "Dwelltime.csv");
            logDwelltime.WriteLine("Time , dwelltime of departing tram");
        }
/*
 *  All RNG-based functions
 *
 */

        override protected int updatePassWaiting()
        {
            //get intervals from the PassArival which fall within lastupdate to Now, from there calculate the passengers waiting.

            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Updating waiting passengers");
            }
            int[] times = PassArrival.getIntervals(lastpassupdate, Time.Now());

            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Calculating passengers at station " + Name + "over interval " + Time.Now().ToString() + " from " + lastpassupdate.ToString());
            }

            int newpass = 0;

            for (int i = 0; i < times.Length - 1; i++)
            {
                int time = times[i + 1] - times[i];
                if (Simulation.EXPLICIT)
                {
                    Console.WriteLine("Calculatign for subinterval " + times[i].ToString() + " to " + times[i + 1].ToString() + ". Passengers per second: " + PassArrival.getRate(times[i]).ToString());
                }
                newpass += Math.Max(0, RNG.Poisson(PassArrival.getRate(times[i]) * Convert.ToDouble(time)));
                //newpass += Convert.ToInt32(PassArrival.getRate(Time.Now()) * Convert.ToDouble (Time.Now() - lastpassupdate)); //HOTFIX: TODO: FIX
            }


//            Console.WriteLine("passengers per second: " + PassArrival.getRate(Time.Now()).ToString() + " time since update: " + (Time.Now() - lastpassupdate).ToString() );
//            newpass = Convert.ToInt32(PassArrival.getRate(Time.Now()) * Convert.ToDouble (Time.Now() - lastpassupdate)); //hotfic, ugle as f**k.
            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("New passengers: " + newpass.ToString());
            }
            lastpassupdate = Time.Now();
            PassWaiting   += newpass;
            TotalIn       += newpass;
            return(newpass);
        }
        public Station (string name, TimeDistr inrate, TimeDistr outrate, TimeDistr indens, int pass, 
                        double driveavg, double drivevar, string datafolder, Simulation sim) { 
            if (Simulation.EXPLICIT) {
                Console.WriteLine("Initialising station " + name);
                if (Simulation.WAIT) Console.ReadLine();
            } 
            Name = name;
            Spaces = new Tram[1];
            lastpassupdate = 0;
            PassWaiting = 0;
            lastDeparture = 0;
            TotalIn = 0;
            TotalOut = 0;
            DriveAvg = driveavg;
            DriveVar = drivevar;
            Sim = sim;


            //reformulate distributions for incoming passengers to something sensible
            int[] times = indens.getTimes();
            double[] passengers = new double[times.Length];
            for (int i = 0; i < passengers.Length; i++) {
//                if (Simulation.EXPLICIT) Console.WriteLine("Calculating passengers at time " + times[i].ToString());
                passengers[i] = Convert.ToDouble(pass) * inrate.getRate(times[i]) * indens.getRate(times[i]);
//                if (Simulation.EXPLICIT) Console.WriteLine("Passengers from time " + times[i].ToString() + " : " + passengers[i].ToString());
            }
            PassArrival = new TimeDistr(times, passengers);

            PassArrival.WriteToFile(datafolder+Name+"PassDistr.csv");

            PassOut = outrate;
    
            logPassengersWaiting = new StreamWriter(datafolder + Name + "PassWaiting.csv");
            logPassengersWaiting.WriteLine("Time , Passengers waiting, passengers in tram");
            logInterDepartureTime = new StreamWriter(datafolder + Name + "IntDepTime.csv");
            logInterDepartureTime.WriteLine("Time , time since last Departure");
            logTramsWaiting = new StreamWriter(datafolder + Name + "TramsWaiting.csv");
            logTramsWaiting.WriteLine("Time , trams waiting , trams at station");
            logWaitingtime = new StreamWriter(datafolder + Name + "WaitingTime.csv");
            logWaitingtime.WriteLine("Time , passengers already waiting , time last departure , new passengers , time since last passenger update , passengers waiting after loading");
            logDwelltime = new StreamWriter(datafolder + name + "Dwelltime.csv");
            logDwelltime.WriteLine("Time , dwelltime of departing tram");

        }