Header files
- From: nikhilvasudeo@xxxxxxxxx
- Date: Thu, 19 Feb 2009 21:21:41 -0800 (PST)
Hi
I'll try to be as detailed as possible this time.
I am doing research in my school. I have a fortran code (2D.F) with
me, which runs well and gives desired output. Now, I need to modify
the code and use it to generate different output, which is my
research.
In the fortran code that I have, there is a subroutine in which
variables are defined as....
#undef BL_LANG_CC
#ifndef BL_LANG_FORT ....specifies the precission
#define BL_LANG_FORT
#endif
#include "REAL.H"
#include "CONSTANTS.H"
#include "BC_TYPES.H"
#include "PROB_AMR_F.H"
#include "PROB_F.H"
#include "ArrayLim.H"
#include "ChemDriver_F.H"
..
..
subroutine FORT_INITDATA(level,time,lo,hi,nscal,
& vel,scal,DIMS(state),press,DIMS(press),
& delta,xlo,xhi)
REAL_T scal(DIMV(state),nscal)
REAL_T press(DIMV(press)) ... i m concerned about array press
()..so im not writing much about other variables..
..
..
..
c Set vorticity into pressure field
c
do j = ARG_L2(press),ARG_H2(press) ...ARG_L2
() and ARG_H2() are defined below
y = float(j)*delta(2)+domnlo
(2) ... delta(2) is the dy, domnlo(2) is
the initial value of domain in y-direction
do i = ARG_L1(press),ARG_H1(press) ...ARG_L2
() and ARG_H2() are defined below
x = float(i)*delta(1)+domnlo
(1) ... delta(1) is the dx, domnlo(1) is the
initial value of domain in x-direction
r1sq = (x-v_xcen)**2 + (y-v_ycen)**2 ....
v_xcen, v_ycen, v_strength, v_width, v_cl are defined
r2sq = (x-(two*v_cl_x-v_xcen))**2 + (y-v_ycen)**2
press(i,j) = 2.d0*v_strength/((1.d0-dexp(-1.d0))*v_width)*
& (dexp(-r1sq/v_width**2)-dexp(-r2sq/v_width**2))
end do
end do
DIMV are macros defined in a header file ArrayLim.H as....the header
file is as follows...
------------------- ArrayLim.H
-------------------------------------------------
#ifndef BL_ARRAYLIM_H
#define BL_ARRAYLIM_H
#if !defined(BL_LANG_FORT)....this signifies the type of precision
needed in the code, it is defined in another header file.
#include <REAL.H> .....This is another header file, which specifies
the data type to be used..REAL_T is a macro which is defined
in REAL.H, which specifies the precision
#ifdef BL_USE_ARLIM
#if (BL_SPACEDIM == 2).....its a 2D array, hence, spacedim = 2
#define DIMS(a) a##_lo, a##_hi
#define DIMDEC(a) a##_lo(2), a##_hi(2)
#define DIMV(a) a##_lo(1):a##_hi(1), a##_lo(2):a##_hi(2)
#define DIM1(a) a##_lo(1):a##_hi(1)
#define DIM2(a) a##_lo(2):a##_hi(2)
#define ARG_L1(a) a##_lo(1)
#define ARG_L2(a) a##_lo(2)
#define ARG_H1(a) a##_hi(1)
#define ARG_H2(a) a##_hi(2)
#endif
..
..
#endif /*BL_USE_ARLIM*/
#endif /*!defined(BL_LANG_FORT)*/
#endif /*BL_ARRAYLIM_H*/
--------------------------------------------------------------------------------------------
----------------------------------- REAL.H
-------------------------------------------
#ifndef BL_REAL_H
#define BL_REAL_H
/*
* $Id: REAL.H,v 1.14 2007/03/29 19:40:57 lijewski Exp $
*/
#ifdef BL_USE_FLOAT
# undef BL_USE_DOUBLE
# undef BL_USE_FLOAT
/*@ManDoc:
The macro BL\_USE\_FLOAT indicates that C++ floating-point
calculations should
use "float" variables and Fortran floating-point calculations should
use
"real*4" variables. One of BL\_USE\_FLOAT or BL\_USE\_DOUBLE must
always be
defined when compiling and using BoxLib.
*/
# define BL_USE_FLOAT 1
#else
# undef BL_USE_FLOAT
# undef BL_USE_DOUBLE
/*@ManDoc:
The macro BL\_USE\_DOUBLE indicates that C++ floating-point
calculations
should use "double" variables and Fortran floating-point
calculations
should use "real*8" variables. One of BL\_USE\_FLOAT or BL\_USE
\_DOUBLE must
always be defined when compiling and using BoxLib.
*/
# define BL_USE_DOUBLE 1
#endif
#if !defined(BL_LANG_FORT)
/*@ManDoc:
Real is a typedef specifying the precision of the floating-point
calculations in C++ code. It will be either `float' or `double'
depending upon which of the macros BL\_USE\_FLOAT or
BL\_USE\_DOUBLE, respectively, is defined during compilations. For
portability, you should write floating-point code in terms of this
typedef, instead of using `float' or `double' directly.
Note that exactly one of these macros must be defined
when compiling any module that uses floating-point.
*/
#ifdef BL_USE_FLOAT
typedef float Real;
#else
typedef double Real;
#endif
#else
/*@ManDoc:
The REAL\_T macro specifies the precision of the floating-point
calculations in Fortran code. It will be either `real*4' or
`real*8' depending upon which of the symbols BL\_USE\_FLOAT or
BL\_USE\_DOUBLE, respectively, is defined during compilations. For
portability, you should write floating-point code in terms of this
macro, instead of using `real*4' or `real*8' directly.
Note that exactly one of these macros must be defined
when compiling any module that uses floating-point.
*/
#ifdef BL_USE_FLOAT
#ifdef BL_USE_FORT_STAR_PRECISION
# define REAL_T real*4
#else
# define REAL_T REAL
#endif
#if __STDC__==1
# define BL_REAL(a) a##E0
# define BL_REAL_E(a,b) a##E##b
#else
# define BL_REAL(a) a/**/E0
# define BL_REAL_E(a,b) a/**/E/**/b
#endif
#else
#ifdef BL_USE_FORT_STAR_PRECISION
# define REAL_T real*8
#else
# define REAL_T DOUBLE PRECISION
#endif
#if __STDC__==1
# define BL_REAL(a) a##D0
# define BL_REAL_E(a,b) a##D##b
#else
# define BL_REAL(a) a/**/D0
# define BL_REAL_E(a,b) a/**/D/**/b
#endif
#endif
#endif /* !BL_LANG_FORT */
#endif /*BL_REAL_H*/
--------------------------------------------------------------------------------------------------------
I am able to compile the code and generate an executable and I am able
submit the executable in the super computers of my school and get
desired output. I am using a pgi compiler to compile 2D.F and my code.
Now, I need to to write a fortran code, which does the job of above
subroutine and generates the data file which contains the values of
press. I wrote the code, with your help, and i got the output which
is the same as the one which is being computed by the code 2D.F. When
I try to read the data file in 2D.F, it is giving all sorts if error
(PGFIO-F-225/list-directed read/unit=55/lexical error...the 1st line
of the data file does not have any Inf or Nan)
So, I tried to write another code on similar lines as 2D.F. I included
all header files that are included in 2D.F in my code. I initialized
the the array press in the same way as it is initialized in 2D.F.
When, I try to compile it, it gives an error saying, unable to read a
character...and it gives the names of all header files. On checking
the header files, I came to know that it is not able to read '#' and
points out an error to all those lines where # is written. I have
searched online and referred fortran books all of them say that # is
not read by fortran.
If that is the case, how am I able to compile 2D.F along with many
other .F files, as they also have statements beginning with #. Is
there some way to include the header files (or the contents of header
files) in my code in the same way as they are defined in the original
code so that I can compile it and generate the data file which has the
values of press()
.
- Follow-Ups:
- Re: Header files
- From: Glen Herrmannsfeldt
- Re: Header files
- Prev by Date: Re: Fortran to C to Fortran Arrays
- Next by Date: Re: Header files
- Previous by thread: Fortran to C to Fortran Arrays
- Next by thread: Re: Header files
- Index(es):
Relevant Pages
|