Friday, July 25, 2014

Extract numerical values from the names of your data file

Well, you generated a series of fantastic data by varying some parameter, which was used to name your data file. Now you need to process these data again but then realize that you didn't save the values of this parameter. What can you do? I hope that you are not thinking of copying every single value in the file names!

Here is how you can do it using awk in two lines. Say the file names are in the following format: "xxxxx_1.553_fsolve.mat." First you save all the file names as a txt file:

ls *fsolve.mat > namelist

Then do the following:

cat namelist | awk '{split($0, a, "_"); print a[2]}' > namelist2

$0 is the stdout from "cat namelist"; "a" is a string array generated from $0 with the delimiter "_", and in our case it has three elements: a[1]="xxxxx", a[2]="1.553", and a[3]=".mat". What remains to finish the task is to print a[2] to a file ("namelist2").

To better understand the use of split, we can accomplish the above using one more split command

cat namelist | awk '{split($0, a, "_fsolve"); split(a[1],b,"_"); print b[2]}' > namelist2

See how it works :)

Thursday, July 24, 2014

Collection on Art of Science (Part I)

One appeal of doing research on photonics is that the results, once properly illustrated, can really be amazing.  Here I am showing two pov-ray illustrations that were generated based on the lasing modes I calculated in random lasers and wave-chaotic microcavity lasers. The authors of these figures are Rob Tandy and Omer Malik, who worked with me on these projects at Yale and Princeton. If you are interested, read more following this link (http://www.eng.yale.edu/stonegroup/science.html) on random lasers. The "butterfly" one will be published soon (hopefully). Keep tuned in!