...
Code Block | ||||
---|---|---|---|---|
| ||||
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
/**
*
* @author tonyj
*/
public class Main
{
/** Creates a new instance of Main2 */
public static void main(String[] args) throws IOException
{
File file = new File(args[0]);
FileInputStream in = new FileInputStream(file);
FileChannel channel = in.getChannel();
ByteBuffer buffer = channel.map(MapMode.READ_ONLY,0,file.length());
buffer.order(ByteOrder.BIG_ENDIAN);
final int size = buffer.getInt();
FloatBuffer floats = buffer.asFloatBuffer();
int nAccept = 0;
float eCut = (float) Math.exp(4);
long start = System.currentTimeMillis();
for (int i=0; i<4*size; i += 4)
{
float time = floats.get(i);
if (time < 20000 || time > 70000) continue;
float energy = floats.get(i+1);
if (energy < eCut) continue;
float rightAscension = floats.get(i+2);
float declination = floats.get(i+3);
float dRA = rightAscension-180;
float dDec = declination-0;
if (dRA*dRA + dDec*dDec > 15*15) continue;
nAccept++;
//System.out.printf("%g %g %g %g\n",time,energy,dRA,dDec);
}
long stop = System.currentTimeMillis();
System.out.println("Elapsed "+(stop-start)+"ms");
System.out.println("Accepted "+nAccept+"/"+size);
in.close();
}
}
|
...