You are viewing lmohanphy

Getopt is a great function for parsing command line arguments in your C program/application.There are two versions of getopt, one is the basic version and other is accepting long options(started with two dashes). In this article I plan to outline usage and example of two versions of getopt one by one.

The getopt() function parses the command-line arguments. It essentially does the work for you!. The goal of this section is to familiarize you with the basic functionality of getopt in C.

The basic form of getopt is:
int getopt(int argc, char * const argv[],const char *optstring);

Where,
int argc, char * const argv[] are the argument count and array as passed to the main(int argc, char **argv) function on program invocation. An element of argv that starts with '-' is an option element.The characters of this element (aside from the initial '-') are option characters. If getopt() is called repeatedly, it returns successively each of the option characters from each of the option elements.

optstring : argument is a string that specifies the option characters that are valid for this program. If getopt receives a character that is not part of optstring or a missing option argument, then getopt will return a question mark ( ? ).

An option character in this string can be followed by a colon (‘:’) to indicate that it takes a required argument. If an option character is followed by two colons (‘::’), its argument is optional; this is a GNU extension.

It should also be noted that getopt will set some external variables that are provided when you include unistd.h to use getopt, they are:
extern char *optarg;
extern int optind, opterr, optopt;

optarg : This variable is set by getopt to point at the value of the option argument, for those options that accept arguments.

optind : This variable is set by getopt to the index of the next element of the argv array to be processed. Once getopt has found all of the option arguments, you can use this variable to determine where the remaining non-option arguments begin. The initial value of this variable is 1.

opterr : If the value of this variable is nonzero, then getopt prints an error message to the standard error stream if it encounters an unknown option character or an option with a missing required argument. This is the default behavior. If you set this variable to zero, getopt does not print any messages, but it still returns the character ? to indicate an error.

optopt : When getopt encounters an unknown option character or an option with a missing required argument, it stores that option character in this variable. You can use this for providing your own diagnostic messages.

Example :
Here is the program all put together, using a, s, m, d, h as our flags. This program accept two number as argument and add, subtract,multiply and divide the numbers based on the option -a(add) ,-s(subtract),-m(multiply),-d (divide) and -h (help).
In this example you can also see I used some of the global external variables that getopt automatically sets including opterr, optind, optarg and optopt.

Here is an example showing how getopt is typically used. The key points to notice are:

  • Normally, getopt is called in a loop. When getopt returns -1, indicating no more options are present, the loop terminates.
  • A switch statement is used to dispatch on the return value from getopt. In typical use, each case just sets a variable that is used later in the program.


/* This very basis example will show you the getopt usage */
/* Program accept two number as argument and add, subtract,multiply and divide the numbers based on the option */
/* arithmetics.c */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int add(int , int);
int sub(int , int);
int mul(int , int);
int divi(int , int);
int uppertolower(int);
int lowertoupper(int);
void usage();

int main(int argc , char *argv[])
{
    int option;
    int num1=0;
    int num2=0;
    int input=0;
    opterr = 0;
    /* process arguments */
    /* once all the command line arguments have been parsed getopt will return a -1 */
    while (-1 != (option = getopt(argc, argv,"a:" "s:" "m:" "d:" "u:" "l:" "h")))
    {
        /* getopt returns an integer which you can compare as ASCII against values in a switch statement.*/
        switch (option)
        {
            case 'a':
                num1=atoi(argv[optind]);
                num2=atoi(argv[--optind]);
                printf("Sum : %d\n",add(num2,num1));
                break;
            case 's':
                num1=atoi(argv[optind]);
                num2=atoi(argv[--optind]);
                printf("Sub : %d\n",sub(num2,num1));
                break;
            case 'm':
                num1=atoi(argv[optind]);
                num2=atoi(argv[--optind]);
                printf("Mul : %d\n",mul(num2,num1));
                break;
            case 'd':
                num1=atoi(argv[optind]);
                num2=atoi(argv[--optind]);
                printf("Div : %d\n",divi(num2,num1));
                break;
            case 'u':
                input=*optarg;
                printf("Lower case : %c\n",uppertolower(input));
                break;
            case 'l':
                input=*optarg;
                printf("Upper case : %c\n",lowertoupper(input));
                break;
            case 'h':
                usage();
                break;
            case '?':
                /* optopt contain option character passed back to user */
                if (optopt == 'a' || optopt == 's' || optopt == 'm' || optopt == 'd' || optopt == 'u' || optopt == 'l' )
                {
                    fprintf(stderr, " option -%c is specified but not argument present.\n",optopt);
                }
                else if (isprint(optopt))
                {
                    fprintf(stderr,"-%c is not legitimate option characters.\n",optopt);
                }
                else
                {
                    fprintf (stderr,"%x is unknown option character\n",optopt);
                }
                break;
            default:
                usage();
                exit(0);
        }
    }
    return 0;
}

