Monday, December 17, 2007

Google Chart API : part II

I solve my mistake, if you want to use charts into blogger just don't break the src=".." lines into pieces like I did in the example in the last post. The whole src have to be in one line.

Google Chart API

This chart was made using Google Chart API.

After Playing for a while trying to generate the previous plot I couldn't use google API properly. I had to generate the plot on my personal website save it to disk and post it. This API is a great way to make real-time charts, but for some reason it doesn't work within blogger it must disabled for security issues or something.

There is a couple of things I don't like about the API, and some serious limitations so I will stick to gnuplot. but it's nice to have different options with different capabilities.

The biggest problem I find with this API is that you must format your data to make it compatible with the API. Lets say you are running a simulation, and your output data ranges from 1 Tesla to 7.24 Teslas dependent on Temperature, you will need to map the data from 1 to 100, label the chart appropriately so it reads 7.24 on the highest data point and make sure your Temperature interval is uniform. It's not a difficult transformation but it's annoying.

On the other hand, if you are running your simulation on a server, you can easily modify your program so it will write a preview output. Lets say 1 of every 100 points calculated goes to this preview output. And make a web page you can access from any computer with firefox. The web page will then plot in real time what this preview output file looks like. It's also possible to make a web page that will take track of several simulations running on different servers (computers).

The code used to generate the chart is:

<img src="

Tuesday, December 11, 2007

Reasons not to publish.

I recently run into this short story:
Reasons not to publish.
by Gregory Benford.

Friday, November 16, 2007

Multivalued hell

Hello All.
I have been unable to post stuff thanks to my new friends called multivalued funtions and brach which have been keeping from doing any progress on my research. So next time you use any of these multivalued function (i.e. the arcsin(x)) stop to think about it for a second, I will.

I'm working on the second part of the linked list post, that should come out soon. Also this month on the cise publication the article "On the evaluation of Finite Hilbert Transforms" proposes the double exponential method as a good numeric method to find Hilbert Transforms. I talked about Hilbert Transforms before, and I use them in my research so I will implement the method and publish the code on here.

One more thing. This is just a mathematical curiosity. I was trying to calculate the derivate of x^x, as it turns out you can take the natural log on both sides of the equation before taking the derivative. I get ln(x^x) = ln(x*x*x*...) = x*ln(x) but this bugs me since x doesn't have to be an integer. Any ideas?

Friday, October 26, 2007

Leopard. Comming out tomorrow.

Some of you might know this. Leopard is coming out tomorrow at 6pm.

I will go tomorrow to an apple store and play a little bit with it, unfortunately I'm not buying it until a few months from now.

I really want to see spaces working and the new finder. Quick view sounds interesting and I wonder if you can make your own quick views. i.e. if I'm going to store the output of my program on an archive .dat then I can just open it with quick view and see the data as a plot. I guess this would be rather difficult to achieve, but it would be nice anyway.

I will talk about Leopard a little bit more next week. Take care.

Monday, October 8, 2007

Compiling for PPC from an Intel Mac.

Most mac users, might be familiar with universal applications. An universal application is an application such that it will run natively on either an Intel mac or a Power PC (PPC) mac. I was thinking about parallelization and I realized that if I wanted to do it between my two macs (a mac mini PPC and a Mac Book Pro Intel core duo) I have to do universal applications.

If you use Xcode you might know that making universal binaries (programs) is easy just by modifying the project properties. But for the most part I don't use Xcode I mainly use the terminal to compile. In this case the solution is quite easy too.

I made a Hello World application in C. Usually I will compile using

g++ Hello.cpp

the result is an executable file named a.out (17 Kb in size) that will run on my Mac Book Pro, if I try to run this code in my mac mini an error will occur. Using the flag -arch we can specify a different architecture, i.e.

g++ Hello.cpp -flag ppc

the result is once again an executable named a.out (20 Kb in size), this code will run in the mac mini natively. It will also run on the Intel mac but it will not be native reducing the performance of the code.

Finally if we want to run this code on natively on both PPC and Intel we would use the following command

g++ Hello.cpp -flag i386 -flag ppc

the result is an executable a.out (40 Kb in size), that contains both a PPC native and a Intel native binary.

This flag option is exclusive to mac platform, so it won't work on Linux machines. I try running each one of the 3 executables produced on a Linux machines, as expected no one worked.

I have been having trouble using the GSL (Gnu Scientific Library) and generating universal binaries, my best guess is that I have to compile the libraries again for PPC but I don't have the time, energy nor patience to do it.

Friday, October 5, 2007

It's all about linux.

This week I decided to go for linux related links, just because I like linux. It wasn't hard. Enjoy!

Thursday, October 4, 2007

Scientific programing an database structures. The Linked List part 1/3

In my experience many times database structures are not necessary while doing basic scientific simulations. Most of the time we are dealing with fixed length vectors or matrices. Some of you might disagree with me and might point out that appropriate data management is always necessary. In any case is unfortunate that when the occasion arises this structures are often neglected.

I will try to code from scratch in Objective-C some of the basic database structures and talk a little bit about them. This week I will start with a linked list.

If you are familiar with arrays you are familiar with liked lists. A linked list is a list of nodes, each node stores an object (may be an integer, a double, or any complicated class like a molecule) and a link or pointer to the next object in the list. You might think of it like a shoe box storing something (some data). Each shoe box have a string connected to another shoe box, if you want to locate something you just have to look for it on each box one at the time (following the string so you won't look in the same box twice). I will talk more about linked lists in a next post, but now lets code the nodes.

We will implement a linked list in Objective C.

First make the interface file and name it "LinkedListNode.h"

//2007, LinkedListNode.h
//Interface file for the a node to be
//used in a linked list data structure.


@interface LinkedListNode : NSObject {
double value;
LinkedListNode *next;

-(void)setNextNode:(LinkedListNode *)n;
-(LinkedListNode *)next;


Second make the implementation file "LinkedListNode.m"

//2007, LinkedListNode.m
//Implementation file for the a node to
//be used in a linked list data structure.

#import "LinkedListNode.h"

@implementation LinkedListNode

-(id)initWithValue:(double) v{
if(self = [super init]){
[self setValue:v];
[self setNextNode:nil];
return self;

-(void)setNextNode:(LinkedListNode *)n{
next = n;

value = v;

-(double)value{return value;}
-(LinkedListNode *)next{return next;}


Finally make sure they work as expected, make the file "linkedListNode.m"

//2007, linkedListNodeTest.m
//Test LinkedListNode.m and LinkedListNode.h
//To compile use
//gcc -ObjC LinkedListNode.m linkedListNodeTest.m -framework Foundation

#import "./LinkedListNode.h"

int main(){
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Testing LinkedListNode.h");
LinkedListNode *node = [[LinkedListNode alloc] initWithValue:2.0];
LinkedListNode *node2 = [[LinkedListNode alloc] initWithValue:3.0];
[node setNextNode:node2];
NSLog(@"node was initialiazed with value %f.",[node value]);
NSLog(@"the second node is linked an has a value %f."
,[[node next] value]);

[node release];
[node2 release];
[pool release];

Make sure everything is in the same folder and compile typing the following command in terminal.

gcc -ObjC LinkedListNode.m linkedListNodeTest.m -framework Foundation

An executable named a.out will be created, you can execute it typing in the terminal.


The output will look like this. Enjoy!

2007-10-04 23:30:41.786 a.out[609]
Testing LinkedListNode.h
2007-10-04 23:30:41.786 a.out[609]
node was initialiazed with value 2.000000.
2007-10-04 23:30:41.786 a.out[609]
the second node is linked an has a value 3.000000.

Note: I'm still learning ObjC and I'm not familiar yet with memory leaks, I might have to modify this code just as to make sure I don't have them. If you notice any memory leak in this code, please let me know.

Tutorial: Quick trick to make your code run faster on a core duo processor.

The following tutorial should work with an Intel core duo machine regardless the Operating System. Feel free to share with me any suggestions or comments.

Currently I'm working on a code with the following main() method.

int main(){
double T = 0;
double T_delta = 0.01;

for(int i = 0; i < 20; i++){
T += T_delta;
printf("%f %f %f %f %f %f %f %.14f\n",
return 0;

I'm calculating the conductivity (for a given model) with 7 different energies over a range of Temperature. Each calculation is independent of the others. I have to say that each one of this calculations requires a lot of cycles but not a lot of memory. This code is not parallel at all and having a core duo processor limits it.

Here is the CPU activity before and after running such program. Notice that one of the cores tops while running the core, but the other doesn't get that much work to do.

First we need to modify our main method to accept parameters. we will give it 3 parameters in this order initial T, delta T, and number of points to calculate.

Our main() method will look like this now.

int main(int argc, char * const argv[]){
if(argc != 4){
printf("Wrong number of arguments.
Use initial_T delta number of points\n");
return 0;

double T = atof(argv[1]);
double T_delta = atof(argv[2]);
int N = atoi(argv[3]);

for(int i = 0; i < N; i++){
T += T_delta;
printf("%f %f %f %f %f %f %f %.14f\n",
return 0;

To get the same answer as to the other main method we just need to run this method twice with the appropriate parameters. We use the following script to do just that. Just open your favorite text editor and write the following

./run 0 .01 10 >> out &
./run .1 .01 10 >> out &

after saving it (lets say you name it brun) you can use the chmod command on terminal to make it an executable.

chmod 555 brun

running ./brun will produce the same results using more processor resources. In theory this should reduce the computing time by half. In this example it took 12 min to run ./brun vs 20 min it took before splitting the load of work between the two cores.

This tutorial assumes no files are modified during the program execution and the output is printed into screen using the printf command. If not the case some workaround can be found by introducing more program parameters, like input and output files.

I hope this tutorial will be usefull Enjoy.

Tuesday, October 2, 2007

Apple Wireless Keyboard

I run (literally) to the apple store this morning to get the new apple keyboard. I'm posting some pictures of it. So far I really like this keyboard. Long time ago one of my friends ask me if I could find a smaller keyboard. Now I have a smaller keyboard, enjoy.

Friday, September 28, 2007

Firefox 3, Moebius and 1 Gig

A couple of mock ups of what Firefox 3 might look like. Personally I like the current appearence better.

Firefox 3.0

A picture of 1GB 20 years ago alongside 1GB today.

1 Gig

Finally, National Geographic Publish the best Scientific Images of the year. I personally liked the last one, I also included the link to the related video.

National Geographic.

Moebius Transformation Video.


Tuesday, September 25, 2007

New side bar

There is a new element at the side bar called Progress. It's aimed to keep track of what I'm doing related to this blog.

Really Cool.

Monday, September 24, 2007

Net News Wire Lite

My latest addition, to my list of programs I use everyday is Net News Lite. If you want to pay for it you can get extra features, but I don't need them at the moment. Net News Lite is a RSS or Feed reader. I have to say that I have been using it for a couple of weeks now and it already saved a lot of time.

How does it works; you subscribe to your favorite websites, in the preferences you select how often you want it to be actualized. Once there is something new to read in one of your websites it will let you know. If there is nothing new to read you don't need to go from one website to the next hoping for new content. I would recommend giving it a try. I can't recommend a windows one because I don't know any but I'm sure they exist.

Extra some journals like Nature and APL (applies physics letters) are implementing RSS feeds, letting you know when there is new articles, this is pretty useful for people trying to stay on top of the new advances in science.

Friday, September 21, 2007

Cocoa, USB 3 and lots of money

Some cocoa references I found on

A video with lots of money
Lots of Money

And a new USB standard USB 3.0 will be 10 times faster than current USB. I would like to see some USB 3.0 computer displays so you can connect as many as empty USB ports in your computer.
USB 3.0


Wednesday, September 19, 2007

VIsual GSL

I have been working my way around Obj-C for the past two weeks.

It's recommended to learn Obj-C to program mac applications (at least to program the user interface) and I have to say that so far I like it. Basically Obj-C gives regular C Object Oriented Programming (OOP) capabilities. I'm more used to the Java way of doing things, but they are not that different.

One of my motivations lately has been the mac research website, I would recommended to any scientist considering transitioning from windows to mac as their research platform. My favorite part of this website so far is the Obj-C/Cocoa tutorials for scientists, and it's the way I have been learning Obj-C. I hope you will enjoy it.

Friday, September 14, 2007

Evolution, Serial Killers and Islands

This week;
Carl Sagan speaks about evolution. (instead of intelligent design)

Take the test and discover if you can spot a serial killer.
Serial Killer

Finally a map with remote islands. I would prefer Falklands Islands over the others. (Islas Maldivas in spanish, I might be wrong)


Friday, September 7, 2007

Vodkas, Jobs and iPods.

Ok, here is the links for this week:
1. I so want to get some of this vodkas, specially the cactus vodka.

2. Some advice in preparing your resume, most of it is obvious.

3.New iPods. I still have to go to the store to see the new nano.


Wednesday, September 5, 2007

Visual GSL

So I made a outline of what I want to do for this project, but I'm having trouble publishing. I just made an image below, if you click on it is readable. Next week I will try to do it better.

Best. Chuy

Friday, August 31, 2007

This week.

So this are the 3 stories that I pick from digg to post this week. Enjoy


Wireless TV

Metro picnic

In the last one I have no idea what is going on. I like the technology in the second news. Just imagine get home, turn on your tv and start using it as your laptop monitor without having to connect any cables, that would be sweet.

Monday, August 27, 2007

Coming Soon, And this time I mean it.

Well I'm starting to do things a little bit different, and I'm starting to feel confident I can do something worth on this space. Starting this Wednesday I will be introducing 3 new periodic sections on my blog.

On Mondays I will publish, "This week on the Scientific Journals." I will start talking about some articles worth reading on a few scientific journals. As expected this articles will somehow related to my field.

On Wednesdays; "Visual GSL" I will be giving a brief progress on my visual GSL project. I hope I will be able to make the program available to anyone who find some use for it.

Finally on Fridays; "My top 3 stories of the week." After a long week is time to relax so I will be publishing my favorite 3 digg stories of the week.

I hope you will find something in here that you will enjoy.

Sunday, August 26, 2007

MBP will delete your work!

I should have learned the lesson by now. If you are going to carry a USB thumb drive with all your work on it, MAKE A COPY!!!

When I get my thumb drive on December everything was great, I made a copy of all my code on it, after that I just start working on top of it. I would carry it everywhere and if I had a brilliant idea away from home I could just ssh into one of my accounts, code, compile, save results and keep going.

In the middle of march I lost such a small piece of technology. And what a big annoyance it became, losing all that work in 5 seconds just doesn't seem fair. Lucky enough I found it the next weekend. And I made a mental note, "don't loose it again."

When I move on June to a new department I though I had lost it again. Wow saving half a year on such a small device and make no copies of it just seems stupid. Well it is. After one week or so I finally found it, I was relieve. I made a mental note, "make a copy."

Finally the wait was over, my mac book pro arrived, right on my birthday July 12th, that was a nice present, and finally after a few days of installing applications I got a nice system to work on. Took my usb thumb drive and plug it right next to the mag-safe power adapter the mac book pro sports. I know if I put the mag-safe close enough to a magnetic device it will delete its data. But I believed it should be fine since apple put the usb port right next to it. (Put usb device on usb port)

While the mag-safe didn't manage to destroy all my work it did actually manage to delete one of the programs I was working on along with some data. I guess this time I learned my lesson since this time I didn't made a mental note but take action making a backup of everything on the drive.

I will try to get in the habit of posting things on here. In the mean while enjoy this picture I took of my mac mini crashing.

Thursday, August 9, 2007

I will be back soon.

I just moved to a new apartment. But now I'm getting ready to continue with all my crazy ideas, I have a few new ones. I will be back real soon.

Wednesday, June 27, 2007

New Computer is on its way.

I have been really busy last weeks, so I leave my blog and the crazy
projects on a side. I'm buying a new apple computer, this time is a
brand new mac book pro. I can't wait until the machine finally arrives.
In the meanwhile I have to keep working on my mac mini at home and mylinux laptop at school. Once I get the new computer I have to learn the xgrid framework, so I can make my programs run on both, the mini and the pro at the same time.

Saturday, May 26, 2007

This Blog is getting boring!!!

I know, I know. There is no news I'm my blog in over two weeks now. Well nobody reads it anyway, but I feel like starting my blog to post my achievements so maybe one day someone will read about them.

At this moment I have a fair amount of projects I want to start. Unfortunately I don't have the time, energy or money to do all of them, on top of doing full time research, and taking care of my plants. Here is a list of the projects I want to start, Anyone of this projects is enough to keep me away from any other in the list so I will have to make some decisions:

1) Learn Cocoa and Objective C.

Well, since apple have been stealing my soul since the very moment I buy my mac mini I want to develop applications with graphical interface for my personal use, and make them available if anyone else have any use for them.

2) Find a place to Live.

This is kind of obvious why I need to do this.

3) Implement a console window via usb.

I have an extra monitor, check.
I have a computer that doesn't handle dual displays, check.
I use the terminal in my mac a lot, check.
Can I connect my second monitor to my mac and have a full screen terminal on it via usb, nope.
Do I know any device on the market that will do this for me, not that I know of.
Can I do it myself, maybe.

4) Visual GSL.

For my own research I have been using the GSL (GNU Scientific Library) and it is really a nice library for what I do. But I would like to make a graphical implementation of it so I can test if the method will work the way I want it to work. And then it have to generate the code for me the code for me.
For example I have to calculate some Greens functions making a Hilbert transform from the non-interacting electronic density. In doing so I have to allow for an imaginary part on the self-energy. And I find myself coding things like:

gsl_complex var = gsl_complex_add_real(gsl_complex_add(sigma1,sigma2),mu);

witch only means var = sigma1+sigma2+mu; where var, sigma1 and sigma2 are complex numbers. It would be nice to do a little program where I can input sigma1+sigma2+mu, and I can copy paste the generated code to my program.

5) Poker odds.

I have been watching poker on television for a while, and played some games (no real money involved) online, and it's fun. So I would like to code a program that will tell me what are the best hands to start with. And I know AA is the best hand you can start with, but I what about for example, J-10 suited vs Q-K off suite.

6) Learn openGL.

This will help me to make plots for my programs in number 4 with in the same program with only adding a button, plot.

7) Infinite desks.

I can't talk about this.

8) Learn to use Xmgrace.

My advisor suggested I have to discard gnuplot and use xmgrace instead.

9) Write on my own blog.

As you can see I have a lot of things I want to embrace and the day only have 24 hours. I will try to keep posting things here on a regular basis.


Monday, May 7, 2007

Tutorial: Make Latex ready plots using gnuplot.

Gnuplot is a free yet easy to use command line plotter for the Linux OS. You can also install it on Mac OS X and Windows. If you are using Mac OS X and want the OS X feel in your plots you can type
>set terminal aqua

With gnuplot you can either plot data files or functions, in this case we will plot (sin(x)/x)^2, first we want to plot it and make sure we get the right plot.

1) open gnuplot and type
>plot (sin(x)/x)**2

2) Make a new file i.e. plot.txt and open it in any text editor, add the lines

set terminal epslatex
set output "myplot.eps"

This two lines will tell gnuplot that the output file has to be an encapsulated postscript (eps) with name myplot.eps, now you can add to the file the plot you want to make.

set key off
set xlabel '$x$'
set ylabel '$(\frac{sin(x)}{x})^{2}$'
plot (sin(x)/x)**2

First set the options of your plot, xlabel, ylabel, etc, and then input the plot command. Note that you can input data in the latex commands and latex will translate that to actual formatted text equations. Now you can save the file.

3) In the terminal type the command
>gnuplot plot.txt

You will notice two new files in your directory. myplot.eps and myplot.tex

4) If you already have a tex document you insert your new plot on it. First make sure you have the following two lines in the headers of your tex file;


gnuplot warns you about adding the first one but not the second one in the help pages.

now just place your graphic with the command, \input{myplot}

5) Or you could also compile myplot.tex file directly only a few modifications are needed, first open myplot.tex and add the following lines


