Changeset 2752 in Sophya for trunk/SophyaLib/TArray


Ignore:
Timestamp:
May 23, 2005, 6:18:17 PM (20 years ago)
Author:
ansari
Message:

1/ Suppression du constructeur de copie avec specification d'organisation memoire (MemoryMapping) pour TMatrix<T> et TVector<T>
2/ Amelioration de l'impression des TArray/TMatrix avec la specification setw(largeur)
3/ Correction petit bug dans la lecture fichiers ASCII argument non transmis ds utilarr.cc

Reza 23 Mai 2005

Location:
trunk/SophyaLib/TArray
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/tarray.cc

    r2615 r2752  
    77#include <stdlib.h>
    88#include <math.h>
     9#include <iomanip>
     10
    911#include "pexceptions.h"
    1012#include "tarray.h"
     
    13031305  if (maxprt < 0)  maxprt = max_nprt_;
    13041306  sa_size_t npr = 0;
     1307  // keep stream's io flags
     1308  ios_base::fmtflags ioflg = os.flags();
     1309  os << right ;
     1310 
    13051311  Show(os, si);
    13061312  if (ndim_ < 1) return;
     1313
     1314  // Calcul de la largeur d'impression pour chaque element
     1315  int fprtw = os.precision()+7;
     1316  int prtw = 5;
     1317
     1318  if ( (typeid(T) == typeid( int_4 )) || (typeid(T) == typeid( uint_4 )) ) prtw = 8;
     1319  else if ( (typeid(T) == typeid( int_8 )) || (typeid(T) == typeid( uint_8 )) ) prtw = 11;
     1320  else if ( typeid(T) == typeid( r_4 ) ) prtw = fprtw;
     1321  else if ( typeid(T) == typeid( r_8 ) ) prtw = fprtw;
     1322  else if ( typeid(T) == typeid(complex<r_4>) ) prtw = fprtw;
     1323  else if ( typeid(T) == typeid(complex<r_8>) ) prtw = fprtw;
     1324
     1325
    13071326  sa_size_t k0,k1,k2,k3,k4;
    13081327  for(k4=0; k4<size_[4]; k4++) {
     
    13201339          for(k0=0; k0<size_[0]; k0++) {
    13211340            if(k0 > 0) os << " "; 
    1322             os << Elem(k0, k1, k2, k3, k4);     npr++;
     1341            os << setw(prtw) << Elem(k0, k1, k2, k3, k4);     npr++;
    13231342            if (npr >= (sa_size_t) maxprt) {
    13241343              if (npr < totsize_)  os << "\n     .... " << endl; return;
     
    13311350  }
    13321351  os <<  endl;
     1352  os.flags(ioflg);  // reset stream io flags
    13331353}
    13341354
  • trunk/SophyaLib/TArray/tmatrix.cc

    r2615 r2752  
    1 // $Id: tmatrix.cc,v 1.29 2004-09-10 09:55:07 cmv Exp $
     1// $Id: tmatrix.cc,v 1.30 2005-05-23 16:18:17 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "sopnamsp.h"
    44#include "machdefs.h"
     5#include <iostream>
     6#include <iomanip>
    57#include <stdio.h>
    68#include <stdlib.h>
     
    102104
    103105//! Constructor of a matrix from a TArray \b a
    104 template <class T>
    105 TMatrix<T>::TMatrix(const TArray<T>& a)
    106 : TArray<T>(a)
    107 {
    108   if (a.NbDimensions() > 2)
    109     throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions()>2 ");
    110   if (a.NbDimensions() == 1) {
    111     size_[1] = 1;
    112     step_[1] = size_[0]*step_[0];
    113     ndim_ = 2;
    114   }
    115   arrtype_ = 1;   // Type = Matrix
    116   UpdateMemoryMapping(a, SameMemoryMapping);
    117 }
    118 
    119 //! Constructor of a matrix from a TArray \b a
    120106/*!
    121107  \param a : TArray to be copied or shared
    122108  \param share : if true, share data. If false copy data
    123   \param mm : define the memory mapping type
    124  */
    125 template <class T>
    126 TMatrix<T>::TMatrix(const TArray<T>& a, bool share, short mm )
     109 */
     110template <class T>
     111TMatrix<T>::TMatrix(const TArray<T>& a, bool share)
    127112: TArray<T>(a, share)
    128113{
     
    135120  }
    136121  arrtype_ = 1;   // Type = Matrix
    137   UpdateMemoryMapping(a, mm);
     122  UpdateMemoryMapping(a, SameMemoryMapping);
    138123}
    139124
     
    264249TMatrix<T> TMatrix<T>::SubMatrix(Range rline, Range rcol) const
    265250{
     251  Range rx, ry;
    266252  short mm = GetMemoryMapping();
    267   Range rx, ry;
    268253  if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
    269254  else { ry = rcol;  rx = rline; }
    270   TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true, mm);
     255  TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true);
    271256  sm.UpdateMemoryMapping(mm);
    272257  return(sm);
     
    389374  if (maxprt < 0)  maxprt = max_nprt_;
    390375  sa_size_t npr = 0;
     376
     377  // keep stream's io flags
     378  ios_base::fmtflags ioflg = os.flags();
     379  os << right ;
     380
    391381  Show(os, si);
    392382  if (ndim_ < 1)  return;
     383  // Calcul de la largeur d'impression pour chaque element
     384  int fprtw = os.precision()+7;
     385  int prtw = 5;
     386
     387  if ( (typeid(T) == typeid( int_4 )) || (typeid(T) == typeid( uint_4 )) ) prtw = 8;
     388  else if ( (typeid(T) == typeid( int_8 )) || (typeid(T) == typeid( uint_8 )) ) prtw = 11;
     389  else if ( typeid(T) == typeid( r_4 ) ) prtw = fprtw;
     390  else if ( typeid(T) == typeid( r_8 ) ) prtw = fprtw;
     391  else if ( typeid(T) == typeid(complex<r_4>) ) prtw = fprtw;
     392  else if ( typeid(T) == typeid(complex<r_8>) ) prtw = fprtw;
     393
    393394  sa_size_t kc,kr; 
    394395  for(kr=0; kr<size_[marowi_]; kr++) {
     
    396397    for(kc=0; kc<size_[macoli_]; kc++) {
    397398      if(kc > 0) os << " "; 
    398       os << (*this)(kr, kc);   npr++;
     399      os << setw(prtw) << (*this)(kr, kc);   npr++;
    399400      if (npr >= (sa_size_t) maxprt) {
    400401        if (npr < totsize_)  os << "\n     .... " << endl; return;
     
    404405  }
    405406  os << endl;
     407  os.flags(ioflg);  // reset stream io flags
    406408}
    407409
  • trunk/SophyaLib/TArray/tmatrix.h

    r2575 r2752  
    1818  TMatrix(const TMatrix<T>& a);
    1919  TMatrix(const TMatrix<T>& a, bool share);
    20   TMatrix(const TArray<T>& a);
    21   TMatrix(const TArray<T>& a,  bool share, short mm=BaseArray::AutoMemoryMapping);
     20  TMatrix(const TArray<T>& a,  bool share=true);
    2221  TMatrix(const BaseArray& a);
    2322
  • trunk/SophyaLib/TArray/tvector.cc

    r2719 r2752  
    1 // $Id: tvector.cc,v 1.18 2005-05-13 16:44:30 cmv Exp $
     1// $Id: tvector.cc,v 1.19 2005-05-23 16:18:17 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "sopnamsp.h"
     
    9191}
    9292
    93 //! Constructor from a TArray
    94 template <class T>
    95 TVector<T>::TVector(const TArray<T>& a)
    96 : TMatrix<T>(a)
    97 {
    98   if ( (size_[0] != 1) && (size_[1] != 1) )
    99     throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
    100   arrtype_ = 2;   // Type = Vector
    101 }
    10293
    10394//! Constructor of a vector from a TArray \b a
     
    10596  \param a : TArray to be copied or shared
    10697  \param share : if true, share data. If false copy data
    107   \param mm : define the memory mapping type
    10898  \param lcv : line or column vector ?
    10999  \sa SelectVectorType
    110100 */
    111101template <class T>
    112 TVector<T>::TVector(const TArray<T>& a, bool share, short lcv, short mm)
    113 : TMatrix<T>(a, share, mm)
     102TVector<T>::TVector(const TArray<T>& a, bool share, short lcv)
     103: TMatrix<T>(a, share)
    114104{
    115105  if ( (size_[0] != 1) && (size_[1] != 1) )
     
    202192  else cr = relt;
    203193  TMatrix<T> const & mtx = (*this);
    204   TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() );
     194  TVector sv( mtx(rr, cr) , true, GetVectorType() );
    205195  return(sv); 
    206196}
  • trunk/SophyaLib/TArray/tvector.h

    r2719 r2752  
    1717  TVector(const TVector<T>& v);
    1818  TVector(const TVector<T>& v, bool share);
    19   TVector(const TArray<T>& a);
    20   TVector(const TArray<T>& a,  bool share, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
     19  TVector(const TArray<T>& a,  bool share=true, short lcv=AutoVectorType);
    2120  TVector(const BaseArray& a);
    2221  TVector(const vector<T>& v, short lcv=AutoVectorType);
  • trunk/SophyaLib/TArray/utilarr.cc

    r2615 r2752  
    287287    if (is.good()) {
    288288      if ((line.length() > 0) && (line[0]!=clm)) {
    289         nel = Append(line, nbad);
     289        nel = Append(line, nbad, sep);
    290290        if (nel > 0)  {
    291291          nr++;  n += nel;
     
    298298  }
    299299  if ((line.length() > 0) && (line[0]!=clm)) {
    300     nel = Append(line, nbad);
     300    nel = Append(line, nbad, sep);
    301301    //        cout << " Decoding Eline = " << line << " Nel= " << nel << endl;
    302302    if (nel > 0)  {
Note: See TracChangeset for help on using the changeset viewer.