Showing posts with label OsX. Show all posts
Showing posts with label OsX. Show all posts

Monday, September 17, 2012

XCode 4 Build Locations (Lion, Mountain Lion)

Apparently, the "most advanced" operating system in the world is not very friendly for power-users and developers.

The new xcode 4 has had a major rehaul. I just updated to mountain lion and the latest xcode (4.4.1). The first annoying feature that you will notice about xcode is the non-intuitive and complex user interface. I can't even find the console or the debugging tools... oh wait, they're placed at the bottom of the screen and they're practically invisible. Maybe it is time to read the documentation... but who has time for that?

In any event, I went ahead and tested a "Bonjour y'all!" code and it worked. but I could not locate the executable file in the project's directory. Are you serious? It turns out that XCode defaults to some location in your library. Fortunately, I just found a way to go back to standard operation and place your executable where it BELONGS:

  1. Open XCODE
  2. go to: Preferences
  3. Click on the "Locations" tab
  4. Change the path for "Derived Data" to relative and that should do it.
  5. If you want to be a bit more picky, click on Advanced
    1. select "Custom"
      1. Select "Relative to Workspace"
That last step will place your executable in its normal location.

Hope that helps.

Cite as:
Saad, T. "XCode 4 Build Locations (Lion, Mountain Lion)". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2012/09/xcode-4-build-locations-lion-mountain.html

Friday, September 14, 2012

Calling gnuplot from C/C++ on Mac OS X

Here's another way of calling gnuplot from Mac OS X.

First install gnuplot either from their website or using macports. I like the macports model because it installs all dependencies for you automatically.
  1. Install macports from: http://www.macports.org/ 
  2. Open up your terminal
  3. type: sudo port selfupdate (to update port names)
  4. type: sudo port install gnuplot
and Voila! you now have gnuplot installed on your mac. To test it type: gnuplot and you should enter the gnuplot environment. Another caveat that you have to bear in mind when using gnuplot on mac is that you have to tell gnuplot to use x11. You do this as follows:
  1. Open up your terminal
  2. type: gnuplot
  3. type: set terminal x11
Now to the fun stuff. Here's the code that I used before to call gnuplot for windows, but modified to work on Unix based systems such as Mac.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void plotResults(double* xData, double* yData, int dataSize);
int main() {
  int i = 0;
  int nIntervals = 100;
  double intervalSize = 1.0;
  double stepSize = intervalSize/nIntervals;
  double* xData = (double*) malloc((nIntervals+1)*sizeof(double));
  double* yData = (double*) malloc((nIntervals+1)*sizeof(double));
  xData[0] = 0.0;
  double x0 = 0.0;
  for (i = 0; i < nIntervals; i++) {
      x0 = xData[i];
      xData[i+1] = x0 + stepSize;
  }
  for (i = 0; i <= nIntervals; i++) {
      x0 = xData[i];
      yData[i] = sin(x0)*cos(10*x0);
  }
  plotResults(xData,yData,nIntervals);
  return 0;
}
void plotResults(double* xData, double* yData, int dataSize) {
  FILE *gnuplotPipe,*tempDataFile;
  char *tempDataFileName;
  double x,y;
  int i;
  tempDataFileName = "tempData";
  gnuplotPipe = popen("gnuplot","w");
  if (gnuplotPipe) {
      fprintf(gnuplotPipe,"plot \"%s\" with lines\n",tempDataFileName);
      fflush(gnuplotPipe);
      tempDataFile = fopen(tempDataFileName,"w");
      for (i=0; i <= dataSize; i++) {
          x = xData[i];
          y = yData[i];            
          fprintf(tempDataFile,"%lf %lf\n",x,y);        
      }        
      fclose(tempDataFile);        
      printf("press enter to continue...");        
      getchar();        
      remove(tempDataFileName);        
      fprintf(gnuplotPipe,"exit \n");    
  } else {        
      printf("gnuplot not found...");    
  }
} 


This code should run as is. Of course, feel free to take the plot function and use it in your own codes.

Cite as:
Saad, T. "Calling gnuplot from C/C++ on Mac OS X". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2012/09/calling-gnuplot-from-cc-on-mac-os-x.html

Friday, July 16, 2010

Compiling Hypre on Mac OSX

Hypre is a library for solving large, sparse linear systems of equations on massively parallel computers. You can download it from here. Here's my configuration on Mac OSX
./configure --prefix=/Users/USERNAME/pkg/hypre-2.6.0b-install\
--with-MPI-include=/Users/USERNAME/pkg/openmpi-1.4.2-install/include\
--with-MPI-lib-dirs=/Users/USERNAME/pkg/openmpi-1.4.2-install/lib\
CC='gcc -arch x86_64' CXX='g++ -arch x86_64' F77='gfortran -arch x86_64'
then
make
make install
Make sure you download and install this version of gfortran. See also Compiling OpenMPI on MacOSX.

Cite as:
Saad, T. "Compiling Hypre on Mac OSX". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2010/07/compiling-hypre-on-mac-osx.html

Wednesday, July 14, 2010

Compiling OpenMPI on MacOSX

First, you will need a proper gfortran installed on your system. This version (gfortran 4.2.3)worked for me. After installing that download and extract OpenMPI. Here's the config line that I used
./configure --prefix=/Users/USERNAME/pkg/openmpi-1.4.2-install\
F77=gfortran CFLAGS=-m64 CXXFLAGS=-m64 FFLAGS=-m64
then
make
make install
Voila!

If you wish to install to the default location (/usr/local/ etc...) remove the prefix option.

Cite as:
Saad, T. "Compiling OpenMPI on MacOSX". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2010/07/compiling-openmpi-on-macosx.html

Monday, May 3, 2010

Maximize Chrome in Mac OSX

Try:
Shift + maximize button (green button)
Voila!

Cite as:
Saad, T. "Maximize Chrome in Mac OSX". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2010/05/maximize-chrome-in-mac-osx.html