Dealing with MCNP mesh data

MCNP mesh tallies generate a lot of numbers to deal with. It all gets written to a formatted text file. Depending on the size and resolution of your simulation, you can easily end up with GBs of data in a single text file.

The first simulations I did, I decided to stuff it all into a database and use Excel to pull out the bits I wanted. It’s a little clumsy and somewhat cumbersome but it works.

As I work with MCNP more, I’ll probably come up with better ways and find better tools to help deal with the data. For now, this is the snippet of PHP code I wrote to stick the data into my DB.


// Mesh simulation data format
// '   Energy         X         Y         Z     Result     Rel Error     Volume    Rslt * Vol'
// '  1.000E+36   -98.000   -98.000   -94.000 8.44128E-19 4.58915E-03 6.40000E+01 5.40242E-17';
// Open the file for reading
if ($fh = fopen($mesh_file,"r")) {
    // Read file line by line
    while ($mesh_line = fgets($fh)) {
        // Split the data and insert into the database
        if ($c=preg_split("/\s+/",$mesh_line)) {
            $x=(float)$c[2]; // x
            $y=(float)$c[3]; // y
            $z=(float)$c[4]; // z
            $result=(float)$c[5]; // result
            $rel_err=(float)$c[6]; // rel error
//          $vol=(float)$c[7]; // volume
//          $result_vol=(float)$c[8]; // result_vol
            $res =& $dbh->query("insert into MeshData 
                (sim_id,x,y,z,result,rel_err) values ($sim_id,$x,$y,$z,$result,$rel_err)");
            if (PEAR::isError($res)) {
                echo ($res->getMessage().' - '.$res->getUserInfo());
            }
        }
    }
}

Trying to learn about PHP frameworks

A recent discussion on PHP frameworks on the PHP mailing list got me thinking about how I could use them to rewrite some of my DB projects. I looked into a few of the frameworks brought up in the discussion, and they look interesting. The frameworks I picked up on were the MVC (model-view-controller) types, which reminded me of the event-based OO programming style of Objective-C on NeXTStep.
They also made me realize that I’d really be pushing my meager programming skills to the edge trying to figure out how these things work and how to use them. It’s also going to take me a good bit of time to learn them too, which is something that always seems to be in short supply these days.
Well, add one more thing to my ever growing list of things to learn 🙂
Couple of useful articles I stumbled upon over at ONLamp.com that might help me get started.
Understanding MVC in PHP
Implementing MVC in PHP: The Controller
Implementing MVC in PHP: The View
Implementing MVC in PHP: The Model
A list of different PHP frameworks: MVC Frameworks Written in PHP
WASP looks interesting.

phpMyAdmin searching bot

Every now and then, I’ll spot a bot hitting the server looking for an installation of phpMyAdmin. Presumably it’s looking for a version to exploit or one that can be used to swipe data from. They typically come as a burst of requests trying to find it in some variation of commonly used folders.

Today though was the first day I spotted a bot that actually specified a user-agent in it’s HTTP request. Isn’t that kind of like a burgular wearing a bright red shirt that has ‘THIEF’ written on it?

h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:54 -0400] “GET /PMA/main.php HTTP/1.0” 404 4998 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:54 -0400] “GET /phpmyadmin/main.php HTTP/1.0” 404 5005 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:55 -0400] “GET /mysql/main.php HTTP/1.0” 404 5000 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:55 -0400] “GET /admin/main.php HTTP/1.0” 404 5000 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:56 -0400] “GET /db/main.php HTTP/1.0” 404 4997 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:56 -0400] “GET /dbadmin/main.php HTTP/1.0” 404 5002 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:56 -0400] “GET /web/phpMyAdmin/main.php HTTP/1.0” 404 5009 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:56 -0400] “GET /admin/pma/main.php HTTP/1.0” 404 5004 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:57 -0400] “GET /admin/phpmyadmin/main.php HTTP/1.0” 404 5011 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:57 -0400] “GET /admin/mysql/main.php HTTP/1.0” 404 5006 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:57 -0400] “GET /mysql-admin/main.php HTTP/1.0” 404 5006 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:57 -0400] “GET /phpmyadmin2/main.php HTTP/1.0” 404 5006 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:58 -0400] “GET /mysqladmin/main.php HTTP/1.0” 404 5005 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:58 -0400] “GET /mysql-admin/main.php HTTP/1.0” 404 5006 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:59 -0400] “GET /main.php HTTP/1.0” 404 4994 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:19:59 -0400] “GET /phpMyAdmin-2.5.4/main.php HTTP/1.0” 404 5011 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:20:00 -0400] “GET /phpMyAdmin-2.5.1/main.php HTTP/1.0” 404 5011 “-” “PMAFind”
h-69-3-143-228.nycmny83.covad.net – – [11/Oct/2005:08:20:08 -0400] “GET /phpMyAdmin-2.5.6/main.php HTTP/1.0” 404 5011 “-” “PMAFind”

This bot didn’t just hit my server once…it visited three times in the same day…from the same address.

Not much useful in Google about this beast. Just a couple of posts. The rest of Google’s results are just webserver usage statistics showing hits by the bot.

PHP security

One of the problems I’ve run into while writing up some of my little PHP web scripts is how to make them reasonably secure. Everybody talks about how code need to be made secure, but so far I’ve found it difficult to find actual examples or guides on just how to write secure code. Maybe it’s just the non-programmer in me that has a hard time with this.
So I was somewhat pleased to hear about the formation of the PHP Security Consortium. Hopefully this will become a good resource for people like me (as well as more experienced coders).

Continue reading “PHP security”

Forms with PHP

Over at ONLamp.com there’s a very good article with a number of good tips for handling forms with PHP.

Tip 7 looks like a pretty good one which I think I’ll use when I start redesigning some of my web database projects. I’ll have to check out this HTML_Quickform thing too.

PHP Form Handling by David Sklar — If your PHP program is a dynamic web page (and it probably is) and your PHP program is dealing with user input (and it probably is), then you need to work with HTML forms. David Sklar, author of Learning PHP 5, offers tips for simplifying, securing, and organizing your form-handling PHP code.