Format ReadSizes before changes

This commit is contained in:
Manuel Fuhr 2021-10-17 09:20:56 +02:00
parent ac13b1fe34
commit f5a415bd68

View file

@ -1,62 +1,54 @@
import java.io.*; import java.io.*;
public class ReadSizes public class ReadSizes {
{ private static int[] tileSizes = new int[72 * 36];
private static int[] tileSizes = new int[72*36];
protected static String baseNameForTile( int tileIndex ) protected static String baseNameForTile(int tileIndex) {
{ int lon = (tileIndex % 72) * 5 - 180;
int lon = (tileIndex % 72 ) * 5 - 180; int lat = (tileIndex / 72) * 5 - 90;
int lat = (tileIndex / 72 ) * 5 - 90; String slon = lon < 0 ? "W" + (-lon) : "E" + lon;
String slon = lon < 0 ? "W" + (-lon) : "E" + lon; String slat = lat < 0 ? "S" + (-lat) : "N" + lat;
String slat = lat < 0 ? "S" + (-lat) : "N" + lat; return slon + "_" + slat;
return slon + "_" + slat; }
}
private static int tileForBaseName( String basename )
{
String uname = basename.toUpperCase();
int idx = uname.indexOf( "_" );
if ( idx < 0 ) return -1;
String slon = uname.substring( 0, idx );
String slat = uname.substring( idx+1 );
int ilon = slon.charAt(0) == 'W' ? -Integer.valueOf( slon.substring(1) ) :
( slon.charAt(0) == 'E' ? Integer.valueOf( slon.substring(1) ) : -1 );
int ilat = slat.charAt(0) == 'S' ? -Integer.valueOf( slat.substring(1) ) :
( slat.charAt(0) == 'N' ? Integer.valueOf( slat.substring(1) ) : -1 );
if ( ilon < -180 || ilon >= 180 || ilon % 5 != 0 ) return -1;
if ( ilat < - 90 || ilat >= 90 || ilat % 5 != 0 ) return -1;
return (ilon+180) / 5 + 72*((ilat+90)/5);
}
private static int tileForBaseName(String basename) {
private static void scanExistingFiles( File dir ) String uname = basename.toUpperCase();
{ int idx = uname.indexOf("_");
String[] fileNames = dir.list(); if (idx < 0) return -1;
if ( fileNames == null ) return; String slon = uname.substring(0, idx);
String suffix = ".rd5"; String slat = uname.substring(idx + 1);
for( String fileName : fileNames ) int ilon = slon.charAt(0) == 'W' ? -Integer.valueOf(slon.substring(1)) :
{ (slon.charAt(0) == 'E' ? Integer.valueOf(slon.substring(1)) : -1);
if ( fileName.endsWith( suffix ) ) int ilat = slat.charAt(0) == 'S' ? -Integer.valueOf(slat.substring(1)) :
{ (slat.charAt(0) == 'N' ? Integer.valueOf(slat.substring(1)) : -1);
String basename = fileName.substring( 0, fileName.length() - suffix.length() ); if (ilon < -180 || ilon >= 180 || ilon % 5 != 0) return -1;
int tidx = tileForBaseName( basename ); if (ilat < -90 || ilat >= 90 || ilat % 5 != 0) return -1;
tileSizes[tidx] = (int)new File( dir, fileName ).length(); return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5);
} }
}
}
private static void scanExistingFiles(File dir) {
String[] fileNames = dir.list();
public static void main(String[] args) if (fileNames == null) return;
{ String suffix = ".rd5";
scanExistingFiles( new File( args[0] ) ); for (String fileName : fileNames) {
StringBuilder sb = new StringBuilder(); if (fileName.endsWith(suffix)) {
for( int tidx=0; tidx < tileSizes.length; tidx++ ) String basename = fileName.substring(0, fileName.length() - suffix.length());
{ int tidx = tileForBaseName(basename);
if ( ( tidx % 12 ) == 0 ) sb.append( "\n " ); tileSizes[tidx] = (int) new File(dir, fileName).length();
sb.append( tileSizes[tidx] ).append(',');
} }
System.out.println( sb );
} }
}
public static void main(String[] args) {
scanExistingFiles(new File(args[0]));
StringBuilder sb = new StringBuilder();
for (int tidx = 0; tidx < tileSizes.length; tidx++) {
if ((tidx % 12) == 0) sb.append("\n ");
sb.append(tileSizes[tidx]).append(',');
}
System.out.println(sb);
}
} }