Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 125 additions & 142 deletions src/firefly/java/edu/caltech/ipac/astro/FITSTableReader.java

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/firefly/java/edu/caltech/ipac/astro/IpacTableReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class IpacTableReader {
"r", "float", "f"};
private static final String INT_TYPE[]= { "int.*", "i"} ;
private static final String LONG_TYPE[]= { "long", "l"} ;
private static final String BOOL_TYPE[]= { "bool", "b"} ;
private static final String STRING_TYPE[]= {"cha.*", "str.*", "s", "c"};

private String _line; // to keep the line read from file
Expand Down Expand Up @@ -513,6 +514,10 @@ else if (itc._type!=null &&
ServerStringUtil.matchesRegExpList(itc._type, LONG_TYPE, true)) {
itc._foundType= Long.class;
}
else if (itc._type!=null &&
ServerStringUtil.matchesRegExpList(itc._type, BOOL_TYPE, true)) {
itc._foundType= Boolean.class;
}
else {
itc._foundType= String.class;
}
Expand Down Expand Up @@ -665,6 +670,7 @@ public static boolean isRecongnizedType(String type) {
return ServerStringUtil.matchesRegExpList(type, DOUBLE_TYPE, true) ||
ServerStringUtil.matchesRegExpList(type, INT_TYPE, true) ||
ServerStringUtil.matchesRegExpList(type, LONG_TYPE, true) ||
ServerStringUtil.matchesRegExpList(type, BOOL_TYPE, true) ||
ServerStringUtil.matchesRegExpList(type, STRING_TYPE, true);
}

Expand All @@ -675,6 +681,8 @@ public static Class resolveClass(String type) {
return Integer.class;
} else if ( ServerStringUtil.matchesRegExpList(type, LONG_TYPE, true) ) {
return Long.class;
} else if ( ServerStringUtil.matchesRegExpList(type, BOOL_TYPE, true) ) {
return Boolean.class;
}
return String.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TableServerRequest extends ServerRequest implements Serializable, D
public static final String META_INFO = "META_INFO";
public static final String SYS_PARAMS = "|" + StringUtils.toString(new String[]{FILTERS,SORT_INFO,PAGE_SIZE,START_IDX,INCL_COLUMNS,FIXED_LENGTH,META_INFO,TBL_ID,DECIMATE_INFO}, "|") + "|";

public static final String TBL_INDEX = "tbl_index"; // the table to show if it's a multi-table file.

private int pageSize;
private int startIdx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,15 @@ protected static void writeLine(BufferedWriter writer, String text) throws IOExc
protected static File convertToIpacTable(File tblFile, TableServerRequest request) throws IOException, DataAccessException{
// if the file is not in IPAC table format - convert
DataGroupReader.Format format = DataGroupReader.guessFormat(tblFile);
int tblIdx = request.getIntParam(TableServerRequest.TBL_INDEX, 0);
boolean isFixedLength = request.getBooleanParam(TableServerRequest.FIXED_LENGTH, true);
if (format == DataGroupReader.Format.IPACTABLE && isFixedLength) {
// file is already in ipac table format
return tblFile;
} else {
if ( format != DataGroupReader.Format.UNKNOWN) {
// format is unknown.. convert it into ipac table format
DataGroup dg = DataGroupReader.readAnyFormat(tblFile);
DataGroup dg = DataGroupReader.readAnyFormat(tblFile, tblIdx);
File convertedFile; //= createFile(request, ".tbl");
if (format == DataGroupReader.Format.IPACTABLE) {
convertedFile = FileUtil.createUniqueFileFromFile(tblFile);
Expand All @@ -636,7 +637,7 @@ protected static File convertToIpacTable(File tblFile, TableServerRequest reques
convertedFile = FileUtil.createUniqueFileFromFile(convertedFile);
}

DataGroupWriter.write(convertedFile, dg, 0);
DataGroupWriter.write(convertedFile, dg, 0, request.getMeta());
return convertedFile;
} else {
throw new DataAccessException("Source file has an unknown format:" + ServerContext.replaceWithPrefix(tblFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class IpacTableFromSource extends IpacTablePartProcessor {
public static final String TBL_TYPE = "tblType";
public static final String TYPE_CATALOG = "catalog";
public static final String TBL_INDEX = TableServerRequest.TBL_INDEX; // the table to show if it's a multi-table file.

protected File loadDataFile(TableServerRequest request) throws IOException, DataAccessException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public static enum Format { TSV(CSVFormat.TDF), CSV(CSVFormat.DEFAULT), IPACTABL
}

public static DataGroup readAnyFormat(File inf) throws IOException {
return readAnyFormat(inf, 0);
}

public static DataGroup readAnyFormat(File inf, int tableIndex) throws IOException {
Format format = guessFormat(inf);
if (format == Format.IPACTABLE) {
return read(inf, false, false);
Expand All @@ -42,10 +46,9 @@ public static DataGroup readAnyFormat(File inf) throws IOException {
} else if (format == Format.FITS ) {
try {
// Switch to the new function:
//List<DataGroup> retval = FITSTableReader.convertFITSToDataGroup(inf.getAbsolutePath(), null);
List<DataGroup> retval = FITSTableReader.convertFitsToDataGroup(inf.getAbsolutePath(), null, null, "TOP_MOST");
List<DataGroup> retval = FITSTableReader.convertFitsToDataGroup(inf.getAbsolutePath(), null, null, FITSTableReader.DEFAULT);
if (retval != null && retval.size() > 0) {
return retval.get(0);
return retval.get(tableIndex);
} else {
return null;
}
Expand Down
7 changes: 6 additions & 1 deletion src/firefly/java/edu/caltech/ipac/util/DataGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ public void shrinkToFitData(boolean force) {
int maxDataWidth = dt.getMaxDataWidth();
if (force || maxDataWidth == 0) {
for (DataObject row : this) {
int vlength = Number.class.isAssignableFrom(dt.getDataType()) ? row.getFormatedData(dt).length() : String.valueOf(row.getDataElement(dt)).length();
int vlength = 0;
if (Number.class.isAssignableFrom(dt.getDataType())) {
vlength = dt.getFormatInfo().formatDataOnly(row.getDataElement(dt)).length();
} else {
vlength = String.valueOf(row.getDataElement(dt)).length();
}
maxDataWidth = Math.max(maxDataWidth, vlength);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/firefly/java/edu/caltech/ipac/util/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public enum Importance { HIGH, MEDIUM, LOW, IGNORE}
private static final String INTEGER = "int";
private static final String LONG = "long";
private static final String CHAR = "char";
private static final String BOOL = "bool";
private static final String S_DOUBLE = "d";
private static final String S_FLOAT = "f";
private static final String S_INTEGER = "i";
private static final String S_LONG = "l";
private static final String S_CHAR = "c";
private static final String S_BOOL = "b";

private Class _type;
private String _units;
Expand Down Expand Up @@ -221,6 +223,8 @@ else if (dt.equals(Integer.class) || dt.equals(Short.class))
_typeDesc = useShortType ? S_INTEGER : INTEGER;
else if (dt.equals(Long.class))
_typeDesc = useShortType ? S_LONG : LONG;
else if (dt.equals(Boolean.class))
_typeDesc = useShortType ? S_BOOL : BOOL;
else
_typeDesc = useShortType ? S_CHAR : CHAR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/js/charts/ChartUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function colWithName(cols, name) {
function getNumericCols(cols) {
const ncols = [];
cols.forEach((c) => {
if (c.type !== 'char') {
if (c.type.match(/^[dfil]/) != null) { // int, float, double, long .. or their short form.
ncols.push(c);
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/firefly/js/tables/ui/BasicTableView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,16 @@ function tableToText(columns, dataAry, showUnits=false) {

const colWidths = calcColumnWidths(columns, dataAry);

// column's name
var textHead = columns.reduce( (pval, col, idx) => {
return pval + (get(columns, [idx,'visibility'], 'show') === 'show' ? `${padEnd(col.name, colWidths[idx])}|` : '');
}, '|');

// column's type
textHead += '\n' + columns.reduce( (pval, col, idx) => {
return pval + (get(columns, [idx,'visibility'], 'show') === 'show' ? `${padEnd(col.type || '', colWidths[idx])}|` : '');
}, '|');

if (showUnits) {
textHead += '\n' + columns.reduce( (pval, col, idx) => {
return pval + (get(columns, [idx,'visibility'], 'show') === 'show' ? `${padEnd(col.units || '', colWidths[idx])}|` : '');
Expand Down
18 changes: 15 additions & 3 deletions src/firefly/js/ui/SearchPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,21 @@ export const SearchPanel = (props) => {
<FileUpload
wrapperStyle = {{margin: '5px 0'}}
fieldKey = 'fileUpload'
groupKey='TBL_BY_URL_PANEL'
initialState= {{
tooltip: 'Select a file to upload',
label: 'Upload File:'}}
tooltip: 'Select a file to upload',
label: 'Upload File:'
}}
/>
<ValidationField fieldKey='tbl_index'
groupKey='TBL_BY_URL_PANEL'
initialState= {{
value: 0,
size: 4,
validator: Validate.intRange.bind(null, 0, 100000),
label : 'Table Index:',
labelWidth : 60
}}
/>
</FieldGroup>
</FormPanel>
Expand All @@ -83,7 +95,7 @@ function hideSearchPanel() {

function onSearchSubmit(request) {
if (request.fileUpload) {
const treq = TblUtil.makeFileRequest(null, request.fileUpload, null, {filters: request.filters});
const treq = TblUtil.makeFileRequest(null, request.fileUpload, null, {...request});
dispatchTableSearch(treq);
} else if (request.srcTable) {
const treq = TblUtil.makeFileRequest(null, request.srcTable, null, {filters: request.filters});
Expand Down