Subversion Repositories test

Compare Revisions

Ignore whitespace Rev 10 → Rev 11

/.classpath
New file
0,0 → 1,8
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/JSAP-2.1"/>
<classpathentry exported="true" kind="lib" path="/JSAP-2.1/ImportedClasses"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/.project
New file
0,0 → 1,17
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JSpec</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/src/org/geoscope/JSpec/INIFile.java
New file
0,0 → 1,1421
/*------------------------------------------------------------------------------
* PACKAGE: com.freeware.inifiles
* FILE : iniFile.java
* CREATED: Jun 30, 2004
* AUTHOR : Prasad P. Khandekar
*------------------------------------------------------------------------------
* Change Log:
* 05/07/2004 - Added support for date time formats.
* Added support for environment variables.
* 07/07/2004 - Added support for data type specific getters and setters.
* Updated main method to reflect above changes.
* 26/08/2004 - Added support for section level and property level comments.
* Introduction of seperate class for property values.
* Added addSection method.
* Sections and properties now retail their order (LinkedHashMap)
* Method implementation changes.
*-----------------------------------------------------------------------------*/
//package com.freeware.inifiles;
 
package org.geoscope.JSpec;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
 
 
/**
* INIFile class provides methods for manipulating (Read/Write) windows ini files.
*
* @author Prasad P. Khandekar
* @version 1.0
* @since 1.0
*/
public final class INIFile
{
/** Variable to represent the date format */
private String mstrDateFmt = "yyyy-MM-dd";
 
/** Variable to represent the timestamp format */
private String mstrTimeStampFmt = "yyyy-MM-dd HH:mm:ss";
 
/** Variable to denote the successfull load operation. */
private boolean mblnLoaded = false;
 
/** Variable to hold the ini file name and full path */
private String mstrFile;
 
/** Variable to hold the sections in an ini file. */
private LinkedHashMap mhmapSections;
 
/** Variable to hold environment variables **/
private Properties mpropEnv;
 
/**
* Create a iniFile object from the file named in the parameter.
* @param pstrPathAndName The full path and name of the ini file to be used.
*/
public INIFile(String pstrPathAndName)
{
this.mpropEnv = getEnvVars();
this.mhmapSections = new LinkedHashMap();
this.mstrFile = pstrPathAndName;
// Load the specified INI file.
if (checkFile(pstrPathAndName)) loadFile();
}
 
/*------------------------------------------------------------------------------
* Getters
------------------------------------------------------------------------------*/
/**
* Returns the ini file name being used.
* @return the INI file name.
*/
public String getFileName()
{
return this.mstrFile;
}
 
/**
* Returns the specified string property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the string property value.
*/
public String getStringProperty(String pstrSection, String pstrProp)
{
String strRet = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
if (objProp != null)
{
strRet = objProp.getPropValue();
objProp = null;
}
objSec = null;
}
return strRet;
}
 
/**
* Returns the specified boolean property from the specified section.
* This method considers the following values as boolean values.
* <ol>
* <li>YES/yes/Yes - boolean true</li>
* <li>NO/no/No - boolean false</li>
* <li>1 - boolean true</li>
* <li>0 - boolean false</li>
* <li>TRUE/True/true - boolean true</li>
* <li>FALSE/False/false - boolean false</li>
* </ol>
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the boolean value
*/
public Boolean getBooleanProperty(String pstrSection, String pstrProp)
{
boolean blnRet = false;
String strVal = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
if (objProp != null)
{
strVal = objProp.getPropValue().toUpperCase();
if (strVal.equals("YES") || strVal.equals("TRUE") ||
strVal.equals("1"))
{
blnRet = true;
}
objProp = null;
}
objSec = null;
}
return new Boolean(blnRet);
}
 
/**
* Returns the specified integer property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the integer property value.
*/
public Integer getIntegerProperty(String pstrSection, String pstrProp)
{
Integer intRet = null;
String strVal = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
try
{
if (objProp != null)
{
strVal = objProp.getPropValue();
if (strVal != null) intRet = new Integer(strVal);
}
}
catch (NumberFormatException NFExIgnore)
{
}
finally
{
if (objProp != null) objProp = null;
}
objSec = null;
}
return intRet;
}
 
/**
* Returns the specified long property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the long property value.
*/
public Long getLongProperty(String pstrSection, String pstrProp)
{
Long lngRet = null;
String strVal = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
try
{
if (objProp != null)
{
strVal = objProp.getPropValue();
if (strVal != null) lngRet = new Long(strVal);
}
}
catch (NumberFormatException NFExIgnore)
{
}
finally
{
if (objProp != null) objProp = null;
}
objSec = null;
}
return lngRet;
}
 
/**
* Returns the specified double property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the double property value.
*/
public Double getDoubleProperty(String pstrSection, String pstrProp)
{
Double dblRet = null;
String strVal = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
try
{
if (objProp != null)
{
strVal = objProp.getPropValue();
if (strVal != null) dblRet = new Double(strVal);
}
}
catch (NumberFormatException NFExIgnore)
{
}
finally
{
if (objProp != null) objProp = null;
}
objSec = null;
}
return dblRet;
}
 
/**
* Returns the specified date property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the date property value.
*/
public Date getDateProperty(String pstrSection, String pstrProp)
{
Date dtRet = null;
String strVal = null;
DateFormat dtFmt = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
try
{
if (objProp != null) strVal = objProp.getPropValue();
if (strVal != null)
{
dtFmt = new SimpleDateFormat(this.mstrDateFmt);
dtRet = dtFmt.parse(strVal);
}
}
catch (ParseException PExIgnore)
{
}
catch (IllegalArgumentException IAEx)
{
}
finally
{
if (objProp != null) objProp = null;
}
objSec = null;
}
return dtRet;
}
 
/**
* Returns the specified date property from the specified section.
* @param pstrSection the INI section name.
* @param pstrProp the property to be retrieved.
* @return the date property value.
*/
public Date getTimestampProperty(String pstrSection, String pstrProp)
{
Timestamp tsRet = null;
Date dtTmp = null;
String strVal = null;
DateFormat dtFmt = null;
INIProperty objProp = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objProp = objSec.getProperty(pstrProp);
try
{
if (objProp != null) strVal = objProp.getPropValue();
if (strVal != null)
{
dtFmt = new SimpleDateFormat(this.mstrDateFmt);
dtTmp = dtFmt.parse(strVal);
tsRet = new Timestamp(dtTmp.getTime());
}
}
catch (ParseException PExIgnore)
{
}
catch (IllegalArgumentException IAEx)
{
}
finally
{
if (objProp != null) objProp = null;
}
objSec = null;
}
return tsRet;
}
 
/*------------------------------------------------------------------------------
* Setters
------------------------------------------------------------------------------*/
/**
* Sets the comments associated with a section.
* @param pstrSection the section name
* @param pstrComments the comments.
*/
public void addSection(String pstrSection, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setSecComments(delRemChars(pstrComments));
objSec = null;
}
 
/**
* Sets the specified string property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @pstrVal the string value to be persisted
*/
public void setStringProperty(String pstrSection, String pstrProp,
String pstrVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, pstrVal, pstrComments);
}
 
/**
* Sets the specified boolean property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param pblnVal the boolean value to be persisted
*/
public void setBooleanProperty(String pstrSection, String pstrProp,
boolean pblnVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
if (pblnVal)
objSec.setProperty(pstrProp, "TRUE", pstrComments);
else
objSec.setProperty(pstrProp, "FALSE", pstrComments);
}
 
/**
* Sets the specified integer property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param pintVal the int property to be persisted.
*/
public void setIntegerProperty(String pstrSection, String pstrProp,
int pintVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, Integer.toString(pintVal), pstrComments);
}
 
/**
* Sets the specified long property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param plngVal the long value to be persisted.
*/
public void setLongProperty(String pstrSection, String pstrProp,
long plngVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, Long.toString(plngVal), pstrComments);
}
 
/**
* Sets the specified double property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param pdblVal the double value to be persisted.
*/
public void setDoubleProperty(String pstrSection, String pstrProp,
double pdblVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, Double.toString(pdblVal), pstrComments);
}
 
/**
* Sets the specified java.util.Date property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param pdtVal the date value to be persisted.
*/
public void setDateProperty(String pstrSection, String pstrProp,
Date pdtVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, utilDateToStr(pdtVal, this.mstrDateFmt),
pstrComments);
}
 
/**
* Sets the specified java.sql.Timestamp property.
* @param pstrSection the INI section name.
* @param pstrProp the property to be set.
* @param ptsVal the timestamp value to be persisted.
*/
public void setTimestampProperty(String pstrSection, String pstrProp,
Timestamp ptsVal, String pstrComments)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec == null)
{
objSec = new INISection(pstrSection);
this.mhmapSections.put(pstrSection, objSec);
}
objSec.setProperty(pstrProp, timeToStr(ptsVal, this.mstrTimeStampFmt),
pstrComments);
}
 
/**
* Sets the format to be used to interpreat date values.
* @param pstrDtFmt the format string
* @throws IllegalArgumentException if the if the given pattern is invalid
*/
public void setDateFormat(String pstrDtFmt) throws IllegalArgumentException
{
if (!checkDateTimeFormat(pstrDtFmt))
throw new IllegalArgumentException("The specified date pattern is invalid!");
this.mstrDateFmt = pstrDtFmt;
}
 
/**
* Sets the format to be used to interpreat timestamp values.
* @param pstrTSFmt the format string
* @throws IllegalArgumentException if the if the given pattern is invalid
*/
public void setTimeStampFormat(String pstrTSFmt)
{
if (!checkDateTimeFormat(pstrTSFmt))
throw new IllegalArgumentException("The specified timestamp pattern is invalid!");
this.mstrTimeStampFmt = pstrTSFmt;
}
 
/*------------------------------------------------------------------------------
* Public methods
------------------------------------------------------------------------------*/
public int getTotalSections()
{
return this.mhmapSections.size();
}
 
/**
* Returns a string array containing names of all sections in INI file.
* @return the string array of section names
*/
public String[] getAllSectionNames()
{
int iCntr = 0;
Iterator iter = null;
String[] arrRet = null;
 
try
{
if (this.mhmapSections.size() > 0)
{
arrRet = new String[this.mhmapSections.size()];
for (iter = this.mhmapSections.keySet().iterator();;iter.hasNext())
{
arrRet[iCntr] = (String) iter.next();
iCntr++;
}
}
}
catch (NoSuchElementException NSEExIgnore)
{
}
finally
{
if (iter != null) iter = null;
}
return arrRet;
}
 
/**
* Returns a string array containing names of all the properties under specified section.
* @param pstrSection the name of the section for which names of properties is to be retrieved.
* @return the string array of property names.
*/
public String[] getPropertyNames(String pstrSection)
{
String[] arrRet = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
arrRet = objSec.getPropNames();
objSec = null;
}
return arrRet;
}
 
/**
* Returns a map containing all the properties under specified section.
* @param pstrSection the name of the section for which properties are to be retrieved.
* @return the map of properties.
*/
public Map getProperties(String pstrSection)
{
Map hmRet = null;
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
hmRet = objSec.getProperties();
objSec = null;
}
return hmRet;
}
 
/**
* Removed specified property from the specified section. If the specified
* section or the property does not exist, does nothing.
* @param pstrSection the section name.
* @param pstrProp the name of the property to be removed.
*/
public void removeProperty(String pstrSection, String pstrProp)
{
INISection objSec = null;
 
objSec = (INISection) this.mhmapSections.get(pstrSection);
if (objSec != null)
{
objSec.removeProperty(pstrProp);
objSec = null;
}
}
 
/**
* Removes the specified section if one exists, otherwise does nothing.
* @param pstrSection the name of the section to be removed.
*/
public void removeSection(String pstrSection)
{
if (this.mhmapSections.containsKey(pstrSection))
this.mhmapSections.remove(pstrSection);
}
 
/**
* Flush changes back to the disk file. If the disk file does not exists then
* creates the new one.
*/
public boolean save()
{
boolean blnRet = false;
File objFile = null;
String strName = null;
String strTemp = null;
Iterator itrSec = null;
INISection objSec = null;
FileWriter objWriter = null;
 
try
{
if (this.mhmapSections.size() == 0) return false;
objFile = new File(this.mstrFile);
if (objFile.exists()) objFile.delete();
objWriter = new FileWriter(objFile);
itrSec = this.mhmapSections.keySet().iterator();
while (itrSec.hasNext())
{
strName = (String) itrSec.next();
objSec = (INISection) this.mhmapSections.get(strName);
strTemp = objSec.toString();
objWriter.write(strTemp);
objWriter.write("\r\n");
objSec = null;
}
blnRet = true;
}
catch (IOException IOExIgnore)
{
}
finally
{
if (objWriter != null)
{
closeWriter(objWriter);
objWriter = null;
}
if (objFile != null) objFile = null;
if (itrSec != null) itrSec = null;
}
return blnRet;
}
 
/*------------------------------------------------------------------------------
* Helper functions
*----------------------------------------------------------------------------*/
/**
* Procedure to read environment variables.
* Thanx to http://www.rgagnon.com/howto.html for this implementation.
*/
private Properties getEnvVars()
{
Process p = null;
Properties envVars = new Properties();
 
try
{
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
 
if (OS.indexOf("windows 9") > -1)
{
p = r.exec("command.com /c set");
}
else if ((OS.indexOf("nt") > -1) ||
(OS.indexOf("windows 2000") > -1) ||
(OS.indexOf("windows xp") > -1))
{
p = r.exec("cmd.exe /c set");
}
else
{
// our last hope, we assume Unix (thanks to H. Ware for the fix)
p = r.exec("env");
}
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = br.readLine()) != null)
{
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
}
}
catch (Exception ExIgnore)
{
}
return envVars;
}
 
/**
* Helper function to check the date time formats.
* @param pstrDtFmt the date time format string to be checked.
* @return true for valid date/time format, false otherwise.
*/
private boolean checkDateTimeFormat(String pstrDtFmt)
{
boolean blnRet = false;
DateFormat objFmt = null;
 
try
{
objFmt = new SimpleDateFormat(pstrDtFmt);
blnRet = true;
}
catch (NullPointerException NPExIgnore)
{
}
catch (IllegalArgumentException IAExIgnore)
{
}
finally
{
if (objFmt != null) objFmt = null;
}
return blnRet;
}
 
/**
* Reads the INI file and load its contentens into a section collection after
* parsing the file line by line.
*/
private void loadFile()
{
int iPos = -1;
String strLine = null;
String strSection = null;
String strRemarks = null;
BufferedReader objBRdr = null;
FileReader objFRdr = null;
INISection objSec = null;
 
try
{
objFRdr = new FileReader(this.mstrFile);
if (objFRdr != null)
{
objBRdr = new BufferedReader(objFRdr);
if (objBRdr != null)
{
while (objBRdr.ready())
{
iPos = -1;
strLine = null;
strLine = objBRdr.readLine().trim();
if (strLine == null)
{
}
else if (strLine.length() == 0)
{
}
else if (strLine.substring(0, 1).equals(";"))
{
if (strRemarks == null)
strRemarks = strLine.substring(1);
else if (strRemarks.length() == 0)
strRemarks = strLine.substring(1);
else
strRemarks = strRemarks + "\r\n" + strLine.substring(1);
}
else if (strLine.startsWith("[") && strLine.endsWith("]"))
{
// Section start reached create new section
if (objSec != null)
this.mhmapSections.put(strSection.trim(), objSec);
objSec = null;
strSection = strLine.substring(1, strLine.length() - 1);
objSec = new INISection(strSection.trim(), strRemarks);
strRemarks = null;
}
else if ((iPos = strLine.indexOf("=")) > 0 && objSec != null)
{
// read the key value pair 012345=789
objSec.setProperty(strLine.substring(0, iPos).trim(),
strLine.substring(iPos + 1).trim(),
strRemarks);
strRemarks = null;
}
}
if (objSec != null)
this.mhmapSections.put(strSection.trim(), objSec);
this.mblnLoaded = true;
}
}
}
catch (FileNotFoundException FNFExIgnore)
{
this.mhmapSections.clear();
}
catch (IOException IOExIgnore)
{
this.mhmapSections.clear();
}
catch (NullPointerException NPExIgnore)
{
this.mhmapSections.clear();
}
finally
{
if (objBRdr != null)
{
closeReader(objBRdr);
objBRdr = null;
}
if (objFRdr != null)
{
closeReader(objFRdr);
objFRdr = null;
}
if (objSec != null) objSec = null;
}
}
 