//addition
int add(int x , int y)
{
    return (x+y);
}

//subtraction
int sub(int x, int y)
{
    return (x-y);
}

//Multiplication
int mul(int x, int y)
{
    return (x*y);
}

//devision
int divi(int x, int y)
{
    return (x/y);
}

//upper case into lower case
int uppertolower(int x)
{
    if (x >= 65 && x <= 90)
        x=x+32;
    return x;
}

// lower case into upper case
int lowertoupper(int x)
{
    if (x >= 97 && x <= 122)
        x=x-32;
    return x;
}

void usage()
{
    fprintf(stdout,"./arithmetics -a <num1> <num2> : to add two numbers\n");
    fprintf(stdout,"./arithmetics -s <num1> <num2> : to subtract two numbers\n");
    fprintf(stdout,"./arithmetics -m <num1> <num2> : to multiply two numbers\n");
    fprintf(stdout,"./arithmetics -d <num1> <num2> : to divide two numbers\n");

    fprintf(stdout, "./arithmetics -u <any upper case character> : convert upper  to lower case\n");
    fprintf(stdout,"./arithmetics -d <any lower case character> : convert lower  to upper case\n");

    fprintf(stdout,"./arithmetics -h : to print this help message\n");
}


Okay, now that the program is made, lets compile and run it:

compile the program using gcc :

$ gcc arithmetics.c  -o arithmetics

here is the output :

To add two numbers :

$ ./arithmetics  -a 10 12
Sum : 22

To subtract two numbers :

$ ./arithmetics  -s 20 10
Sub : 10

To multiply two numbers :

$ ./arithmetics  -m 20 3
Mul : 60

To devide two numbers :

$ ./arithmetics  -d 18 3
Div : 6

To convert upper case character to lower case :

$ ./arithmetics  -u A
Lower case : a

To convert lower case character to upper case :
$ ./arithmetics  -l a
Upper case : A

You can also do all the above in one run like:

$ ./arithmetics  -a 10 12 -s 20 10 -m 20 3 -d 18 3 -u A -l a
Sum : 22
Sub : 10
Mul : 60
Div : 6
Lower case : a
Upper case : A

To print help message :

$ ./arithmetics  -h
./arithmetics -a <num1> <num2> : to add two numbers
./arithmetics -s <num1> <num2> : to subtract two numbers
./arithmetics -m <num1> <num2> : to multiply two numbers
./arithmetics -d <num1> <num2> : to divide two numbers
./arithmetics -u <any upper case character> : convert upper case character to lower case
./arithmetics -d <any lower case character> : convert lower case character to upper case
./arithmetics -h : to print this help message

$ ./arithmetics  -n
-n is not legitimate option characters.

$ ./arithmetics  -a
 option -a is specified but not argument present.


Name 
basename - Strip directory and suffix from a file name

Synopsis
basename NAME [SUFFIX]

What is basename?
When you provide a string that contains a filename with full path, basename will remove only the directory portion of it, and return only the filename portion of that string. It can also remove the file extension, and return only the filename without an extension (i.e., basename removes any leading directory components from NAME. If SUFFIX is specified and is identical to the end of NAME, it is removed from NAME as well).

I). Examples

i). Basename with no file extension
Basename removes the path and displays only the filename. 

$ basename /etc/shadow
shadow

$ basename /etc/passwd
passwd

ii). Display with file extension
When the filename contains an extension, basename by default will remove the path and return the filename with the extension.

$ basename /etc/apache2/httpd.conf 
httpd.conf

$ basename  /usr/include/stdio.h 
stdio.h

iii). Display only the filename without extension or remove directory and suffix from filenames
If you want to get only the filename without the extension, you should pass the extension as 2nd argument to the basename command as shown below.

$ basename /usr/include/stdio.h .h
stdio

$ basename /etc/httpd/conf/httpd.conf .conf
httpd

$ basename /etc/httpd/conf/httpd.conf d.conf
http

$ basename /usr/bin/perlscript script
perl

iv). You can remove multiple extensions:

$ basename /etc/syslog.conf.old .conf.old
syslog

v). You can remove everything up to the first letter of a file's name

$ basename /etc/syslog.conf.old  yslog.conf.old
s

vi). strip off everything up to and including the final slash (/).

$ basename 1/2
2

$ basename "I want to buy 1/4 cat"
4 cat

vii). basename command is mostly used in shell scripts to get the name of the shell script file you are running. Sample shell script code is shown below:

$ cat shellscript.sh
#!/bin/bash
cmd=$(which basename)
filename1=`$cmd $0`
#prints filename with extention
echo $filename1
#remove extention
filename2=`$cmd $0 .sh`
echo $filename2

$ chmod x shellscript.sh

$ ./shellscript.sh
shellscript.sh
shellscript

(OR)
$ /home/cassandra/learning/shellscript.sh
shellscript.sh
shellscript

II). Implementation of simple basename command using C



/*
 * =====================================================================================
 *
 *       Filename:  mybasename.c
 *
 *    Description: basename - strip directory and suffix from filenames 
 *
 *        Version:  1.0
 *        Created:  Sunday 07 October 2012 10:54:34  IST
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Mohan L (mohanphy), L.mohanphy@gmail.com
 *   Organization:  http://lmohanphy.livejournal.com/ 
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*-----------------------------------------------------------------------------
 * This function returns a pointer to the last occurrence of the character 
 * '/' in the string filename.  
 *-----------------------------------------------------------------------------*/
char * return_basename (char *filename)
{
  char *p = strrchr (filename, '/');
  return p ? p + 1 : (char *) filename;
}

/*-----------------------------------------------------------------------------
 * This function remove a trailing SUFFIX from name.
 *-----------------------------------------------------------------------------*/
void remove_suffix(char *name,char *suffix) 
{
    char *pn;
    char *ps;
    pn = name + strlen(name);
    ps = suffix + strlen(suffix);
    while ( pn > name && ps > suffix )
        if ( *--pn != *--ps )
            return ;
    if ( pn > name )
        *pn = '\0';
}

/*-----------------------------------------------------------------------------
 *  main function of mybasename starts here
 *-----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    char *bp;
    switch (argc) 
    {
        default:
            printf("Improper Number of arguments\n");
            exit(1);
        case 2:
            bp = return_basename(argv[1]);
            printf("%s\n",bp);    
            break;
        case 3:
            bp = return_basename(argv[1]);
            remove_suffix(bp,argv[2]);
            printf("%s\n",bp);
            break;
    }
    return (0);
}



Output of all the above examples using mybasename

$ ./mybasename /etc/shadow
shadow
$ ./mybasename /etc/passwd
passwd
$ ./mybasename /etc/apache2/httpd.conf 
httpd.conf
$ ./mybasename  /usr/include/stdio.h 
stdio.h
$ ./mybasename  /usr/include/stdio.h .h
stdio
$ ./mybasename  /etc/httpd/conf/httpd.conf .conf
httpd
$ ./mybasename  /etc/httpd/conf/httpd.conf d.conf
http
$ ./mybasename  /usr/bin/perlscript script
perl
$ ./mybasename  /etc/syslog.conf.old .conf.old
syslog
$ ./mybasename  /etc/syslog.conf.old  yslog.conf.old
s
$ ./mybasename  1/2
2
$ ./mybasename  "I want to buy 1/4 cat"
4 cat

Introduction
OpenCV (Open Source Computer Vision) is an open source (see) computer vision library available from here. The library is written in C and C++ and runs under Linux, Windows and Mac OS X. There is active development on interfaces for Python, Ruby, PHP, Matlab, and other languages.

Example applications of the OpenCV library are Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Motion Tracking, Ego Motion, Motion Understanding; Structure From Motion (SFM); Stereo and Multi-Camera Calibration and Depth Computation; Mobile Robotics.

This Shell Script will download OpenCV-2.1.0 and install it on Ubuntu 10.04 (lucid)
I have installed OpenCV on my Ubuntu 10.04(lucid) box today and also created a shell script called install_opencv.sh. This shell script will automatically install All necessary packages and build OpenCV also. I hope it will help some one new to Ubuntu and OpenCV.

I). Common Prerequisites
You should have
1). Ubuntu 10.04 (lucid) installed box with sudo enabled
2). Internet (It will download the all necessary packages and install it)

II). Instruction to run the script

1). Create a file and copy and paste the below script and save install_opencv.sh(here).


################################################################
# Shell Script will download OpenCV 2.1 and install it on Ubuntu 10.04(lucid)      # 
################################################################

#!/bin/bash

### All necessary packages
### build-essential - Informational list of build-essential packages
### cmake - A cross-platform, open-source make system
### cmake-qt-gui - Qt4 based user interface for CMake (cmake-gui)
### libgtk2.0-0 - The GTK+ graphical user interface library
### libgtk2.0-dev - Development files for the GTK+ library
### libgtk2.0-common - Common files for the GTK+ graphical user interface library
### libavcodec-dev - development files for libavcodec
### libavformat-dev - development files for libavformat
### libjpeg62 - The Independent JPEG Group's JPEG runtime library
### libjpeg62-dev - Development files for the IJG JPEG library
### libtiff4 - Tag Image File Format (TIFF) library
### libtiff4-dev - Tag Image File Format library (TIFF), development files
### libdc1394-22 - high level programming interface for IEEE1394 digital camera
### libdc1394-22-dev - high level programming interface for IEEE1394 digital camera
### libdc1394-utils - utilities for IEEE1394 digital cameras
### libjasper-dev - Development files for the JasPer JPEG-2000 library
### libjasper1 - The JasPer JPEG-2000 runtime library
### libgstreamer0.10-0 - Core GStreamer libraries and elements
### libgstreamer0.10-dev - GStreamer core development files
### libgstreamermm-0.10-2 - C++ wrapper library for the multimedia library GStreamer
### libgstreamermm-0.10-dev - C++ wrapper library for the multimedia library GStreamer
### libswscale-dev - development files for libswscale
### libswscale0 - ffmpeg video scaling library
### libv4l-0 - Collection of video4linux support libraries
### libv4l-dev - Collection of video4linux support libraries (development files)
### libxine-dev - the xine video player library, development packages
### libunicap2 - unified interface to video capture devices - shared libraries
### libunicap2-dev - unified interface to video capture devices - development files

clear
echo Installing the necessary packages....
sudo apt-get install build-essential cmake cmake-qt-gui  libgtk2.0-0 libgtk2.0-dev libgtk2.0-common libavcodec-dev libavformat-dev libjpeg62 libjpeg62-dev libtiff4  libtiff4-dev  libdc1394-22 libdc1394-22-dev libdc1394-utils libjasper-dev libjasper1 libgstreamer0.10-0 libgstreamer0.10-dev libgstreamermm-0.10-2 libswscale-dev libswscale0 libv4l-0 libv4l-dev libxine-dev libunicap2 libunicap2-dev

clear
if [ ! -d $1 ]
then
    /bin/mkdir -p $1 >/dev/null 2>&1 && echo "Directory $1 created." ||  echo "Error: Failed to create $1 directory."

else
    echo "Warning: $1 directory exits!"
fi

echo Enter the Directory $1
cd $1

clear
### Download the OpenCV-2.1.0.tar.bz2 package from sourceforge.net
echo Downloading 1. Source pack : OpenCV-2.1.0.tar.bz2
wget -c  http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download

clear
### Extract the OpenCV-2.1.0.tar.bz2 package with the command:
echo Extract the OpenCV-2.1.0.tar.bz2 package ...
tar vxjf OpenCV-2.1.0.tar.bz2

clear
cd $1/OpenCV-2.1.0

clear
echo configuring........
cmake -D BUILD_EXAMPLES=ON $1/OpenCV-2.1.0

cd $1/OpenCV-2.1.0
echo building package .....
make

clear
echo installing opencv....
sudo make install

sudo echo /usr/local/lib > /etc/ld.so.conf.d/opencv.conf

sudo ldconfig

############################################
#                      end of script                                                    #                                               ############################################


2). set execute permission for install_opencv script as follows
          $ chmod u+x install_opencv.sh
           (OR)
          $ chmod 0755  install_opencv.sh
3). Run the script by typing (It will ask you the password of user you logged in)
          $ ./ install_opencv.sh  /home/mohan/Linux/opencv
Where /home/mohan/Linux/opencv directory I want to download and Install OpenCV. You can pass whatever the directory you want to use.  It installs OpenCV-2.1.0 on  Ubuntu 10.04 (lucid) without any error for me.

4). Finally open the opencv.conf and edit /usr/local/lib and save it
     $ sudo vim  /etc/ld.so.conf.d/opencv.conf
            /usr/local/lib
  
 5). Run the below command
      $ sudo ldconfig    

That's it!. Now you have done the installation of OpenCV-2.1.0 in your Ubuntu box.    

III). Testing your Installation


#########################################
#  File Name : test.sh                                                       #
# This script will test your  installation by                    #
# executing  "morphology" demo program that         #
# comes with OpenCV                                                   #
########################################

#!/bin/bash

echo Enter the Directory $1
cd $1/OpenCV-2.1.0/samples/c
echo `pwd`

# Set execute permission for build_all.sh(script comes with Opencv )script as follows

chmod u+x build_all.sh

./build_all.sh

./morphology

#press Esc to quit the program

##############################
#         end of script                                  #
##############################


1). Copy and paste the above script in test.sh file and save it.

2). Set execute permission for test.sh
      $ chmod u+x test.sh
3). Run test.sh (
installation path for me : /home/mohan/Linux/opencv)
     $ ./test.sh  <Your OpenCV installad path>

This script will compile the demo program that comes with OpenCV and runs the "
morphology" demo program. It open rectangle morphology image.  Now you have the working version of OpenCV in your system.  I will post more example program here.

IV). Resources
1). OpenCV Wiki-pages
2).
Learning OpenCV Book published by O'Reilly
3).
OpenCV discussion Group
4).
Documentation


I will appreciate any bug reports, comments or suggestions. Any questions or complaints can be directed to L.mohanphy@gmail.com or you can use below comments form.



Tags:

Introduction
OpenFOAM(Open Field Operation and Manipulation) is a free, open source CFD software package produced by a commercial company, OpenCFD Ltd and is released open source under the GPL.OpenFOAM was one of the first major scientific packages written in C++. This article I will explain you installation of latest version of OpenFOAM (OpenFOAM-1.7.0) on OpenSUSE 11.2.

OpenFOAM®  version 1.7.0
released
OpenCFD® released OpenFOAM 1.7.0.  OpenFOAM-1.7.0 is the latest release of OpenFOAM that contains new features both from OpenCFD’s development version of OpenFOAM and the repository 1.6.x distribution.  A summary of the new features can be found here, while more details are available in the release notes of the code.

Installation of OpenFOAM 1.7.0 on OpenSUSE 11.2

In order to install OpenFOAM on OpenSuSe 11.2, the following packages are necessary. So use YaST to install the following packages.

  • cmake  - Cross-platform, open-source make system.
  • gcc-c++  - The system GNU C++ Compiler.
  • flex         - Fast Lexical Analyzer Generator(flex++).
  • bison      - The GNU Parser Generator.
  • python    - Python Interpreter.
  • binutils   - GNU Binutils.
  • binutils-devel  - GNU binutils (BFD development files).
  • zlib         -  Data Compression Library.
  • zlib-devel   - Include Files and Libraries mandatory for Development.
  • libqt4         -  C++ Program Library, Core Components.
  • libqt4-devel   - Qt Development Kit.
  • libqt4-devel-doc - Qt documentation.
  • libqt4-devel-doc-data - Qt documentation (architecture independent files).
  • libQtWebKit-devel - Qt 4 SQL related libraries.
[root@OpenSuSe ~]#  yast  -i  cmake  gcc-c++  flex  bison  python  binutils  binutils-devel  zlib  zlib-devel  libqt4  libqt4-devel  libqt4-devel-doc  libqt4-devel-doc-data

I) . A very brief introduction on the compilation

1).  Create a directory called OpenFOAM in your home directory

$
mkdir  ~/OpenFOAM

Enter the OpenFOAM directory

$ cd   ~/OpenFOAM

2).  Download OpenFOAM 1.7.0
You can download both the OpenFOAM and ThirdParty packages from here and save them in your ~/OpenFOAM directory. I am using the below shell script to download OpenFOAM 1.7. If you want to use this create a file name download.sh and copy below shell script and save it:

$ vim  download.sh

###########################################################
# This Shell Script will download OpenFOAM 1.7 in your working directory    #
###########################################################

#!/bin/bash

clear
### Download the OpenFOAM-1.7.0.gtgz package
echo Downloading 1. Source pack : OpenFOAM-1.7.0.gtgz
wget -c http://downloads.sourceforge.net/foam/OpenFOAM-1.7.0.gtgz?use_mirror=mesh

### Download the ThirdParty-1.7.0.gtgz package
echo Downloading 2. Binary pack:ThirdParty-1.7.0.gtgz
wget -c http://downloads.sourceforge.net/foam/ThirdParty-1.7.0.gtgz?use_mirror=mesh

### Extract the OpenFOAM-1.7.0.gtgz package with the command:
echo Extract the OpenFOAM-1.7.0.gtgz package ...
tar xzf OpenFOAM-1.7.0.gtgz

### Extract the ThirdParty-1.7.0.gtgz package with the command:
echo Extract the ThirdParty-1.7.0.gtgz package ...
tar xzf ThirdParty-1.7.0.gtgz

########################################
#                      end of script                                          #
########################################

save and quit

Run the shell script to download

$ ./download.sh

3). Setting environment variables
The environment variable settings are contained in files in an OpenFOAM-1.7.0/etc directory in the OpenFOAM release. e.g. for the case where the installation is in $HOME/OpenFOAM, in: $HOME/OpenFOAM/OpenFOAM-1.7.0/etc . So Open your ~/.bashrc file in a text editor and add the line at the end of the file and save it.

$ vim   ~/.bashrc

. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc

save and quit

source your ~/.bashrc file with the command:

$ source  ~/.bashrc

4). Compile OpenFOAM

Enter the OpenFOAM-1.7.0 directory with the command:

$ cd   $FOAM_INST_DIR/OpenFOAM-1.7.0

Compile OpenFOAM with the command:

$  ./Allwmake

5).Rebuild Paraview 3.8.0
 Paraview is the third-party software that we provide for graphical post-processing in OpenFOAM. It’s compilation is automated using a script called makeParaView in the ThirdParty-1.7.0 directory. Installation of Paraview 3.8.0 requires a version of QT that is 3.5.? or newer and cmake which is 2.6.4 or newer, so again make sure that this is on your system.

To install Paraview, execute the following:
 
$ cd  $WM_THIRD_PARTY_DIR

$  ./Allclean
 
Compile Paraview 3.8.0 with the command:

$ ./makeParaView

Set environment variables:

$ export   ParaView_DIR=/home/Mohan/OpenFOAM/ThirdParty-1.7.0/platforms/linuxGcc/paraview-3.8.0

$ export   PATH=$ParaView_DIR/bin:$PATH
       
$ export   PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-3.8

6). Rebuild the PV3FoamReader  
 
$ cd   $FOAM_UTILITIES/postProcessing/graphics/PV3FoamReader

$  ./Allwclean

Compile PV3FoamReader with the command:

$  ./Allwmake

7). Testing the installation
To check your installation setup, execute the foamInstallationTest script (in the OpenFOAM-1.7.0/bin directory). If no problems are reported, proceed to getting started with OpenFOAM.

$ cd  $HOME/OpenFOAM/OpenFOAM-1.7.0/bin

8). Getting Started
Create a directory named run within <USER>-1.7.0 (e.g.Mohan-1.7.0 for me) by typing:

$ mkdir -p  $FOAM_RUN

Copy the tutorial examples directory in the OpenFOAM distribution to the run directory.

$ cp -r  $FOAM_TUTORIALS  $FOAM_RUN

Run the first example case of incompressible laminar flow in a cavity:

$ cd  $FOAM_RUN/tutorials/incompressible/icoFoam/cavity

$ blockMesh

$ icoFoam

$ paraFoam

This will builds the whole OpenFOAM and paraview, and provide you a fully working installation.

Tags: