From: shravan <sad...@us...> - 2005-12-29 23:14:50
|
Update of /cvsroot/jmol/Jmol/src/org/jmol/jcamp/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23420/src/org/jmol/jcamp/utils Added Files: NumericDataUtils.java StringDataUtils.java Log Message: First check-in of jcamp graphing tool related files. Shravan Sadasivan --- NEW FILE: NumericDataUtils.java --- package org.jmol.jcamp.utils; public class NumericDataUtils { public static int convToIntelInt(int i) { int byte0 = i & 0xff; int byte1 = (i>>8) & 0xff; int byte2 = (i>>16) & 0xff; int byte3 = (i>>24) & 0xff; // swap the byte order return (byte0<<24) | (byte1<<16) | (byte2<<8) | byte3; } public static float convToIntelFloat(int i) { int byte0 = i & 0xff; int byte1 = (i>>8) & 0xff; int byte2 = (i>>16) & 0xff; int byte3 = (i>>24) & 0xff; // swap the byte order int new_i = (byte0<<24) | (byte1<<16) | (byte2<<8) | byte3; return Float.intBitsToFloat(new_i); } public static double convToIntelDouble(long i) { long byte0 = i & 0xff; long byte1 = (i>>8) & 0xff; long byte2 = (i>>16) & 0xff; long byte3 = (i>>24) & 0xff; long byte4 = (i>>32) & 0xff; long byte5 = (i>>40) & 0xff; long byte6 = (i>>48) & 0xff; long byte7 = (i>>56) & 0xff; // swap the byte order long l = (byte0<<56) | (byte1<<48) | (byte2<<40) | (byte3<<32) | (byte4<<24) | (byte5<<16) | (byte6<<8) | byte7; return Double.longBitsToDouble(l); } } --- NEW FILE: StringDataUtils.java --- /** * Copyright (c) 2005, Shravan Sadasivan & Richard Spinney * Department of Chemisty - The Ohio State University */ package org.jmol.jcamp.utils; public class StringDataUtils { /** * Returns the sub-string of the string provided * @param str * @param i * @param j * @return String */ public static String jcampSubString(String str, int i, int j){ if (str.length()<j) return str; return str.substring(i,j); } /** * Truncates blank spaces at the end of the string provided * @param str * @return String */ public static String truncateEndBlanks(String str) { while (str.charAt(str.length()-1)==' ') str=str.substring(0,str.length()-1); return str; } /** * Compares two strings provided and returns an expected integer value based on the comparison * @param str1 * @param str2 * @return int */ public static int compareStrings(String str1, String str2){ if (str1==null) return -1; if (str2==null) return -1; if (str1.length()!=str2.length()) return -1; return str1.compareTo(str2); } /** * Reduces the precision of numerical data strings provided * @param data * @return String */ public static String reduceDataPrecision(String data) { // trop de precision sur Communicator! if (data.length()>10) { if (data.indexOf('E')!=-1) data=data.substring(0,data.indexOf('E')-1)+"e"+data.substring(data.indexOf('E')+1); if (data.indexOf('e')==-1) data=data.substring(0,9); else data=String.valueOf( Math.pow(10,Double.valueOf(data.substring(data.indexOf('e')+1)).doubleValue())* Double.valueOf(data.substring(0,Math.min(9,data.indexOf('e')-1))).doubleValue() ); } return data; } } |