Update of /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/reflux/io In directory sc8-pr-cvs1:/tmp/cvs-serv6254/dodico/src/org/fudaa/dodico/reflux/io Added Files: CorEleBthFileFormat.java CorEleBthReader.java CorEleBthInterface.java CorEleBthAdapter.java CorEleBthWriter.java Log Message: ajout des interfaces et des classes necessaires a la lecture ecriture des fichiers reflux --- NEW FILE: CorEleBthFileFormat.java --- /* * @file TrFileFormatCorEleBth.java * @creation 13 mars 2003 * @modification $Date: 2003/03/18 14:01:02 $ * @license GNU General Public License 2 * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne * @mail de...@fu... */ package org.fudaa.dodico.reflux.io; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import org.fudaa.dodico.commun.DodicoLib; import org.fudaa.dodico.commun.ProgressionInterface; import org.fudaa.dodico.tr.TrFileFormat; import org.fudaa.dodico.tr.TrReaderAbstract; import org.fudaa.dodico.tr.TrWriterAbstract; /** * * @author deniger * @version $Id: CorEleBthFileFormat.java,v 1.1 2003/03/18 14:01:02 deniger Exp $ */ public class CorEleBthFileFormat extends TrFileFormat { public static int NB_FILE=3; private static final CorEleBthFileFormat INSTANCE=new CorEleBthFileFormat(); public static final CorEleBthFileFormat getInstance() { return INSTANCE; } protected CorEleBthFileFormat() { super(NB_FILE); extensions_=new String[]{"cor","ele","bth"}; ID_="CORELEBTH"; nom_="cor,ele,bth"; description_="Contient des données concernant le modèle numérique de terrain uniquement. Compatible avec le format MEF/Mosaic v2.6"; mode_=MODE_ASCII; software_=null; } /** * Largeur simple. */ public int getSimpleColumLength() { return 5; } /** * Largeur double. */ public int getDoubleColumLength() { return 10; } /** * Largeur de la 2eme colonne du fichier ele. */ public int getEleSecondColumnLength() { return 25; } /** * Largeur d'une colonne du fichier bth. */ public int getBthColumnLength() { return 12; } /** * Nombre de points par ligne dans le fichier bth. */ public int getBthPointByLine() { return 6; } /** * @see org.fudaa.dodico.tr.TrFileFormat#createReader(File[]) */ public TrReaderAbstract createReader(File[] _f,ProgressionInterface _progress,boolean _onlyMNT,int _bufSize) { File f=_f[0]; FileReader cor=null; try { cor=new FileReader(f); } catch(FileNotFoundException _ex) { if(DodicoLib.DEBUG) _ex.printStackTrace(); } FileReader ele=null; try { ele=new FileReader(f); } catch(FileNotFoundException _ex) { if(DodicoLib.DEBUG) _ex.printStackTrace(); } FileReader bth=null; try { bth=new FileReader(f); } catch(FileNotFoundException _ex) { if(DodicoLib.DEBUG) _ex.printStackTrace(); } CorEleBthReader r=new CorEleBthReader(); r.setOnlyMNT(_onlyMNT); if(_bufSize>0) r.setIn(cor,ele,bth,_bufSize); else r.setIn(cor,ele,bth); r.setProgressReceiver(_progress); return r; } /** * @see org.fudaa.dodico.tr.TrFileFormat#createWriter(File[], Object, ProgressionInterface) */ public TrWriterAbstract createWriter( File[] _f, Object _source, ProgressionInterface _progress) { CorEleBthWriter r=new CorEleBthWriter(); File f=_f[0]; FileWriter cor=null; if(f!=null) { try { cor=new FileWriter(f); } catch(IOException _ex) { r.getAnalyzeFor(0).addError(DodicoLib.geti18n("Problème à l'ouverture du flux")+" "+_ex.getMessage()); if(DodicoLib.DEBUG) _ex.printStackTrace(); } } f=_f[1]; FileWriter ele=null; if(f!=null) { try { ele=new FileWriter(f); } catch(IOException _ex) { r.getAnalyzeFor(1).addError(DodicoLib.geti18n("Problème à l'ouverture du flux")+" "+_ex.getMessage()); if(DodicoLib.DEBUG) _ex.printStackTrace(); } } f=_f[2]; FileWriter bth=null; if(f!=null) { try { bth=new FileWriter(f); } catch(IOException _ex) { r.getAnalyzeFor(2).addError(DodicoLib.geti18n("Problème à l'ouverture du flux")+" "+_ex.getMessage()); if(DodicoLib.DEBUG) _ex.printStackTrace(); } } r.setOut(cor,ele,bth); r.setCorEleBthInterface((CorEleBthInterface)_source); r.setProgressReceiver(_progress); return r; } } --- NEW FILE: CorEleBthReader.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: CorEleBthInterface.java --- /* * @file CorEleBthInterface.java * @creation 10 mars 2003 * @modification $Date: 2003/03/18 14:01:03 $ * @license GNU General Public License 2 * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne * @mail de...@fu... */ package org.fudaa.dodico.reflux.io; import org.fudaa.dodico.corba.geometrie.SMaillageIndex; /** * * @author deniger * @version $Id: CorEleBthInterface.java,v 1.1 2003/03/18 14:01:03 deniger Exp $ */ public interface CorEleBthInterface { SMaillageIndex getMaillage(); } --- NEW FILE: CorEleBthAdapter.java --- /* * @file CorEleBthAdapter.java * @creation 10 mars 2003 * @modification $Date: 2003/03/18 14:01:03 $ * @license GNU General Public License 2 * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne * @mail de...@fu... */ package org.fudaa.dodico.reflux.io; import org.fudaa.dodico.corba.geometrie.SMaillageIndex; /** * * @author deniger * @version $Id: CorEleBthAdapter.java,v 1.1 2003/03/18 14:01:03 deniger Exp $ */ public class CorEleBthAdapter implements CorEleBthInterface { private SMaillageIndex maillage_; /** * @see org.fudaa.dodico.tr.reflux.CorEleBthInterface#getMaillage() */ public SMaillageIndex getMaillage() { return maillage_; } public void setMaillage(SMaillageIndex _s) { maillage_=_s; } } --- NEW FILE: CorEleBthWriter.java --- /* * @file CorEleBthWriter.java * @creation 2003-03-12 * @modification $Date: 2003/03/18 14:01:04 $ * @license GNU General Public License 2 * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne * @mail de...@fu... */ package org.fudaa.dodico.reflux.io; import java.io.IOException; import java.io.Writer; import org.fudaa.dodico.corba.geometrie.SMaillageIndex; import org.fudaa.dodico.corba.geometrie.SPoint; import org.fudaa.dodico.fortran.FortranWriter; import org.fudaa.dodico.tr.TrLib; import org.fudaa.dodico.tr.TrWriterCharAbstract; /** * * @author deniger * @version $Id: CorEleBthWriter.java,v 1.1 2003/03/18 14:01:04 deniger Exp $ */ public class CorEleBthWriter extends TrWriterCharAbstract { private CorEleBthInterface source_; private SMaillageIndex maillage_; private FortranWriter corOut_; private FortranWriter eleOut_; private FortranWriter bthOut_; private CorEleBthFileFormat fileFormat_; private int sf_; private int df_; public CorEleBthWriter() { this(null); } public CorEleBthWriter( CorEleBthFileFormat _f) { super(CorEleBthFileFormat.NB_FILE); fileFormat_ = _f; if (fileFormat_ == null) fileFormat_ = CorEleBthFileFormat.getInstance(); sf_ = fileFormat_.getSimpleColumLength(); df_ = fileFormat_.getDoubleColumLength(); } public final void setOut(Writer _cor, Writer _ele, Writer _bth) { corOut_ = _cor == null ? null : new FortranWriter(_cor); eleOut_ = _ele == null ? null : new FortranWriter(_ele); bthOut_ = _bth == null ? null : new FortranWriter(_bth); } public void setCorEleBthInterface(CorEleBthInterface _s) { source_ = _s; maillage_ = source_.getMaillage(); } public void write() throws IOException { int format = fileFormat_.getDoubleColumLength(); if (source_ == null) { getAnalyzeFor(0).addError("L'objet source est nul.", -1, true); return; } //Si le nombre de points ne tiend pas dans le format simple //on suppose que nbElments<NbPoints ... int l = maillage_.points.length; int nbDigits = String.valueOf(l).length(); // if (nbDigits > CorEleBthInterface.COLUMN_SIMPLE_LENGTH) //on ecrit toujours dans le format double.a voir if (nbDigits > fileFormat_.getDoubleColumLength()) { getAnalyzeFor(0).addError( "Le nombre de points est trop important.", -1, true); return; } boolean afficheAvance = (progressReceiver_ == null ? false : true); //pour le pourcentage d'avancement on suppose que la lecture //des points prend 40% du temps. int percBegin = 0; int percLength = 40; writeCor(percBegin, percLength, afficheAvance, format); //pour le pourcentage d'avancement on suppose que la lecture //des elements prend 40% du temps et part de 40. percBegin += percLength; writeEle(percBegin, percLength, afficheAvance, format); percBegin += percLength; percLength = 20; writeBth(percBegin, percLength, afficheAvance); } public void writeCor( int _percBegin, int _percLength, boolean _afficheAvance, int _format) throws IOException { if (corOut_ == null) { getAnalyzeFor(0).addError( "Le flux pour les coordonnées est nul.", -1, true); return; } corOut_.setLineSeparator(getLineSeparator()); corOut_.setStringQuoted(false); SPoint[] pts = maillage_.points; int l = pts.length; int[] fmt = new int[] { _format, sf_, sf_, df_, df_, df_ }; //on fixe le dernier element corOut_.doubleField(5, 1D); corOut_.intField(0, l); corOut_.intField(1, 6); corOut_.intField(2, 2); corOut_.doubleField(3, 1D); corOut_.doubleField(4, 1D); corOut_.writeFields(fmt); int pourc = _percBegin; if (_afficheAvance) progressReceiver_.setProgression(pourc); int step = TrLib.getStep(l, (int) _percLength / 10); int pourcStep = (int) (_percLength / step); int pas = (int) (l / step); int pMax = pas; SPoint pt; fmt = new int[] { _format, df_, df_ }; for (int i = 0; i < l; i++) { pt = pts[i]; corOut_.doubleField(2, pt.y); corOut_.intField(0, i + 1); corOut_.doubleField(1, pt.x); corOut_.writeFields(fmt); //maj de l'avancement if (_afficheAvance) { if (i > pMax) { pourc += pourcStep; progressReceiver_.setProgression(pourc); pMax += pas; } } } corOut_.flush(); } public void writeEle( int _percBegin, int _percLength, boolean _afficheAvance, int _format) throws IOException { if (eleOut_ == null) { getAnalyzeFor(1).addError("Le flux pour les éléments est nul.", -1, true); return; } eleOut_.setLineSeparator(getLineSeparator()); eleOut_.setStringQuoted(false); int[][] ele = maillage_.elements; int l = ele.length; //dans le cas double ?? int[] fmt = new int[] { _format, sf_, sf_, sf_, sf_ }; //utilite de ces 3 champs ? eleOut_.intField(4, 0); eleOut_.intField(3, 0); eleOut_.intField(2, 0); eleOut_.intField(1, 6); eleOut_.intField(0, l); eleOut_.writeFields(fmt); fmt = new int[] { _format, //le num fileFormat_.getEleSecondColumnLength(), //? _format, //ele 1 _format, //ele 2 _format, //ele 3 _format, //ele 4 _format, //ele 5 _format, //ele 6 _format //le 0 final }; //Gestion de l'avancement int pourc = _percBegin; if (_afficheAvance) progressReceiver_.setProgression(pourc); int step = TrLib.getStep(l, (int) _percLength / 10); int pourcStep = (int) (_percLength / step); int pas = (int) (l / step); int pMax = pas; int[] elei; int taille; for (int i = 0; i < l; i++) { elei = ele[i]; taille = elei.length; //le 0 final. eleOut_.intField(2 + taille, 0); eleOut_.intField(0, i + 1); eleOut_.stringField(1, "-1"); for (int j = 0; j < taille; j++) { //les indexs de elei commencent a 0 ! eleOut_.intField(2 + j, elei[j] + 1); } eleOut_.writeFields(fmt); //maj de l'avancement if (_afficheAvance) { if (i > pMax) { pourc += pourcStep; progressReceiver_.setProgression(pourc); pMax += pas; } } } eleOut_.flush(); } public void writeBth(int _percBegin, int _percLength, boolean _afficheAvance) throws IOException { int pointParLigne=fileFormat_.getBthPointByLine(); if (bthOut_ == null) { getAnalyzeFor(2).addError("Le flux pour la bathymétrie est nul.", -1, true); return; } bthOut_.setLineSeparator(getLineSeparator()); bthOut_.setStringQuoted(false); //le format des lignes. int[] fmt = new int[pointParLigne]; for (int i = pointParLigne - 1; i >= 0; i--) { fmt[i] = fileFormat_.getBthColumnLength(); } //les points concernes SPoint[] pts = maillage_.points; int l = pts.length; //gestion de l'avancement int pourc = _percBegin; if (_afficheAvance) progressReceiver_.setProgression(pourc); int nbLigne = (int) (l / pointParLigne); int step = TrLib.getStep(nbLigne, (int) _percLength / 10); int pourcStep = (int) (_percLength / step); int pas = (int) (nbLigne / step); int pMax = pas; //Le nombre de ligne entiere a ecrire. System.out.println(nbLigne); int index = 0; for (int numLigne = 0; numLigne < nbLigne; numLigne++) { for (int j = pointParLigne - 1; j >= 0; j--) { bthOut_.doubleField(j, pts[index + j].z); } index += pointParLigne; bthOut_.writeFields(fmt); //maj de l'avancement if (_afficheAvance) { if (numLigne > pMax) { pourc += pourcStep; progressReceiver_.setProgression(pourc); pMax += pas; } } } int coteRestante = l - nbLigne * pointParLigne; if (index != l - coteRestante) { System.out.println("prob!!!!!!!"); } if (coteRestante > 0) { for (int j = coteRestante - 1; j >= 0; j--) { bthOut_.doubleField(j, pts[index + j].z); } bthOut_.writeFields(fmt); } bthOut_.flush(); } public IOException[] close() { return FortranWriter.close(new FortranWriter[]{corOut_,eleOut_,bthOut_}); } } |