The newer versions of Microsoft Powerpoint (2007+) offer a simple and intuitive interface to quickly create nice illustrations. It would be really nice if you could use this to create diagrams for paper submissions to conferences/journals.
If you want to import pptx diagrams into your papers, typically, the best way is to export as pdf (Microsoft has an export to pdf plugin). Now you could simply import the pdf images in your Latex file, and things work pretty well.
The only hitch is that many conference templates enforce eps images. Now most paths that convert pptx->pdf->eps completely mess up the image. Sometimes the pdf may be converted into a Huge bitmap in the eps file. We certainly don't want that. Here is a technique that you can use to directly convert pptx drawings to eps, while keeping the vector format. No more "Yuck! Bitmap..." comments from your advisor :) ... and you don't have to tell Microsoft Haters that you used Powerpoint :) and that you converted it to eps using tools that come by default with Windows ;)
Anyway, before I begin, here are the places from where I picked up this info (everything is just a web-search away):
http://people.csail.mit.edu/dalleyg/faqs/20010425.html
http://www.sketchpad.net/postscript-printer-winxp-1.htm
Note: I am using Win7 & Office 2010, so some things may be a bit different in other versions.
Now the first step is to create an EPS File Printer. (Yes you can do that)
Go to 'Control Panel'->'Devices and Printers'->[Right Click]->'Add a Printer'
Click 'Add a local printer'.
Choose 'Use an existing port'->'FILE: Print to File'
Pick some printer that has a 'PS' suffix to it.
Now this may take some trial and error to find a color printer with decent number of options.
You can print a test page and check if things are working now. (Just save the page as a .eps file). To view this, you may need to install GhostScript & GhostView on Windows. Linux should have this by default.
Now to prepare the PPT diagram for printing:
Create a blank presentation.
Select 'Design' -> 'Slide Orientation' -> 'Portrait'
(This is the only limitation I came across. In Landscape mode, the EPS printer rotates the image through 270 degrees)
Select 'Design' -> 'Page Setup'
Setup the page dimensions here (This should be the boundary of your diagram)
Now copy-paste the actual drawing into this slide from wherever you created it.
(The reason for this is, if you draw first and then rescale the page size, it will stretch the diagram. Maybe there is a workaround for this.)
Now select 'Print', and pick the PS printer from the list.
Select 'Printer Properties'->'Advanced'
Setup the PostScript options as shown in this screenshot:
The Postscript output option should be EPS.
Postscript language level be 1 (could be higher I suppose, but this is safer)
TrueType font download options: Outline (This converts fonts to curves I guess. Play around with other options if you want, but stay away from 'Bitmap' of course).
As shown in the next image, set the Paper Size to 'Postscript custom page size'. Keep this the same as your Slide dimensions, because this will be the size of the CropBox in the EPS file.
Now we are all set. Just click 'Print' and save the file with a .eps extension.
GhostView correctly rendered this file for me, and the file size was reasonable.
Note however, that eps is limited in its ability to handle transparency (i think there is no transparency whatsoever), and gradients, so try to use solid colors in the drawings.
Let me know how this goes for you :)
Saturday, April 9, 2011
Thursday, April 7, 2011
How to use Windows Phone 7 Marketplace in India
Having recently 'procured' a HTC HD7, I was hoping to post a review of some sort on this blog. But none of my review plans (for this phone, the PS3 and a few PC games) seem to materialize in any reasonable time frame, so here are some tricks for anyone finding themselves in the less than desirable position of owning a Windows Phone 7 device in India.
[ Feel free to skip over this next part. Just scroll over to the 'End of Rant' below ]
Well, here is the fundamental problem: Smartphones are not much if you can't run applications on them. And Microsoft decided that it would be a very prudent move to sell WP7 phones in India, without any app-store support. (FYI, Microsoft has screwed over users in many countries like this, so this is certainly not a special case).
Here is how things typically play out:
Step1: You shell out 25,000/- for a WP7 of your choice.
Step2: You start the phone, and it tells you to sign in with your 'Live ID'. You can create one if you don't have it. I have a Hotmail account since the Stone age, and decided to use that.
Step3: You decide you want some apps, and click on the Marketplace icon. You are greeted with a message that says 'Marketplace is not yet available in your country/region'
Step4: Ah! But we are clever, no? Simply have to change the country to 'USA'. The country is tied to your Live ID. Once you create it, you can't change the country. So, we go and create a new Live ID. I, for instance, am a retired Sith Lord living a peaceful life in Kansas...
Step5: Oops. You can't change the first Live ID that you used in the phone. It is now inexorably tied to the phone. What do we do now?
Step6: Factory Reset the phone. This will clear everything (all photos,videos,music,downloaded apps, mail, settings...the whole shebang) And how do we do that? Quite intuitive really. Go to Settings -> about -> reset your phone. ('About'?!! seriously Microsoft??)
Step7: Now you enter your new Live ID details. This works great on your phone, except that you can't really buy any apps because everything is listed in Dollars, and Microsoft does not support credit cards outside your region. Now all you need is an obliging chap with an American credit card. Yeah right...
[ End of Rant ]
Now for the good news: There actually IS an app-store for India, where everything is listed in INR and leprechauns stash heaps of gold at the ends of rainbows.
The problem is that the Phone does not seem to acknowledge its existence. The only way to access this store is through Zune Software (MS equivalent of iTunes).
You can login on Zune, using your India based Live ID, and it will (sometimes) show you the Marketplace.
I say Sometimes, because Zune has this nasty habit of setting some registry entries that removes India (IN) from the list of valid Marketplace regions. There is a nice hack described HERE, to overcome it.
A short summary of the registry tweak:
Go to this registry key: HKEY_CURRENT_USER\Software\Microsoft\Zune\Features
Here you will see the codes of the following countries in 3 entries:
AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US
Just add IN to all the entries, so they become: AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US,IN
These guys have even made a helpful reg file: Here
Now for my trick: When you purchase/download apps from Zune Marketplace, they don't always turn up on your phone. Infact, the phone starts downloading these apps in its download manager, and sometimes the downloads stop due to network errors or whatever. Typically, you would simply resume the download by going to the Marketplace through your phone. But you can't open the official Marketplace app on your phone...
The trick is to simply install a 3rd party marketplace app through Zune (there are 3 or 4 marketplace search apps which should install fairly quickly). HTC phones come preloaded with 'HTC Hub' from which you can access some apps. Just find an app listed on one of these marketplace apps, download that app from Zune Software on your PC (while your phone is connected of course), and now you should see a 'check install' button on that app, in your 3rd party marketplace app on the phone.
Clicking this takes you to the Download manager, where you can resume/pause/cancel (oh wait, no you can't cancel downloads... another brilliant feature).
Anyway, if someone knows a better way to get the Marketplace working properly in India, do let me know...
[ Feel free to skip over this next part. Just scroll over to the 'End of Rant' below ]
Well, here is the fundamental problem: Smartphones are not much if you can't run applications on them. And Microsoft decided that it would be a very prudent move to sell WP7 phones in India, without any app-store support. (FYI, Microsoft has screwed over users in many countries like this, so this is certainly not a special case).
Here is how things typically play out:
Step1: You shell out 25,000/- for a WP7 of your choice.
Step2: You start the phone, and it tells you to sign in with your 'Live ID'. You can create one if you don't have it. I have a Hotmail account since the Stone age, and decided to use that.
Step3: You decide you want some apps, and click on the Marketplace icon. You are greeted with a message that says 'Marketplace is not yet available in your country/region'
Step4: Ah! But we are clever, no? Simply have to change the country to 'USA'. The country is tied to your Live ID. Once you create it, you can't change the country. So, we go and create a new Live ID. I, for instance, am a retired Sith Lord living a peaceful life in Kansas...
Step5: Oops. You can't change the first Live ID that you used in the phone. It is now inexorably tied to the phone. What do we do now?
Step6: Factory Reset the phone. This will clear everything (all photos,videos,music,downloaded apps, mail, settings...the whole shebang) And how do we do that? Quite intuitive really. Go to Settings -> about -> reset your phone. ('About'?!! seriously Microsoft??)
Step7: Now you enter your new Live ID details. This works great on your phone, except that you can't really buy any apps because everything is listed in Dollars, and Microsoft does not support credit cards outside your region. Now all you need is an obliging chap with an American credit card. Yeah right...
[ End of Rant ]
Now for the good news: There actually IS an app-store for India, where everything is listed in INR and leprechauns stash heaps of gold at the ends of rainbows.
The problem is that the Phone does not seem to acknowledge its existence. The only way to access this store is through Zune Software (MS equivalent of iTunes).
You can login on Zune, using your India based Live ID, and it will (sometimes) show you the Marketplace.
I say Sometimes, because Zune has this nasty habit of setting some registry entries that removes India (IN) from the list of valid Marketplace regions. There is a nice hack described HERE, to overcome it.
A short summary of the registry tweak:
Go to this registry key: HKEY_CURRENT_USER\Software\Microsoft\Zune\Features
Here you will see the codes of the following countries in 3 entries:
AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US
Just add IN to all the entries, so they become: AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US,IN
These guys have even made a helpful reg file: Here
Now for my trick: When you purchase/download apps from Zune Marketplace, they don't always turn up on your phone. Infact, the phone starts downloading these apps in its download manager, and sometimes the downloads stop due to network errors or whatever. Typically, you would simply resume the download by going to the Marketplace through your phone. But you can't open the official Marketplace app on your phone...
The trick is to simply install a 3rd party marketplace app through Zune (there are 3 or 4 marketplace search apps which should install fairly quickly). HTC phones come preloaded with 'HTC Hub' from which you can access some apps. Just find an app listed on one of these marketplace apps, download that app from Zune Software on your PC (while your phone is connected of course), and now you should see a 'check install' button on that app, in your 3rd party marketplace app on the phone.
Clicking this takes you to the Download manager, where you can resume/pause/cancel (oh wait, no you can't cancel downloads... another brilliant feature).
Anyway, if someone knows a better way to get the Marketplace working properly in India, do let me know...
Tuesday, January 4, 2011
Automating tasks in Outlook using VB for Applications
It has been ages since I wrote anything on this blog...
Since a lot of people at work may be using the Outlook mail client, I thought it would be useful to introduce the scripting capabilities that Visual Basic for Applications (VBA) offers in Outlook. (This is also the first post where I will be using the code->HTML converter from Notepad++. Trying this as an alternative to vim. Let me know what you think.)
This post demonstrates a simple script to delete duplicate emails in an Outlook folder. While this seems quite specific, it should present enough info for you to get started with VBA for Outlook. So here goes:
Hmm, why would anyone want to do Visual Basic scripting in Outlook??
I have long been a proponent of VBA (Visual Basic for Applications), specially in MS Excel and CorelDraw, but only recently have I got my hands dirty with Outlook.
The problem I faced a while back was that I accidentally created two copies of every email in my conversations folder. There being around 250 items to sift through, I decided it would be better to spend a half hour learning how to write Outlook macros, than to find and delete the duplicate items.
So, lets get down to business. To write a macro in Outlook, go to Tools->Macros->Visual Basic Editor.
In the Project window, select Project1->Microsoft Office Outlook->ThisOutlookSession. You should be presented with a code window, where you will write the macro.
The macro will be a VB subroutine. In this post, I will discuss how to write a macro that moves only duplicate emails to some folder of your choice (maybe trash). We could delete the emails instead, but I usually refrain from writing destructive statements in code, atleast until it is fully tested ;)
Before we start off, this is the URL that I referred to for help: http://support.microsoft.com/?kbid=208520
I will provide the code listing below, with inline comments (comment lines start with an apostrophe in VB).
And that completes the code. VBA can be used to write all kinds of neat macros that speed up day to day tasks. Finding duplicate mails is just one of them.
Since a lot of people at work may be using the Outlook mail client, I thought it would be useful to introduce the scripting capabilities that Visual Basic for Applications (VBA) offers in Outlook. (This is also the first post where I will be using the code->HTML converter from Notepad++. Trying this as an alternative to vim. Let me know what you think.)
This post demonstrates a simple script to delete duplicate emails in an Outlook folder. While this seems quite specific, it should present enough info for you to get started with VBA for Outlook. So here goes:
Hmm, why would anyone want to do Visual Basic scripting in Outlook??
I have long been a proponent of VBA (Visual Basic for Applications), specially in MS Excel and CorelDraw, but only recently have I got my hands dirty with Outlook.
The problem I faced a while back was that I accidentally created two copies of every email in my conversations folder. There being around 250 items to sift through, I decided it would be better to spend a half hour learning how to write Outlook macros, than to find and delete the duplicate items.
So, lets get down to business. To write a macro in Outlook, go to Tools->Macros->Visual Basic Editor.
In the Project window, select Project1->Microsoft Office Outlook->ThisOutlookSession. You should be presented with a code window, where you will write the macro.
The macro will be a VB subroutine. In this post, I will discuss how to write a macro that moves only duplicate emails to some folder of your choice (maybe trash). We could delete the emails instead, but I usually refrain from writing destructive statements in code, atleast until it is fully tested ;)
Before we start off, this is the URL that I referred to for help: http://support.microsoft.com/?kbid=208520
I will provide the code listing below, with inline comments (comment lines start with an apostrophe in VB).
'We start off with the name of the subroutine,
'Also make it public, so outlook can access it.
'Sub means Subroutine
Public Sub deleteDuplicateMails()
'Now for some variable declarations.
'Note that this is not needed in VB, but
'its a good practice, and also helps VB to
'autocomplete your code.
Dim oldEmail As MailItem, newEmail As MailItem
Dim i As Integer, dupcount As Integer, totalcount As Integer
Dim folder1 As Folder, folder2 As Folder
Dim myfolder As Folder, dupfolder As Folder
'Now, we need to access the folders where
'emails are stored. The following lines do that.
'This is to help VB access the stuff inside outlook
'MAPI is "Messaging Application Programming Interface"
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
'Note: I am assuming these folders and subfolders
'already exist. The code won't run otherwise.
'We could make it more robust, and create
'the folders here, but thats too much work :P
'set the source folder
Set folder1 = olns.Folders("Personal Folders")
'go to subfolder inside folder1
Set myfolder = folder1.Folders("Conversations")
'set the destination folder
Set folder2 = folder1.Folders("Deleted Items")
'again, we want a subfolder here
Set dupfolder = folder2.Folders("Conversations")
'sort items based on sent-on date and time
Set myitems = myfolder.Items
myitems.Sort "[SentOn]", olAscending
'iterate through mails, checking for duplicates
totalcount = myitems.Count
dupcount = 0
'start from end and go towards first item, deleting duplicates from the end
For i = totalcount - 1 To 1 Step -1 'assuming there are atleast 2 emails
Set oldEmail = myitems(i)
Set newEmail = myitems(i + 1)
'check if 2 emails are same
If (oldEmail.ConversationTopic = newEmail.ConversationTopic) And _
(oldEmail.SentOn = newEmail.SentOn) _
Then
'no short circuit of boolean expressions, so we have inner if statement
'len(oldEmail.Body): comparing message length, faster than full string compare
If (Len(oldEmail.Body) = Len(newEmail.Body)) Then
dupcount = dupcount + 1
newEmail.Move dupfolder
End If
End If
Next i
MsgBox "Duplicates: " & dupcount
'clean up any references
Set myitems = Nothing
Set myfolder = Nothing
Set dupfolder = Nothing
Set folder2 = Nothing
Set folder1 = Nothing
Set olns = Nothing
Set ol = Nothing
End Sub
'Also make it public, so outlook can access it.
'Sub means Subroutine
Public Sub deleteDuplicateMails()
'Now for some variable declarations.
'Note that this is not needed in VB, but
'its a good practice, and also helps VB to
'autocomplete your code.
Dim oldEmail As MailItem, newEmail As MailItem
Dim i As Integer, dupcount As Integer, totalcount As Integer
Dim folder1 As Folder, folder2 As Folder
Dim myfolder As Folder, dupfolder As Folder
'Now, we need to access the folders where
'emails are stored. The following lines do that.
'This is to help VB access the stuff inside outlook
'MAPI is "Messaging Application Programming Interface"
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
'Note: I am assuming these folders and subfolders
'already exist. The code won't run otherwise.
'We could make it more robust, and create
'the folders here, but thats too much work :P
'set the source folder
Set folder1 = olns.Folders("Personal Folders")
'go to subfolder inside folder1
Set myfolder = folder1.Folders("Conversations")
'set the destination folder
Set folder2 = folder1.Folders("Deleted Items")
'again, we want a subfolder here
Set dupfolder = folder2.Folders("Conversations")
'sort items based on sent-on date and time
Set myitems = myfolder.Items
myitems.Sort "[SentOn]", olAscending
'iterate through mails, checking for duplicates
totalcount = myitems.Count
dupcount = 0
'start from end and go towards first item, deleting duplicates from the end
For i = totalcount - 1 To 1 Step -1 'assuming there are atleast 2 emails
Set oldEmail = myitems(i)
Set newEmail = myitems(i + 1)
'check if 2 emails are same
If (oldEmail.ConversationTopic = newEmail.ConversationTopic) And _
(oldEmail.SentOn = newEmail.SentOn) _
Then
'no short circuit of boolean expressions, so we have inner if statement
'len(oldEmail.Body): comparing message length, faster than full string compare
If (Len(oldEmail.Body) = Len(newEmail.Body)) Then
dupcount = dupcount + 1
newEmail.Move dupfolder
End If
End If
Next i
MsgBox "Duplicates: " & dupcount
'clean up any references
Set myitems = Nothing
Set myfolder = Nothing
Set dupfolder = Nothing
Set folder2 = Nothing
Set folder1 = Nothing
Set olns = Nothing
Set ol = Nothing
End Sub
And that completes the code. VBA can be used to write all kinds of neat macros that speed up day to day tasks. Finding duplicate mails is just one of them.
Friday, September 18, 2009
Symbolic math with Matlab
A lot of people in academia use Matlab on a regular basis. But it turns out that Matlab has so many cool features that most often, nobody knows about. This post is about one such feature, symbolic math in matlab. Matlab allows you to solve equations, do integration, differentiation and so on. All you need to do is install the Symbolic Math toolkit (which is also available on the student edition).
Here is a hello world sorta example:
>> syms x y
>> x+x
ans =
2*x
The first line says that we are using 2 symbols x and y.
The second line is any arbitrary algebra you want to do on these variables.
The symbolic math toolkit also allows you to do math using fractions:
>> sym(1/5) + sym(1/3)
ans =
9/20
Here is another simple algebra example:
>> quadeqn='a*x*x+b*x+c=0';
>> solve(quadeqn,'x')
ans =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
This solves the quadratic equation for variable 'x'.
To actually evaluate this at some value, we can simply specify more equations. The solve function can solve a system of equations, and generate a set of results, one for each variable in the system.
>> [a,b,c,x]=solve(quadeqn,'a=1','b=1','c=1')
x =
(3^(1/2)*i)/2 - 1/2
- (3^(1/2)*i)/2 - 1/2
(it gives the values of a, b, c also, which i have removed here for brevity)
Now, typing:
>> simplify((3^(1/2)*i)/2 - 1/2)
-0.5000 + 0.8660i
This is the more easy to read answer we wanted :)
Speaking of simplify, there are some really whacky functions in matlab for symbolic simplification:
>> simplify(cos(x)^2 + sin(x)^2)
ans =
1
>> simplify(a*a + 2*a*b + b*b)
ans =
(a + b)^2
Lets try something harder...
>> simplify(cos(x) + i*sin(x))
ans =
cos(x) + i*sin(x)
Oops! did it give up already? not to worry. Matlab has a bunch of simplification routines, and simplify is only one of them. We can invoke ALL (mwuahahaahahaa!!) of them by using the 'simple' function.
>> simple(cos(x) + i*sin(x))
(matlab goes on a big spin, spews out lots of stuff, but finally...)
ans =
exp(i*x)
Sometimes you want to go the other way:
>> expand ((a+b)^2)
ans =
a^2 + 2*a*b + b^2
And then, we have differentiation:
>> diff(sin(x)^3)
ans =
3*cos(x)*sin(x)^2
...partial differentiation with respect to x:
>> diff(x^2 + y^2 + c, 'x')
ans =
2*x
...And integration:
>> int(sin(x)^3)
ans =
cos(3*x)/12 - (3*cos(x))/4
And all this with discontinuous functions and limits :D :D :D
>> int(dirac(x-a)*x^2,-inf,inf)
ans =
a^2
Then there is function composition:
>> f=log(x);
>> g=sin(x);
>> compose(f,g)
ans =
log(sin(x))
And a whole host of other cool things waiting for you... hope this kick starts a new interest in the awesome powers of matlab.
Note: Matlab by no means has the best symbolic math toolkit, but its more commonly found than Mathematica :P
Here is a hello world sorta example:
>> syms x y
>> x+x
ans =
2*x
The first line says that we are using 2 symbols x and y.
The second line is any arbitrary algebra you want to do on these variables.
The symbolic math toolkit also allows you to do math using fractions:
>> sym(1/5) + sym(1/3)
ans =
9/20
Here is another simple algebra example:
>> quadeqn='a*x*x+b*x+c=0';
>> solve(quadeqn,'x')
ans =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
This solves the quadratic equation for variable 'x'.
To actually evaluate this at some value, we can simply specify more equations. The solve function can solve a system of equations, and generate a set of results, one for each variable in the system.
>> [a,b,c,x]=solve(quadeqn,'a=1','b=1','c=1')
x =
(3^(1/2)*i)/2 - 1/2
- (3^(1/2)*i)/2 - 1/2
(it gives the values of a, b, c also, which i have removed here for brevity)
Now, typing:
>> simplify((3^(1/2)*i)/2 - 1/2)
-0.5000 + 0.8660i
This is the more easy to read answer we wanted :)
Speaking of simplify, there are some really whacky functions in matlab for symbolic simplification:
>> simplify(cos(x)^2 + sin(x)^2)
ans =
1
>> simplify(a*a + 2*a*b + b*b)
ans =
(a + b)^2
Lets try something harder...
>> simplify(cos(x) + i*sin(x))
ans =
cos(x) + i*sin(x)
Oops! did it give up already? not to worry. Matlab has a bunch of simplification routines, and simplify is only one of them. We can invoke ALL (mwuahahaahahaa!!) of them by using the 'simple' function.
>> simple(cos(x) + i*sin(x))
(matlab goes on a big spin, spews out lots of stuff, but finally...)
ans =
exp(i*x)
Sometimes you want to go the other way:
>> expand ((a+b)^2)
ans =
a^2 + 2*a*b + b^2
And then, we have differentiation:
>> diff(sin(x)^3)
ans =
3*cos(x)*sin(x)^2
...partial differentiation with respect to x:
>> diff(x^2 + y^2 + c, 'x')
ans =
2*x
...And integration:
>> int(sin(x)^3)
ans =
cos(3*x)/12 - (3*cos(x))/4
And all this with discontinuous functions and limits :D :D :D
>> int(dirac(x-a)*x^2,-inf,inf)
ans =
a^2
Then there is function composition:
>> f=log(x);
>> g=sin(x);
>> compose(f,g)
ans =
log(sin(x))
And a whole host of other cool things waiting for you... hope this kick starts a new interest in the awesome powers of matlab.
Note: Matlab by no means has the best symbolic math toolkit, but its more commonly found than Mathematica :P
Thursday, July 2, 2009
A visit to the Wine Cellar
WINE (Wine is not an emulator), is a nifty tool that you can use to run Windows applications on Linux. WINE is currently an incomplete implementation of the Windows API, and as such, not everything will run on it. This article will explore some of the things that WINE is capable of.
For starters, to install wine, simply get it from your distribution's repository (like sudo apt-get install wine), or go to winehq.org and get more info on how to install it. You could also download the sources and compile it yourself, though that is not the simplest path here.
WINE Commandments
Well, more like guidelines, really...
1. Thou Shalt use the command line: You can start a windows app by double clicking it (or right clicking it and selecting "Open with WINE", but this is not recommended. The correct way to start applications using WINE is to use the command line. Type "wine" in the terminal to get usage details. For example, "wine test.exe" will launch the file called test.exe present in the current directory.
2. winecfg shalt light your path: To set various wine parameters, type "winecfg". This will bring up a control panel that will be discussed in detail later.
3. WINE shalt hide from you in the shadows: WINE creates its files in a hidden directory in your home folder. "cd ~/.wine" will take you there. Here, you will see a "drive_c" directory. This is your virtual C Drive. It contains a Windows folder, a Program Files folder etc... The .wine directory also contains a regedit.exe, a notepad.exe and some other small utilities. Typing "regedit" in the terminal will take you to your "new" registry, in case you want to do something there.
4. Seek in system32, and you shall find: When you (try to) run a windows program using WINE, one of 3 things will happen: It will run, or it will complain about missing dlls, or it will segfault and throw up. If it runs, fine. If it throws up, there is no easy answer, but its mostly that the program won't run. If it complains about DLLs, which happens often, all you need to do, is copy the correct windows DLL file to your "new" system32 directory... which is located here: "~/.wine/drive_c/windows/system32". Where can you get these DLL files? Online, or from your licensed copy of Windows, which you have installed on a different partition on this machine. Most often, if you try to play games, you will have to copy DirectX dll files from your original Windows\system32. Note that this is the reason I ask you to use the command line. If you use WINE from the GUI, you cannot the error messages, and wont know why a program is not working.
Installing apps on WINE
You could install applications on WINE using the regular Setup programs you use in Windows, or you could try to run these programs directly from where you had installed them on windows (without reinstalling in linux). The second option is less recommended, but works often, specially with games.
WINE also adds a menu item in your default gnome / kde menu. So you can also 'uninstall' programs from here. You could also simply go to the ".wine/drive_c/Program Files" directory and delete the application from there.
Mounting images in WINE
If you are using backed up CD-Images to run your games on windows, doing the same thing on linux may be a bit harder. Firstly, some (many) copy protection systems like securom and Tages may not work on linux.
But anyway, you probably have a CD image (ISO / cue / bin / mdf ) file that you want to mount. If you have an ISO for example, make a directory (say, virtualdrive) in your home folder and simply mount the image in that directory:
sudo mount image.iso ~/virtualdrive -t iso9660 -oloop
Now, the image is mounted, but your game does not know where to find it. So type 'winecfg' into the terminal, to bring up the wine configuration tool. Here, go to the "Devices" tab, and click on "Add" to add a new device. Type the path to your device (~/virtualdrive for example) under the field "Device Mapping". winecfg would have automatically assigned a drive letter to this drive. You can also click on "Advanced" and select "CD-ROM" as the device Type. Now, your game can read the new virtual drive as though it was a regular CD drive.
Note that its not generally possible (AFAIK) to mount mdf files in linux. You can download and install the tool IAT that converts from various formats to ISO format.
WINE Extras
Sometimes, a few programs will complain that a certain library is missing, or that HTML rendering is disabled, etc... Here are a few solutions to such problems:
1. Microsoft TrueType Fonts: Sometimes, while using WINE, you will have problems with fonts in the application you are running. This is because you do not have the microsoft fonts installed on linux. Here is how you should do it:
Ubuntu (man, these deb guys are crazy, they have every damn package in their repository):
apt-cache search msttcorefonts
Other distros (slightly longer method): Visit corefonts.sourceforge.net
2. HTML Renderer on WINE: Wine Gecko is a HTML rendering engine that you can use to see webpages in applications that you run on wine. For example, CounterStrike displays a html page on loading a new map. To install Gecko, simply visit the Official Gecko Page and follow the instructions given there.
3. VB Runtimes: You may want to install visual basic runtimes from here. In case this microsoft link expires, just google for vbrun60sp6.exe
4. DirectX: Similar story here, just go to the microsoft webpage, get their latest Direct X installer, and run it. The application you are trying to install may also come with a DirectX installer.
I can't really think of anything more to write right now, but if I may add a new post sometime later, to discuss some specific wine feature...
For starters, to install wine, simply get it from your distribution's repository (like sudo apt-get install wine), or go to winehq.org and get more info on how to install it. You could also download the sources and compile it yourself, though that is not the simplest path here.
WINE Commandments
Well, more like guidelines, really...
1. Thou Shalt use the command line: You can start a windows app by double clicking it (or right clicking it and selecting "Open with WINE", but this is not recommended. The correct way to start applications using WINE is to use the command line. Type "wine" in the terminal to get usage details. For example, "wine test.exe" will launch the file called test.exe present in the current directory.
2. winecfg shalt light your path: To set various wine parameters, type "winecfg". This will bring up a control panel that will be discussed in detail later.
3. WINE shalt hide from you in the shadows: WINE creates its files in a hidden directory in your home folder. "cd ~/.wine" will take you there. Here, you will see a "drive_c" directory. This is your virtual C Drive. It contains a Windows folder, a Program Files folder etc... The .wine directory also contains a regedit.exe, a notepad.exe and some other small utilities. Typing "regedit" in the terminal will take you to your "new" registry, in case you want to do something there.
4. Seek in system32, and you shall find: When you (try to) run a windows program using WINE, one of 3 things will happen: It will run, or it will complain about missing dlls, or it will segfault and throw up. If it runs, fine. If it throws up, there is no easy answer, but its mostly that the program won't run. If it complains about DLLs, which happens often, all you need to do, is copy the correct windows DLL file to your "new" system32 directory... which is located here: "~/.wine/drive_c/windows/system32". Where can you get these DLL files? Online, or from your licensed copy of Windows, which you have installed on a different partition on this machine. Most often, if you try to play games, you will have to copy DirectX dll files from your original Windows\system32. Note that this is the reason I ask you to use the command line. If you use WINE from the GUI, you cannot the error messages, and wont know why a program is not working.
Installing apps on WINE
You could install applications on WINE using the regular Setup programs you use in Windows, or you could try to run these programs directly from where you had installed them on windows (without reinstalling in linux). The second option is less recommended, but works often, specially with games.
WINE also adds a menu item in your default gnome / kde menu. So you can also 'uninstall' programs from here. You could also simply go to the ".wine/drive_c/Program Files" directory and delete the application from there.
Mounting images in WINE
If you are using backed up CD-Images to run your games on windows, doing the same thing on linux may be a bit harder. Firstly, some (many) copy protection systems like securom and Tages may not work on linux.
But anyway, you probably have a CD image (ISO / cue / bin / mdf ) file that you want to mount. If you have an ISO for example, make a directory (say, virtualdrive) in your home folder and simply mount the image in that directory:
sudo mount image.iso ~/virtualdrive -t iso9660 -oloop
Now, the image is mounted, but your game does not know where to find it. So type 'winecfg' into the terminal, to bring up the wine configuration tool. Here, go to the "Devices" tab, and click on "Add" to add a new device. Type the path to your device (~/virtualdrive for example) under the field "Device Mapping". winecfg would have automatically assigned a drive letter to this drive. You can also click on "Advanced" and select "CD-ROM" as the device Type. Now, your game can read the new virtual drive as though it was a regular CD drive.
Note that its not generally possible (AFAIK) to mount mdf files in linux. You can download and install the tool IAT that converts from various formats to ISO format.
WINE Extras
Sometimes, a few programs will complain that a certain library is missing, or that HTML rendering is disabled, etc... Here are a few solutions to such problems:
1. Microsoft TrueType Fonts: Sometimes, while using WINE, you will have problems with fonts in the application you are running. This is because you do not have the microsoft fonts installed on linux. Here is how you should do it:
Ubuntu (man, these deb guys are crazy, they have every damn package in their repository):
apt-cache search msttcorefonts
Other distros (slightly longer method): Visit corefonts.sourceforge.net
2. HTML Renderer on WINE: Wine Gecko is a HTML rendering engine that you can use to see webpages in applications that you run on wine. For example, CounterStrike displays a html page on loading a new map. To install Gecko, simply visit the Official Gecko Page and follow the instructions given there.
3. VB Runtimes: You may want to install visual basic runtimes from here. In case this microsoft link expires, just google for vbrun60sp6.exe
4. DirectX: Similar story here, just go to the microsoft webpage, get their latest Direct X installer, and run it. The application you are trying to install may also come with a DirectX installer.
I can't really think of anything more to write right now, but if I may add a new post sometime later, to discuss some specific wine feature...
Wednesday, July 1, 2009
Beep Beep!!
The PC speaker is a relic from the medieval times when people were awed by the sound effects of Dangerous Dave... But strangely enough, it is used heavily by most linux distros. This is most noticeable if you do text editing in the terminal, or inside gnome(sometimes kde) default apps like gedit...
If you are one of those people who does not appreciate the fact that their machine can do a very good Road Runner impression, here is how you can fix things:
Firstly, if you are facing this problem only in gnome-terminal, you can turn off system beep from the terminal options (Edit->Profile Preferences, uncheck "Terminal Bell")
If you want a slightly geekier (and more effective) solution, you can disable the PC speaker in this way:
sudo modprobe -r pcspkr
This will disable the PC Speaker for the current session. If you want a more permanent solution, you can blacklist the PC Speaker by editing the "/etc/modprobe.d/blacklist" file.
sudo gedit /etc/modprobe.d/blacklist
Then add this line at the end of the file:
blacklist pcspkr
Save the file, and next time you start your machine, and there should be no more of that infernal beeping.
modprobe is a utility that can load and unload linux modules. To learn more about it visit the Wiki page
If you are one of those people who does not appreciate the fact that their machine can do a very good Road Runner impression, here is how you can fix things:
Firstly, if you are facing this problem only in gnome-terminal, you can turn off system beep from the terminal options (Edit->Profile Preferences, uncheck "Terminal Bell")
If you want a slightly geekier (and more effective) solution, you can disable the PC speaker in this way:
sudo modprobe -r pcspkr
This will disable the PC Speaker for the current session. If you want a more permanent solution, you can blacklist the PC Speaker by editing the "/etc/modprobe.d/blacklist" file.
sudo gedit /etc/modprobe.d/blacklist
Then add this line at the end of the file:
blacklist pcspkr
Save the file, and next time you start your machine, and there should be no more of that infernal beeping.
modprobe is a utility that can load and unload linux modules. To learn more about it visit the Wiki page
Monday, June 29, 2009
A foray into OpenMP
(This post has been moved from my other blog on the grounds that it is quite general, and not all that technical).
This is sort of an intro to how easy it is to write multi threaded programs these days. Most people don't bother about parallelizing their applications because the prospect of managing threads and synchronization is too daunting. This is where OpenMP steps in. It is a simple system to use, based on pre-processor directives. It works portably in both windows and linux. And best of all, if you do not invoke the OpenMP option while compiling the code, the parallelization part of your code is ignored, and it works as a single threaded app. Below, you will find a quite pointless program, but it serves well to test my dual core dual socket setup :)
it computes the sum of: [sin(i/128) + cos(i/128)]... don't ask me why :-/
where i ranges from 0 to 98765432
#include <iostream>
#include <cmath>
using namespace std;
#define MAXNUM 98765432
int main(){
double sum=0;
#pragma omp parallel for reduction(+:sum)
for (int i=0;i<MAXNUM;i++)
sum+=sin(i/128.0)+cos(i/128.0);
cout<<sum<<endl;
}
The #pragma statement automatically parallelizes the for loop. Also, since the 'sum' is updated each time in the loop, synchronization is ensured by the reduction(+:sum) statement. This says that the for loop is performing a reduction operation (like sum of n numbers), and that the operator used is Addition (+).
Pretty neat! And very very simple to use!
To compile this, all i needed to do was:
g++ -fopenmp main.cpp
In case I wanted a version without any of the parallel threading, a single threaded version is easily generated by not using the fopenmp compiler flag:
g++ main.cpp
Amazing simplicity! And this works for all the complicated constructs that OpenMP provides.
So, how well did we fare in this parallelization endeavour? Lets find out:
Single Threaded run (1 core): 16 seconds
Multi threaded run (4 cores): 4.7 seconds
Thats almost a linear scaling from 1 to four cores. Now I cant wait to see what more OpenMP can do for me :)
Learn more about OpenMP at openmp.org or at this comprehensive tutorial.
This is sort of an intro to how easy it is to write multi threaded programs these days. Most people don't bother about parallelizing their applications because the prospect of managing threads and synchronization is too daunting. This is where OpenMP steps in. It is a simple system to use, based on pre-processor directives. It works portably in both windows and linux. And best of all, if you do not invoke the OpenMP option while compiling the code, the parallelization part of your code is ignored, and it works as a single threaded app. Below, you will find a quite pointless program, but it serves well to test my dual core dual socket setup :)
it computes the sum of: [sin(i/128) + cos(i/128)]... don't ask me why :-/
where i ranges from 0 to 98765432
#include <iostream>
#include <cmath>
using namespace std;
#define MAXNUM 98765432
int main(){
double sum=0;
#pragma omp parallel for reduction(+:sum)
for (int i=0;i<MAXNUM;i++)
sum+=sin(i/128.0)+cos(i/128.0);
cout<<sum<<endl;
}
The #pragma statement automatically parallelizes the for loop. Also, since the 'sum' is updated each time in the loop, synchronization is ensured by the reduction(+:sum) statement. This says that the for loop is performing a reduction operation (like sum of n numbers), and that the operator used is Addition (+).
Pretty neat! And very very simple to use!
To compile this, all i needed to do was:
g++ -fopenmp main.cpp
In case I wanted a version without any of the parallel threading, a single threaded version is easily generated by not using the fopenmp compiler flag:
g++ main.cpp
Amazing simplicity! And this works for all the complicated constructs that OpenMP provides.
So, how well did we fare in this parallelization endeavour? Lets find out:
Single Threaded run (1 core): 16 seconds
Multi threaded run (4 cores): 4.7 seconds
Thats almost a linear scaling from 1 to four cores. Now I cant wait to see what more OpenMP can do for me :)
Learn more about OpenMP at openmp.org or at this comprehensive tutorial.
Subscribe to:
Posts (Atom)