?

Log in

No account? Create an account
Why CLI kicks ass - The Mad Schemes of Dr. Tectonic [entries|archive|friends|userinfo]
Beemer

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Why CLI kicks ass [Jan. 29th, 2008|10:48 am]
Beemer
[Tags|]

GUIs are awesome and powerful, and it's really cool how many things I can do in my browser anymore, but here's why the command-line interface and toolkit-style command utilities do and will continue to totally kick ass: because you can hook all these simple little independent modules together to do really complicated things.

foreach v ( `ls *nc | cut -f 1 -d _ | uniq` )
  foreach f ( $v*nc )
    set n = `ncdump -h $f | grep long_name | cut -f 2 -d '"' | grep _ | perl -pe 's/_/ /g'`
    ncatted -h -a long_name,$v,m,c,"$n" $f
  end
end


Isn't that horrible-looking? But it works. For those who don't speak shell, that means "Please go through all the NetCDF datafiles in this directory, find the 'long_name' attribute of the main variable in the metadata, and replace all the underscores in that tag with spaces. Because the modeler did it wrong."

It came to me this morning while I was waking up that it really was this easy to implement the fix, so I had to get up and write it all down while I was still in my bathrobe. It took longer to make sure I was doing it right before I ran it on the real data than it did to actually work out the details in the first place.

Go pipe! Go backticks!
LinkReply

Comments:
[User Picture]From: dr_tectonic
2008-01-30 05:09 am (UTC)
No, it's just modelers writing code that spits out "Mean_Temperature" instead of "Mean Temperature" for no particularly good reason.

We're actually close to NetCDF-4 at this point, so if anybody's still writing 2-style output, they're waaaay behind the times.
(Reply) (Parent) (Thread)