/**
* Helper function to close a reader object.
* @param pobjRdr the reader to be closed.
*/
private void closeReader(Reader pobjRdr)
{
if (pobjRdr == null) return;
try
{
pobjRdr.close();
}
catch (IOException IOExIgnore)
{
}
}
 
/**
* Helper function to close a writer object.
* @param pobjWriter the writer to be closed.
*/
private void closeWriter(Writer pobjWriter)
{
if (pobjWriter == null) return;
 
try
{
pobjWriter.close();
}
catch (IOException IOExIgnore)
{
}
}
/**
* Helper method to check the existance of a file.
* @param the full path and name of the file to be checked.
* @return true if file exists, false otherwise.
*/
private boolean checkFile(String pstrFile)
{
boolean blnRet = false;
File objFile = null;
 
try
{
objFile = new File(pstrFile);
blnRet = (objFile.exists() && objFile.isFile());
}
catch (Exception e)
{
blnRet = false;
}
finally
{
if (objFile != null) objFile = null;
}
return blnRet;
}
 
/**
* Converts a java.util.date into String
* @param pd Date that need to be converted to String
* @param pstrFmt The date format pattern.
* @return String
*/
private String utilDateToStr(Date pdt, String pstrFmt)
{
String strRet = null;
SimpleDateFormat dtFmt = null;
 
try
{
dtFmt = new SimpleDateFormat(pstrFmt);
strRet = dtFmt.format(pdt);
}
catch (Exception e)
{
strRet = null;
}
finally
{
if (dtFmt != null) dtFmt = null;
}
return strRet;
}
 
/**
* Converts the given sql timestamp object to a string representation. The format
* to be used is to be obtained from the configuration file.
*
* @param pobjTS the sql timestamp object to be converted.
* @param pblnGMT If true formats the string using GMT timezone
* otherwise using local timezone.
* @return the formatted string representation of the timestamp.
*/
private String timeToStr(Timestamp pobjTS, String pstrFmt)
{
String strRet = null;
SimpleDateFormat dtFmt = null;
 
try
{
dtFmt = new SimpleDateFormat(pstrFmt);
strRet = dtFmt.format(pobjTS);
}
catch (IllegalArgumentException iae)
{
strRet = "";
}
catch (NullPointerException npe)
{
strRet = "";
}
finally
{
if (dtFmt != null) dtFmt = null;
}
return strRet;
}
 
/**
* This function deletes the remark characters ';' from source string
* @param pstrSrc the source string
* @return the converted string
*/
private String delRemChars(String pstrSrc)
{
int intPos = 0;
 
if (pstrSrc == null) return null;
while ((intPos = pstrSrc.indexOf(";")) >= 0)
{
if (intPos == 0)
pstrSrc = pstrSrc.substring(intPos + 1);
else if (intPos > 0)
pstrSrc = pstrSrc.substring(0, intPos) + pstrSrc.substring(intPos + 1);
}
return pstrSrc;
}
 
/**
* This function adds a remark character ';' in source string.
* @param pstrSrc source string
* @return converted string.
*/
private String addRemChars(String pstrSrc)
{
int intLen = 2;
int intPos = 0;
int intPrev = 0;
 
String strLeft = null;
String strRight = null;
 
if (pstrSrc == null) return null;
while (intPos >= 0)
{
intLen = 2;
intPos = pstrSrc.indexOf("\r\n", intPrev);
if (intPos < 0)
{
intLen = 1;
intPos = pstrSrc.indexOf("\n", intPrev);
if (intPos < 0) intPos = pstrSrc.indexOf("\r", intPrev);
}
if (intPos == 0)
{
pstrSrc = ";\r\n" + pstrSrc.substring(intPos + intLen);
intPrev = intPos + intLen + 1;
}
else if (intPos > 0)
{
strLeft = pstrSrc.substring(0, intPos);
strRight = pstrSrc.substring(intPos + intLen);
if (strRight == null)
pstrSrc = strLeft;
else if (strRight.length() == 0)
pstrSrc = strLeft;
else
pstrSrc = strLeft + "\r\n;" + strRight;
intPrev = intPos + intLen + 1;
}
}
if (!pstrSrc.substring(0, 1).equals(";"))
pstrSrc = ";" + pstrSrc;
pstrSrc = pstrSrc + "\r\n";
return pstrSrc;
}
/*------------------------------------------------------------------------------
* Main entry point to test the functionality.
*----------------------------------------------------------------------------*/
/**
* The main entry point for testing.
* @param pstrArgs the command line arguments array if any.
*/
public static void main(String[] pstrArgs)
{
INIFile objINI = null;
String strFile = null;
 
if (pstrArgs.length == 0) return;
 
strFile = pstrArgs[0];
// Following call will load the strFile if one exists.
objINI = new INIFile(strFile);
 
// objINI.addSection("QADatabase", "QA database connection details\nUsed for QA Testing");
// objINI.setStringProperty("QADatabase", "SID", "ORCL", null);
// objINI.setStringProperty("QADatabase", "UserId", "System", null);
// objINI.setStringProperty("QADatabase", "Password", "Manager", null);
// objINI.setStringProperty("QADatabase", "HostName", "DBServer", null);
// objINI.setIntegerProperty("QADatabase", "Port", 1521, null);
// objINI.setStringProperty("QADatabase", "OracleHome", "%ORACLE_HOME%", null);
//
// objINI.setSectionComments("Folders", "Directories where generated files are stored");
objINI.setStringProperty("Folders", "folder1", "G:\\Temp", null);
objINI.setStringProperty("Folders", "folder2", "G:\\Temp\\Backup", null);
 
// Save changes back to strFile.
objINI.save();
objINI = null;
}
 
/*------------------------------------------------------------------------------
* Private class representing the INI Section.
*----------------------------------------------------------------------------*/
/**
* Class to represent the individual ini file section.
* @author Prasad P. Khandekar
* @version 1.0
* @since 1.0
*/
private class INISection
{
/** Variable to hold any comments associated with this section */
private String mstrComment;
 
/** Variable to hold the section name. */
private String mstrName;
/** Variable to hold the properties falling under this section. */
private LinkedHashMap mhmapProps;
 
/**
* Construct a new section object identified by the name specified in
* parameter.
* @param pstrSection The new sections name.
*/
public INISection(String pstrSection)
{
this.mstrName = pstrSection;
this.mhmapProps = new LinkedHashMap();
}
 
/**
* Construct a new section object identified by the name specified in
* parameter and associated comments.
* @param pstrSection The new sections name.
* @param pstrComments the comments associated with this section.
*/
public INISection(String pstrSection, String pstrComments)
{
this.mstrName = pstrSection;
this.mstrComment = delRemChars(pstrComments);
this.mhmapProps = new LinkedHashMap();
}
/**
* Returns any comments associated with this section
* @return the comments
*/
public String getSecComments()
{
return this.mstrComment;
}
 
/**
* Returns name of the section.
* @return Name of the section.
*/
public String getSecName()
{
return this.mstrName;
}
 
/**
* Sets the comments associated with this section.
* @param pstrComments the comments
*/
public void setSecComments(String pstrComments)
{
this.mstrComment = delRemChars(pstrComments);
}
 
/**
* Sets the section name.
* @param pstrName the section name.
*/
public void setSecName(String pstrName)
{
this.mstrName = pstrName;
}
 
/**
* Removes specified property value from this section.
* @param pstrProp The name of the property to be removed.
*/
public void removeProperty(String pstrProp)
{
if (this.mhmapProps.containsKey(pstrProp))
this.mhmapProps.remove(pstrProp);
}
 
/**
* Creates or modifies the specified property value.
* @param pstrProp The name of the property to be created or modified.
* @param pstrValue The new value for the property.
* @param pstrComments the associated comments
*/
public void setProperty(String pstrProp, String pstrValue, String pstrComments)
{
this.mhmapProps.put(pstrProp, new INIProperty(pstrProp, pstrValue, pstrComments));
}
 
/**
* Returns a map of all properties.
* @return a map of all properties
*/
public Map getProperties()
{
return Collections.unmodifiableMap(this.mhmapProps);
}
 
/**
* Returns a string array containing names of all the properties under
* this section.
* @return the string array of property names.
*/
public String[] getPropNames()
{
int iCntr = 0;
String[] arrRet = null;
Iterator iter = null;
 
try
{
if (this.mhmapProps.size() > 0)
{
arrRet = new String[this.mhmapProps.size()];
for (iter = this.mhmapProps.keySet().iterator();iter.hasNext();)
{
arrRet[iCntr] = (String) iter.next();
iCntr++;
}
}
}
catch (NoSuchElementException NSEExIgnore)
{
arrRet = null;
}
return arrRet;
}
 
/**
* Returns underlying value of the specified property.
* @param pstrProp the property whose underlying value is to be etrieved.
* @return the property value.
*/
public INIProperty getProperty(String pstrProp)
{
INIProperty objRet = null;
 
if (this.mhmapProps.containsKey(pstrProp))
objRet = (INIProperty) this.mhmapProps.get(pstrProp);
return objRet;
}
 
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
Set colKeys = null;
String strRet = "";
Iterator iter = null;
INIProperty objProp = null;
StringBuffer objBuf = new StringBuffer();
 
if (this.mstrComment != null)
objBuf.append(addRemChars(this.mstrComment));
objBuf.append("[" + this.mstrName + "]\r\n");
colKeys = this.mhmapProps.keySet();
if (colKeys != null)
{
iter = colKeys.iterator();
if (iter != null)
{
while (iter.hasNext())
{
objProp = (INIProperty) this.mhmapProps.get(iter.next());
objBuf.append(objProp.toString());
objBuf.append("\r\n");
objProp = null;
}
}
}
strRet = objBuf.toString();
 
objBuf = null;
iter = null;
colKeys = null;
return strRet;
}
}
 
/*------------------------------------------------------------------------------
* Private class representing the INI Property.
*----------------------------------------------------------------------------*/
/**
* This class represents a key value pair called property in an INI file.
* @author Prasad P. Khandekar
* @version 1.0
* @since 1.0
*/
private class INIProperty
{
/** Variable to hold name of this property */
private String mstrName;
/** Variable to hold value of this property */
private String mstrValue;
/** Variable to hold comments associated with this property */
private String mstrComments;
 
/**
* Constructor
* @param pstrName the name of this property.
* @param pstrValue the value of this property.
*/
public INIProperty(String pstrName, String pstrValue)
{
this.mstrName = pstrName;
this.mstrValue = pstrValue;
}
 
/**
* Constructor
* @param pstrName the name of this property.
* @param pstrValue the value of this property.
* @param pstrComments the comments associated with this property.
*/
public INIProperty(String pstrName, String pstrValue, String pstrComments)
{
this.mstrName = pstrName;
this.mstrValue = pstrValue;
this.mstrComments = delRemChars(pstrComments);
}
 
/**
* Returns the string identifier (key part) of this property.
* @return the string identifier of this property.
*/
public String getPropName()
{
return this.mstrName;
}
 
/**
* Returns value of this property. If value contains a reference to
* environment avriable then this reference is replaced by actual value
* before the value is returned.
* @return the value of this property.
*/
public String getPropValue()
{
int intStart = 0;
int intEnd = 0;
String strVal = null;
String strVar = null;
String strRet = null;
 
strRet = this.mstrValue;
intStart = strRet.indexOf("%");
if (intStart >= 0)
{
intEnd = strRet.indexOf("%", intStart + 1);
strVar = strRet.substring(intStart + 1, intEnd);
strVal = mpropEnv.getProperty(strVar);
if (strVal != null)
{
strRet = strRet.substring(0, intStart) + strVal +
strRet.substring(intEnd + 1);
}
}
return strRet;
}
 
/**
* Returns comments associated with this property.
* @return the associated comments if any.
*/
public String getPropComments()
{
return this.mstrComments;
}
 
/**
* Sets the string identifier (key part) of a property
* @param pstrName the string identifier of a property
*/
public void setPropName(String pstrName)
{
this.mstrName = pstrName;
}
 
/**
* Sets the property value
* @param pstrValue the value for the property
*/
public void setPropValue(String pstrValue)
{
this.mstrValue = pstrValue;
}
 
/**
* Sets the comments for a property
* @param pstrComments the comments
*/
public void setPropComments(String pstrComments)
{
this.mstrComments = delRemChars(pstrComments);
}
 
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
String strRet = "";
 
if (this.mstrComments != null)
strRet = addRemChars(mstrComments);
strRet = strRet + this.mstrName + " = " + this.mstrValue;
return strRet;
}
}
}
/src/org/geoscope/JSpec/Seed_File.java
New file
0,0 → 1,5
package org.geoscope.JSpec;
 
public class Seed_File {
 
}
/src/org/geoscope/JSpec/test.java
New file
0,0 → 1,24
package org.geoscope.JSpec;
 
import java.io.*;
 
public class test {
 
 
 
 
public static void main(String args[]) throws Exception {
final String sdrsplit_location ="/opt/bruit/spec3/sdrsplit";
final String ms2sac_location="/opt/bruit/spec3/ms2sac";
final String sac2000_location="/opt/bruit/spec3/sac/bin/sac";
final String sacaux_location="/opt/bruit/spec3/sac/aux/";
final String pre_pspecsac_jour_location="/opt/bruit/spec3/pre_pspecsac_jour";
final String pspecsac_jour_location="/opt/bruit/spec3/pspecsac_jour";
final String leapseconds_location="/opt/bruit/spec3/leapseconds";
 
 
 
 
}
}
/src/org/geoscope/JSpec/Utils.java
New file
0,0 → 1,41
package org.geoscope.JSpec;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
 
public class Utils {
 
public static void copy_file(String initial_path, String initial_name, String to_path, String to_name) throws IOException{
FileChannel inChannel = new
FileInputStream((initial_path+'/'+initial_name)).getChannel();
 
FileChannel outChannel = new
FileOutputStream( (to_path+'/'+to_name)).getChannel();
try {
inChannel.transferTo(0, inChannel.size(),outChannel);
}
 
finally {
if (inChannel != null) inChannel.close();
if (outChannel != null) outChannel.close();
}
}
 
 
public static String padZeroLeft(String input, int final_size)
{
String output=input;
while (output.length()< final_size) {
output="0"+output;
}
return output;
}
public static void main(String[] args) throws IOException {
 
}
 
}
/src/org/geoscope/JSpec/References.java
New file
0,0 → 1,404
package org.geoscope.JSpec;
 
import java.io.File;
 
public class References {
private String legend;
private String location_code;
private String sdrsplit_location;
private String ms2sac_location;
private String sac2000_location;
private String sacaux_location;
private String pre_pspecsac_jour_location;
private String pspecsac_jour_location;
private String leapseconds_location;
private String rdseed_location;
private String dataless_initial_path;
private String refres_location;
private String octave_location;
private String fix_spec_location;
private String decime_spectre_location;
private String gnuplot_location;
private String qedit_location;
private String save_png_dir;
private String save_png_file_name;
private String tmp_dir_location;
private String lnm_location;
private String hnm_location;
public String getTmp_dir_location() {
return tmp_dir_location;
}
public void setTmp_dir_location(String tmp_dir_location) {
this.tmp_dir_location = tmp_dir_location;
}
public String getLnm_location() {
return lnm_location;
}
public void setLnm_location(String lnm_location) {
this.lnm_location = lnm_location;
}
public String getHnm_location() {
return hnm_location;
}
public void setHnm_location(String hnm_location) {
this.hnm_location = hnm_location;
}
 
 
public String getLegend() {
return legend;
}
public void setLegend(String legend) {
this.legend = legend;
}
public String getLocation_code() {
return location_code;
}
public void setLocation_code(String location_code) {
this.location_code = location_code;
}
public String getSdrsplit_location() {
return sdrsplit_location;
}
public void setSdrsplit_location(String sdrsplit_location) {
this.sdrsplit_location = sdrsplit_location;
}
public String getMs2sac_location() {
return ms2sac_location;
}
public void setMs2sac_location(String ms2sac_location) {
this.ms2sac_location = ms2sac_location;
}
public String getSac2000_location() {
return sac2000_location;
}
public void setSac2000_location(String sac2000_location) {
this.sac2000_location = sac2000_location;
}
public String getSacaux_location() {
return sacaux_location;
}
public void setSacaux_location(String sacaux_location) {
this.sacaux_location = sacaux_location;
}
public String getPre_pspecsac_jour_location() {
return pre_pspecsac_jour_location;
}
public void setPre_pspecsac_jour_location(String pre_pspecsac_jour_location) {
this.pre_pspecsac_jour_location = pre_pspecsac_jour_location;
}
public String getPspecsac_jour_location() {
return pspecsac_jour_location;
}
public void setPspecsac_jour_location(String pspecsac_jour_location) {
this.pspecsac_jour_location = pspecsac_jour_location;
}
public String getLeapseconds_location() {
return leapseconds_location;
}
public void setLeapseconds_location(String leapseconds_location) {
this.leapseconds_location = leapseconds_location;
}
public String getRdseed_location() {
return rdseed_location;
}
public void setRdseed_location(String rdseed_location) {
this.rdseed_location = rdseed_location;
}
public String getDataless_initial_path() {
return dataless_initial_path;
}
public void setDataless_initial_path(String dataless_initial_path) {
this.dataless_initial_path = dataless_initial_path;
}
public String getRefres_location() {
return refres_location;
}
public void setRefres_location(String refres_location) {
this.refres_location = refres_location;
}
public String getOctave_location() {
return octave_location;
}
public void setOctave_location(String octave_location) {
this.octave_location = octave_location;
}
public String getFix_spec_location() {
return fix_spec_location;
}
public void setFix_spec_location(String fix_spec_location) {
this.fix_spec_location = fix_spec_location;
}
public String getDecime_spectre_location() {
return decime_spectre_location;
}
public void setDecime_spectre_location(String decime_spectre_location) {
this.decime_spectre_location = decime_spectre_location;
}
public String getGnuplot_location() {
return gnuplot_location;
}
public void setGnuplot_location(String gnuplot_location) {
this.gnuplot_location = gnuplot_location;
}
public String getQedit_location() {
return qedit_location;
}
public void setQedit_location(String qedit_location) {
this.qedit_location = qedit_location;
}
public String getSave_png_dir() {
return save_png_dir;
}
public void setSave_png_dir(String save_png_dir) {
this.save_png_dir = save_png_dir;
}
public String getSave_png_file_name() {
return save_png_file_name;
}
public void setSave_png_file_name(String save_png_file_name) {
this.save_png_file_name = save_png_file_name;
}
References(String jspec_ini,String save_png_dir,String save_png_file_name, String legende){
this.setLegend(legende);
if (!new File(save_png_dir).exists())
{
System.out.println("Le repertoire de sauvegarde :" + save_png_dir+" n existe pas");
System.exit(-1);
}
this.setSave_png_dir(save_png_dir);
this.setSave_png_file_name(save_png_file_name);
if (!this.getParameters(new File(jspec_ini))) {
System.out.println("Erreur avec le fichier des parametres");
System.exit(-1);
}
 
 
}
//public boolean getParameters(String path_ini_file_name, String ini_file_name) {
public boolean getParameters(File jspec_ini) {
 
if (!jspec_ini.exists())
{
System.out.println("Le fichier "+jspec_ini.getName() +" n existe pas....");
return false;
}
INIFile objINI = new INIFile(jspec_ini.getPath());
//System.out.println("Lecture du fichier de paramètres: " + jspec_ini.getPath());
 
this.setLeapseconds_location(objINI.getStringProperty("paths","leapseconds_location"));
if (this.getLeapseconds_location() == null) {
return false;
}
if (!new File(this.getLeapseconds_location()).exists())
{
System.out.println("Le fichier " + this.getLeapseconds_location()+" n existe pas");
return false;
 
}
this.setMs2sac_location(objINI.getStringProperty("paths","ms2sac_location"));
if (this.getMs2sac_location() == null) {
return false;
}
if (!new File(this.getMs2sac_location()).exists())
{
System.out.println("Le fichier " + this.getMs2sac_location()+" n existe pas");
return false;
 
 
}
 
this.setSac2000_location(objINI.getStringProperty("paths","sac2000_location"));
if (this.getSac2000_location() == null) {
return false;
}
if (!new File(this.getSac2000_location()).exists())
{
System.out.println("Le fichier " + this.getSac2000_location()+" n existe pas");
return false;
 
 
}
 
this.setSacaux_location(objINI.getStringProperty("paths",
"sacaux_location"));
if (this.getSacaux_location() == null) {
return false;
}
if (!new File(this.getSacaux_location()).exists())
{
System.out.println("Le fichier " + this.getSacaux_location()+" n existe pas");
return false;
 
}
this.setSdrsplit_location(objINI.getStringProperty("paths",
"sdrsplit_location"));
if (this.getSdrsplit_location() == null) {
return false;
}
if (!new File(this.getSdrsplit_location()).exists())
{
System.out.println("Le fichier " + this.getSdrsplit_location()+" n existe pas");
return false;
}
this.setMs2sac_location(objINI.getStringProperty("paths",
"ms2sac_location"));
if (this.getMs2sac_location() == null) {
return false;
}
if (!new File(this.getMs2sac_location()).exists())
{
System.out.println("Le fichier " + this.getMs2sac_location()+" n existe pas");
return false;
}
this.setPre_pspecsac_jour_location(objINI.getStringProperty("paths",
"pre_pspecsac_jour_location"));
if (this.getPre_pspecsac_jour_location() == null) {
return false;
}
if (!new File(this.getPre_pspecsac_jour_location()).exists())
{
System.out.println("Le fichier " + this.getPre_pspecsac_jour_location()+" n existe pas");
return false;
}
this.setPspecsac_jour_location(objINI.getStringProperty("paths",
"pspecsac_jour_location"));
if (this.getPspecsac_jour_location() == null) {
return false;
}
if (!new File(this.getPspecsac_jour_location()).exists())
{
System.out.println("Le fichier " + this.getPspecsac_jour_location()+" n existe pas");
return false;
}
this.setRdseed_location(objINI.getStringProperty("paths",
"rdseed_location"));
if (this.getRdseed_location() == null) {
return false;
}
if (!new File(this.getRdseed_location()).exists())
{
System.out.println("Le fichier " + this.getRdseed_location()+" n existe pas");
return false; }
this.setRefres_location(objINI.getStringProperty("paths",
"refres_location"));
if (this.getRefres_location() == null) {
return false;
}
if (!new File(this.getRefres_location()).exists())
{
System.out.println("Le fichier " + this.getRefres_location()+" n existe pas");
return false; }
this.setOctave_location(objINI.getStringProperty("paths",
"octave_location"));
if (this.getOctave_location() == null) {
return false;
}
if (!new File(this.getOctave_location()).exists())
{
System.out.println("Le fichier " + this.getOctave_location()+" n existe pas");
return false;
}
this.setFix_spec_location(objINI.getStringProperty("paths",
"fix_spec_location"));
if (this.getFix_spec_location() == null) {
return false;
}
if (!new File(this.getFix_spec_location()).exists())
{
System.out.println("Le fichier " + this.getFix_spec_location()+" n existe pas");
return false;
}
this.setDecime_spectre_location(objINI.getStringProperty("paths",
"decime_spectre_location"));
if (this.getDecime_spectre_location() == null) {
return false;
}
if (!new File(this.getDecime_spectre_location()).exists())
{
System.out.println("Le fichier " + this.getDecime_spectre_location()+" n existe pas");
return false;
}
this.setGnuplot_location(objINI.getStringProperty("paths",
"gnuplot_location"));
if (this.getGnuplot_location() == null) {
return false;
}
if (!new File(this.getGnuplot_location()).exists())
{
System.out.println("Le fichier " + this.getGnuplot_location()+" n existe pas");
return false;
}
this.setQedit_location(objINI.getStringProperty("paths",
"qedit_location"));
if (this.getQedit_location() == null) {
return false;
}
if (!new File(this.getQedit_location()).exists())
{
System.out.println("Le fichier " + this.getQedit_location()+" n existe pas");
return false;
}
this.setTmp_dir_location(objINI.getStringProperty("paths",
"tmp_dir_location"));
if (this.getTmp_dir_location() == null) {
return false;
}
if (!new File(this.getTmp_dir_location()).exists())
{
System.out.println("Le fichier " + this.getTmp_dir_location()+" n existe pas");
return false; }
this.setHnm_location(objINI.getStringProperty("paths",
"hnm_location"));
if (this.getHnm_location() == null) {
return false;
}
if (!new File(this.getHnm_location()).exists())
{
System.out.println("Le fichier " + this.getHnm_location()+" n existe pas");
return false;
}
this.setLnm_location(objINI.getStringProperty("paths",
"lnm_location"));
if (this.getLnm_location() == null) {
return false;
}
if (!new File(this.getLnm_location()).exists())
{
System.out.println("Le fichier " + this.getLnm_location()+" n existe pas");
return false;
}
 
return true;
 
}
 
 
}
/src/org/geoscope/JSpec/JSpec.ini
New file
0,0 → 1,15
[paths]
sdrsplit_location = /opt/bruit/spec3/sdrsplit
ms2sac_location = /opt/bruit/spec3/ms2sac
sac2000_location = /opt/bruit/spec3/sac/bin/sac
sacaux_location = /opt/bruit/spec3/sac/aux/
pre_pspecsac_jour_location = /opt/bruit/spec3/pre_pspecsac_jour
pspecsac_jour_location = /opt/bruit/spec3/pspecsac_jour
leapseconds_location = /opt/bruit/spec3/leapseconds
refres_location = /opt/bruit/spec3/refres
rdseed_location = /opt/passcal/bin/rdseed
octave_location = /usr/bin/octave
fix_spec_location = /opt/bruit/spec3/octave_geoscope_seb.m1
decime_spectre_location = /opt/bruit/spec3/decime_spectre_db
gnuplot_location = /usr/bin/gnuplot
qedit_location=/opt/passcal/bin/qedit
/src/org/geoscope/JSpec/JSpec.java
New file
0,0 → 1,268
package org.geoscope.JSpec;
 
//import java.awt.Frame;
//import javax.swing.JFileChooser;
 
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.FileWriter;
//import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
 
//import javax.swing.JOptionPane;
 
import com.martiansoftware.jsap.*;
 
 
 
 
public class JSpec {
private static References References;
public static void main(String[] args) throws Exception {
 
 
JSAP jsap = new JSAP();
 
FlaggedOption opt0 = new FlaggedOption("jspec.ini")
.setStringParser(JSAP.STRING_PARSER)
.setShortFlag('j')
.setLongFlag("jspec.ini")
.setAllowMultipleDeclarations(false)
.setRequired(true);
 
opt0.setHelp("The JSpec.ini file to use");
jsap.registerParameter(opt0);
 
FlaggedOption opt1 = new FlaggedOption("png_save_dir")
.setStringParser(JSAP.STRING_PARSER)
.setShortFlag('p')
.setLongFlag("png_save_dir")
.setAllowMultipleDeclarations(false)
.setRequired(true);
 
opt1.setHelp("The Directory to save the png");
jsap.registerParameter(opt1);
 
 
FlaggedOption opt2 = new FlaggedOption("legende")
.setStringParser(JSAP.STRING_PARSER)
.setShortFlag('l')
.setLongFlag("legende")
.setAllowMultipleDeclarations(false)
.setRequired(false);
 
opt2.setHelp("The legend of the spectrum");
jsap.registerParameter(opt2);
 
 
FlaggedOption opt3 = new FlaggedOption("dataless")
.setStringParser(JSAP.STRING_PARSER)
.setShortFlag('d')
.setLongFlag("dataless")
.setAllowMultipleDeclarations(true)
.setRequired(true);
 
opt3.setHelp("The dataless to use");
jsap.registerParameter(opt3);
 
 
UnflaggedOption opt4 = new UnflaggedOption("miniseed_1")
.setStringParser(JSAP.STRING_PARSER)
.setList(true)
.setListSeparator(',')
.setRequired(true);
 
opt4.setHelp("The miniseed files to use for the first group");
jsap.registerParameter(opt4);
 
 
UnflaggedOption opt5 = new UnflaggedOption("miniseed_2")
.setStringParser(JSAP.STRING_PARSER)
.setDefault("")
.setList(true)
.setListSeparator(',')
.setRequired(false);
 
opt5.setHelp("The miniseed files to use for the second group");
jsap.registerParameter(opt5);
 
 
 
 
JSAPResult config = jsap.parse(args);
if (!config.success()) {
 
System.err.println();
 
// print out specific error messages describing the problems
// with the command line, THEN print usage, THEN print full
// help. This is called "beating the user with a clue stick."
for (java.util.Iterator errs = config.getErrorMessageIterator();
errs.hasNext();) {
System.err.println("Error: " + errs.next());
}
 
System.err.println();
System.err.println("Usage: java "
+ JSpec.class.getName());
System.err.println(" "
+ jsap.getUsage());
System.err.println();
System.err.println(jsap.getHelp());
System.exit(1);
}
 
 
 
// On a donner tout les bons arguments
 
// Ce test sera a priori toujours vrai car 1 dataless est necessaire au bon fonctionnement...
if (config.getStringArray("dataless").length==1) {
// les infos du premier groupe
System.out.println("dataless groupe 1");
System.out.println(config.getStringArray("dataless")[0]);
 
System.out.println("Fichiers miniseed groupe 1");
 
String[] miniseed_1 = config.getStringArray("miniseed_1");
System.out.println("On va traiter "+miniseed_1.length+" fichiers");
 
MSeed_Group mseed_group =new MSeed_Group();
 
References= new References(config.getString("jspec.ini"),config.getString("png_save_dir"),config.getString("legende"),config.getString("legende"));
 
 
//ArrayList<MSeed_File> hash_miniseed = new ArrayList<MSeed_File>();
 
// MSeed_File[] tablo_Mseed_files=null;
 
if (miniseed_1.length == 1)
{//Dans le cas d'un seul fichier, on ne fait pas de moyenne
//MSeed_File mseed_file= new MSeed_File(new File(miniseed_1[0]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), new File(config.getString("jspec.ini")).getAbsoluteFile(), new File(config.getString("png_save_dir")).getAbsoluteFile().getPath(),config.getString("legende") );
MSeed_File mseed_file = new MSeed_File(new File(miniseed_1[0]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), References);
 
mseed_file.parse_mseed();
mseed_file.to_sac();
mseed_file.read_dataless_3();
 
mseed_file.spec();
 
mseed_file.plot_spec();
mseed_file.clean();
//System.out.println("on a fini");
 
}
else
{
 
// On est dans le cas d'un groupe de plus d'un fichier miniseed.
 
int nb_fichiers_miniseed=miniseed_1.length;
 
for (int j = 0; j < nb_fichiers_miniseed; ++j) {
// On va traiter le fichier machin
System.out.println("Debut de traitement du fichier :"+j+" /"+nb_fichiers_miniseed);
 
MSeed_File Mseed_tmp = new MSeed_File(new File(miniseed_1[j]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), References);
Mseed_tmp.parse_mseed();
Mseed_tmp.to_sac();
Mseed_tmp.read_dataless_3();
Mseed_tmp.spec();
 
//On rajoute l'objet miniseed au hash
//hash_miniseed.add(Mseed_tmp);
mseed_group.add_MSeed_file(Mseed_tmp);
 
//test.plot_spec();
}
//moyenne_les_spectres_et_sauve(hash_miniseed);
 
// On va créer un instance de l'objet qui fait les moyennes et les graphes
ArrayList<MSeed_Group> liste_des_mseed_groupes= new ArrayList<MSeed_Group>();
liste_des_mseed_groupes.add(mseed_group);
Spec_Trace traceur = new Spec_Trace(liste_des_mseed_groupes, References);
traceur.do_collections_group_means();
traceur.do_graphs();
 
 
// maintenant que les calculs ont été fait, on peut virer les fichiers temporaires
 
for ( MSeed_Group tmp_mseed_group : liste_des_mseed_groupes) {
tmp_mseed_group.clean();
}
 
}
}
else if (config.getStringArray("dataless").length==2) {
 
// les infos du premier groupe
System.out.println("dataless groupe 1");
System.out.println(config.getStringArray("dataless")[0]);
 
System.out.println("Fichiers miniseed groupe 1");
String[] miniseed_1 = config.getStringArray("miniseed_1");
int nb_fichiers_miniseed_1=miniseed_1.length;
for (int j = 0; j < nb_fichiers_miniseed_1; ++j) {
System.out.println(miniseed_1[j]);
}
 
// les infos du deuxieme groupe
System.out.println("dataless groupe 2");
System.out.println(config.getStringArray("dataless")[1]);
 
System.out.println("Fichiers miniseed groupe 2");
String[] miniseed_2 = config.getStringArray("miniseed_2");
 
int nb_fichiers_miniseed_2=miniseed_2.length;
 
for (int j = 0; j < nb_fichiers_miniseed_2; ++j) {
System.out.println(miniseed_2[j]);
}
}
else if (config.getStringArray("dataless").length==3) {
//On est dans le cas de trois groupes de fichiers avec 3 dataless
}
 
 
//System.err.println("Usage: JSpec [-legende \"legend of the graph\"] -png_save_dir png_save_directory -jspec.ini jspec_ini_file -dataless dataless_file -miniseed miniseed_file");
 
 
 
 
 
// MSeed_File test = new MSeed_File(new File(miniseed_string).getAbsoluteFile(),new File(dataless_string).getAbsoluteFile(), new File(jspec_ini_string).getAbsoluteFile(), new File(png_save_dir_string).getAbsoluteFile().getPath(),legende_string );
//
//
// // test.get_location_code_and_station_name();
// //
// // if (!test.is_location_code()) {
// // System.out.println("Il va falloir mettre un location code");
// // }
//
// test.parse_mseed();
// test.to_sac();
// test.read_dataless_3();
//
// test.spec();
// test.plot_spec();
// test.clean();
// System.exit(0);
 
}
 
 
 
 
}
/src/org/geoscope/JSpec/Filter.java
New file
0,0 → 1,35
package org.geoscope.JSpec;
 
import java.io.File;
import java.io.FilenameFilter;
public class Filter implements FilenameFilter {
 
protected String pattern;
 
public Filter (String str) {
pattern = str;
}
 
public boolean accept (File dir, String name) {
// return name.toLowerCase().endsWith(pattern.toLowerCase());
return name.contains(pattern);
}
 
public static void main (String args[]) {
 
if (args.length != 1) {
System.err.println ("usage: java Filter ex. java Filter java");
return;
}
 
Filter nf = new Filter (args[0]);
 
// current directory
File dir = new File (".");
String[] strs = dir.list(nf);
 
for (int i = 0; i < strs.length; i++) {
System.out.println (strs[i]);
}
}
}
/src/org/geoscope/JSpec/JSAP-2.1.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/src/org/geoscope/JSpec/Spec_Trace.java
New file
0,0 → 1,198
package org.geoscope.JSpec;
 
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
//import java.util.Collection;
 
 
// cette classe trace les spectres des collection de collection de Mseed_Files donnees en input avec gnuplot dans un premier temps
// par la suite tout se fera en java
 
public class Spec_Trace {
private ArrayList<MSeed_Group> collection_of_MSeed_group;
private References References;
 
public Spec_Trace(ArrayList<MSeed_Group> mseedgroup__collection_input,References references) {
this.collection_of_MSeed_group = mseedgroup__collection_input;
this.References =references;
}
 
 
public void do_collections_group_means() throws Exception{
 
// On va parcourir la collection de Mseed_group
//Et pour chaque mseed_group, on fait la moyenne des spectres de chaque groupe
 
for (MSeed_Group tmp_mseed_group : collection_of_MSeed_group) {
// Pour chaque group de Mseed_file, on va faire la moyenne des canaux
tmp_mseed_group.do_canaux_mean();
}
 
}
 
public void do_graphs(){
 
// On commence avec le cas d'un seul group...
if(this.collection_of_MSeed_group.size()==1){
 
try {
 
Runtime r = Runtime.getRuntime();
 
Process p =r.exec(this.References.getGnuplot_location());
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
// on prepare la mise en page de gnuplot
 
out.writeBytes("set logscale x \n");
out.flush();
 
out.writeBytes("set grid \n");
out.flush();
 
out.writeBytes("set title \"" + this.References.getLegend() + "\" \n");
out.flush();
 
// premiere_courbe sert à gere le pb de plot et replot. on fait
// "plot [...]" avec la pemiere courbe et replot avec les
// suivantes...
int premiere_courbe = 0;
String plot = "plot [0.1:10000] [-200:-40] \"";
String replot = "replot \"";
 
// z_nb_legend sert a n'écrire la legende que pour le 1er fichier
// tracé, dans le cas ou il y a LH et BH..
int Z_nb_legend = 0;
 
//On recupere le premier groupe de mseed files
MSeed_Group mseed_group=this.collection_of_MSeed_group.get(0);
 
for (String nom_tmp: mseed_group.getZ_files()){
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (Z_nb_legend == 0)
out.writeBytes(" title \"Z\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 3 \n");
 
Z_nb_legend++;
premiere_courbe++;
}
out.flush();
 
int N_nb_legend = 0;
for (String nom_tmp: mseed_group.getN_files()){
 
 
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (N_nb_legend == 0)
out.writeBytes(" title \"N\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 1 \n");
 
N_nb_legend++;
premiere_courbe++;
 
}
out.flush();
 
int E_nb_legend = 0;
for (String nom_tmp: mseed_group.getE_files()){
 
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (E_nb_legend == 0)
out.writeBytes(" title \"E\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 2 \n");
 
E_nb_legend++;
premiere_courbe++;
 
}
out.flush();
 
out.writeBytes("replot \""+this.References.getHnm_location()+"\" linestyle 0 title \"hnm\" with lines\n");
out.flush();
 
out.writeBytes("replot \""+this.References.getLnm_location()+"\" linestyle 0 title \"lnm\" with lines\n");
out.flush();
 
out.writeBytes("show grid\n");
out.flush();
 
 
out.writeBytes("pause 1 \n");
out.flush();
 
out.writeBytes("set terminal png \n");
out.flush();
 
out.writeBytes("set size 1,1 \n");
out.flush();
 
out.writeBytes("replot \n");
out.flush();
 
 
//On cree le nom du fichier de sortie qui sera enregistre dans le repertoire courant
out.writeBytes("set output \""+this.References.getSave_png_dir()+ "/" +this.References.getSave_png_file_name()+".png\" \n");
out.flush();
 
 
out.writeBytes("set size 1,1 \n");
out.flush();
 
out.writeBytes("replot \n");
out.flush();
 
 
 
out.writeBytes("quit \n");
out.flush();
 
String line = null;
String line_err = null;
 
while (((line = Resultset.readLine()) != null)|| ((line_err = error.readLine()) != null)) {
// if (line !=null) System.out.println("stdout:"+line);
// if (line_err != null)
// System.out.println("stderr:" + line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
}
 
catch (Exception e) {
 
System.out.println("erreur gnuplot: " + e);
}
 
}
 
 
}
 
 
}
/src/org/geoscope/JSpec/MSeed_Group.java
New file
0,0 → 1,245
package org.geoscope.JSpec;
 
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
 
public class MSeed_Group {
 
private ArrayList<MSeed_File> mseedfile_collection;
 
private ArrayList<String> Z_files;
private ArrayList<String> N_files;
private ArrayList<String> E_files;
 
 
public ArrayList<String> getZ_files() {
return Z_files;
}
 
public ArrayList<String> getN_files() {
return N_files;
}
 
public ArrayList<String> getE_files() {
return E_files;
}
 
// Le constructeur qui ne fait rien... super !!!
MSeed_Group(){
mseedfile_collection = new ArrayList<MSeed_File>();
}
 
public void add_MSeed_file(MSeed_File mseed_file_input){
mseedfile_collection.add(mseed_file_input);
}
 
public void do_canaux_mean() throws Exception {
 
 
// On va faire des collections de tout les noms de fichiers par catégories
 
Collection<String> collection_canaux_BZ= new ArrayList<String>();
Collection<String> collection_canaux_BN= new ArrayList<String>();
Collection<String> collection_canaux_BE= new ArrayList<String>();
Collection<String> collection_canaux_LZ= new ArrayList<String>();
Collection<String> collection_canaux_LN= new ArrayList<String>();
Collection<String> collection_canaux_LE= new ArrayList<String>();
 
 
// On parcours tout les fichiers miniseed contenu dans ce group
 
 
for ( MSeed_File tmp_miniseed : this.mseedfile_collection){
 
// System.out.println("Que contient le fichier "+tmp_miniseed.getName());
 
//pour chacun des fichiers miniseed, on parcours ses canaux
 
for (Canal_File canal : tmp_miniseed.hash_set_canaux){
 
if ((canal.getChannel_0() == 'B')&&(canal.getChannel_2() == 'Z')) {
// System.out.println("canal BZ: "+canal.getFile_name_to_plot());
collection_canaux_BZ.add(canal.getFile_name_to_plot());
}
if ((canal.getChannel_0() == 'B')&&(canal.getChannel_2() == 'N')){
// System.out.println("canal BN: "+canal.getFile_name_to_plot());
collection_canaux_BN.add(canal.getFile_name_to_plot());
}
if ((canal.getChannel_0() == 'B')&&(canal.getChannel_2() == 'E')){
// System.out.println("canal BE: "+canal.getFile_name_to_plot());
collection_canaux_BE.add(canal.getFile_name_to_plot());
}
if ((canal.getChannel_0() == 'L')&&(canal.getChannel_2() == 'Z')){
// System.out.println("canal LZ: "+canal.getFile_name_to_plot());
collection_canaux_LZ.add(canal.getFile_name_to_plot());
}
if ((canal.getChannel_0() == 'L')&&(canal.getChannel_2() == 'N')) {
// System.out.println("canal LN: "+canal.getFile_name_to_plot());
collection_canaux_LN.add(canal.getFile_name_to_plot());
}
if ((canal.getChannel_0() == 'L')&&(canal.getChannel_2() == 'E')) {
// System.out.println("canal LE: "+canal.getFile_name_to_plot());
collection_canaux_LE.add(canal.getFile_name_to_plot());
}
}
}
 
 
// mean(collection_canaux_BZ,BZ_plot_file_location);
// mean(collection_canaux_BN,BN_plot_file_location);
// mean(collection_canaux_BE,BE_plot_file_location);
// mean(collection_canaux_LZ,LZ_plot_file_location);
// mean(collection_canaux_LN,LN_plot_file_location);
// mean(collection_canaux_LE,LE_plot_file_location);
//
// //On rassemble les canaux à tracer ensembles par composantes
// Z_files= new ArrayList<String>();
// N_files= new ArrayList<String>();
// E_files= new ArrayList<String>();
//
// for (String file_name:collection_canaux_BZ) { Z_files.add(file_name); }
// for (String file_name:collection_canaux_LZ) { Z_files.add(file_name); }
//
// for (String file_name:collection_canaux_BN) { N_files.add(file_name); }
// for (String file_name:collection_canaux_LN) { N_files.add(file_name); }
//
// for (String file_name:collection_canaux_BE) { E_files.add(file_name); }
// for (String file_name:collection_canaux_LE) { E_files.add(file_name); }
//
 
 
//On rassemble les canaux à tracer ensembles par composantes dans des ArralyList
Z_files= new ArrayList<String>();
N_files= new ArrayList<String>();
E_files= new ArrayList<String>();
 
mean(collection_canaux_BZ,Z_files);
mean(collection_canaux_BN,N_files);
mean(collection_canaux_BE,E_files);
mean(collection_canaux_LZ,Z_files);
mean(collection_canaux_LN,N_files);
mean(collection_canaux_LE,E_files);
 
// System.out.println("Les fichiers moyennes Z:");
// for (String nom_fichier : Z_files){System.out.println(nom_fichier);}
// System.out.println("Les fichiers moyennes N:");
// for (String nom_fichier : N_files){System.out.println(nom_fichier);}
// System.out.println("Les fichiers moyennes E:");
// for (String nom_fichier : E_files){System.out.println(nom_fichier);}
 
 
}
 
 
// cette fonction fait la moyenne des spectres contenus dans la collection de canaux passée en argument.
// Cette moyenne est stockée dans le premier fichier canal de la collection
 
private void mean(Collection<String> collection_canaux,ArrayList<String> collection_de_fichier) throws IOException {
 
 
InputStream input_stream;
 
int nb_canaux=collection_canaux.size();
 
// Si il y a au moins un canal, on fait la moyenne
// et si il y a seulement un canal ?
 
if (!collection_canaux.isEmpty()) {
 
ArrayList<Float> tab_freqs = new ArrayList<Float>();
ArrayList<Float> tab_amplitudes = new ArrayList<Float>();
 
String ligne;
String file_name_to_save="";
String splitligne[];
int compteur_ligne;
boolean premier_canal=true;
 
for (String nom_fichier:collection_canaux ) {
// On recupere le nom du fichier du premier canal. c'est dans ce fichier que l'on va stocker la moyenne
//On stocke aussi ce nom dans la liste des fichier de cette composante
 
if (premier_canal){
file_name_to_save=nom_fichier;
collection_de_fichier.add(nom_fichier);
// System.out.println("On va sauver les donnes dans: "+file_name_to_save);
}
 
// System.out.println("nom_fichier: "+nom_fichier);
input_stream = new FileInputStream(nom_fichier);
InputStreamReader ipsr=new InputStreamReader(input_stream);
BufferedReader br=new BufferedReader(ipsr);
compteur_ligne=0;
 
while ((ligne=br.readLine())!=null){
// System.out.print("ligne brute: "+ligne);
splitligne=ligne.split(" ++");
String frequence=splitligne[1];
//System.out.print("champ 1 #"+frequence+'#');
 
String amplitude=splitligne[2];
//System.out.print(" champ 2 #"+amplitude+"#\n");
// System.out.println("numero ligne: "+compteur_ligne + " frequence: "+frequence+ "amplitude:"+amplitude);
 
 
if (premier_canal) {
// System.out.println("premier fichier: "+nom_fichier+" ligne: "+compteur_ligne+ " frequence: "+frequence+ " amplitude:"+amplitude);
 
tab_freqs.add(Float.parseFloat(frequence));
tab_amplitudes.add(Float.parseFloat(amplitude));
 
}
else {
// System.out.println("autre fichier: "+nom_fichier+" ligne: "+compteur_ligne+ " frequence: "+frequence+ " amplitude:"+amplitude);
 
tab_freqs.set(compteur_ligne,Float.parseFloat(frequence));
tab_amplitudes.set(compteur_ligne,((Float)tab_amplitudes.get(compteur_ligne))+Float.parseFloat(amplitude));
}
//tab_amplitudes[compteur_ligne]+=Float.parseFloat(amplitude);
compteur_ligne++;
}
br.close();
premier_canal=false;
 
}
 
 
// il reste a divier les elements de tab_amplitudes par le nombre de fichier lus
// Et a réécrire dans le premier fichier ces valeurs
 
 
FileWriter outFile = new FileWriter(file_name_to_save);
PrintWriter out = new PrintWriter(outFile);
 
int taille_tab_freq=tab_freqs.size();
 
for (int i=0; i<(taille_tab_freq);i++){
tab_amplitudes.set(i,((Float)tab_amplitudes.get(i)/nb_canaux));
 
//System.out.println("freq: "+tab_freq[i]+" ampl: "+tab_amplitudes[i]);
out.write((Float)tab_freqs.get(i)+"\t\t"+(Float)tab_amplitudes.get(i)+'\n');
}
out.close();
}
 
 
 
}
 
public void clean() {
for ( MSeed_File tmp_miniseed : this.mseedfile_collection){
tmp_miniseed.clean();
}
}
 
}
/src/org/geoscope/JSpec/MSeed_File.java
New file
0,0 → 1,1464
package org.geoscope.JSpec;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
 
import java.util.Calendar;
import java.io.IOException;
 
import java.io.*;
 
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
 
 
 
import java.util.HashSet;
 
public class MSeed_File {
 
// fields
private String initial_path; // Initial path of the file
private String working_path; // working path
private String name; // Name of the file miniseed file
private String dataless_name; // Name of the dataless file
private String station_name; // Name of the station in 4 char_max
private String full_station_name; // Full name of the station
private String network_name;// Name of the network
private String start_year;
private String start_day;
private String comment;
private String location_code;
private String dataless_initial_path;
 
 
References References;
 
 
 
public String getDataless_name() {
return dataless_name;
}
 
public void setDataless_name(String dataless_name) {
this.dataless_name = dataless_name;
}
 
HashSet<Canal_File> hash_set_canaux;
 
 
public String getStart_day() {
return start_day;
}
 
public void setStart_day(String start_day) {
this.start_day = start_day;
}
 
public String getLocation_code() {
return location_code;
}
 
public String getFull_station_name() {
return full_station_name;
}
 
public void setFull_station_name(String full_station_name) {
this.full_station_name = full_station_name;
}
 
public void setLocation_code(String location_code) {
this.location_code = location_code;
}
 
public String getNetwork_name() {
return network_name;
}
 
public void setNetwork_name(String network_name) {
this.network_name = network_name;
}
 
public String getStart_year() {
return start_year;
}
 
public void setStart_year(String start_year) {
this.start_year = start_year;
}
 
public String getStation_name() {
return station_name;
}
 
public void setStation_name(String station_name) {
this.station_name = station_name;
}
 
// constructors
public MSeed_File(File mseed_file, File dataless_file, References references) {
//super();
 
 
if (!mseed_file.exists())
{
System.out.println("Le fichier "+mseed_file.getName() +" n existe pas....");
System.exit(0);
}
this.References=references;
 
this.setInitial_path(mseed_file.getParent());
this.setName(mseed_file.getName());
 
if (!dataless_file.exists())
{
System.out.println("Le fichier "+dataless_file.getName() +" n existe pas....");
System.exit(0);
}
this.setDataless_initial_path(dataless_file.getParent());
this.setDataless_name(dataless_file.getName());
 
 
 
 
// We create a random working directory
java.util.Random rand = new java.util.Random();
int leNombreAleatoire = rand.nextInt(999999999);
int leNombreAleatoire2 = rand.nextInt(999999999);
 
//System.out.println("References.getTmp_dir_location(): "+References.getTmp_dir_location());
 
this.working_path = References.getTmp_dir_location() + "/tmp"+ Integer.toString(leNombreAleatoire)+ Integer.toString(leNombreAleatoire2);
 
// Now we have to really create the dir
 
if (!new File(this.working_path).mkdir()) {
System.out.println("Probleme de creation du repertoire de travail");
System.exit(1);
}
 
this.hash_set_canaux = new HashSet<Canal_File>();
 
}
 
 
 
 
 
// Si la station a un nom long (>4 char), cette fonction retourne true
public boolean is_long_Station_name() {
if (this.getStation_name().compareTo(this.getFull_station_name()) == 0)
return false;
else
return true;
}
 
// Si la station a un location code cette fonction retourne true
public boolean is_location_code() {
if (this.getLocation_code().compareTo("XX") != 0)
return true;
else
return false;
}
 
public String getComment() {
return comment;
}
 
public void setComment(String comment) {
this.comment = comment;
}
 
 
 
public String getWorking_path() {
return working_path;
}
 
public void setWorking_path(String working_path) {
this.working_path = working_path;
}
 
public void add_canal(Canal_File canal) {
// System.out.println(canal);
this.hash_set_canaux.add(canal);
}
 
public String getInitial_path() {
return initial_path;
}
 
public void setInitial_path(String initial_path) {
this.initial_path = initial_path;
}
 
public String getName() {
return name;
}
 
public void setName(String name) {
this.name = name;
}
 
public void copy_to_working_dir() throws IOException {
// Pas tres tres beau...
// Utils tmp_util = new Utils();
Utils.copy_file(this.initial_path, this.name, this.working_path,
this.name);
}
 
public void to_sac() {
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for(Canal_File canal: this.hash_set_canaux) {
// System.out.print("\t(toString()=" + val + ",class="+
// val.getClass().getName() + ",identityHashCode="+
// System.identityHashCode(val) + ")");
canal.to_sac();
}
}
 
public void clean() {
 
this.remove_mseed();
this.remove_sac();
this.remove_resp();
this.remove_nrr();
this.remove_rdseed_log();
 
// Then we can delete the working_path directory
new File(this.working_path).delete();
 
// System.out.print("Fin de clean");
}
 
 
private void remove_rdseed_log() {
 
Calendar cal= Calendar.getInstance();
 
// cal.set(Calendar.YEAR,Integer.parseInt(this.getStart_year()));
// cal.set(Calendar.DAY_OF_YEAR,Integer.parseInt(this.getStart_day()));
 
String jour =org.geoscope.JSpec.Utils.padZeroLeft((Integer.toString(cal.get(Calendar.DAY_OF_MONTH))),2);
//In Java calendar, january = 0 => +1
String mois =org.geoscope.JSpec.Utils.padZeroLeft((Integer.toString((cal.get(Calendar.MONTH)+1))),2);
 
String annee=Integer.toString(cal.get(Calendar.YEAR)).substring(2,4);
 
//System.out.println("rdseed_log:"+this.getWorking_path() + '/' +"rdseed.err_log."+mois+"."+jour+"."+annee);
new File(this.getWorking_path() + '/' +"rdseed.err_log."+mois+"."+jour+"."+annee).delete();
 
// On recommence si le traitement a commencer le jour d'avant....
jour =org.geoscope.JSpec.Utils.padZeroLeft(((Integer.toString(cal.get(Calendar.DAY_OF_MONTH)-1))),2);
//System.out.println("rdseed_log:"+this.getWorking_path() + '/' +"rdseed.err_log."+mois+"."+jour+"."+annee);
new File(this.getWorking_path() + '/' +"rdseed.err_log."+mois+"."+jour+"."+annee).delete();
 
 
 
 
}
 
public void remove_mseed() {
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for(Canal_File canal: this.hash_set_canaux) {
new File(canal.getWorking_path() + '/' + canal.getName()).delete();
 
}
}
 
public void remove_resp() {
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
//
// while (it.hasNext()) {
// Canal_File canal = it.next();
for(Canal_File canal: this.hash_set_canaux) {
new File(canal.getWorking_path() + '/' +canal.getDataless_channel_name()).delete();
 
}
}
 
public void remove_nrr() {
// nom_station_4char needs to be filled with 4 char.
String nom_station_4char=this.getStation_name();
 
while (nom_station_4char.length() < 4) {
nom_station_4char=nom_station_4char+"_";
}
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for(Canal_File canal :this.hash_set_canaux) {
 
new File(canal.getWorking_path() + '/' +nom_station_4char+"."+canal.getChannel_name()+".all.nrrc" ).delete();
new File(canal.getWorking_path() + '/' +nom_station_4char+"."+canal.getChannel_name()+".all.nrrcdbnc" ).delete();
 
new File(canal.getWorking_path() + '/' +nom_station_4char+"."+canal.getLocation_code()+"."+canal.getChannel_name()+"."+canal.getStart_day()+".nrrcdb").delete();
//System.out.println(canal.getWorking_path() + '/' +nom_station_4char+"."+canal.getLocation_code()+"."+canal.getChannel_name()+"."+canal.getStart_day()+".all.nrrcdb");
new File(canal.getFile_name_to_plot() ).delete();
//System.out.println(canal.getFile_name_to_plot());
}
}
 
 
public void remove_sac() {
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for (Canal_File canal :this.hash_set_canaux) {
 
// Iterator<Canal_File> it_canal_horraire = canal.hash_set_canaux_horraires.iterator();
// while (it_canal_horraire.hasNext()) {
// Canal_File canal_h = it_canal_horraire.next();
//
for (Canal_File canal_h:canal.hash_set_canaux_horraires ) {
 
 
new File(canal_h.getWorking_path() + '/'
+ canal_h.getSAC_name()).delete();
}
new File(canal.getWorking_path() + '/' + canal.getSAC_name())
.delete();
}
}
 
 
 
public void set_XX_location_code_en_mseed(){
 
// Patch Madani pour mettre le location code à XX
try {
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(References.getQedit_location()+" " + this.initial_path
+ "/" + this.name, null, new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
// out.writeBytes("disp \n ");
// System.out.println(this.getLocation_code());
// out.flush();
 
// out.writeBytes("from first thru last set station SSB\n");
// //System.out.println(this.getStation_name());
// out.flush();
 
out.writeBytes("from first thru last set loc XX \n");
// System.out.println(this.getStation_name());
out.flush();
 
out.writeBytes("file " + this.getWorking_path() + "/" + this.name
+ " \n");
// System.out.println(this.getChannel_0());
out.flush();
 
out.writeBytes("OK \n");
// System.out.println(this.getChannel_0());
out.flush();
 
String line = null;
String line_err = null;
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line != null)
System.out.println("stdout:" + line);
if (line_err != null)
System.out.println("stderr:" + line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
System.out.println("erreur set_XX_location_code_en_mseed");
}
 
System.out.println("Fin set_XX_location_code_en_mseed");
}
 
 
public void parse_mseed() throws IOException {
 
 
//this.set_00_location_code_en_mseed();
if(this.get_location_code_from_mseed() == "XX"){
 
System.out.println("Pas de location code => loc_code=XX");
set_XX_location_code_en_mseed();
 
}
 
 
if(this.get_station_name_from_mseed().length()>=5)
{
//On est dans le cas d'une station dont le nom a 5 lettres...
this.setFull_station_name(this.get_station_name_from_mseed());
this.setStation_name(this.getFull_station_name().substring(0, 2));
//System.out.println("nom de station à 5 lettres");
 
//On renomme les donnees de "canal"
// this.change_station_name_in_mseed();
}
else
this.setStation_name(this.get_station_name_from_mseed());
 
 
 
// on va extraire les canaux contenus dans le fichier miniseeed
try {
 
Runtime r = Runtime.getRuntime();
Process p = r.exec(References.getSdrsplit_location() + " -ciP "
+ this.initial_path + "/" + this.name, null, new File(
this.working_path));
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
 
String line;
String split_line[];
String time[];
String date[];
Canal_File canal_tmp;
File working_dir = new File(this.getWorking_path());
String[] files_list = working_dir.list();
 
 
while ((line = Resultset.readLine()) != null) {
// Each line correspond a mseed file
// System.out.println(line);
if (line.length() != 0) {
// We create a tmp Canal_File object
canal_tmp = new Canal_File(this);
 
split_line = line.split(" ");
 
// Informations related to the station
canal_tmp.setNetwork_name(split_line[2]);
 
canal_tmp.setStation_name(split_line[0]);
 
//Attention au nom de station à 5 letttres...
 
//
// if(split_line[0].length()>=5)
// {
// //On est dans le cas d'une station dont le nom a 5 lettres...
// canal_tmp.setStation_name(split_line[0].substring(0, 2));
// //On renomme les donnees de "canal"
// canal_tmp.change_station_name_in_mseed();
//
// }
 
 
canal_tmp.setChannel_name(split_line[1]);
canal_tmp.setNpts(split_line[12]);
 
canal_tmp.setNetwork_name(split_line[2]);
 
// time and date informations
time = split_line[7].split(":");
 
// System.out.println("time[0]=hour="+time[0]+" time[1]=minute="+time[1]+" time[2]=sec="+time[2]);
 
canal_tmp.setStart_hour(time[0]);
canal_tmp.setStart_minute(time[1]);
canal_tmp.setStart_second(((time[2]).split("\\."))[0]);
canal_tmp.setFich_ml("0000");
 
date = split_line[6].split("\\.");
canal_tmp.setStart_year(((date[0]).split("\\("))[1]);
canal_tmp.setStart_day(date[1]);
 
 
//Filter filter = new Filter(canal_tmp.getfile_name_without_location_code());
Filter filter = new Filter(canal_tmp.getfile_name_without_location_code());
 
files_list = working_dir.list(filter);
 
 
// files_list[0] should be the name of the canal_tmp file
// if (files_list.length>0)
// System.out.println(files_list[0]);
 
canal_tmp.setName(files_list[0]);
 
canal_tmp.setWorking_path(this.getWorking_path());
 
 
// We set the location code of the canal_tmp file
// If there is no location code => lc=XX
// if ((files_list[0].split("\\.").length)==9)
// {
canal_tmp.setLocation_code(files_list[0].split("\\.")[8]);
// }
// else
// canal_tmp.setLocation_code("XX");
//
 
// Now we can build the future SAC name file
canal_tmp.build_SAC_file_name();
//System.out.println(canal_tmp.getSAC_name());
 
 
// Il faut virer les fichiers VH si il y en a ....
// Todo
 
// On rajoute le canal_tmp au dictionnaire du mseed file
this.add_canal(canal_tmp);
}
 
// We fill the Mseed_File fields with the information of the
// first Canal_file
// It is not a very good idea...
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
//
for(Canal_File canal : this.hash_set_canaux) {
 
 
// this.setStation_name(canal.getStation_name());
 
this.setNetwork_name(canal.getNetwork_name());
this.setStart_year(canal.getStart_year());
this.setStart_day(canal.getStart_day());
this.setLocation_code(canal.getLocation_code());
}
this.build_legend();
}
 
while ((line = error.readLine()) != null) {
// Each line correspond a mseed file
System.out.println(line);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
 
} catch (Exception e) {
System.out.println("erreur d'execution " + e.toString());
}
 
}
 
private void build_legend() {
 
// if (this.getLocation_code().compareTo("XX")==0)
// this.legend=this.getStation_name()+"."+"."+this.getStart_day()+"."+this.getStart_year()+"."+this.comment;
// else
References.setLegend(this.getStation_name() + "." + this.getLocation_code()
+ "." + this.getStart_day() + "." + this.getStart_year() + "."
+ this.comment);
 
}
 
// public void read_dataless() {
//
// // first, we copy the initial dataless file to the working directory
// try {
// Utils.copy_file(this.getDataless_initial_path(), this.getDataless_name(),
// this.getWorking_path(), this.getDataless_name());
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// // Now we can extract the response files from the dataless file
// try {
// Runtime r = Runtime.getRuntime();
//
// Process p = r.exec(this.getRdseed_location() + " -R -f "
// + this.getWorking_path()+ "/" + this.getDataless_name(),
// new String[] { "SACAUX=" + this.getSacaux_location(),
// "LEAPSECONDS=" + this.getLeapseconds_location()}, new File(
// this.getWorking_path()));
//
// // System.out.println(this.getRdseed_location()+" -R -f "+this.working_path+"/"+this.getDataless_name());
//
// BufferedReader Resultset = new BufferedReader(
// new InputStreamReader(p.getInputStream()));
// BufferedReader error = new BufferedReader(new InputStreamReader(p
// .getErrorStream()));
//
// String line = null;
// String line_err = null;
//
// while (((line = Resultset.readLine()) != null)
// || ((line_err = error.readLine()) != null)) {
// // if (line !=null) System.out.println(line);
// if (line_err != null)
// System.out.println("Read dataless:" + ":" + line_err);
//
// }
//
// if (p.waitFor() != 0) {
// System.err.println("exit value = " + p.exitValue());
// }
// } catch (Exception e) {
// System.out.println("erreur read_dataless");
// }
// // Now we can remove the copied dataless file
// new File(this.getWorking_path() + "/" + this.getDataless_name())
// .delete();
//
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
//
// // System.out.println("il y a "+this.hash_set_canaux.size()+" canaux");
//
// while (it.hasNext()) {
// Canal_File canal = it.next();
// canal.read_dataless();
// }
//
// }
 
// public void read_dataless_2() {
//
// // Now we can extract the response files from the dataless file
// try {
// Runtime r = Runtime.getRuntime();
//
// Process p = r.exec(this.getRdseed_location(), new String[] {
// "SACAUX=" + this.getSacaux_location(),
// "LEAPSECONDS=" + this.getLeapseconds_location() }, new File(this
// .getWorking_path()));
//
// // System.out.println(this.getRdseed_location()+" -R -f "+this.working_path+"/"+this.getDataless_name());
//
// BufferedReader Resultset = new BufferedReader(
// new InputStreamReader(p.getInputStream()));
// BufferedReader error = new BufferedReader(new InputStreamReader(p
// .getErrorStream()));
// DataOutputStream out = new DataOutputStream(p.getOutputStream());
//
// // on donne le nom du fichier
// out.writeBytes(this.getDataless_initial_path() + "/"
// + this.getDataless_name() + "\n");
// out.flush();
//
// // le fichier aura le nom par défaut donc "\n"
// out.writeBytes("\n");
// out.flush();
//
// // volume: défaut donc "\n"
// out.writeBytes("\n");
// out.flush();
//
// // Reponse donc donc "R\n"
// out.writeBytes("R\n");
// out.flush();
//
// // on veut seulement les reponses de la station this.getstationname
// out.writeBytes(this.getStation_name() + "\n");
// out.flush();
//
// // tout les canaux... enfin on pourrait faire mieux..
// out.writeBytes("\n");
// out.flush();
//
// // Les reponses du reseau reseau...
// out.writeBytes(this.getNetwork_name() + "\n");
// out.flush();
//
// // Loc ids...
// out.writeBytes("\n");
// out.flush();
//
// // Quit...
// out.writeBytes("Quit\n");
// out.flush();
//
// String line = null;
// String line_err = null;
//
// while (((line = Resultset.readLine()) != null)
// || ((line_err = error.readLine()) != null)) {
// // if (line !=null) System.out.println(line);
// if (line_err != null)
// System.out
// .println("erreur Read dataless:" + ":" + line_err);
//
// }
//
// if (p.waitFor() != 0) {
// System.err.println("exit value = " + p.exitValue());
// }
// } catch (Exception e) {
// System.out.println("erreur read_dataless");
// }
//
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
//
// // System.out.println("il y a "+this.hash_set_canaux.size()+" canaux");
//
// while (it.hasNext()) {
// Canal_File canal = it.next();
// canal.read_dataless();
// }
//
// }
 
public void read_dataless_3() {
 
// On extrait le dataless de chacun des canaux
// System.out.println("il y a "+this.hash_set_canaux.size()+" canaux");
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for(Canal_File canal :this.hash_set_canaux) {
 
canal.read_dataless_2();
}
 
}
 
public void spec() {
// La legende a déja ete construite....
 
// Delta is the increment between two samples
float delta = 0;
// System.out.println("il y a "+this.hash_set_canaux.size()+" canaux");
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
//
for (Canal_File canal: this.hash_set_canaux){
 
// System.out.println(canal.getSAC_name());
// System.out.println("=====================");
 
 
 
// We open and write the sac script file .
// try {
// BufferedWriter outfile = new BufferedWriter(new FileWriter(
// canal.getWorking_path() + "/saccmd."
// + canal.getChannel_name()));
//
// outfile.write("r " + canal.getSAC_name() + "\n");
// outfile.write("lh delta\n");
// outfile.write("quit\n");
// outfile.close();
// } catch (IOException e) {
// System.out.println("pouet:erreur dans spec()");
// }
 
try {
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(References.getSac2000_location() , new String[] {"SACAUX=" + References.getSacaux_location(),"LEAPSECONDS=" + References.getLeapseconds_location() }, new File(canal.getWorking_path()));
// Process p = r.exec(this.getSac2000_location() + " ./saccmd."+ canal.getChannel_name(), new String[] {"SACAUX=" + this.getSacaux_location(),"LEAPSECONDS=" + this.getLeapseconds_location() }, new File(canal.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
 
out.writeBytes("r " + canal.getSAC_name() + "\n");
out.flush();
out.writeBytes("lh delta\n");
out.flush();
out.writeBytes("quit\n");
out.flush();
 
 
 
String line = null, line_err = null;
String split_line[];
 
while (((line = Resultset.readLine()) != null)|| ((line_err = error.readLine()) != null)) {
if (line.contains("delta")) {
split_line = line.split("=");
// System.out.println(split_line[1]);
canal.setDelta(split_line[1]);
// System.out.println("delta:"+canal.getDelta());
// System.out.println(delta);
}
 
if ((line_err = error.readLine()) != null)
System.out.println("stderr:" + line_err);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
System.out.println("delta erreur dans spec()");
}
// Si on ne passe plus apr un fichier intermediaire, le fichier n'est plus a supprimer...
//new File(canal.getWorking_path() + "/saccmd."+ canal.getChannel_name()).delete();
 
if (delta == 0.025) {
// We open and write the sac script file .
// try {
// BufferedWriter outfile = new BufferedWriter(new FileWriter(
// canal.getWorking_path() + "/saccmd."
// + canal.getChannel_name()));
//
// outfile.write("r " + canal.getSAC_name() + "\n");
// outfile.write("decimate 2\nw over\n");
// outfile.write("lh npts\n'");
// outfile.write("quit\n");
// outfile.close();
// } catch (IOException e) {
// System.out.println("decimate erreur dans spec()");
// }
 
delta = delta * 2;
 
try {
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(References.getSac2000_location() , new String[] {"SACAUX=" + References.getSacaux_location(),"LEAPSECONDS=" + References.getLeapseconds_location() }, new File(canal.getWorking_path()));
// Process p = r.exec(this.getSac2000_location() + " ./saccmd."+ canal.getChannel_name(), new String[] {"SACAUX=" + this.getSacaux_location(),"LEAPSECONDS=" + this.getLeapseconds_location() }, new File(canal.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
 
out.writeBytes("r " + canal.getSAC_name() + "\n");
out.flush();
out.writeBytes("decimate 2\nw over\n");
out.flush();
out.writeBytes("lh npts\n'");
out.flush();
out.writeBytes("quit\n");
out.flush();
 
 
String line = null, line_err = null;
String split_line[];
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line.contains("npts")) {
split_line = line.split("=");
// System.out.println(split_line[1]);
canal.setNpts(split_line[1]);
// System.out.println("npts:"+canal.getNpts());
 
// System.out.println(canal.getNtps());
}
if ((line_err = error.readLine()) != null)
System.out.println("stderr:" + line_err);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
System.out.println("npts erreur dans spec()");
}
// Si on ne passe plus apr un fichier intermediaire, le fichier n'est plus a supprimer...
//new File(canal.getWorking_path() + "/saccmd."+ canal.getChannel_name()).delete();
} else if (delta == 0.02) {
String fich_sac_mod = canal.getStart_year() + '.'
+ canal.getStart_day() + '.' + canal.getStart_hour()
+ '.' + canal.getStart_minute() + '.'
+ canal.getStart_second() + '.' + canal.getFich_ml()
+ '.' + canal.getNetwork_name() + '.'
+ canal.getStation_name() + '.'
+ canal.getLocation_code() + ".LH"
+ canal.getChannel_name().charAt(2) + ".D.SAC";
 
// try {
// BufferedWriter outfile = new BufferedWriter(new FileWriter(
// canal.getWorking_path() + "/saccmd."
// + canal.getChannel_name()));
//
// outfile.write("r " + canal.getSAC_name() + "\n");
// outfile.write("decimate 5\nw " + fich_sac_mod + "\n");
// outfile.write("lh npts\n'");
// outfile.write("quit\n");
// outfile.close();
// } catch (IOException e) {
// System.out.println("decimate 2 erreur dans spec()");
// }
 
try {
Runtime r = Runtime.getRuntime();
 
// Process p = r.exec(this.getSac2000_location()+ " ./saccmd."+ canal.getChannel_name(), new String[] {"SACAUX=" + this.getSacaux_location(),"LEAPSECONDS=" + this.getLeapseconds_location() }, new File(canal.getWorking_path()));
Process p = r.exec(References.getSac2000_location(), new String[] {"SACAUX=" + References.getSacaux_location(),"LEAPSECONDS=" + References.getLeapseconds_location() }, new File(canal.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
 
out.writeBytes("r " + canal.getSAC_name() + "\n");
out.flush();
out.writeBytes("decimate 5\nw " + fich_sac_mod + "\n");
out.flush();
out.writeBytes("lh npts\n'");
out.flush();
out.writeBytes("quit\n");
out.flush();
 
 
 
String line = null, line_err = null;
String split_line[];
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line.contains("npts")) {
split_line = line.split("=");
// System.out.println(split_line[1]);
canal.setNpts(split_line[1]);
// System.out.println("npts:"+canal.getNpts());
}
 
if (line_err != null)
System.out.println("stderr:" + line_err);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
System.out.println("npts 3 erreur dans spec()");
}
 
// Si on ne passe plus apr un fichier intermediaire, le fichier n'est plus a supprimer...
//new File(canal.getWorking_path() + "/saccmd."+ canal.getChannel_name()).delete();
 
 
delta = delta * 5;
canal.setChannel_name("LH" + canal.getChannel_2());
canal.build_SAC_file_name();
}
 
// creation du fichier de commandes pour pre_pspecsac_jour
 
// System.out.println(canal.getChannel_name().charAt(0));
if ((canal.getChannel_name().charAt(0) == 'B')
&& (Float.valueOf(canal.getNpts()).floatValue() > 80000)) {
// decoupage du canal B en morceaux de 1h
//System.out.println(canal.getName());
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// reglage initial=1... les autres valeur => erreur d'un prg en
// fortran...
canal.decoupe_sac(1);
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// System.out.println("il y a "+ canal.hash_set_canaux_horraires.size()+ " canaux horraires");
 
try {
BufferedWriter outfile = new BufferedWriter(new FileWriter(canal.getWorking_path() + "/filelist."+ canal.getChannel_name()));
 
// Iterator<Canal_File> iterator = canal.hash_set_canaux_horraires .iterator();
// while (iterator.hasNext()) {
// Canal_File canal_horaire = iterator.next();
//
for(Canal_File canal_horaire: canal.hash_set_canaux_horraires ) {
 
canal_horaire.read_npts();
outfile.write(canal_horaire.getSAC_name() + " "
+ canal_horaire.getNpts() + " "
+ canal.getDelta() + "\n");
 
}
outfile.close();
} catch (IOException e) {
System.out.println("decimate erreur dans spec()");
}
}// fin du if B et 80000
else if ((canal.getChannel_name().charAt(0) == 'L')
&& (Float.valueOf(canal.getNpts()).floatValue() > 80000)) {
// decoupage du canal L en morceaux de 12h
// System.out.println(canal.getName());
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// reglage originale = 12
canal.decoupe_sac(12);
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// System.out.println("il y a "+ canal.hash_set_canaux_horraires.size()+ " canaux horraires");
 
try {
BufferedWriter outfile = new BufferedWriter(new FileWriter(canal.getWorking_path() + "/filelist."+ canal.getChannel_name()));
 
// Iterator<Canal_File> iterator = canal.hash_set_canaux_horraires .iterator();
// while (iterator.hasNext()) {
// Canal_File canal_horaire = iterator.next();
 
for (Canal_File canal_horaire : canal.hash_set_canaux_horraires) {
canal_horaire.read_npts();
outfile.write(canal_horaire.getSAC_name() + " "
+ canal_horaire.getNpts() + " "
+ canal.getDelta() + "\n");
}
outfile.close();
} catch (IOException e) {
System.out.println("decimate erreur dans spec()");
}
 
}// fin du if L et 80000
else {
if (Float.valueOf(canal.getNpts()).floatValue() > 80000) {
canal.setNpts("80000");
}
 
try {
BufferedWriter outfile = new BufferedWriter(new FileWriter(
canal.getWorking_path() + "/filelist."
+ canal.getChannel_name()));
outfile.write(canal.getSAC_name() + " " + canal.getNpts()
+ " " + canal.getDelta() + "\n");
outfile.close();
} catch (IOException e) {
System.out.println("decimate erreur dans spec()");
}
 
}// fin du else
 
// pre_pspecsac_jour
canal.pre_pspecsac();
 
// pspecsac_jour
canal.pspecsac();
 
// correction de la reponse avec octave
canal.response_correction();
 
// decimation du spectre
canal.decime_spectre();
 
}// End of the canal_file iteration
 
 
}
 
// Cette fonction va regrouper les fichier LH? et BH? entre eux
// ex BHZ et LHZ
public void plot_spec() {
// new
// File(this.getWorking_path()+"/"+this.getStart_day()+"."+this.getLocation_code()+"."+this.getChannel_name()+"."+this.getChannel_2()+"."+this.getStart_day()+"."+this.getStart_year()+"."+"nrrcdbd")
 
HashSet<String> hash_canaux_Z;
hash_canaux_Z = new HashSet<String>();
 
HashSet<String> hash_canaux_N;
hash_canaux_N = new HashSet<String>();
 
HashSet<String> hash_canaux_E;
hash_canaux_E = new HashSet<String>();
 
// Iterator<Canal_File> it = this.hash_set_canaux.iterator();
// while (it.hasNext()) {
// Canal_File canal = it.next();
 
for (Canal_File canal: this.hash_set_canaux){
 
// System.out.println(canal.getChannel_name());
if (canal.getChannel_2() == 'Z')
hash_canaux_Z.add(canal.getFile_name_to_plot());
if (canal.getChannel_2() == 'N')
hash_canaux_N.add(canal.getFile_name_to_plot());
if (canal.getChannel_2() == 'E')
hash_canaux_E.add(canal.getFile_name_to_plot());
}
 
// On a maintenant la liste des canaux a plotter range par composante
 
try {
 
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(References.getGnuplot_location(), null, new File(this
.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
// on prepare la mise en page de gnuplot
 
out.writeBytes("set logscale x \n");
out.flush();
 
out.writeBytes("set grid \n");
out.flush();
 
out.writeBytes("set title \"" + References.getLegend() + " "
+ this.getStation_name() + " " + this.getStart_year() + " "
+ this.getStart_day() + "\" \n");
out.flush();
 
// cette variable sert à gere le pb de plot et replot. on fait
// "plot [...]" avec la pemiere courbe et replot avec les
// suivantes...
int premiere_courbe = 0;
String plot = "plot [0.1:10000] [-200:-40] \"";
String replot = "replot \"";
 
// z_nb_legend sert a n'écrire la legende que pour le 1er fichier
// tracé, dans le acs ou il y a LH et BH..
int Z_nb_legend = 0;
 
// Iterator<String> it_Z = hash_canaux_Z.iterator();
// while (it_Z.hasNext()) {
// String nom_tmp = it_Z.next();
//
for (String nom_tmp:hash_canaux_Z ) {
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (Z_nb_legend == 0)
out.writeBytes(" title \"Z\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 3 \n");
 
Z_nb_legend++;
premiere_courbe++;
}
out.flush();
 
int N_nb_legend = 0;
// Iterator<String> it_N = hash_canaux_N.iterator();
// while (it_N.hasNext()) {
// String nom_tmp = it_N.next();
 
for (String nom_tmp:hash_canaux_N ) {
 
 
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (N_nb_legend == 0)
out.writeBytes(" title \"N\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 1 \n");
 
N_nb_legend++;
premiere_courbe++;
 
}
out.flush();
 
int E_nb_legend = 0;
// Iterator<String> it_E = hash_canaux_E.iterator();
// while (it_E.hasNext()) {
// String nom_tmp = it_E.next();
 
for (String nom_tmp:hash_canaux_E ) {
 
if (premiere_courbe != 0) {
plot = replot;
}
out.writeBytes(plot + nom_tmp + "\" ");
 
if (E_nb_legend == 0)
out.writeBytes(" title \"E\" ");
else
out.writeBytes(" notitle ");
out.writeBytes("with lines lw 1 lt 2 \n");
 
E_nb_legend++;
premiere_courbe++;
 
}
out.flush();
 
out.writeBytes("replot \""+References.getHnm_location()+"\" linestyle 0 title \"hnm\" with lines\n");
out.flush();
 
out.writeBytes("replot \""+References.getLnm_location()+"\" linestyle 0 title \"lnm\" with lines\n");
out.flush();
 
out.writeBytes("show grid\n");
out.flush();
 
 
out.writeBytes("pause 1 \n");
out.flush();
 
out.writeBytes("set terminal png \n");
out.flush();
 
out.writeBytes("set size 1,1 \n");
out.flush();
 
out.writeBytes("replot \n");
out.flush();
 
 
//On cree le nom du fichier de sortie qui sera enregistre dans le repertoire courant
out.writeBytes("set output \""+References.getSave_png_dir()+ "/" +this.getStation_name()+"."+this.getStart_year()+"."+this.getStart_day()+".png\" \n");
out.flush();
 
 
out.writeBytes("set size 1,1 \n");
out.flush();
 
out.writeBytes("replot \n");
out.flush();
 
 
 
out.writeBytes("quit \n");
out.flush();
 
String line = null;
String line_err = null;
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
// if (line !=null) System.out.println("stdout:"+line);
// if (line_err != null)
// System.out.println("stderr:" + line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
 
System.out.println("erreur gnuplot: " + e);
}
 
}
 
//Si le location existe, on le retourne sinon, le retour est XX
public String get_location_code_from_mseed() {
 
String location_code="XX";
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(References.getQedit_location()+" "+ this.initial_path
+ "/" + this.name, null, new File(this.getWorking_path()));
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
out.writeBytes("disp \n ");
out.flush();
 
out.writeBytes("quit\n");
out.flush();
 
String line = null;
String line_err = null;
String[] line_tmp;
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line != null) {
if (line.startsWith("location")) {
line_tmp = line.split("= ");
 
if (line_tmp.length == 2) {
System.out.println("le location code est:##"+ line_tmp[1] + "##");
location_code=line_tmp[1];
} else {
System.out.println("Pas de location code");
 
}
}
}
 
if (line_err != null)
System.out.println("stderr:" + line_err);
}
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
 
}
return location_code;
}
 
public String get_station_name_from_mseed() {
 
 
String station_name="";
 
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(References.getQedit_location()+" "+ this.initial_path
+ "/" + this.name, null, new File(this.getWorking_path()));
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
out.writeBytes("disp \n ");
out.flush();
 
out.writeBytes("quit\n");
out.flush();
 
String line = null;
String line_err = null;
String[] line_tmp;
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line != null) {
 
if (line.startsWith("station")) {
line_tmp = line.split("= ");
// System.out.println("le nom de la station est:##"+ line_tmp[1] + "##");
station_name=line_tmp[1];
}
 
}
 
 
if (line_err != null)
System.out.println("stderr:" + line_err);
}
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
 
}
return station_name;
 
}
 
public static void main(String[] args) throws IOException {
 
File mseed_file =null;
File dataless_file=null;
 
// JFileChooser chooser = new JFileChooser();
//
// chooser.setDialogTitle("Choix du fichier miniseed");
//
// // FileNameExtensionFilter filter = new
// // FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
// // chooser.setFileFilter(filter);
// chooser.setCurrentDirectory(new File("/tmp/test/"));
// Frame a = new Frame();
// int returnVal = chooser.showOpenDialog(a);
// if (returnVal == JFileChooser.APPROVE_OPTION) {
// mseed_file=chooser.getSelectedFile();
// //choosen_mseed_file = chooser.getSelectedFile().getName();
// //choosen_mseed_file_dir = chooser.getSelectedFile().getParent();
//
// }
//
// chooser.setDialogTitle("Choix du fichier dataless");
//
// // FileNameExtensionFilter filter = new
// // FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
// // chooser.setFileFilter(filter);
// chooser.setCurrentDirectory(new File("/tmp/test/"));
// a = new Frame();
// returnVal = chooser.showOpenDialog(a);
// if (returnVal == JFileChooser.APPROVE_OPTION) {
// dataless_file=chooser.getSelectedFile();
// }
//
// chooser.setDialogTitle("Choix repertoire de sauvegarde du PNG");
//
// // FileNameExtensionFilter filter = new
// // FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
// // chooser.setFileFilter(filter);
// chooser.setCurrentDirectory(new File("/tmp/test/"));
// a = new Frame();
// returnVal = chooser.showOpenDialog(a);
// if (returnVal == JFileChooser.APPROVE_OPTION) {
// save_png_dir=chooser.getSelectedFile();
// }
//
//
// //final String legende = "De belles courbes...";
// String legende = "";
//
// legende = (String)JOptionPane.showInputDialog(a,"Entrez la legende de la courbe ","Legende de la courbe",JOptionPane.PLAIN_MESSAGE,null,null,"Une jolie courbe");
//
//
// // MSeed_File test = new
// // MSeed_File("/tmp/test","SSB_2009_150","/tmp/test","dataless",legende,"/home/bonaime/workspace/JSpec/src/org/geoscope/JSpec","JSpec.ini");
// // MSeed_File test = new
// // MSeed_File(choosen_file_dir,choosen_file,"/tmp/test","dataless",legende,"/home/bonaime/workspace/JSpec/src/org/geoscope/JSpec","JSpec.ini");
 
mseed_file =new File("/tmp/test/UNM_BHZ_2009_100");
dataless_file=new File("/tmp/test/dataless_geoscope");
String JSpec_ini_file= "/home/bonaime/workspace/JSpec/src/org/geoscope/JSpec/JSpec.ini";
String save_png_dir="/tmp/test/";
String legende = "Des courbes jolies";
 
References references= new References(JSpec_ini_file,save_png_dir,"toto.png", "la legende");
MSeed_File test = new MSeed_File(mseed_file,dataless_file, references);
 
 
// test.get_location_code_and_station_name();
//
// if (!test.is_location_code()) {
// System.out.println("Il va falloir mettre un location code");
// }
 
test.parse_mseed();
// test.to_sac();
// test.read_dataless_3();
//
// test.spec();
//
// test.plot_spec();
test.clean();
System.exit(0);
 
}
 
public void setDataless_initial_path(String dataless_initial_path) {
this.dataless_initial_path = dataless_initial_path;
}
 
public String getDataless_initial_path() {
return dataless_initial_path;
}
 
}
/src/org/geoscope/JSpec/Canal_File.java
New file
0,0 → 1,965
package org.geoscope.JSpec;
 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
 
 
 
public class Canal_File {
 
// fields
private String working_path; //working path
private String name; //Name of the miniseed file
private String SAC_name; //Name of the sac file
private String dataless_channel_name;
private String file_name_to_plot;
private String start_year;
private String start_day;
private String start_hour;
private String start_minute;
private String start_second;
private String station_name;
private String channel_name;
private String location_code;
private String network_name;
private String fich_ml;
//npts is the number of sample per file
private String npts;
// Delta is the increment between two samples
private String delta;
ArrayList<Canal_File> hash_set_canaux_horraires;
private String seismometer;
private String digitizer;
private MSeed_File papa_mseed;
 
public String getFile_name_to_plot() {
return file_name_to_plot;
}
 
public void setFile_name_to_plot(String file_name_to_plot) {
this.file_name_to_plot = file_name_to_plot;
}
 
public String getDataless_channel_name() {
return dataless_channel_name;
}
 
public void setDataless_channel_name(String dataless_channel_name) {
this.dataless_channel_name = dataless_channel_name;
}
 
 
public String getDelta() {
return delta;
}
 
public void setDelta(String delta) {
this.delta = delta;
}
 
 
public char getChannel_0(){
return this.getChannel_name().charAt(0);
}
public char getChannel_2(){
return this.getChannel_name().charAt(2);
}
 
public String getWorking_path() {
return working_path;
}
public void setWorking_path(String working_path) {
this.working_path = working_path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSAC_name() {
return SAC_name;
}
public void setSAC_name(String sac_name) {
SAC_name = sac_name;
}
public String getStart_year() {
return start_year;
}
public void setStart_year(String start_year) {
this.start_year = start_year;
}
 
public String getStart_day() {
return start_day;
}
public void setStart_day(String start_day) {
this.start_day = start_day;
}
public String getNpts() {
return npts;
}
public void setNpts(String npts) {
this.npts = npts;
}
public String getStart_hour() {
return start_hour;
}
public void setStart_hour(String start_hour) {
this.start_hour = start_hour;
}
public String getStart_minute() {
return start_minute;
}
public void setStart_minute(String start_minute) {
this.start_minute = start_minute;
}
public String getStart_second() {
return start_second;
}
public void setStart_second(String start_second) {
this.start_second = start_second;
}
public String getStation_name() {
return station_name;
}
public void setStation_name(String station_name) {
this.station_name = station_name;
}
public String getChannel_name() {
return channel_name;
}
public void setChannel_name(String channel_name) {
this.channel_name = channel_name;
}
public String getLocation_code() {
return location_code;
}
public void setLocation_code(String location_code) {
this.location_code = location_code;
}
public String getNetwork_name() {
return network_name;
}
public void setNetwork_name(String network_name) {
this.network_name = network_name;
}
public String getFich_ml() {
return fich_ml;
}
public void setFich_ml(String fich_ml) {
this.fich_ml = fich_ml;
}
public String getSeismometer() {
return seismometer;
}
public void setSeismometer(String seismometer) {
this.seismometer = seismometer;
}
public String getDigitizer() {
return digitizer;
}
public void setDigitizer(String digitizer) {
this.digitizer = digitizer;
}
 
 
public Canal_File(MSeed_File papa) {
this.papa_mseed=papa;
this.hash_set_canaux_horraires = new ArrayList<Canal_File>();
}
 
 
 
public void add_canal(Canal_File canal){
//System.out.println(canal);
this.hash_set_canaux_horraires.add(canal);
}
 
 
public void read_npts(){
// We create a random number
// java.util.Random rand = new java.util.Random();
// int leNombreAleatoire = rand.nextInt(99999999);
//
// try
// {
// BufferedWriter outfile = new BufferedWriter(new FileWriter(this.getWorking_path()+"/saccmd."+Integer.toString(leNombreAleatoire)));
//
// outfile.write("r "+this.getSAC_name()+"\n");
// outfile.write("lh npts\n'");
// outfile.write("quit\n");
// outfile.close();
// }
// catch (IOException e) {
// System.out.println("erreur dans le read_npts");
// }
 
try {
Runtime r = Runtime.getRuntime();
 
 
// Process p = r.exec(this.sac2000_location+" ./saccmd."+Integer.toString(leNombreAleatoire),new String[] { "SACAUX="+this.sacaux_location},new File(this.getWorking_path()));
// Process p = r.exec(papa_mseed.getSac2000_location()+" ./saccmd."+Integer.toString(leNombreAleatoire),new String[] { "SACAUX="+papa_mseed.getSacaux_location()},new File(this.getWorking_path()));
Process p = r.exec(papa_mseed.References.getSac2000_location(),new String[] { "SACAUX="+papa_mseed.References.getSacaux_location()},new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
out.writeBytes("r "+this.getSAC_name()+"\n");
out.flush();
out.writeBytes("lh npts\n'");
out.flush();
out.writeBytes("quit\n");
out.flush();
String line;
String split_line[];
 
 
while ((line = Resultset.readLine()) != null) {
if (line.contains("npts")) {
split_line = line.split("=");
this.setNpts(split_line[1]);
}
}
 
 
while ((line = error.readLine()) != null) {
//Each line correspond a mseed file
System.out.println("stderr:"+line);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
 
}
catch (Exception e) {
System.out.println("npts 3 erreur dans spec()");
}
// new File(this.getWorking_path()+"/saccmd."+Integer.toString(leNombreAleatoire)).delete();
 
}
 
void build_SAC_file_name(){
// if (this.getLocation_code().compareTo("XX")!=0)
this.SAC_name= this.start_year+'.'+this.start_day+'.'+this.start_hour+'.'+this.start_minute+'.'+this.start_second+'.'+this.fich_ml+'.'+this.network_name+'.'+this.station_name+'.'+this.location_code+'.'+this.channel_name+".D.SAC";
// else
// this.SAC_name= this.start_year+'.'+this.start_day+'.'+this.start_hour+'.'+this.start_minute+'.'+this.start_second+'.'+this.fich_ml+'.'+this.network_name+'.'+this.station_name+'.'+'.'+this.channel_name+".D.SAC";
 
}
 
 
 
public String getfile_name_without_location_code(){
return this.start_year.substring(2,4)+'.'+this.start_day+'.'+this.start_hour+'.'+this.start_minute+'.'+this.start_second+'.'+this.network_name+'.'+this.station_name+'.'+this.channel_name+'.';
}
 
//nouvelle version avec la recuperation du nom de station par le pere pour des pb de nom de station a 5 lettres...
public String getfile_name_without_location_code_2(){
return this.start_year.substring(2,4)+'.'+this.start_day+'.'+this.start_hour+'.'+this.start_minute+'.'+this.start_second+'.'+this.network_name+'.'+papa_mseed.getFull_station_name()+'.'+this.channel_name+'.';
}
 
public void to_sac() {
 
 
Runtime r = Runtime.getRuntime();
 
try {
 
Process p = r.exec(papa_mseed.References.getMs2sac_location()+" "+this.getWorking_path()+"/"+this.getName()+" "+this.getWorking_path()+"/"+this.getSAC_name(),null,new File(this.working_path));
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
 
String line=null;
String line_err=null;
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
//if (line !=null) System.out.println(line);
if (line_err!=null) System.out.println("stderr:"+line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
 
} catch (Exception e) {
System.out.println("erreur d'execution " + e.toString());
}
 
}
 
// this function splits a canal_file sac_file in nb_hour sac files
public void decoupe_sac(int nb_hour) {
 
System.out.println("decoupage du fichier "+this.getDataless_channel_name()+" en morceaux de "+nb_hour);
int deb_offset=3600-60*(Integer.parseInt(this.getStart_minute()))-(Integer.parseInt(this.getStart_second()));
int hh_dec=(Integer.parseInt(this.getStart_hour()))+1;
int jjj_dec=(Integer.parseInt(this.getStart_day()));
int yyyy=(Integer.parseInt(this.getStart_year()));
if (hh_dec >= 24) {
hh_dec= hh_dec - 24;
jjj_dec= jjj_dec + 1;
 
// Attention aux annees bissextiles !!!
//Bug previsible...
if (jjj_dec > 365) {
yyyy= yyyy+1;
//En python l'expression suivante "caste" yyyy en double
//yyyy= '%(yyyy)d' %vars()
jjj_dec= 1;
}
}
try
{
Canal_File canal_tmp;
 
BufferedWriter outfile = new BufferedWriter(new FileWriter(this.getWorking_path()+"/dec_sac."+this.getChannel_name()));
 
outfile.write("r "+this.getSAC_name()+"\n");
//outfile.write("cut B "+deb_offset+" E\n");
//outfile.write("r\n");
 
//We create for each file a Canal_file object
canal_tmp=new Canal_File(this.papa_mseed);
canal_tmp.setSAC_name(this.getSAC_name());
canal_tmp.setWorking_path(this.getWorking_path());
this.add_canal(canal_tmp);
 
// System.out.println("delta:"+this.getDelta());
// System.out.println("npts:"+this.getNpts());
 
 
int duree_fich= (int) (Float.valueOf(this.getDelta()).floatValue() * (Integer.parseInt(this.getNpts())-deb_offset));
int num_ss_fich=duree_fich/(nb_hour*3600);
//int n_fin,n_deb=0;
int n_fin,n_deb=deb_offset;
String fich_dec,jour,heure;
 
for (int i = 0; i < num_ss_fich; i++){
jour= Integer.toString(jjj_dec);
jour=org.geoscope.JSpec.Utils.padZeroLeft(jour,3);
heure=org.geoscope.JSpec.Utils.padZeroLeft(Integer.toString(hh_dec),2);
 
// if (this.getLocation_code().compareTo("XX")!=0)
fich_dec=Integer.toString(yyyy)+'.'+jour+'.'+heure+".00.00.0000."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.getLocation_code()+"."+this.getChannel_name()+".D.SAC";
// else
// fich_dec=Integer.toString(yyyy)+'.'+jour+'.'+heure+".00.00.0000."+this.getNetwork_name()+"."+this.getStation_name()+"."+"."+this.getChannel_name()+".D.SAC";
 
//We create for each file a Canal_file object
// canal_tmp=new Canal_File(this.papa_mseed,this.getRdseed_location(),this.getSac2000_location(), this.getSacaux_location(),this.getMs2sac_location(),this.getLeapseconds_location(), this.getPre_pspecsac_jour_location(), this.getPspecsac_jour_location());
canal_tmp=new Canal_File(this.papa_mseed);
canal_tmp.setSAC_name(fich_dec);
canal_tmp.setWorking_path(this.getWorking_path());
this.add_canal(canal_tmp);
 
n_fin=n_deb+nb_hour*3600;
//n_fin=n_deb+3600;
// System.out.println("cut "+n_deb+" "+n_fin);
 
outfile.write("cut "+n_deb+" "+n_fin+"\n");
//outfile.write("cut B "+n_deb+" B "+n_fin+"\n");
outfile.write("r\n");
outfile.write("w "+fich_dec+"\n");
n_deb=n_fin;
hh_dec= hh_dec + nb_hour;
if (hh_dec >= 24){
hh_dec= hh_dec - 24;
jjj_dec=jjj_dec+1;
if (jjj_dec > 365){
yyyy= yyyy+1;
jjj_dec=1;
}
}
 
}
 
//We can create the first file now...
//System.out.println("cut 0 "+deb_offset);
outfile.write("cut 0 "+deb_offset+" \n");
outfile.write("r\n");
outfile.write("w "+this.getSAC_name()+"\n");
 
 
outfile.write("quit\n");
outfile.close();
 
}
catch (IOException e) {
System.out.println("erreur dans spec()");
}
 
try {
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(papa_mseed.References.getSac2000_location()+" ./dec_sac."+this.getChannel_name(),new String[] { "SACAUX="+papa_mseed.References.getSacaux_location()},new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
 
 
String line=null;
String line_err=null;
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
//if (line !=null) System.out.println(line);
if (line_err!=null) System.out.println("stderr:"+line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur dans spec()");
}
new File(this.getWorking_path()+"/dec_sac."+this.getChannel_name()).delete();
System.out.println("fin du decoupage du fichier "+this.getDataless_channel_name()+" en morceaux de "+nb_hour);
}
 
public void pre_pspecsac() {
try {
Runtime r = Runtime.getRuntime();
 
// Process p = r.exec(papa_mseed.getPre_pspecsac_jour_location(),new String[]{ "SACAUX="+sacaux_location, "LEAPSECONDS="+leapseconds_location},new File(this.getWorking_path()));
Process p = r.exec(papa_mseed.References.getPre_pspecsac_jour_location(),new String[]{ "SACAUX="+papa_mseed.References.getSacaux_location(), "LEAPSECONDS="+papa_mseed.References.getLeapseconds_location()},new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
out.writeBytes("filelist."+this.getChannel_name()+"\n"+this.getStation_name()+"\n");
out.flush();
 
String line=null;
String line_err=null;
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
// if (line !=null) System.out.println("stdout:"+line);
if (line_err!=null) System.out.println("stderr:"+line_err);
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur pre_pspecsac_jour");
}
//on peut maintenant virer le fichier filelist.machin...
//System.out.println("On vire le fichier: "+this.getWorking_path()+"/"+"filelist."+this.getChannel_name());
new File(this.getWorking_path()+"/"+"filelist."+this.getChannel_name()).delete();
 
}
 
public void pspecsac() {
 
// nom_station_4char needs to be filled with 4 char.
String nom_station_4char=this.getStation_name();
while (nom_station_4char.length() < 4) {
nom_station_4char=nom_station_4char+"_";
}
try {
 
 
Runtime r = Runtime.getRuntime();
//Process p = r.exec(this.pspecsac_jour_location,new String[] { "SACAUX="+sacaux_location, "LEAPSECONDS="+leapseconds_location},new File(this.getWorking_path()));
Process p = r.exec(papa_mseed.References.getPspecsac_jour_location(),new String[] { "SACAUX="+papa_mseed.References.getSacaux_location(), "LEAPSECONDS="+papa_mseed.References.getLeapseconds_location()},new File(this.getWorking_path()));
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
FileInputStream file_in = new FileInputStream(this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.cmd");
 
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
byte[] buffer = new byte[4096];
 
while ((file_in.read(buffer)) != -1){
out.write(buffer);
}
 
out.flush();
 
String line=null;
String line_err=null;
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
//if (line !=null) System.out.println(line);
if (line_err!=null) System.out.println("pspecsac_stderr:"+this.getChannel_name()+":"+line_err);
 
}
 
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur pspecsac_jour");
}
 
 
new File(this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.cmd").delete();
 
 
}
 
// public void read_dataless(){
// String refres_location=papa_mseed.getRefres_location();
//
// try {
// Runtime r = Runtime.getRuntime();
// Process p = r.exec(refres_location,null,new File(this.getWorking_path()));
// BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
// BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
// DataOutputStream out = new DataOutputStream(p.getOutputStream());
//
// String line=null;
// String line_err=null;
//
// // Nombre de fichier reponse a lire
// out.writeBytes("1\n");
//
// //Le nom du fichier a lire...
// out.writeBytes(this.getWorking_path()+"/"+"RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.location_code+"."+this.getChannel_name()+"\n");
//
// // nombre de reponse a lire dans le fichier en question.. ce n'est a priori pas 1 !!! Mais si on met 1000, cela ne doit pas poser de pb...
// //out.writeBytes("1\n");
// out.writeBytes("1000\n");
//
// //Le nom du fichier a ecrire...
// this.setDataless_channel_name("resp."+this.getStation_name()+"."+this.getStart_day()+"."+java.lang.Character.toLowerCase(this.getChannel_0())+java.lang.Character.toLowerCase(this.getChannel_2()));
// out.writeBytes(this.getWorking_path()+"/"+this.getDataless_channel_name()+"\n");
// //java.lang.Character.toLowerCase(this.getChannel_2())
//
// out.flush();
//
// line=null;
// line_err=null;
//
// // cette fonction genere des erreurs mais c'est normal ! voir un peu plus haut pour le nb de reponses lues
// // c'est pourquoi la sortie erreur est commentee
// while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
// {
// //if (line !=null) System.out.println("stdout:"+line);
// //if (line_err!=null) System.out.println("stderr:"+line_err);
//
// }
//
//
//
// if (p.waitFor() != 0) {
// System.err.println("exit value = " +
// p.exitValue());
// }
// }
// catch (Exception e) {
// System.out.println("erreur Canal_file.read_dataless");
// }
//
// new File(this.getWorking_path()+"/RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.location_code+"."+this.getChannel_name()).delete();
//
//
// }
 
 
 
public void read_dataless_2(){
 
// Now we can extract the response files from the dataless file
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(papa_mseed.References.getRdseed_location(),new String[] { "SACAUX="+papa_mseed.References.getSacaux_location(), "LEAPSECONDS="+papa_mseed.References.getLeapseconds_location()},new File(this.getWorking_path()));
 
// System.out.println(papa_mseed.getRdseed_location()+" "+"SACAUX="+papa_mseed.getSacaux_location()+" LEAPSECONDS="+papa_mseed.getLeapseconds_location()+" "+this.getWorking_path());
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
// //on donne le nom du fichier
// System.out.print(papa_mseed.getDataless_initial_path()+"/"+papa_mseed.getDataless_name()+"\n");
out.writeBytes(papa_mseed.getDataless_initial_path()+"/"+papa_mseed.getDataless_name()+"\n");
out.flush();
 
//le fichier aura le nom par défaut donc "\n"
// System.out.print("\n");
out.writeBytes("\n");
out.flush();
 
//volume: défaut donc "\n"
// System.out.print("\n");
out.writeBytes("\n");
out.flush();
 
//Reponse donc donc "R\n"
// System.out.print("R\n");
out.writeBytes("R\n");
out.flush();
 
//on veut seulement les reponses de la station this.getstationname
// System.out.print(this.getStation_name()+"\n");
out.writeBytes(this.getStation_name()+"\n");
out.flush();
 
//on extrait seulement la reponse du canal
// System.out.print(this.getChannel_name()+"\n");
out.writeBytes(this.getChannel_name()+"\n");
out.flush();
 
//Les reponses du reseau reseau...
// System.out.print(this.getNetwork_name()+"\n");
out.writeBytes(this.getNetwork_name()+"\n");
out.flush();
 
//Loc ids...
// if (this.getLocation_code().compareTo("XX")!=0)
// System.out.print(this.getLocation_code()+"\n");
out.writeBytes(this.getLocation_code()+"\n");
// else
// out.writeBytes("\n");
out.flush();
 
//Quit...
// System.out.print("Quit\n");
out.writeBytes("Quit\n");
out.flush();
 
 
String line=null;
String line_err=null;
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
// if (line !=null) System.out.println(line);
if (line_err!=null) System.out.println("erreur Read dataless:"+":"+line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur read_dataless");
}
 
//on peut virer le fichier rdseedlog... il faut rajouter la date...TODO
//new File(this.getWorking_path()+"rdseed.err_log.*").delete();
 
 
 
// refres met en forme
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(papa_mseed.References.getRefres_location(),null,new File(this.getWorking_path()));
//System.out.println("refres: "+papa_mseed.getRefres_location()+ new File(this.getWorking_path()));
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
String line=null;
String line_err=null;
 
// Nombre de fichier reponse a lire
out.writeBytes("1\n");
out.flush();
 
// if (this.getLocation_code().compareTo("XX")!=0)
// out.writeBytes(this.getWorking_path()+"/"+"RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+"."+this.getChannel_name()+"\n");
// else
out.writeBytes(this.getWorking_path()+"/"+"RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.getLocation_code()+"."+this.getChannel_name()+"\n");
out.flush();
 
//System.out.println(this.getWorking_path()+"/"+"RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.getLocation_code()+"."+this.getChannel_name()+"\n");
// nombre de reponse a lire dans le fichier en question.. ce n'est a priori pas 1 !!! Mais si on met 1000, cela ne doit pas poser de pb...
//out.writeBytes("1\n");
out.writeBytes("1000\n");
out.flush();
 
//le fichier de sortie...
this.setDataless_channel_name("resp."+this.getStation_name()+"."+this.getStart_day()+"."+java.lang.Character.toLowerCase(this.getChannel_0())+java.lang.Character.toLowerCase(this.getChannel_2()));
out.writeBytes(this.getWorking_path()+"/"+this.getDataless_channel_name()+"\n");
//java.lang.Character.toLowerCase(this.getChannel_2())
out.flush();
 
line=null;
line_err=null;
 
// cette fonction genere des erreurs mais c'est normal ! voir un peu plus haut pour le nb de reponses lues
// c'est pourquoi la sortie erreur est commentee
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
//if (line !=null) System.out.println("stdout:"+line);
//if (line_err!=null) System.out.println("stderr:"+line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur Canal_file.read_dataless");
}
// if (this.getLocation_code().compareTo("XX")!=0)
new File(this.getWorking_path()+"/RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+this.location_code+"."+this.getChannel_name()).delete();
// else
// new File(this.getWorking_path()+"/RESP."+this.getNetwork_name()+"."+this.getStation_name()+"."+"."+this.getChannel_name()).delete();
 
 
}
 
 
// Cette fonction corrige le spectre calculee avec le fichier reponse. le resultat est mis dans un fichier de nom
//this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.nrrcdb"
public void response_correction() {
 
// nom_station_4char needs to be filled with 4 char.
String nom_station_4char=this.getStation_name();
 
while (nom_station_4char.length() < 4) {
nom_station_4char=nom_station_4char+"_";
}
//nom_station_4char=nom_station_4char.substring(0,3);
 
Calendar cal= Calendar.getInstance();
cal.set(Calendar.YEAR,Integer.parseInt(this.getStart_year()));
cal.set(Calendar.DAY_OF_YEAR,Integer.parseInt(this.getStart_day()));
//In Java calendar, january = 0 => +1
String mois =org.geoscope.JSpec.Utils.padZeroLeft((Integer.toString((cal.get(Calendar.MONTH)+1))),2);
String jour =org.geoscope.JSpec.Utils.padZeroLeft((Integer.toString(cal.get(Calendar.DAY_OF_MONTH))),2);
 
 
String date_octave=this.getStart_year()+"."+mois+jour;
//System.out.println("date_octave:"+date_octave);
 
 
 
try {
Runtime r = Runtime.getRuntime();
 
// Process p = r.exec(this.pre_pspecsac_jour_location+" < "+canal.getWorking_path()+"/filecmd."+canal.getChannel_name(),new String[]{ "SACAUX="+sacaux_location, "LEAPSECONDS="+leapseconds_location},new File(canal.getWorking_path()));
 
// Process p = r.exec(octave_location+" "+fix_spec_location,null,new File(this.getWorking_path()));
Process p = r.exec(papa_mseed.References.getOctave_location()+" "+papa_mseed.References.getFix_spec_location(),null,new File(papa_mseed.References.getFix_spec_location()).getParentFile());
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
 
out.writeBytes(this.getLocation_code()+"\n");
// System.out.println(this.getLocation_code());
out.flush();
 
out.writeBytes((this.getStation_name()).toLowerCase()+"\n");
// System.out.println(this.getStation_name());
out.flush();
 
out.writeBytes(java.lang.Character.toLowerCase(this.getChannel_0())+"\n");
// System.out.println(this.getChannel_0());
out.flush();
 
 
out.writeBytes(this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.nrrc"+"\n");
// System.out.print(this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.nrrc"+"\n");
out.flush();
 
out.writeBytes(date_octave+"\n");
// System.out.print(date_octave+"\n");
out.flush();
 
out.writeBytes(date_octave+"\n");
// System.out.print(date_octave+"\n");
out.flush();
 
out.writeBytes(this.getWorking_path()+"/"+this.getDataless_channel_name()+"\n");
// System.out.print("\n"+this.getWorking_path()+"/"+this.getDataless_channel_name()+"\n");
out.flush();
 
String line=null;
String line_err=null;
 
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
// if (line !=null) System.out.println("stdout:"+line);
if (line_err!=null) System.out.println("stderr:"+line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur Canal_file.Octave");
}
}
 
///Cette fonction decime le spectre ??? Dans quel but ???
//public void decime_spectre(String decime_spectre_location){
public void decime_spectre(){
System.out.println("############ Decime_spectre ###################");
// nom_station_4char needs to be filled with 4 char.
String nom_station_4char=this.getStation_name();
while (nom_station_4char.length() < 4) {
nom_station_4char=nom_station_4char+"_";
}
 
try {
Runtime r = Runtime.getRuntime();
 
// Process p = r.exec(this.pre_pspecsac_jour_location+" < "+canal.getWorking_path()+"/filecmd."+canal.getChannel_name(),new String[]{ "SACAUX="+sacaux_location, "LEAPSECONDS="+leapseconds_location},new File(canal.getWorking_path()));
 
// Process p = r.exec(octave_location+" "+fix_spec_location,null,new File(this.getWorking_path()));
Process p = r.exec(papa_mseed.References.getDecime_spectre_location(),null,new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(new InputStreamReader (p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader (p.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
 
out.writeBytes("1\n");
out.flush();
 
 
// Ce programme est très con et cree un fichier de sortie a partir du nom du fichier d'entree => si on met le chemin complet
// comme nom d entree, cela fait n'importe quoi...=> une solution est de ne pas mettre le working_path du fichier... mais bon
//decime spectre est trop trop con...
 
out.writeBytes(nom_station_4char+"."+this.getChannel_name()+".all.nrrcdb\n");
out.flush();
 
out.writeBytes(this.getStart_day()+"\n");
out.flush();
 
if(this.getLocation_code().length()==0) this.setLocation_code("99");
 
out.writeBytes(this.getLocation_code()+"\n");
out.flush();
 
String line=null;
String line_err=null;
 
 
 
while (((line = Resultset.readLine()) != null) || ((line_err = error.readLine()) != null))
{
//if (line !=null) System.out.println("stdout:"+line);
// if (line_err!=null) System.out.println("stderr:"+line_err);
 
}
 
 
 
if (p.waitFor() != 0) {
System.err.println("exit value = " +
p.exitValue());
}
}
catch (Exception e) {
System.out.println("erreur canal.decime_spectre");
}
 
// On renomme maintenant le fichier de sortie...
new File(this.getWorking_path()+"/"+nom_station_4char+"."+this.getLocation_code()+"."+this.getChannel_name()+"."+this.getStart_day()+".nrrcdbd").renameTo(new File(this.getWorking_path()+"/"+this.getStart_day()+"."+this.getLocation_code()+"."+this.getChannel_name()+"."+this.getChannel_2()+"."+this.getStart_day()+"."+this.getStart_year()+"."+"nrrcdbd"));
this.setFile_name_to_plot(this.getWorking_path()+"/"+this.getStart_day()+"."+this.getLocation_code()+"."+this.getChannel_name()+"."+this.getChannel_2()+"."+this.getStart_day()+"."+this.getStart_year()+"."+"nrrcdbd");
 
//On vire le fichier .all.nrrcdb
new File(this.getWorking_path()+"/"+nom_station_4char+"."+this.getChannel_name()+".all.nrrcdb").delete();
 
}
 
public void change_station_name_in_mseed() {
 
System.out.println("Debut de changement de station_name_dans fichier mseed");
try {
Runtime r = Runtime.getRuntime();
 
Process p = r.exec(papa_mseed.References.getQedit_location()+" " + this.getWorking_path()
+ "/" + this.name, null, new File(this.getWorking_path()));
 
BufferedReader Resultset = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
DataOutputStream out = new DataOutputStream(p.getOutputStream());
 
// out.writeBytes("disp \n ");
// System.out.println(this.getLocation_code());
// out.flush();
 
out.writeBytes("from first thru last set name "+this.getStation_name()+"\n");
// System.out.println(this.getStation_name());
out.flush();
 
out.writeBytes("file " + this.getWorking_path() + "/" + this.name
+ " \n");
// System.out.println(this.getChannel_0());
out.flush();
 
out.writeBytes("OK \n");
// System.out.println(this.getChannel_0());
out.flush();
 
String line = null;
String line_err = null;
 
while (((line = Resultset.readLine()) != null)
|| ((line_err = error.readLine()) != null)) {
if (line != null)
System.out.println("stdout:" + line);
if (line_err != null)
System.out.println("stderr:" + line_err);
 
}
 
if (p.waitFor() != 0) {
System.err.println("exit value = " + p.exitValue());
}
} catch (Exception e) {
System.out.println("erreur change_station_name_in_mseed");
}
 
System.out.println("Fin de changement de station_name_dans fichier mseed");
}
 
}
 
/bin/org/geoscope/JSpec/MSeed_File.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/Canal_File.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/JSpec.ini
New file
0,0 → 1,15
[paths]
sdrsplit_location = /opt/bruit/spec3/sdrsplit
ms2sac_location = /opt/bruit/spec3/ms2sac
sac2000_location = /opt/bruit/spec3/sac/bin/sac
sacaux_location = /opt/bruit/spec3/sac/aux/
pre_pspecsac_jour_location = /opt/bruit/spec3/pre_pspecsac_jour
pspecsac_jour_location = /opt/bruit/spec3/pspecsac_jour
leapseconds_location = /opt/bruit/spec3/leapseconds
refres_location = /opt/bruit/spec3/refres
rdseed_location = /opt/passcal/bin/rdseed
octave_location = /usr/bin/octave
fix_spec_location = /opt/bruit/spec3/octave_geoscope_seb.m1
decime_spectre_location = /opt/bruit/spec3/decime_spectre_db
gnuplot_location = /usr/bin/gnuplot
qedit_location=/opt/passcal/bin/qedit
/bin/org/geoscope/JSpec/INIFile.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/Seed_File.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/test.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/Utils.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/References.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/JSAP-2.1.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/JSpec.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/Filter.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/INIFile$INIProperty.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/INIFile$INISection.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/Spec_Trace.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/bin/org/geoscope/JSpec/MSeed_Group.class
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream