Friday, February 22, 2013

C++: 3 Dimensional STL Vector with dynamic Re-sizing

Problem:

I want to create a 3 Dimensional Array whose dimensions are not known a priori. Let us that our 3 dimensional array is A[NP][NR][NC].  In my case, I know NP and NC a priori (before the execution of the program), but NR will be known only during run time.

Well I could make this array using pointers and using dynamic allocation functions like new/delete to get the desired effect. That is something I do regularly.

STL Vectors provide much better interface with several useful functions that can make your life lot easier. For instance, it is possible to resize these vectors during runtime. You can check for index bounds while accessing the elements etc.

So, I want to use STL vector to solve this problem.

Solution:

The following code demonstrates two ways by which you can accomplish the above objective.


  size_t np = 5; // no of pages
  size_t nc = 2; // no. of columns
  

  Method 1: Keep pushing the matrices into the page


  std::vector > matrix;
  std::vector > >page;

  for(size_t i = 0; i < np; ++i)
  {
    matrix.resize(i+1, std::vector(nc));
    for(size_t j = 0; j < matrix.size(); ++j)
    {
      for(size_t k = 0; k < matrix[j].size(); ++k)
        matrix.at(j).at(k) = rand()/(double)RAND_MAX;
    }
    page.push_back(matrix);
  }   


Method 2: Dynamically re-sizing 3D Array

  std::vector < std::vector > > page;

  page.resize(np); //np is known

  for(size_t i = 0; i < np; ++i)
  {
    page[i].resize(i+1, std::vector(nc));
    for(size_t j = 0; j < page[i].size(); ++j)
      for(size_t k = 0; k < page[i][j].size(); ++k)
        page[i][j][k] = rand()/(double)RAND_MAX;
  }        

           

                                


Tuesday, February 12, 2013

Installing Lotus Notes 8.5.3 on Ubuntu 12.04 64bit LTS


My office mail supports only Lotus Notes and hence I want to configure it on my ubuntu 12.04 64 bit LTS system. A very good tutorial on this is available here. I will not repeat the steps that are already mentioned at this site. Rather, I will only elaborate on errors that I encountered during my installation and tell you how I got around them.

It is easy to follow the steps from 1 to 5 of this tutorial.

Update:   In step 5, you need to download the getlibs from this link. The original link is not working any more.



 On step 6, when I execute the installation process:

$ sudo getlibs -p libgnomeprintui2.2-0 libgnomeprint2.2-0 libgnomevfs2-0 libgnomeui-0 libxkbfile1 libstartup-notification0 libsepol1 libselinux1 libgsf-1-114 libgsf-1-dev librsvg2-2 librsvg2-common libavahi-client3 libavahi-common3 libavahi-glib1 libbonoboui2-0 libcroco3 libdbus-1-3 libdbus-glib-1-2  libgnome2-0 libgnomecanvas2-0 libgnome-keyring0 libgnome-menu2 libesd0 gtk2-engines libgnome-desktop-2-17 libmotif4 libmotif3 libgnome-desktop-3-0 libavahi-glib1 gtk2-engines-oxygen gtk2-engines-aurora gtk2-engines-qtcurve  gtk2-engines-murrine gtk2-engines-equinox  alsa-base alsa-utils iproute libgnome-desktop-3-2 liborbit2 libbonobo2-0 libgconf2-4 libx11-6 libxt6 libxext6  libc6  libgcc1  libgtk2.0-0  libxkbfile1 libglib2.0-0  libstdc++6 bash libart-2.0-2 libpopt0 libgnomeui-0


libmotif3 was not found in your repositories
Make sure you have all repositories enabled and updated
E: No packages found
libgnome-desktop-3-0 was not found in your repositories
Make sure you have all repositories enabled and updated
Downloading ...
Installing libraries ...

But I think this is not serious enough and I decided to proceed further.



 In step 7, I get the following error when I try to install sametime:

$ sudo dpkg -i ibm-lotus-sametime-8.5.3.i586.deb

dpkg: regarding ibm-lotus-sametime-8.5.3.i586.deb containing ibm-lotus-sametime:i386, pre-dependency problem:
 ibm-lotus-sametime:i386 pre-depends on alsa-base
  alsa-base is not installed.
dpkg: error processing ibm-lotus-sametime-8.5.3.i586.deb (--install):
 pre-dependency problem - not installing ibm-lotus-sametime:i386
Errors were encountered while processing:
 ibm-lotus-sametime-8.5.3.i586.deb

I decide to ignore this as I am not worried about using same time at this time.


Update:  On a fresh install of Ubuntu 12.04 64 bit LTS, I could install the above package for 'sametime' without any error.  

Step 8 also works well.


Now in Step 9, I get the following error when I attempt to run the 'make' command:

$ make
gcc -Wall -Wextra -m32 `pkg-config –cflags gtk+-2.0`–shared libnotesgtkfix.c -o libnotesgtkfix.so -ldl 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s

When I search for this library, I find that it is available at two locations: 

$ locate libgcc_s.so
/lib/i386-linux-gnu/libgcc_s.so.1
/lib/x86_64-linux-gnu/libgcc_s.so.1
/lib32/i386-linux-gnu/libgcc_s.so.1
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.6/32/libgcc_s.so

Somehow the linker was not able to link the 32-bit version of this library. So I decided to create a hard link inside the folder '/usr/lib/gcc/x86_64-linux-gnu/4.6'. 

$ sudo rm libgcc_s.so
$ sudo ln /lib32/i386-linux-gnu/libgcc_s.so.1 ./libgcc_s.so

It seemed to solve the problem and 'libnotesgtkfix.so' library is created.  


