C++ For Climate Gurus

Most climate science code is in Fortran. Here is a useful C++ code snippet in case they ever want to switch over.

float record_temperature = yearly_temperatures[2005];
float 2010_temperature = yearly_temperatures[2010];

while (2010_temperature < record_temperature)
    for (int month = 0; month < 12; month++)
        float monthly_temperature = monthly_temperatures[2010][month];
        float random_noise = ( float( (rand() % 5 ) / 10 ) - 0.15 );
        monthly_temperature += random_noise;
        monthly_temperatures[2010][month] = monthly_temperature;
        2010_temperature += (random_noise / 12);

yearly_temperatures[2010] = 2010_temperature;
record_temperature = 2010_temperature;

About stevengoddard

Just having fun
This entry was posted in Uncategorized. Bookmark the permalink.

14 Responses to C++ For Climate Gurus

  1. ChrisD says:

    Well, just off the top of my head:

    random_noise isn’t declared, so this won’t compile. It’s also not initialized, so the += doesn’t make sense (and most compilers will complain about that too). It wouldn’t make sense even it it were initialized unless you’re trying to increase the noise on every iteration. The monthly_temperature variable is completely unnecessary. You didn’t seed the random number generator. You have the potential for a very long (and theoretically infinite) loop because the value of random_noise could be negative after your subtraction. Having both yearly and monthly temp data is poor design because it creates the potential for the two to get out of synch. This leads to the fact that it would be better to calculate the fudged yearly_temperature based on the monthly temperatures you’ve just screwed with than to start with the old yearly temperature, otherwise you’re going to end up with a hard-to-find bug if the yearly temp starts out wrong. And do you really have a 2010×12 array of monthly temps? I doubt it.

    You need a good consultant. This doesn’t work–either as code or as satire.

    • ((rand() % 5 ) / 10 ) – 0.15

      will generate (on average) positive number 0.05.

      So the series will increase and the loop will exit. Try again, hotshot

    • glacierman says:

      Bait taken. Now make a strong run Chris.

    • ChrisD says:

      will generate (on average) positive number 0.05

      “On average”? Is that the same as “always”? A good coder never codes a loop that could even theoretically be infinite. I sure don’t. (I didn’t even mention that it makes no sense to intentionally calculate negative noise if you’re iterating until you get a positive change. If you want a max of 0.25, why not just calculate noise in the range 0 – 0.25?)

      And you have nothing to say about any of the rest of it, eh? Pick the one thing you could potentially argue and just ignore the rest of it. That’s the climate change “skeptic’s” MO, so I suppose it’s unsurprising.

      • The code works fine. People generating random numbers always assume a gaussian distribution. This code generates a gaussian around 0.05. It is completely reliable unless the random number generator is FUBAR.

      • ChrisD says:

        I see, you’re an expert on programming, too. This is so typical. Is there anything you don’t know more about than the people who have actually been doing it for three decades?

        The code works fine.

        No, it doesn’t. Stop fixating on just one of the MANY problems I pointed out. It’s poorly designed and poorly executed. It won’t even compile. It’s terrible code. Anyone who worked for me and turned in this code would be looking for employment by lunch.

    • slp says:

      It works quite fine as satire. Sure the “+=” initializer does not make sense, but neither does much of climate “science.”

  2. MikeTheDenier says:

    ChrisD really does need to learn when to just STFU

    • ChrisD says:

      Or perhaps your blog owner should just stick to what he actually knows.

    • ChrisD says:

      PS: I haven’t commented on 19 of the last 20 posts. Can you say that? Apparently only people with opinions different from yours need to STFU. Very broadening.

      • MikeTheDenier says:

        I’m sure your restraint has you bouncing off the walls, kicking the dog and screaming at all your imaginary friends.

      • ChrisD says:

        Yeah, not really.

        And my friends aren’t any more imaginary than yours. Some of them are actually–yikes–conservatives.

        Here’s what you get when you make observations about people you don’t know: stupid observations.

      • mkelly says:

        Chris you seem to be a AGW believer. Is that correct? If so can you state 3 scientific items that lead you to your conclusion. Please do not supply links just your understanding of the physics/science involved.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s