skip the rest of the text and locate the last line
and delete it. Finally add the line


And that is it, now you just need to compile your tex document to make it a pdf. Sometimes pdflatex have problems making the plot when both files have the same name myplot.tex & myplot.eps, in such a case, change the name of the eps file. i.e. othername.eps and change the line in myplot.tex


Friday, April 13, 2007

About Myself

Ok, I think I should talk a little bit about myself.
First of all, you can mail me to cruzrojas at and please no spam!

About me: I was born in Mexico 24 years ago, and right now I have a B.S in Physics Engineering and I'm studying a PhD in Physics at Washington DC. So it's hard for me to write in English some times, and I still make a lot of grammatical mistakes.

About my programming experience: I Have been fan of Linux since I was in high school. I installed it for the first time in 1999, but for some reason or another I always came back to windows. I have been using a mac as my main computer over a year now. I choose to switch since I could use the Unix terminal to run my projects and still be able to go to the store and buy commercial applications, a.k.a. office.

I started programing around 14 years ago with GW BASIC. Then at High school we have to learn VB witch was a pretty easy transition for me. Eventually I learned JAVA one year before I had to take it in college, after JAVA we learned C++ in college, along the way I have also learned to use, MATLAB and MAPLE being a physics major. I also have a little bit of experience in programing for the Motorola 68000 in my electronics classes.

About the system I use:
Yes, A mac mini, I work on a mac mini G4 1.4 GHz and 512 Mb of ram, the main programs I use when coding on it are, the terminal to compile my C files, gnuplot to visualize my output, and emacs to modify those C++ files.

I don't write too many user oriented programs, they are more physics simulations, and everything I do is on the terminal window, but I want to change that and hence this blog. Cheers.

Thursday, April 12, 2007

Chuy and Mac

I just created this blog for mac enthusiasts. I will start this blog a little bit slowly but I hope to start posting more frequently in the future.

The main focus of the blog is programming for the Mac OS X. As I mentioned before I will start with small projects. If you want to contribute to the blog let me know.

I will start coding a Hello World Application and move from there. Cheers.

#include <stdio.h>
int main(void) { printf("Hello World!!!, Welcome to"); }