Update: Compiling notes-wrapper works fine. It does not give any error.  So, the make command works properly without any error generating 'libnotesgtkfix.so' library.  Just make sure your 'Makefile' looks something like this:

----------

all:
    gcc -Wall -Wextra -shared -m32 -L/lib32/i386-linux-gnu -lgcc_s `pkg-config --cflags gtk+-2.0`-shared libnotesgtkfix.c -o libnotesgtkfix.so -ldl

clean:
    rm -f libnotesgtkfix.so  

------------------


Also, while applying 'sed' to notes-wrapper, you still need to do the following:


While applying sed to the 'notes-wrapper' file, replace the command 

sudo sed -i ‘s/../notes %F/../notes-wrapper %F/g’ /usr/share/applications/LotusNotes8.5.desktop

with

sudo sed -i ‘s/\.\.\/notes\ \%F/\.\.\/notes\-wrapper\ \%F/g’ /usr/share/applications/LotusNotes8.5.desktop


Step 10 is OK. Only change the LD_LIBRARY_PATH from

LD_LIBRARY_PATH=$NOTESBIN:/usr/lib/i386-linux-gnu:$NOTESBIN/jvm/bin/classic:$NOTESBIN/jvm/bin:$LD_LIBRARY_PATH

to 

LD_LIBRARY_PATH=$NOTESBIN:/usr/lib32/:/usr/lib32/i386-linux-gnu:$NOTESBIN/jvm/bin/classic:$NOTESBIN/jvm/bin:$LD_LIBRARY_PATH 


In step 11, You need to include some more symlinks as given below:

$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libgnomevfs-2.so.0.2400.4 /usr/lib32/libgnomevfs-2.so.0
$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libgnome-2.so.0.3200.1 /usr/lib32/libgnome-2.so.0
$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libart_lgpl_2.so.2.3.21 /usr/lib32/libart_lgpl_2.so.2
$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libbonobo-2.so.0.0.0 /usr/lib32/libbonobo-2.so.0
$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libbonobo-activation.so.4.0.0 /usr/lib32/libbonobo-activation.so.4
$ sudo ln -s /usr/lib/i386-linux-gnu/i386-linux-gnu/libbonoboui-2.so.0.0.0 /usr/lib32/libbonoboui-2.so.0

If you get any error related to a library not found, just find its location and create a symbolic link within /usr/lib32 folder.

First time, run from the command line as a normal user as shown below: 

$ /opt/ibm/lotus/notes/notes-wrapper


setting locale …

setting notes environment …

starting notes …

`menu_proxy_module_load': /opt/ibm/lotus/notes/notes: undefined symbol: menu_proxy_module_load



(notes:3116): Gtk-WARNING **: Failed to load type module: (null)


`menu_proxy_module_load': /opt/ibm/lotus/notes/notes: undefined symbol: menu_proxy_module_load

(notes:3116): Gtk-WARNING **: Failed to load type module: (null)

ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
[03116:00002-4078790848] Error writing to process file pid.nbf, (other applications may be inappropriately accessing this file)SUT: OSSmartUpgradeInit: OSFileCreateDirectory: error: Cannot write or create file (file or disk is read-only)
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/ibm/lotus/notes/libnotesgtkfix.so' from LD_PRELOAD cannot be preloaded: ignored.
[03116:00002-4078790848] 02/12/2013 03:17:01.49 PM NEMInit> The declaration for notation '{0}' is invalid! Errorcode=39054.


[03116:00002-4078790848]  Thread=[03116:00002-4078790848]
Stack base=0xFFE2A25C, Stack size = 2268 bytes
PANIC: DESK create failed
Stack base = 0xffe2a25c, Stack size = 4092 bytes 
Fatal Error signal = 0x0000000b PID/TID = 3116/-216176448 
2/12/2013 15:17:02  Running NSD
2/12/2013 15:17:14  Termination is in progress
2/12/2013 15:17:14  Too many crashes, restart disabled
2/12/2013 15:17:14  Terminating tasks
2/12/2013 15:17:19  Freeing resources
2/12/2013 15:17:19  Termination completed


First time, it gives error and lotus note crashes. Ignore the error related to 'libnotesgtkfix.so' not getting preloaded. 

Not able to write the pid.nbf file is the real problem here. It is related to NSD. It does not let you start the notes. It gives a warning and terminates the program.  Little search on google lead to this link.

To solve this, add the following lines to the file /home/lotus/notes/data/notes.ini 

DISABLE_SAVENSDCONFIG=1

and Change the line

NotesProgram=/opt/ibm/lotus/notes/notes 

to 

NotesProgram=/opt/ibm/lotus/notes/notes-wrapper


You might need root permission to edit this file even though it is in your home directory.  Now when you give the above command, it finally starts without any error.  You need to have your ID file in order to configure the Lotus Client.  I also use the modification as suggested in this link as well: 

sudo mv /opt/ibm/lotus/notes/openwith /opt/ibm/lotus/notes/openwith.bak
sudo ln -s /usr/bin/gnome-open /opt/ibm/lotus/notes/openwith


The home screen opens after you give the password. But I get an error : CWPCA4003W: Failed to load application from url:nrpc:/ ....  (see the screenshot below). It has to do with some template design problem. I tried refreshing the template, but it did not help.


I am also able to create a local replica and synchronize it with the server. But I am not able to view my mailbox.  I am able to send a mail though. I think the problem lies with updating / upgrading templates.

Update: I don't get any error when I run the command '$ /opt/ibm/lotus/notes/notes-wrapper'. Everything works seamlessly.Put your lotus note ID file into "~/lotus/notes/data/"  folder located in your home directory.