|
From: <de...@us...> - 2003-04-17 17:26:23
|
Update of /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/telemac
In directory sc8-pr-cvs1:/tmp/cvs-serv1427/org/fudaa/dodico/telemac
Added Files:
TelemacCasProcess.java TelemacDicoManager.java
TelemacProjet.java
Log Message:
Mise a jour diverses
--- NEW FILE: TelemacCasProcess.java ---
/*
* @file TelemacCasProcess.java
* @creation 16 avr. 2003
* @modification $Date: 2003/04/17 17:26:19 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.telemac;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.fudaa.dodico.commun.DodicoLib;
import org.fudaa.dodico.commun.ProgressionInterface;
import org.fudaa.dodico.telemac.io.TelemacCasFileFormat;
import org.fudaa.dodico.tr.TrFileFormat;
import org.fudaa.dodico.tr.TrReaderInterface;
/**
* @author deniger
* @version $Id: TelemacCasProcess.java,v 1.1 2003/04/17 17:26:19 deniger Exp $
*/
public class TelemacCasProcess
{
ProgressionInterface progress_;
boolean error_;
public TelemacCasProcess()
{
}
public TelemacProjet createProjet(File _f, TelemacCasFileFormat ft_)
{
TelemacProjet r = new TelemacProjet();
r.setCas(ft_, _f, this);
if (error_)
return null;
r.loadAll(this);
return r;
}
// protected TelemacCasInterface readCas(TelemacCasFileFormat _ft, File _f, TelemacProjet.FileLoadState _fd)
// {
// TelemacCasReader r = (TelemacCasReader) _ft.createReader();
// IOException[] e = _ft.read(_f, r, progress_);
// manageException(e, r, _f);
// _fd.setAnalyze(r.getAnalyze());
// _fd.setFormat(_ft);
// _fd.setTimeLoaded(System.currentTimeMillis());
// _fd.setAbsolutePath(DodicoLib.getConanicalPath(_f));
// return r.getTelemacCasInterface();
// }
public void error(String _s)
{
error_ = true;
System.out.println(_s);
}
public void maj(TelemacProjet.TrSpecialEntiteFile _e)
{
TelemacProjet.FileLoadState l=_e.getLoadState();
if(l.containsErrors())
{
l.getAnalyze().printResume();
}
}
protected Object read(String _baseDir, String _file, TrFileFormat _fileFormat, TelemacProjet.FileLoadState _f)
{
File f = DodicoLib.getAbsolutePath(_baseDir, _file);
return read(f, _fileFormat, _f);
}
protected Object read(File _file, TrFileFormat _fileFormat, TelemacProjet.FileLoadState _fileDesc)
{
TrReaderInterface reader = _fileFormat.createReader();
IOException[] e = _fileFormat.read(_file, reader, progress_);
manageException(e, reader, _file);
updateFileDescription(reader, _file, _fileDesc);
return reader.getInterface();
}
protected void manageException(IOException[] e, TrReaderInterface _i, File _f)
{
if (e != null)
{
System.out.println("impossible de fermer " + _f);
e[0].printStackTrace();
}
}
protected static TelemacProjet.FileLoadState createFor(TrReaderInterface _reader, File _f)
{
TelemacProjet.FileLoadState r = new TelemacProjet.FileLoadState();
updateFileDescription(_reader, _f, r);
return r;
}
protected static void updateFileDescription(TrReaderInterface _reader, File _f, TelemacProjet.FileLoadState _r)
{
_r.setAnalyze(_reader.getAnalyze());
_r.setFormat(_reader.getFileFormat());
_r.setAbsolutePath(DodicoLib.getConanicalPath(_f));
_r.setTimeLoaded(System.currentTimeMillis());
}
public static void main(String[] args)
{
HashMap arg = DodicoLib.parseArgs(args);
String fileName = (String) arg.get("-file");
File f = new File(fileName);
TelemacCasProcess p = new TelemacCasProcess();
p.createProjet(f, TelemacCasFileFormat.getInstance());
}
}
--- NEW FILE: TelemacDicoManager.java ---
/*
* @file TelemacDicoManager.java
* @creation 14 avr. 2003
* @modification $Date: 2003/04/17 17:26:20 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.telemac;
import org.fudaa.dodico.telemac.dico.TelemacDicoInterface;
import org.fudaa.dodico.telemac.dico.TelemacDicov5p2;
/**
* @author deniger
* @version $Id: TelemacDicoManager.java,v 1.1 2003/04/17 17:26:20 deniger Exp $
*/
public class TelemacDicoManager
{
protected TelemacDicoInterface[] defautDicos_;
private final static TelemacDicoManager INSTANCE=new TelemacDicoManager();
public final static TelemacDicoManager getINSTANCE()
{
return INSTANCE;
}
protected TelemacDicoManager()
{
defautDicos_=new TelemacDicoInterface[1];
defautDicos_[0]=new TelemacDicov5p2();
}
public final TelemacDicoInterface getDefaut()
{
return defautDicos_[0];
}
}
--- NEW FILE: TelemacProjet.java ---
/*
* @file TelemacProjet.java
* @creation 16 avr. 2003
* @modification $Date: 2003/04/17 17:26:20 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.telemac;
import java.io.File;
import java.util.Hashtable;
import org.fudaa.dodico.commun.DodicoAnalyze;
import org.fudaa.dodico.commun.DodicoLib;
import org.fudaa.dodico.corba.tr.LTrCodeCalcul;
import org.fudaa.dodico.corba.tr.STrProjetH2d;
import org.fudaa.dodico.telemac.io.SerafinFileFormat;
import org.fudaa.dodico.telemac.io.SerafinInterface;
import org.fudaa.dodico.telemac.io.TelemacCLInterface;
import org.fudaa.dodico.telemac.io.TelemacCasFileFormat;
import org.fudaa.dodico.telemac.io.TelemacCasInterface;
import org.fudaa.dodico.telemac.io.TelemacLiquideInterface;
import org.fudaa.dodico.tr.TrDicoEntite;
import org.fudaa.dodico.tr.TrFileFormat;
import org.fudaa.dodico.tr.TrLib;
import org.fudaa.dodico.tr.TrProjetH2d;
/**
* @author deniger
* @version $Id: TelemacProjet.java,v 1.1 2003/04/17 17:26:20 deniger Exp $
*/
public class TelemacProjet extends TrProjetH2d
{
STrProjetH2d projet_;
private String dirBase_;
private TelemacCasFileFormat ft_;
/**
* Entites-valeurs de ce projet.
*/
private Hashtable keys_;
/**
* contient l'id et la description des fichies speciaux de ce projet
*/
private Hashtable idSpecialEntiteFiles_;
public TelemacProjet()
{
}
private void initProjet(TelemacCasFileFormat _ft)
{
projet_ = new STrProjetH2d();
projet_.codeCalcul = LTrCodeCalcul.TELEMAC;
projet_.version = _ft.getVersion();
ft_ = _ft;
idSpecialEntiteFiles_ = new Hashtable(ft_.getNbSpecialFiles());
}
protected void addSpecialEntiteFiles(String _ID,TrSpecialEntiteFile _ent)
{
if(idSpecialEntiteFiles_.containsKey(_ID))
{
System.err.println("ce fichier special est deja ajoute");
}
idSpecialEntiteFiles_.put(_ID, _ent);
}
public void setCas(TelemacCasFileFormat _ft, File _fichierCas, TelemacCasProcess _p)
{
initProjet(_ft);
dirBase_ = DodicoLib.getConanicalPath(_fichierCas.getParentFile());
System.out.println(dirBase_);
TrDicoEntite fichierPrincEntite=ft_.getSpecialFiles(FICHIER_PRINCIPAL);
if ( fichierPrincEntite== null)
{
_p.error("La definition du fichier principal n'a pas été trouvée");
return;
}
TrSpecialEntiteFile specialEntite = new TrSpecialEntiteFile(fichierPrincEntite,_fichierCas.getName());
FileLoadState fd=new FileLoadState();
TelemacCasInterface inter = (TelemacCasInterface) _p.read(_fichierCas, _ft, fd);
if((fd.containsErrors()) )
{
_p.error("Le fichier cas est invalide");
}
else
{
specialEntite.setLoadState(fd);
addSpecialEntiteFiles(FICHIER_PRINCIPAL, specialEntite);
keys_ = inter.getInputs();
keys_.remove(fichierPrincEntite);
//Les entites representant des fichiers present dans le fichier cas
TrDicoEntite[] entFichiers = ft_.getDico().getFichierEntitesFor(keys_);
int n = entFichiers.length - 1;
TrDicoEntite e;
for (int i = n; i >= 0; i--)
{
e = entFichiers[i];
//si fichier special
if (ft_.isSpecialFiles(e))
{
String s = ft_.getSpecialFilesID(e);
//si ce n'est pas le principal, on l'ajoute
if (!s.equals(FICHIER_PRINCIPAL))
{
addSpecialEntiteFiles(s, new TrSpecialEntiteFile(e,(String)keys_.get(e)));
}
}
}
}
}
public boolean loadAll(TelemacCasProcess _p)
{
return loadGeometrie(_p) && loadConditionsLimite(_p) && loadConditionsLimiteLiquide(_p);
}
protected TrSpecialEntiteFile getSpecialFileEntite(String _ID)
{
return (TrSpecialEntiteFile) idSpecialEntiteFiles_.get(_ID);
}
protected String getEntiteValue(TrDicoEntite _e)
{
return (String) keys_.get(_e);
}
public boolean loadGeometrie(TelemacCasProcess _p)
{
SerafinFileFormat serafinft = ft_.getDefaultSerafinFormat();
SerafinInterface sInter = (SerafinInterface) read(_p, FICHIER_GEOMETRIE, serafinft, true);
if(sInter==null) return false;
String fond = ft_.getDefaultSerafinFormat().getVariableFond();
int numVariable = DodicoLib.findObject(sInter.getVariables(), fond);
if (numVariable < 0)
{
//pour l'instant
_p.error("bathymétrie non trouvée variable FOND ou es-tu ?");
return false;
}
int nbPasTemps = sInter.getNbPasDeTemps();
if (nbPasTemps > 1)
{
System.out.println("la variable à t=0 sera prise");
}
double[] fondValues = sInter.getDonnees(0, numVariable);
projet_.maillage = sInter.getMaillage();
return TrLib.setBathymetrie(projet_.maillage, fondValues);
}
public boolean loadConditionsLimite(TelemacCasProcess _p)
{
TelemacCLInterface inter = (TelemacCLInterface) read(_p, FICHIER_CL, ft_.getDefaultTelemacCLFormat(), true);
if (inter == null)
return false;
projet_.conditionsLimites = inter.getLines();
return true;
}
public boolean loadConditionsLimiteLiquide(TelemacCasProcess _p)
{
TelemacLiquideInterface inter = (TelemacLiquideInterface) read(_p, FICHIER_CL_LIQUIDE, ft_.getDefaultTelemacLiquideFormat(), false);
if (inter == null)
return false;
projet_.evolutionFrontieresLiquides = inter.getEvolutionsFrontieresLiquides();
return true;
}
public boolean loadFond(TelemacCasProcess _p)
{
_p.error("non supporté pour l'instant");
return false;
}
private Object read(TelemacCasProcess _p, String _specialFileID, TrFileFormat _fileFormat, boolean _isVideError)
{
TrDicoEntite ent = ft_.getSpecialFiles(_specialFileID);
if (ent == null)
{
if (_isVideError)
{
_p.error("ce n'est pas une entree valide du fichier dico !");
}
return null;
}
TrSpecialEntiteFile specialFileEntite = getSpecialFileEntite(_specialFileID);
if (specialFileEntite== null)
{
if (_isVideError)
{
_p.error(ent.getNom() + " non spécifié !");
}
return null;
}
String value = getEntiteValue(ent);
//ne devrait jamais arriver
if (value == null)
{
if (_isVideError)
{
_p.error(ent.getNom() + " spécifié mais vide !!!");
}
return null;
}
FileLoadState fileLoad=new FileLoadState();
Object r = _p.read(dirBase_, value, _fileFormat, fileLoad);
specialFileEntite.setLoadState(fileLoad);
if (fileLoad.containsErrors())
{
_p.error(ent.getNom() + " fichier invalide");
_p.maj(specialFileEntite);
return null;
}
return r;
}
public static class TrSpecialEntiteFile
{
private TrDicoEntite entite_;
private String entiteValue_;
private FileLoadState loadState_;
public TrSpecialEntiteFile(TrDicoEntite _entite, String _entiteValue)
{
entite_ = _entite;
entiteValue_ = _entiteValue;
}
public void setLoadState(FileLoadState _fls)
{
loadState_ = _fls;
}
public FileLoadState getLoadState()
{
return loadState_;
}
}
public static class FileLoadState
{
private DodicoAnalyze analyze_;
private long timeLoaded_;
private TrFileFormat format_;
private String absolutePath_;
/**
* @return
*/
public DodicoAnalyze getAnalyze()
{
return analyze_;
}
public boolean containsErrors()
{
return (analyze_!=null) && (analyze_.containsErrors());
}
/**
* @return
*/
public TrFileFormat getFormat()
{
return format_;
}
/**
* @return
*/
public long getTimeLoaded()
{
return timeLoaded_;
}
/**
* @param _analyze
*/
public void setAnalyze(DodicoAnalyze _analyze)
{
analyze_ = _analyze;
}
/**
* @param _format
*/
public void setFormat(TrFileFormat _format)
{
format_ = _format;
}
/**
* @param _l
*/
public void setTimeLoaded(long _l)
{
timeLoaded_ = _l;
}
/**
* @return
*/
public String getAbsolutePath()
{
return absolutePath_;
}
/**
* @param _string
*/
public void setAbsolutePath(String _string)
{
absolutePath_ = _string;
}
}
/**
* @return
*/
public String getDirBase()
{
return dirBase_;
}
/**
* @param _string
*/
public void setDirBase(String _string)
{
dirBase_ = _string;
}
}
|