Guest User

Untitled

a guest
Jun 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.94 KB | None | 0 0
  1. public class JavaDB {
  2.  
  3. public static Variable time;
  4. public static Variable cloud_1st;
  5. public static Variable cloud_2nd;
  6. public static Variable cloud_3th;
  7. public static Variable cloud_4th;
  8. public static Variable cloud_5th;
  9. public static Variable Layer_1st;
  10. public static Variable Layer_2nd;
  11. public static Variable Layer_3th;
  12. public static Variable Layer_4th;
  13. public static Variable Layer_5th;
  14. public static Variable CBN;
  15.  
  16. public static void getDataNC(String location, ArrayList<Integer> Values) throws Exception{
  17.  
  18.  
  19.  
  20. String version = System.getProperty("java.version");
  21. NetcdfFileWriter ncfile = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf4, location, null);
  22. // add dimensions
  23.  
  24. Dimension heightDim = ncfile.addDimension(null,"height",1539);
  25. Dimension timeDim = ncfile.addUnlimitedDimension("time");
  26.  
  27. //define variables
  28. for(int k=0; k<Values.size(); k++){
  29.  
  30. switch(Values.get(k)){
  31.  
  32.  
  33. case 1: Variable time = ncfile.addVariable(null, "time", DataType.DOUBLE,"time");
  34. time.addAttribute( new Attribute("units", "days since 1970-01-01"));
  35. break;
  36. case 2: Variable cloud_1st = ncfile.addVariable(null,"cloud_1st", DataType.INT,"time");
  37. cloud_1st.addAttribute( new Attribute("long_name", "cloud amount in 1st layer1"));
  38. cloud_1st.addAttribute( new Attribute("units", "octa"));
  39. cloud_1st.addAttribute(new Attribute("_FillValue",-9999));
  40. cloud_1st.addAttribute(new Attribute("Vertical Visibility",9));
  41. cloud_1st.addAttribute(new Attribute("No enough data",99));
  42. break;
  43. case 3: Variable cloud_2nd = ncfile.addVariable(null,"cloud_2nd", DataType.INT,"time");
  44. cloud_2nd.addAttribute( new Attribute("long_name", "cloud amount in 2nd layer"));
  45. cloud_2nd.addAttribute( new Attribute("units", "octa"));
  46. cloud_2nd.addAttribute(new Attribute("_FillValue",-9999));
  47. cloud_2nd.addAttribute(new Attribute("Vertical Visibility",9));
  48. cloud_2nd.addAttribute(new Attribute("No enough data",99));
  49. break;
  50. case 4: Variable cloud_3th = ncfile.addVariable(null,"cloud_3th", DataType.INT,"time");
  51. cloud_3th.addAttribute( new Attribute("long_name", "cloud amount in 3th layer"));
  52. cloud_3th.addAttribute( new Attribute("units", "octa"));
  53. cloud_3th.addAttribute(new Attribute("_FillValue",-9999));
  54. cloud_3th.addAttribute(new Attribute("Vertical Visibility",9));
  55. cloud_3th.addAttribute(new Attribute("No enough data",99));
  56. break;
  57. case 5: Variable cloud_4th = ncfile.addVariable(null, "cloud_4th", DataType.INT, "time");
  58. cloud_4th.addAttribute( new Attribute("long_name", "cloud amount in 4th layer"));
  59. cloud_4th.addAttribute( new Attribute("units", "octa"));
  60. cloud_4th.addAttribute(new Attribute("_FillValue",-9999));
  61. cloud_4th.addAttribute(new Attribute("Vertical Visibility", 9));
  62. cloud_4th.addAttribute(new Attribute("No enough data",99));
  63. break;
  64. case 6: Variable cloud_5th = ncfile.addVariable(null, "cloud_5th", DataType.INT, "time");
  65. cloud_5th.addAttribute( new Attribute("long_name", "cloud amount in 5th layer"));
  66. cloud_5th.addAttribute( new Attribute("units", "octa"));
  67. cloud_5th.addAttribute(new Attribute("_FillValue",-9999));
  68. cloud_5th.addAttribute(new Attribute("Vertical Visibility",9));
  69. cloud_5th.addAttribute(new Attribute("no enough data",99));
  70. break;
  71. case 7: Variable Layer_1st = ncfile.addVariable(null,"Layer_1st",DataType.INT,"time");
  72. Layer_1st.addAttribute(new Attribute("long_name", "1st cloud layer height"));
  73. Layer_1st.addAttribute(new Attribute("units","meter"));
  74. Layer_1st.addAttribute(new Attribute("_FillValue",-9999));
  75. break;
  76. case 8: Variable Layer_2nd = ncfile.addVariable(null,"Layer_2nd",DataType.INT,"time");
  77. Layer_2nd.addAttribute(new Attribute("long_name", "2nd cloud layer height"));
  78. Layer_2nd.addAttribute(new Attribute("units","meter"));
  79. Layer_2nd.addAttribute(new Attribute("_FillValue",-9999));
  80. break;
  81. case 9: Variable Layer_3th = ncfile.addVariable(null,"Layer_3th",DataType.INT,"time");
  82. Layer_3th.addAttribute(new Attribute("long_name", "3th cloud layer height"));
  83. Layer_3th.addAttribute(new Attribute("units","meter"));
  84. Layer_3th.addAttribute(new Attribute("_FillValue",-9999));
  85. break;
  86. case 10: Variable Layer_4th = ncfile.addVariable(null,"Layer_4th",DataType.INT,"time");
  87. Layer_4th.addAttribute(new Attribute("long_name", "4th cloud layer height"));
  88. Layer_4th.addAttribute(new Attribute("units","meter"));
  89. Layer_4th.addAttribute(new Attribute("_FillValue",-9999));
  90. break;
  91. case 11: Variable Layer_5th = ncfile.addVariable(null,"Layer_5th",DataType.INT,"time");
  92. Layer_5th.addAttribute(new Attribute("long_name", "5th cloud layer height"));
  93. Layer_5th.addAttribute(new Attribute("units","meter"));
  94. Layer_5th.addAttribute(new Attribute("_FillValue",-9999));
  95. break;
  96.  
  97. case 12: Variable CBN = ncfile.addVariable(null,"CBN",DataType.INT,"time");
  98. CBN.addAttribute(new Attribute("long_name","cloud base number"));
  99. CBN.addAttribute(new Attribute("units", "number"));
  100. CBN.addAttribute(new Attribute("no significant backscatter",0));
  101. CBN.addAttribute(new Attribute("obscuration but no cloud",4));
  102. CBN.addAttribute(new Attribute("transparent obscuration",5));
  103. CBN.addAttribute(new Attribute("_FillValue",-9));
  104. break;
  105. }
  106. }
  107.  
  108. ncfile.create();
  109.  
  110.  
  111. try{
  112.  
  113.  
  114. ArrayDouble.D1 timeData = new ArrayDouble.D1(countLinesResult);
  115. ArrayInt.D1 cloudL1Data = new ArrayInt.D1(countLinesResult);
  116. Index ima = cloudL1Data.getIndex();
  117. ArrayInt.D1 cloudL2Data = new ArrayInt.D1(countLinesResult);
  118. ArrayInt.D1 cloudL3Data = new ArrayInt.D1(countLinesResult);
  119. ArrayInt.D1 cloudL4Data = new ArrayInt.D1(countLinesResult);
  120. ArrayInt.D1 cloudL5Data = new ArrayInt.D1(countLinesResult);
  121. ArrayInt.D1 cLayer1Data = new ArrayInt.D1(countLinesResult);
  122. ArrayInt.D1 cLayer2Data = new ArrayInt.D1(countLinesResult);
  123. ArrayInt.D1 cLayer3Data = new ArrayInt.D1(countLinesResult);
  124. ArrayInt.D1 cLayer4Data = new ArrayInt.D1(countLinesResult);
  125. ArrayInt.D1 cLayer5Data = new ArrayInt.D1(countLinesResult);
  126. ArrayInt.D1 CBNData = new ArrayInt.D1(countLinesResult);
  127.  
  128.  
  129. for (int timeIdx = 0; timeIdx < countLinesResult;timeIdx++){
  130. for(int k=0; k<Values.size(); k++){
  131. // System.out.println(Values.get(k));
  132. if(Values.get(k)==1){
  133. timeData.setDouble(timeIdx,tdate.get(timeIdx));}
  134. if(Values.get(k)==2){
  135. cloudL1Data.setInt(ima.set(timeIdx), cloud_layer_1st.get(timeIdx));}
  136. if(Values.get(k)==3){
  137. cloudL2Data.setInt(ima.set(timeIdx), cloud_layer_2nd.get(timeIdx));}
  138. if(Values.get(k)==4){
  139. cloudL3Data.setInt(ima.set(timeIdx), cloud_layer_3th.get(timeIdx));}
  140. if(Values.get(k)==5){
  141. cloudL4Data.setInt(ima.set(timeIdx), cloud_layer_4th.get(timeIdx));}
  142. if(Values.get(k)==6){
  143. cloudL5Data.setInt(ima.set(timeIdx), cloud_layer_5th.get(timeIdx));}
  144. if(Values.get(k)==7){
  145. cLayer1Data.setInt(ima.set(timeIdx), LayerC_1st.get(timeIdx));}
  146. if(Values.get(k)==8){
  147. cLayer2Data.setInt(ima.set(timeIdx), LayerC_2nd.get(timeIdx));}
  148. if(Values.get(k)==9){
  149. cLayer3Data.setInt(ima.set(timeIdx), LayerC_3th.get(timeIdx));}
  150. if(Values.get(k)==10){
  151. cLayer4Data.setInt(ima.set(timeIdx), LayerC_4th.get(timeIdx));}
  152. if(Values.get(k)==11){
  153. cLayer5Data.setInt(ima.set(timeIdx), LayerC_5th.get(timeIdx));}
  154. if(Values.get(k)==12){
  155. CBNData.setInt(ima.set(timeIdx),nbcb.get(timeIdx));}
  156. }
  157. }
  158.  
  159. // write the data into netCDF file
  160. for(int k=0; k<Values.size(); k++){
  161. if(Values.get(k)==1){
  162. ncfile.write(time, timeData);}
  163. if(Values.get(k)==2){
  164. ncfile.write(cloud_1st, cloudL1Data);}
  165. if(Values.get(k)==3){
  166. ncfile.write(cloud_2nd, cloudL2Data);}
  167. if(Values.get(k)==4){
  168. ncfile.write(cloud_3th, cloudL3Data);}
  169. if(Values.get(k)==5){
  170. ncfile.write(cloud_4th, cloudL4Data);}
  171. if(Values.get(k)==6){
  172. ncfile.write(cloud_5th, cloudL5Data);}
  173. if(Values.get(k)==7){
  174. ncfile.write(Layer_1st, cLayer1Data);}
  175. if(Values.get(k)==8){
  176. ncfile.write(Layer_2nd, cLayer2Data);}
  177. if(Values.get(k)==9){
  178. ncfile.write(Layer_3th, cLayer3Data);}
  179. if(Values.get(k)==10){
  180. ncfile.write(Layer_4th, cLayer4Data);}
  181. if(Values.get(k)==11){
  182. ncfile.write(Layer_5th, cLayer5Data);}
  183. if(Values.get(k)==12){
  184. ncfile.write(CBN,CBNData);}
  185. }
  186.  
  187. }catch(Exception e){
  188. e.printStackTrace();}
  189.  
  190. finally{
  191. try{
  192.  
  193. ncfile.close();
  194.  
  195. }catch(IOException ex){
  196. ex.printStackTrace();
  197.  
  198. }
  199.  
  200. }
Add Comment
Please, Sign In to add comment