Skip to content

Commit

Permalink
ttools: generate multi-coordinate coord names consistently
Browse files Browse the repository at this point in the history
Add a new method PlotUtil.getIndexSuffix which is used consistently
wherever multi-position coordinate sets are used.  This allows them
to be identified by name without guesswork.
  • Loading branch information
mbtaylor committed Dec 17, 2013
1 parent d5977cc commit 020a901
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uk.ac.starlink.table.DomainMapper;
import uk.ac.starlink.table.ValueInfo;
import uk.ac.starlink.ttools.plot2.DataGeom;
import uk.ac.starlink.ttools.plot2.PlotUtil;
import uk.ac.starlink.ttools.plot2.data.Coord;
import uk.ac.starlink.ttools.plot2.data.StorageType;

Expand Down Expand Up @@ -69,7 +70,7 @@ public static Coord[] multiplyCoords( Coord[] coords, int ncopy ) {
* @return new coord like the input one
*/
private static Coord relabel( final Coord baseCoord, int iPoint ) {
String iptxt = Integer.toString( iPoint + 1 );
String iptxt = PlotUtil.getIndexSuffix( iPoint );
final ValueInfo[] infos = baseCoord.getUserInfos().clone();
int nuc = infos.length;
for ( int iuc = 0; iuc < nuc; iuc++ ) {
Expand Down
16 changes: 16 additions & 0 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/PlotUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ public static boolean storeFullPrecision() {
return true;
}

/**
* Returns a suffix to append to one of a set of similar coordinate
* names for disambiguation.
* Where there are several sets of positional coordinates that would
* otherwise have the same names, use this method to come up with
* a consistent suffix. It is only usual to invoke this method
* if there are in fact multiple positions, if there's only one just
* don't give it a suffix.
*
* @param ipos zero-based position number
* @return suffix; currently <code>1+ipos</code>
*/
public static String getIndexSuffix( int ipos ) {
return Integer.toString( 1 + ipos );
}

/**
* Writes message through the logging system
* about the time a named step has taken.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ private DataSpec createDataSpec( Environment env, String suffix,
List<CoordValue> cvlist = new ArrayList<CoordValue>();
for ( int ipos = 0; ipos < npos; ipos++ ) {
Coord[] posCoords = geom.getPosCoords();
String posSuffix = npos > 1 ? Integer.toString( ipos + 1 ) : "";
String posSuffix = npos > 1 ? PlotUtil.getIndexSuffix( ipos ) : "";
for ( int ic = 0; ic < posCoords.length; ic++ ) {
cvlist.add( getCoordValue( env, posCoords[ ic ],
posSuffix + suffix ) );
Expand Down

0 comments on commit 020a901

Please sign in to comment.