Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Wednesday, May 30, 2007

A bug

A stupid bug in my program:

vector < a > content;
vector < a* > cp_array; // content pointer array

Constructing content and cp_array at the same time, using cp_array[x] = &content[y]. Later I found some pointers in cp_array didn't point to the correct content element. I doubted the logic of my program first, and then looked for all pointer assignments, but all seemed to be correct. After step by step debugging and printing intermediate array values (damn, it's hard to debug stl using gdb even though none optimizations were switched on), I found the content cp_array pointed to changed after a content.push_back(a), it is the push_back operation that caused content to reallocate memory and then what cp_array pointed to was nullified because the address of content vector was changed.

What I've learned: Do not use pointers on dynamically allocatable content, use indices instead.

Wednesday, March 28, 2007

Get fonts right in pdf formated papers

I was struggling with font problem in my paper these days, and finally got done with it. I use winedt/MikTex companions under windows XP since 3-4 years ago. And PowerPoint for the figures, since I can directly print to pdf-printer (feature of acrobat) to get pdf figures nowadays. All these tools works efficiently. However, they didn't comply with ACM's strict requirement of fonts in publications, which restricts to the use of "type 1" and "embedded" fonts ONLY. Now, I have two problems. First one, I always have "truetype" font in my figures, since I don't have any "type 1" font installed on my windows. Second one, there are several "type 1" fonts cannot be embedded, such as "times", "courier" and etc.

================================================================

For the first problem, I need to install and use the "type 1" font corresponding to the "truetype" font I used in PowerPoint, so that the pdf figures generated contain "type 1". The free way of getting "type 1" font is to convert from existing truetype font (under \WINDOWS\Fonts). There are two ways of doing this:

First, use fft2pt1 (truetype to type 1 converter) to convert the truetype font (from a .fft file to a .pfb file and a .afm file), then use afm2pfm to convert the .afm to a .pfm file that windows recognizes, and finally drag the .pfm file to \WINDOWS\Fonts folder to get it installed. Note that if you're NOT using windows XP or 2000, you need to install Adobe Type Manager (ATM) to install the type 1 font. For now, if you're lucky, you can see and use the type 1 font in the PowerPoint font box (I cannot for some reason I don't know).

The second way to do this is to use FontLab (a commercial software) to generate the type 1 font. Just open the .ttf font, go to File->Font Info to give it a different font name (first page), go to File->Generate font, and choose to generate the "type 1 binary file (*.pfb)". Then install the font by dragging the .pfm file to \WINDOWS\Fonts folder. I managed to see the font in PowerPoint using this second method.

In PowerPoint, substitute all the fonts with the type 1 fonts you generated. When printing to the pdf printer, make sure to set the options of pdf printer to embed all the fonts (for my case, under "conversion settings->fonts->embedding" and add all the fonts to the "always embed" list). When the pdf file is produced, open it with acrobat, press CTRL+D to see the fonts. Most likely, you'll have all the fonts embedded.

An exception may occur if you use a non-English version of PowerPoint. For me, Chinese version. The default font is Sim-Sun. Some times, even all the places you can touch is set to non Sim-Sun font, it will still be included in the pdf file. In this case, open a new PowerPoint file, copy and paste you figure part by part to the new file. Produce a pdf file and check the font to see where Sim-Sun is introduced, and then try to modify or remove them. For me, I found starting spaces (by accident) introduces Sim-Sun, so I removed them.

==================================================================

For the second problem, the cannot-be-embedded fonts are from the text compiled with pdflatex, which are assumed (by whom?) to be available on all systems (but not true), and referred as Base14 fonts.

To embed them, the simplest way is to install the latest version of MikTex (2.5) and ensure the pdfeTex version is above 1.20. By default, Base14 fonts are embedded. If you're using Tex system under Linux, similarly you need to ensure the pdfeTex (or pdfTex, or pdflatex) is above version 1.20. And then edit "/web2c/updmap.cfg" to ensure the following options is set to true: pdftexDownloadBase14, dvipdfmDownloadBase14. Finally, run updmap as root to update the configuration.

Another way of doing this is save your pdf document with the not-yet-embedded fonts as a PS file, using "save as..." in acrobat. Then use the command "ps2pdf14 -dPDFSETTINGS=/prepress -dEmbedAllFonts=true mydoc.ps" to generate the pdf file with fonts embedded.

I compared the results of the above two approaches, i.e., the direct pdflatex generating approach and the pdf->ps->pdf approach. It seems to me that the former approach is better in the following aspects. It includes less redundant fonts, so the file size is smaller. The graphs looks more original, and scrolls faster especially when complex patterns are used (pdf->ps->pdf approach converts 2 times, and may introduce some distortions and more fragments to the vector graph, thus show up slowly).

We're done.

Monday, March 19, 2007

Tips

Do not try to compile a large program not compatible with your current version of gcc, instead, compile a version of gcc compatible with the program, and then use the gcc to compile it. (however, newest gcc does not even compile the old versions. In this case, compile a not-that-old version which compiles the old version to compile the old version. What a mess!)

Saturday, March 17, 2007

My Must-have Firefox Addons

As a IT guy, switching among different OS and migrating from systems to systems (e.g., my desktop and a few of my laptops) is not uncommon. Whenever this happens, the first thing I would make sure is the up-to-date Firefox is installed with the following must-have addons:
  1. Del.icio.us Bookmarks: for online bookmarking service, sharing bookmark links with others or myself (so that i don't need to synchronize the bookmarks from 3, 4 computers I use).
  2. GUtil: grants me instant access to various google services I'm using (i.e., gmail, reader, docs, calendar, blogger, album) with button click.
  3. ScrapBook: great substitution for "save page as..." function, which allows you to capture (and capture certain parts), organize, comment and edit on interesting web pages. The only problem is that it's not an online thing, and you need to export/import among different systems you have.
  4. Google Toolbar for Firefox: this is actually with Firefox package, but I remind you to click on the "G" icon with the downward arrow, you will find it's not only for googling (i.g., I need Webster for English words that doesn't recognize me).
  5. Session Manager: resume the tabs I was reading last time after restarting Firefox.
  6. FireFTP: for lazy guys.

Thursday, February 08, 2007

After reading in all the parameters and setting all neccesary environments, compile_script will call the following scripts to compile benchmark programs step by step:

1. compile_bench:
Under trimaran/impact/scripts/compile_bench
This script including a dozen scripts that front-end IMPACT processes from source code to various intermediate representations (including profiling).

2. gen_elcor -> .0_el file

3. gen_EtoC -> .c file used to simulate execution

4. gen_CtoO -> executable of the simulator

Tuesday, October 31, 2006

Sth about IP

A Integer Programming without a objective function is a decision problem, instead of an optimization problem. Although the computational complexity is the same for both of them, decision problem is faster to solve, for it only requires one feasible solution (rather than the optimal one). In case an optimal solution is not neccesary, and bounds are given for a feasible one, such formulation is helpful.