-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grib2json #17
Comments
It's Java Code, Can be use on both Linux and Windows. |
你好,我可以请教下你是怎么处理GRIB2数据的吗? 我能加下你QQ吗? 本人QQ419513210 |
你好,
if you use Java , use the netCDF library
This is an example you can refer to.
public float[][] TempMax0_0(String FilePath, String FileName) throws
IOException, InvalidRangeException {
int previous_index;
int numTime = 1, numHeight = 1, numRow = 781, numCol = 602;
int[] start = { 0, 0, 0, 0 };
int[] size = { numTime, numHeight, numRow, numCol };
// System.out.println(input_FileName);
File f2 = new File(infol);
String[] f_list_000 = f2.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(".gb2") && name.contains("h000");
}
});
String[] f_list_001 = f2.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(".gb2") && name.contains("h001");
}
});
String[] f_list_002 = f2.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(".gb2") && name.contains("h002");
}
});
previous_index = Arrays.asList(f_list_000).indexOf(FileName);
int next_index = previous_index + 1;
// if (previous_index <= 11) {
// return null;
// }
float[][] Max_Temp_000 = new float[781][602];
float[][] Current_Temp_000 = new float[781][602];
float[][] Max_Temp_001 = new float[781][602];
float[][] Current_Temp_001 = new float[781][602];
float[][] Max_Temp_002 = new float[781][602];
float[][] Current_Temp_002 = new float[781][602];
float[][] Next_Temp_000 = new float[781][602];
float[][] Next_Temp_001 = new float[781][602];
float[][] Next_Temp_002 = new float[781][602];
float[][] last_Max_Temp = new float[781][602];
NetcdfFile ncFile_000 = null;
NetcdfFile ncFile_001 = null;
NetcdfFile ncFile_002 = null;
for (int k = 0; k <= 8; k++) {
if (k <= 4) {
System.out.println(FilePath + f_list_000[previous_index]);
ncFile_000 = NetcdfFile.open(FilePath + f_list_000[previous_index]);
ncFile_001 = NetcdfFile.open(FilePath + f_list_001[previous_index]);
ncFile_002 = NetcdfFile.open(FilePath + f_list_002[previous_index]);
previous_index--;
} else {
System.out.println(FilePath + f_list_000[next_index]);
ncFile_000 = NetcdfFile.open(FilePath + f_list_000[next_index]);
ncFile_001 = NetcdfFile.open(FilePath + f_list_001[next_index]);
ncFile_002 = NetcdfFile.open(FilePath + f_list_002[next_index]);
next_index++;
}
List<Variable> lst_000 = ncFile_000.getVariables();
Variable temp_var_000 = (Variable) lst_000.get(19); // SM
Array temp_arr_000 = temp_var_000.read(start, size); // read(origin,
// shape);
List<Variable> lst_001 = ncFile_001.getVariables();
Variable temp_var_001 = (Variable) lst_001.get(19); // SM
Array temp_arr_001 = temp_var_001.read(start, size); // read(origin,
// shape);
List<Variable> lst_002 = ncFile_002.getVariables();
Variable temp_var_002 = (Variable) lst_002.get(19); // SM
Array temp_arr_002 = temp_var_002.read(start, size); // read(origin,
// shape);
Index idx = temp_arr_000.getIndex();
for (int i = 0; i < 781; i++) {
for (int j = 0; j < 602; j++) {
Next_Temp_000[i][j] = temp_arr_000.getFloat(idx.set(0, 0, i, j));
Next_Temp_001[i][j] = temp_arr_001.getFloat(idx.set(0, 0, i, j));
Next_Temp_002[i][j] = temp_arr_002.getFloat(idx.set(0, 0, i, j));
if (Float.isNaN(Next_Temp_000[i][j])) {
// System.out.println("NaN");
} else {
Max_Temp_000[i][j] = Math.max(Current_Temp_000[i][j], Next_Temp_000[i][j]);
Current_Temp_000[i][j] = Max_Temp_000[i][j];
}
if (Float.isNaN(Next_Temp_001[i][j])) {
// System.out.println("NaN");
} else {
Max_Temp_001[i][j] = Math.max(Current_Temp_001[i][j], Next_Temp_001[i][j]);
Current_Temp_001[i][j] = Max_Temp_001[i][j];
}
if (Float.isNaN(Next_Temp_002[i][j])) {
// System.out.println("NaN");
} else {
Max_Temp_002[i][j] = Math.max(Current_Temp_002[i][j], Next_Temp_002[i][j]);
Current_Temp_002[i][j] = Max_Temp_002[i][j];
}
last_Max_Temp[i][j] = threeMax(Max_Temp_000[i][j], Max_Temp_001[i][j],
Max_Temp_002[i][j]);
}
}
}
ncFile_000.close();
ncFile_001.close();
ncFile_002.close();
System.out.println("-------------------------------------------------------------");
return last_Max_Temp;
}
2018년 8월 21일 (화) 오후 12:09, 苏俊波 <notifications@github.com>님이 작성:
… 你好,我可以请教下你是怎么处理GRIB2数据的吗? 我能加下你QQ吗? 本人QQ419513210
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#17 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARBM3rgD2J32py6neND-cNulKVgW5W34ks5uS3n1gaJpZM4Hy2fz>
.
--
============================================
In-Hak Kong.
Dept. of Spatial Information Engineering
Pukyong National University
Daeyoen-3, Nam-Gu, Busan 608-737, Korea
Cell phone : +82-10-9966-0889
E-mail : zzang1454@gmail.com
============================================
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Linux? Windows also uses it possible?
In what ways do you use?
The text was updated successfully, but these errors were encountered: