Showing posts with label Computer. Show all posts
Showing posts with label Computer. Show all posts

Saturday, February 16, 2008

Compile Fortran and C++ together under VS2005

Since the new release of windows vista system, the old mixed-language programming under WS6.0 and Compaq Fortran 6.0 does not work anymore since both compilers are not compatible with the new windows OS system. In order to response to such changes, here I did my first test of the mixed-language programming under VS2005 and Intel Fortran. The example codes are copied from the website. It should be noticed that the calling convention between Compaq Fortran 6.0 and VS6.0 is different from that between Intel Fortran and VS2005. Here is a table shown in Steve's article "Porting applications from Compaq frotran to Intel Fortran" to list the difference calling conventions.



Therefore, in Intel Fortran, we no longer require the __stdcall put ahead of the fortran functions in the C code. Instead, __stdcall should be replaced by __cdecl or simply be removed. The original codes in the website become

(1) The C++ file:

// This illustrates how a Fortran routine and function may be
// called from a main program in C++
#include
extern "C"
{
void FR1(int*,int *);
int FF1(int *);
}
int main()
{
int n=10,nSq,nCube;
FR1(&n,&nSq);
cout << "The square is:" << ncube="FF1(&n);" style="font-weight: bold;"> (2) The Fortran File:

SUBROUTINE FR1(N,M)
C COMPUTES THE SQUARE OF N, RETURNS IN M
M=N*N
RETURN
END
C
INTEGER FUNCTION FF1(N)
C COMPUTES THE CUBE OF N
FF1=N*N*N
RETURN
END

To build mixed-language the VS2005 project, it is not similar to what we did in VS6.0 where we put both C++ files and fortran files in the same project and then compile them together as a whole. In VS2005, we should separate them into two projects, one for C++ and one form Fortran.
  1. Create a static library package for Fortran files by File > New> Intel Fortran > Library > Static Library when creating the package.
  2. Create a Win32 console application package for C++ files by File > New> Visual C++ > Win32 console application
  3. Create a VS2005 solution by going to File > New > Other Studio solutions > VS solution and add both created packages in.
  4. Add the Fortran and C++ into their packages respectively.
  5. Right-click both packages to confirm their runtime libraries are consistent. For C++, it is at Property > C/C++ > Code Generation > runtime library. For Fortran, it is at Property > Fortran > Libraries and also make sure that "Disable OBJCOMMENT ....." is set to be NO
  6. Add the new created lib file (from the Fortran package) into the solution by add the Fortran package name (FortranName.lib) at Property > Linker > Input > Additional dependence by right-click the C++ package
  7. Add the additional library path for C++ package by going to Tools > Options > Projects and Solutions > Library files and click the white boards to add Intel Fortran library at \IntelFortranRoot\Compiler\Fortran\versioncode\IA32\Lib and the location where the new lib file is generated.
  8. After all these settings, I successfully my first package built under VS2005.

Tuesday, July 24, 2007

Making the vacation message in the unix email system

I do not know if the commands apply to every server. It is the way how our department email server works now.
  1. Check and see current vacation message: cat .vacation.msg
  2. Edit vacation message: vi .vacation.msg
  3. Edit vacation message within vi editor: I am not familiar with vi at all, and for me to remember all the commands. Here are some essentials:
    • dd: delete entire line
    • dw: delete the character before the cursor
    • ":" : go to the command line
    • wq: save and quit of the file used in command line
  4. Activate vacation message: mv inactiveDotForward .forward
  5. De-activate vacation message: mv .forward inactiveDotForward

Tuesday, July 17, 2007

DLL creation and calling by VC++6

In Yahoo Kimo knowledge base, there is a very good example to learn the dll creation and calling in VC++6. I do use this example to create the dll file for my own project and it runs well.

Here I borrow some of the content from the website and add some of my interpretation.
The essential part to generate a usable dll file is the modification of the header file from the original one for exe file.
For example, the hello.h should be

// hello.h___________________

#ifdef __cpluscplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif

EXPORT void hello();
// end hello.h___________________________________________

The red bold part is the required addition to the original header file.

In the main file, hello.c, we can simply keep the original file as the original one, such as
// hello.c___________________

#include"hello.h"
#include

EXPORT void hello(){
printf("The First Hello World !");
}

  • To build a hello.dll, in visual C++ 6, we can create a dll project with the inclusion of the files above.
  • To use the hello.dll, we should include the hello.lib generated from the compiler into the main executable code. Then the dll, lib and other codes are put in the same folder to make a new executable file which can use the functions in dll files.

Fortran and C/C++ interaction

To develop a C++-based program with the support of built Fortran library, the mixed language programming is the essential part. It had been a frustrated process for me to figure this out. Here are some very important documents for the interaction between Fortran and C++ with the usage of visual Fortran and visual C++.
  1. A introductory website
  2. The MSDN mixed-language programming page
  3. Some tips: some of them are not quite right but it is still worthwhile to consult with.
  4. The most important: the table to see which library and settings has to be done in visual studio. It is also briefly shown here in Table 1 and Table 2
Table 1: The library combination for Visual Studio (both Visual Fortran and Visual C++)


Table 2

Useful website for Mac users

Applewoods is a very good website for Mac users, especially Taiwanese. It is very consistently updated and fast. You can very easily find useful information or little software from the site.

As a newbie to Mac, I like it very much, especially it is posted in traditional Chinese. Surfing there makes me feel like home.....Ha.

How to see MLB.TV full screen in Mac

After 2006, mlb.tv only supports windows media player format. It makes a lot of Mac users suffer in watching mlb.tv. In order to workaround this, two little programs are required to download, Flip4Mac and QuickTime FS. After downloading and installing, here are the instruction to see the mlb.tv in full screen.
  1. Go to the mlb.tv and now you can see the game in the default small screen.
  2. Use right button to adjust setting to "Launch Quicktime player" (I do not remember the exact word in the setting menu).
  3. Shut out your firefox (browser), and reopen it to mlb.tv.
  4. This time the quicktime player should launch in a new window rather than playing in the browser.
  5. Run QuickTime FS. In its window menu, press Quicktime FS, and then go Full screen.
Note: for the QuickTime FS, there also have the widget for download and it is even easier to use.