Posts Tagged ‘fortran’

Debugging Fortran Programs Using IDB How To Debug Fortran Code Ifort Commands

how to debug fortran code using idb
debugging Fortran programs.

Compiling your Fortran program for debugging

To prepare your program for debugging when using the command line (ifort command):
In a command window, (such as the Fortran command window available from the Intel Fortran program folder), compile and link the program with full debug information and no optimization:

      ifort -g file.f90 (Linux OS and Mac OS X)

      ifort /debug:full file.f90 (Windows OS)

On Windows OS, specify the /debug:full compiler option to produce full debugging information. It produces symbol table information needed for full symbolic debugging of unoptimized code and global symbol information needed for linking.
How to use Intel idb as debugger.
IDB comes with good help information
eg, (idb) help run
Run the debugger program.

Usage:

    run   (arguments) (redirections)

Arguments:

     Run the program with the specified arguments.

                Run the program with the specified input and output
                redirections.

If no arguments and redirections are specified, program is run with arguments
and redirections specified by previous “run” command with arguments or by “set
args” command.

Synonyms: “r”.
To run the exe in debug mode from command line, use devenv with debugexe option.. read more for How To Run .exe In Debug Mode Microsoft Visual Studio.

Eg. > devenv /DebugExe r280test01.exe

After windows debugger starts Hit F10 key to start debugging.
Check out How to use dbx as debugger for fortan debugging here.
Check out Debugging Fortran programs with gdb here
Intel® Debugger (IDB) Manual

Number of View :4855

Tags: , , ,

1 Comment


Emulate Fortran Function Btest In C Language

Emulate the fortran function btest in C language
BTEST function is as part of Bit Functions library in Fortran,
description of BTEST function

btest( m, i ) Tests bit i in m; returns .true. if the bit is 1, and .false. if it is 0.
Here is C language code implementation of BTEST function, which checks for bit and returns true ie 1 if bit is SET or else returns 0.

int btest(int word, int bit)
{
  unsigned int mask;

  /* Create the bit mask */
  mask = 0x0000001 << bit;

  /* Return TRUE or FALSE*/
  return (( word & mask ) != 0);
}
Number of View :2080

Tags: , ,

No Comments


This USE Statement Is Not Positioned Correctly Within The Scoping Unit

Error: This USE statement is not positioned correctly within the scoping unit.

check help / man page of IFORT but no luck..
https://i0.wp.com/www.intel.com/sites/sitewide/HAT/40recode/pix/main-logo.png This thread at intel.com also here.
the answer at this thread is

“USE YourModule” must preceed local variable declarations and  Your include file is declaring at least one variable.

put your code of  USE to preceed the include statements.

But that did not work completely,

and another half part of answer is
Add an only clause to select only the GETENV routine:
use IFPORT, only: GETENV
This will hide any other names in IFPORT;
This post will talk about why added USE IFPORT
This worked fine..
share your experience as well..

USE should be preceded any IMPLICIT statements. They should be after the SUBROUTINE or FUNCTION statement.

We can have USE and IMPORT statements in the same interface body, but the ‘mixing’  forbidden referring to was that of placing any IMPORT statement before USE statement ..

Number of View :2731

Tags: , , ,

No Comments


Ifort -extend-source Option Errors & Fortran Fixed Formatting Use nofree

Problem Definition
Working on FORTRAN source code migrations from Solaris operating system to windows XP.  Fortran being most portable code so most of the time we do not see any problems while porting fortran code, but there is always problem with columns length exceeds to default value and while compilations we forgot to take care of option extend-source.

Intel® Fortran compiler(ifort) – Option -extend-source

       -extend-source [size]
	      Specifies the column number to use to end the  statement	field
	      in  fixed-form source files. [size] can be 72, 80, or 132.  The
	      default behavior is -noextend-source, which implies column  72.
	      If  you  do  not	specify	 size,	it  is the same as specifying
	      -extend-source 132.

source ifort help or man ifort

Solution
The Makefile has a compiler flag called /extend_source:132, which basically extends the number of columns the Fortran compiler looks at. The default value is 72. /extend_source extends the number of columns that the compiler looks at to 132.

Fortran generally uses something called as Fixed Formatting – which takes 72 valid columns, ignores the rest and also considers tabs and spaces as comments inside a statement field.
/nofree tells the compiler that fixed formatting needs to be used. Most of the time code follows fixed formatting.

TO remove all compiler errors which pertain to syntax errors at Format statement just add some variable in your makefile, like
COLEXTEND=/extend_source:132

And when facing problem while compiling any fortran module in Windows just compile with COLEXTEND= /nofree.

example of make command, assuming windows makefile name as win.make

on command prompt type : nmake /f win.make COLEXTEND=/nofree

Good luck and do comment your experiences as well.

Related problem regarding

-extend-source option

Number of View :4587

Tags: , , , ,

2 Comments


Unresolved External Symbol _getenv_ USE IFPORT Link Error For Application Porting From UNIX To Win32

Was getting below link errors when compiling application with fortran files and c files. Was using ifort.exe and cl.exe to compile and link.
error LNK2019: unresolved external symbol _getenv_ referenced in function xyz
error LNK2001: unresolved external symbol _getenv_

Usage in fortran file, this is call to getenv
CALL GETENV (“LIB”,libname)
After few hours of google got different solutions, saying using assume:nounderscore flag in compilations.

tried with assume:underscore , assume:nounderscore and assume:no2underscore
And use ifport.lib and ifcore.lib but did not got the error resolved.
If this error was happen to come from .c file then solution is direct ie use stdlib.h include file.
Finally got the Solution
Add these two lines in your FORTRAN file,
USE IFPORT
USE IFCORE

and compile again the error goes away.
Some description about USE
The USE statement gives a program unit accessibility to public entities in a module.
getenv and _putenv use the copy of the environment pointed to by the global variable _environ to access the environment. getenv operates only on the data structures accessible to the run-time library and not on the environment segment created for the process by the operating system.

In a program that uses the main function, _environ is initialized at program startup to settings taken from the operating system’s environment.
Happy application porting from UNIX to win32.

Number of View :2332

Tags: , ,

No Comments



SetPageWidth
Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache