Commit f97f5e87 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new code

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1233
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 336ac2cb
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.11 2002-12-23 11:44:03 forbrig Exp $
# $Id: Makefile,v 1.12 2002-12-23 13:54:57 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -52,7 +52,7 @@ HEADERS=$(shell find . -name \*.h)
# (see below for the configuration of a preinstantiated version of template
# code)
SRC=lib/error.cc dump.cc lib/strided.cc lib/stridedstepper.cc \
lib/seriesstepper.cc
lib/seriesstepper.cc fortranshape.cc
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.18 2002-12-23 11:44:03 forbrig Exp $
* $Id: README.changelog,v 1.19 2002-12-23 13:54:58 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,7 +21,7 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.18 2002-12-23 11:44:03 forbrig Exp $
$Id: README.changelog,v 1.19 2002-12-23 13:54:58 forbrig Exp $
\sa \ref page_project_status
......@@ -34,6 +34,8 @@
aff::Subarray and aff::Slice and tested helper classes
- reorganized aff::Iterator code. Inheritance from Stepper does not work.
- aff::Array::copyin() and aff::Array::copyout() work
- introduced fortranshape.h and fortranshape.cc and herein
aff::FortranArray and aff::util::FortranShape
- \b 22/12/2002 (thof)
- started test for interface to Fortran 77 code
......@@ -90,7 +92,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.18 2002-12-23 11:44:03 forbrig Exp $
$Id: README.changelog,v 1.19 2002-12-23 13:54:58 forbrig Exp $
\sa \ref page_changelog
......@@ -125,6 +127,12 @@
<TR><TD>libaff/dump.h</TD>
<TD>19/12/2002</TD><TD>20/12/2002</TD><TD> </TD><TD> </TD>
</TR>
<TR><TD>libaff/fortranshape.cc</TD>
<TD>23/12/02</TD><TD> </TD><TD> </TD><TD> </TD>
</TR>
<TR><TD>libaff/fortranshape.h</TD>
<TD>23/12/02</TD><TD> </TD><TD> </TD><TD> </TD>
</TR>
<TR><TD>libaff/iterator.h</TD>
<TD>20/12/2002</TD><TD> </TD><TD>23/12/02</TD><TD> </TD>
</TR>
......
/*! \file fortranshape.cc
* \brief prepare information to pass to Fortran subroutines (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: fortranshape.cc,v 1.1 2002-12-23 13:54:58 forbrig Exp $
* \author Thomas Forbriger
* \date 23/12/2002
*
* prepare information to pass to Fortran subroutines (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 23/12/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define AFF_FORTRANSHAPE_CC_VERSION \
"AFF_FORTRANSHAPE_CC V1.0 "
#define AFF_FORTRANSHAPE_CC_CVSID \
"$Id: fortranshape.cc,v 1.1 2002-12-23 13:54:58 forbrig Exp $"
#include <aff/fortranshape.h>
#include <aff/lib/error.h>
namespace aff {
namespace util {
//! all calculations are done herein
FortranShape::FortranShape(const Tshape& inshape, const bool& BaseOne)
{
// create a local copy of the shape
Tshape shape(inshape);
// set first index as required
if (BaseOne) shape.setfirst(TIndexVec(1));
// extract first and last index
Mfirst=shape.first();
Mlast=shape.last();
// extract offset to first element
Moffset=shape.first_offset();
// first test for Fortran memory layout
for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
{
AFF_assert((shape.stride(i-1)<=shape.stride(i)),
"ERROR (FortranShape): no Fortran layout!");
}
// native Fortran arrays have stride 1 in base dimension
// In case we ever want to pass a slice, we have to think about how to
// pass strides to the Fortran subroutine
AFF_assert((shape.stride(0)==1),
"ERROR (FortranShape): No native Fortran array layout!");
// We assume that every properly sliced array has strides that are integer
// multiples of the stride of the lower dimension. Just for safety, we
// test for that assumption.
for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
{
Tsize mult=shape.stride(i)/shape.stride(i-1);
AFF_assert((shape.stride(i)==(mult*shape.stride(i-1))),
"ERROR (FortranShape): Stride is no integer multiple!");
}
// calculate dimensioned last
for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
{
Mdimlast[i-1]=shape.stride(i)/shape.stride(i-1)+Mfirst[i-1]-1;
}
Mdimlast[Tshape::Mmax_dimen-1]=Mlast[Tshape::Mmax_dimen-1];
// check bounds (just in case...)
for (Tdim i=0; i<Tshape::Mmax_dimen; i++)
{
AFF_assert((Mlast[i]<=Mdimlast[i]),
"ERROR (FortranShape): illegal index range in shape!");
}
// that's it...
}
} // namespace util
} // namespace aff
/* ----- END OF fortranshape.cc ----- */
/*! \file fortranshape.h
* \brief prepare information to pass to Fortran subroutines (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: fortranshape.h,v 1.1 2002-12-23 13:54:58 forbrig Exp $
* \author Thomas Forbriger
* \date 23/12/2002
*
* prepare information to pass to Fortran subroutines (prototypes)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 23/12/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef AFF_FORTRANSHAPE_H_VERSION
#define AFF_FORTRANSHAPE_H_VERSION \
"AFF_FORTRANSHAPE_H V1.0 "
#define AFF_FORTRANSHAPE_H_CVSID \
"$Id: fortranshape.h,v 1.1 2002-12-23 13:54:58 forbrig Exp $"
#include<aff/array.h>
namespace aff {
namespace util {
/*! \brief find appropriate leading dimensions
*
* This class is used to calculate appropriate leading dimensions from a
* aff::Strided shape. These values are needed to pass an array to a Fortran
* 77 subroutine.
*
* \sa aff::FortranArray
*/
class FortranShape {
public:
//! This is coded for Strided shapes
typedef aff::Strided Tshape;
//! Vector of index values
typedef Tshape::TIndexVec TIndexVec;
//! Vector of size values
typedef Tshape::TSizeVec TSizeVec;
//! construct from shape
explicit FortranShape(const Tshape& shape, const bool& BaseOne=true);
//! first index in dimension \p i
const Tsubscript& first(const Tdim& i) const { return(Mfirst[i]); }
//! last index in dimension \p i
const Tsubscript& last(const Tdim& i) const { return(Mlast[i]); }
//! last index as dimensioned in dimension \p i
const Tsubscript& dimlast(const Tdim& i) const { return(Mdimlast[i]); }
//! offset to access representation
const Tsubscript& offset() const { return(Moffset); }
private:
//! first index
TIndexVec Mfirst;
//! last index
TIndexVec Mlast;
//! last index as dimensioned in memory
TIndexVec Mdimlast;
//! offset of first element in representation
Tsubscript Moffset;
}; // class FortranShape
} // namespace util
/*----------------------------------------------------------------------*/
/*! \brief Class to provide Fortran interface values
*
* \sa aff::util::FortranShape
*/
template<class T>
class FortranArray: private aff::util::FortranShape {
public:
//! type of corresponding array
typedef typename aff::Array<T> Tarray;
//! shape class
typedef typename Tarray::Tshape Tshape;
//! representation class
typedef typename Tarray::Trepresentation Trepresentation;
//! base class
typedef aff::util::FortranShape Tbase;
//! pointer to array base in memory
typedef typename Tarray::Tpointer Tpointer;
//! create
FortranArray(const Tarray& array, const bool& BaseOne=true):
Tbase(array.shape(), BaseOne)
{
Trepresentation repr=array.representation();
Mpointer=&repr[this->Tbase::offset()];
}
//! access declarations
//@{
Tbase::first;
Tbase::last;
Tbase::dimlast;
//@}
Tpointer pointer() const { return(Mpointer); }
private:
//! pointer to memory
Tpointer Mpointer;
}; // class FortranArray
} // namespace aff
#endif // AFF_FORTRANSHAPE_H_VERSION (includeguard)
/* ----- END OF fortranshape.h ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment