1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package au.csiro.netcdf; |
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.io.FileInputStream; |
24 | |
import java.io.IOException; |
25 | |
import java.io.PrintWriter; |
26 | |
import java.io.StringWriter; |
27 | |
import java.util.ArrayList; |
28 | |
import java.util.HashSet; |
29 | |
import java.util.List; |
30 | |
import java.util.Set; |
31 | |
import java.util.regex.PatternSyntaxException; |
32 | |
|
33 | |
import org.apache.commons.cli.BasicParser; |
34 | |
import org.apache.commons.cli.CommandLine; |
35 | |
import org.apache.commons.cli.HelpFormatter; |
36 | |
import org.apache.commons.cli.Option; |
37 | |
import org.apache.commons.cli.OptionBuilder; |
38 | |
import org.apache.commons.cli.Options; |
39 | |
import org.apache.commons.cli.ParseException; |
40 | |
import org.apache.log4j.Logger; |
41 | |
|
42 | |
import ucar.ma2.DataType; |
43 | |
import ucar.nc2.Attribute; |
44 | |
import ucar.nc2.NetcdfFileWriteable; |
45 | |
import ucar.nc2.Variable; |
46 | |
import au.csiro.netcdf.cli.Command; |
47 | |
import au.csiro.netcdf.cli.CommandLineOptionsComparator; |
48 | |
import au.csiro.netcdf.util.NetCDFUtils; |
49 | |
import au.csiro.netcdf.util.Util; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | 2 | public class NcDefineVariable implements Command |
62 | |
{ |
63 | |
|
64 | |
|
65 | |
|
66 | |
public static final String NC_DEFINE_VAR_COMMAND_NAME = "ncdefineVar"; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public static final String OUTPUT_FILE = "outputFileName"; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public static final String INPUT_FILE = "inputFileName"; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
private static final String STANDARD_INPUT = "standardInput"; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public static final String VARIABLE_NAME = "variableName"; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public static final String VARIABLE_DATA_TYPE = "variableDataType"; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public static final String VARIABLE_ATTRIBUTES = "variableAttributes"; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public static final String DIMENSION_NAMES = "dimensionNames"; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public static final String IS_LARGE_FILE = "largeFileSupport"; |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public static final String IS_FILL_VARIABLE = "fillVar"; |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
private static final String DUMMY_VARIABLE = "dummyVariable"; |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | 2 | private static final Logger LOG = Logger.getLogger(NcDefineVariable.class.getName()); |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | 26 | private Options options = null; |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 2 | private static Set<DataType> netCDF3DataTypes = new HashSet<DataType>(); |
134 | |
{ |
135 | 26 | netCDF3DataTypes.add(DataType.DOUBLE); |
136 | 26 | netCDF3DataTypes.add(DataType.FLOAT); |
137 | 26 | netCDF3DataTypes.add(DataType.INT); |
138 | 26 | netCDF3DataTypes.add(DataType.CHAR); |
139 | 26 | netCDF3DataTypes.add(DataType.SHORT); |
140 | 26 | netCDF3DataTypes.add(DataType.BYTE); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | 26 | public NcDefineVariable() |
147 | |
{ |
148 | 26 | this.options = createOptions(); |
149 | 26 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Override |
157 | |
public void execute(String[] args) throws IllegalArgumentException, IOException, ParseException |
158 | |
{ |
159 | |
|
160 | 14 | CommandLine parsedCommandLine = new BasicParser().parse(this.options, args); |
161 | |
|
162 | |
|
163 | 24 | String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine |
164 | 12 | .getOptionValue(OUTPUT_FILE) : ""; |
165 | 24 | String inputFilenameArg = (parsedCommandLine.hasOption(INPUT_FILE)) ? parsedCommandLine |
166 | 0 | .getOptionValue(INPUT_FILE) : ""; |
167 | 12 | boolean isStandardInput = parsedCommandLine.hasOption(STANDARD_INPUT); |
168 | 24 | String variableNameArg = (parsedCommandLine.hasOption(VARIABLE_NAME)) ? parsedCommandLine |
169 | 12 | .getOptionValue(VARIABLE_NAME) : ""; |
170 | 24 | String variableDataTypeArg = (parsedCommandLine.hasOption(VARIABLE_DATA_TYPE)) ? parsedCommandLine |
171 | 12 | .getOptionValue(VARIABLE_DATA_TYPE) : ""; |
172 | 24 | String variableAttributesArg = (parsedCommandLine.hasOption(VARIABLE_ATTRIBUTES)) ? parsedCommandLine |
173 | 4 | .getOptionValue(VARIABLE_ATTRIBUTES) : ""; |
174 | 24 | String dimensionNamesArg = (parsedCommandLine.hasOption(DIMENSION_NAMES)) ? parsedCommandLine |
175 | 12 | .getOptionValue(DIMENSION_NAMES) : ""; |
176 | 12 | boolean isLargeFileSupport = parsedCommandLine.hasOption(IS_LARGE_FILE); |
177 | 12 | boolean isFillVariable = parsedCommandLine.hasOption(IS_FILL_VARIABLE); |
178 | |
|
179 | |
|
180 | 12 | File outputFile = null; |
181 | |
try |
182 | |
{ |
183 | 12 | outputFile = Util.getExistingFile(outputFilenameArg); |
184 | |
} |
185 | 2 | catch (IllegalArgumentException iae) |
186 | |
{ |
187 | 4 | throw new IllegalArgumentException(NcDefineVariable.OUTPUT_FILE + " value refers to non-existent file: " |
188 | 2 | + outputFilenameArg); |
189 | |
} |
190 | |
|
191 | |
|
192 | 10 | if (Util.getExistingFile(outputFilenameArg).length() >= MAX_32BIT_OFFSET_FILE_SIZE && !isLargeFileSupport) |
193 | |
{ |
194 | 0 | throw new IllegalArgumentException("The netCDF file will be too large, please use " + IS_LARGE_FILE |
195 | |
+ " flag."); |
196 | |
} |
197 | |
|
198 | |
|
199 | 10 | if (!inputFilenameArg.isEmpty()) |
200 | |
{ |
201 | 0 | Util.getExistingFile(inputFilenameArg); |
202 | |
} |
203 | |
|
204 | |
|
205 | 10 | String dimensionNamesString = NcDefineVariable.mapStringToDimensionNamesString(dimensionNamesArg); |
206 | |
|
207 | |
|
208 | 10 | List<Attribute> variableAttributes = new ArrayList<Attribute>(); |
209 | |
|
210 | 10 | if (!variableAttributesArg.isEmpty()) |
211 | |
{ |
212 | |
try |
213 | |
{ |
214 | 4 | variableAttributes = NetCDFUtils.mapStringToAttributeValueList(variableAttributesArg); |
215 | |
} |
216 | 2 | catch (IllegalArgumentException iae) |
217 | |
{ |
218 | 4 | throw new IllegalArgumentException(NcDefineVariable.VARIABLE_ATTRIBUTES |
219 | 2 | + " value is not a comma separated String of attribute-value pairs: " + variableAttributesArg); |
220 | |
} |
221 | |
} |
222 | |
|
223 | |
|
224 | 8 | DataType variableDataType = NcDefineVariable.mapStringToDataType(variableDataTypeArg); |
225 | |
|
226 | |
|
227 | 8 | if (!inputFilenameArg.isEmpty()) |
228 | |
{ |
229 | 0 | variableAttributes.addAll(NetCDFUtils.readAttributesFromStream(new FileInputStream(inputFilenameArg))); |
230 | |
} |
231 | 8 | if(isStandardInput) |
232 | |
{ |
233 | 0 | variableAttributes.addAll(NetCDFUtils.readAttributesFromStream(System.in)); |
234 | |
} |
235 | 16 | this.execute(outputFile, variableNameArg, variableDataType, variableAttributes, dimensionNamesString, |
236 | 8 | isLargeFileSupport, isFillVariable); |
237 | 8 | } |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
public void execute(File outputFilename, String variableName, DataType variableDataType, |
262 | |
List<Attribute> variableAttributes, String dimensionNamesString, boolean isLargeFileSupport, |
263 | |
boolean isFillVariable) throws IOException |
264 | |
{ |
265 | |
|
266 | 10 | NetcdfFileWriteable ncfile = null; |
267 | |
|
268 | 10 | ncfile = NetcdfFileWriteable.openExisting(outputFilename.getPath(), isFillVariable |
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
); |
286 | |
try |
287 | |
{ |
288 | |
|
289 | 10 | if (ncfile.getDimensions().isEmpty()) |
290 | |
{ |
291 | 0 | throw new IllegalStateException("No dimensions have been defined in the file: " |
292 | 0 | + outputFilename.getPath()); |
293 | |
} |
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | 10 | if (ncfile.getVariables().isEmpty()) |
306 | |
{ |
307 | 10 | ncfile.setRedefineMode(true); |
308 | 10 | ncfile.setLargeFile(true); |
309 | 20 | Variable variable = new Variable(ncfile, null , null , |
310 | 10 | DUMMY_VARIABLE); |
311 | 10 | variable.setDataType(DataType.DOUBLE); |
312 | 10 | variable.setCaching(false); |
313 | 10 | variable.setDimensions(ncfile.getDimensions().get(0).getName()); |
314 | |
|
315 | 10 | ncfile.addVariable(null, variable); |
316 | 10 | ncfile.setRedefineMode(false); |
317 | 10 | ncfile.close(); |
318 | 10 | ncfile = NetcdfFileWriteable.openExisting(outputFilename.getPath(), isFillVariable |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
); |
344 | 10 | ncfile.setRedefineMode(true); |
345 | 10 | ncfile.removeVariable(null, DUMMY_VARIABLE); |
346 | |
} |
347 | |
else |
348 | |
{ |
349 | 0 | ncfile.setRedefineMode(true); |
350 | |
} |
351 | |
|
352 | 10 | ncfile.setLargeFile(isLargeFileSupport); |
353 | |
|
354 | 20 | Variable variable = new Variable(ncfile, null , null , |
355 | 10 | variableName); |
356 | 10 | variable.setDataType(variableDataType); |
357 | 10 | variable.setCaching(false); |
358 | |
|
359 | |
|
360 | 10 | variable.setDimensions(dimensionNamesString); |
361 | |
|
362 | |
|
363 | 26 | for (Attribute attribute : variableAttributes) |
364 | |
{ |
365 | 6 | variable.addAttribute(attribute); |
366 | |
} |
367 | |
|
368 | 10 | ncfile.addVariable(null, variable); |
369 | |
|
370 | |
|
371 | 10 | ncfile.setRedefineMode(false); |
372 | |
} |
373 | |
finally |
374 | 0 | { |
375 | 10 | if(ncfile!=null) |
376 | |
{ |
377 | |
try |
378 | |
{ |
379 | 10 | ncfile.close(); |
380 | |
} |
381 | 0 | catch(Exception e) |
382 | |
{ |
383 | 0 | LOG.error("Could not close file: " + outputFilename.getPath(), e); |
384 | |
} |
385 | |
} |
386 | 0 | } |
387 | 10 | } |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
@Override |
395 | |
public String getCommandName() |
396 | |
{ |
397 | 34 | return NcDefineVariable.NC_DEFINE_VAR_COMMAND_NAME; |
398 | |
} |
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
public String toString() |
406 | |
{ |
407 | |
|
408 | 2 | String header = "Define a variable in a netCDF file."; |
409 | 2 | String footer = "\nExample: ncdefinevar -outputFileName ABC.nc -variableName Lat " |
410 | |
+ "-variableDataType float -dimensionNames Lat\n" |
411 | |
+ "Will add a variable called Lat to the file ABC.nc. The variable is linked to the " |
412 | |
+ "dimension lat and thus is a 'corresponding' variable. The file must already " |
413 | |
+ "exist and the dimension must be already defined in the file."; |
414 | 2 | StringWriter sw = new StringWriter(); |
415 | 2 | HelpFormatter formatter = new HelpFormatter(); |
416 | 2 | formatter.setOptionComparator(new CommandLineOptionsComparator()); |
417 | 4 | formatter.printHelp(new PrintWriter(sw), PRINT_WIDTH, NcDefineVariable.NC_DEFINE_VAR_COMMAND_NAME, header, |
418 | 2 | this.options, 0, 1, footer); |
419 | 2 | return sw.toString(); |
420 | |
} |
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
@SuppressWarnings("static-access") |
428 | |
@Override |
429 | |
public Options createOptions() |
430 | |
{ |
431 | 90 | Option outputFileName = OptionBuilder.withArgName("file").hasArg().withDescription( |
432 | 90 | "1: the filename of the netCDF file to be modified.").isRequired(true).withLongOpt(OUTPUT_FILE).create( |
433 | 30 | "o"); |
434 | |
|
435 | 30 | Option inputFileName = OptionBuilder |
436 | 30 | .withArgName("file") |
437 | 30 | .hasArg() |
438 | 30 | .withDescription( |
439 | 30 | "2. the filename of a text file containing attributes to be loaded. " |
440 | |
+ "OPTIONAL, ensure that text containing '=' or ',' characters are delimited by a backslash.") |
441 | 30 | .isRequired(false).withLongOpt(INPUT_FILE).create("i"); |
442 | |
|
443 | 60 | Option standardInput = OptionBuilder.withDescription( |
444 | 60 | "3: OPTIONAL, read attributes from Stdin, ensure that text containing '=' or ',' characters are delimited by a backslash.").isRequired(false) |
445 | 30 | .withLongOpt(STANDARD_INPUT).create("s"); |
446 | |
|
447 | 90 | Option variableName = OptionBuilder.withArgName("text").hasArg().withDescription( |
448 | 60 | "4: the name to be given to the variable.").isRequired(true).withLongOpt(VARIABLE_NAME).create("v"); |
449 | |
|
450 | 90 | Option variableType = OptionBuilder.withArgName("text").hasArg().withDescription( |
451 | 60 | "5: the data type of the variable, e.g. " + NcDefineVariable.netCDF3DataTypes).isRequired(true) |
452 | 30 | .withLongOpt(VARIABLE_DATA_TYPE).create("t"); |
453 | |
|
454 | 30 | Option variableAttributes = OptionBuilder |
455 | 30 | .withArgName("text") |
456 | 30 | .hasArg() |
457 | 30 | .withDescription( |
458 | 30 | "6: a comma separated list of attribute-value pairs, OPTIONAL, e.g. \"units=mm\", ensure that text containing '=' or ',' characters are delimited by a backslash.") |
459 | 30 | .isRequired(false).withLongOpt(VARIABLE_ATTRIBUTES).create("a"); |
460 | |
|
461 | 90 | Option dimensionNames = OptionBuilder.withArgName("text").hasArg().withDescription( |
462 | 30 | "7: OPTIONAL, a comma separated list of the variable's dimensions, e.g. date,latitude,longitude.") |
463 | 30 | .isRequired(false).withLongOpt(DIMENSION_NAMES).create("d"); |
464 | |
|
465 | 60 | Option largeFileSupport = OptionBuilder.withDescription( |
466 | 60 | "8: OPTIONAL, set if more than 2 GB of data will need to be stored in this file.").isRequired(false) |
467 | 30 | .withLongOpt(IS_LARGE_FILE).create("l"); |
468 | |
|
469 | 60 | Option fillVariable = OptionBuilder.withDescription( |
470 | 60 | "9: OPTIONAL, set if unwritten variable values should have the fill value.").isRequired(false) |
471 | 30 | .withLongOpt(IS_FILL_VARIABLE).create("f"); |
472 | |
|
473 | 30 | Options options = new Options(); |
474 | |
|
475 | 30 | options.addOption(outputFileName); |
476 | 30 | options.addOption(inputFileName); |
477 | 30 | options.addOption(standardInput); |
478 | 30 | options.addOption(variableName); |
479 | 30 | options.addOption(variableType); |
480 | 30 | options.addOption(variableAttributes); |
481 | 30 | options.addOption(dimensionNames); |
482 | 30 | options.addOption(largeFileSupport); |
483 | 30 | options.addOption(fillVariable); |
484 | |
|
485 | 30 | return options; |
486 | |
} |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
public String getUsageString() |
492 | |
{ |
493 | 2 | return this.toString(); |
494 | |
} |
495 | |
|
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
public String validCommand(String[] commandLine) |
502 | |
{ |
503 | 14 | String errorMsg = ""; |
504 | |
|
505 | |
|
506 | |
try |
507 | |
{ |
508 | |
|
509 | 14 | CommandLine parsedCommandLine = new BasicParser().parse(this.options, commandLine); |
510 | |
|
511 | |
|
512 | |
|
513 | 12 | String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine |
514 | 6 | .getOptionValue(OUTPUT_FILE) : ""; |
515 | 12 | String inputFilenameArg = (parsedCommandLine.hasOption(INPUT_FILE)) ? parsedCommandLine |
516 | 0 | .getOptionValue(INPUT_FILE) : ""; |
517 | 12 | String variableDataTypeArg = (parsedCommandLine.hasOption(VARIABLE_DATA_TYPE)) ? parsedCommandLine |
518 | 6 | .getOptionValue(VARIABLE_DATA_TYPE) : ""; |
519 | 12 | String variableAttributesArg = (parsedCommandLine.hasOption(VARIABLE_ATTRIBUTES)) ? parsedCommandLine |
520 | 0 | .getOptionValue(VARIABLE_ATTRIBUTES) : ""; |
521 | 12 | String dimensionNamesArg = (parsedCommandLine.hasOption(DIMENSION_NAMES)) ? parsedCommandLine |
522 | 4 | .getOptionValue(DIMENSION_NAMES) : ""; |
523 | 6 | boolean isLargeFileSupport = parsedCommandLine.hasOption(IS_LARGE_FILE); |
524 | |
|
525 | |
|
526 | |
try |
527 | |
{ |
528 | 6 | Util.getExistingFile(outputFilenameArg); |
529 | |
} |
530 | 2 | catch (IllegalArgumentException iae) |
531 | |
{ |
532 | 4 | throw new IllegalArgumentException(NcDefineVariable.OUTPUT_FILE |
533 | 2 | + " value refers to non-existent file: " + outputFilenameArg); |
534 | |
} |
535 | |
|
536 | |
|
537 | 4 | if (Util.getExistingFile(outputFilenameArg).length() >= MAX_32BIT_OFFSET_FILE_SIZE && !isLargeFileSupport) |
538 | |
{ |
539 | 0 | throw new IllegalArgumentException("The netCDF file will be too large, please use " + IS_LARGE_FILE |
540 | |
+ " flag."); |
541 | |
} |
542 | |
|
543 | |
|
544 | 4 | if (!inputFilenameArg.isEmpty()) |
545 | |
{ |
546 | 0 | Util.getExistingFile(inputFilenameArg); |
547 | |
} |
548 | |
|
549 | |
|
550 | 4 | NcDefineVariable.mapStringToDimensionNamesString(dimensionNamesArg); |
551 | |
|
552 | |
|
553 | 4 | if (!variableAttributesArg.isEmpty()) |
554 | |
{ |
555 | |
try |
556 | |
{ |
557 | 0 | NetCDFUtils.mapStringToAttributeValueList(variableAttributesArg); |
558 | |
} |
559 | 0 | catch (IllegalArgumentException iae) |
560 | |
{ |
561 | 0 | throw new IllegalArgumentException(NcDefineVariable.VARIABLE_ATTRIBUTES |
562 | |
+ " value is not a comma separated String of attribute-value pairs: " |
563 | 0 | + variableAttributesArg); |
564 | |
} |
565 | |
} |
566 | |
|
567 | |
|
568 | 4 | NcDefineVariable.mapStringToDataType(variableDataTypeArg); |
569 | |
} |
570 | 8 | catch (ParseException pe) |
571 | |
{ |
572 | 8 | errorMsg = errorMsg + "\n" + pe.getMessage(); |
573 | |
} |
574 | 4 | catch (IllegalArgumentException iae) |
575 | |
{ |
576 | 4 | errorMsg = errorMsg + "\n" + iae.getMessage(); |
577 | |
} |
578 | |
|
579 | 14 | return errorMsg; |
580 | |
} |
581 | |
|
582 | |
|
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
private static String mapStringToDimensionNamesString(String dimensionNamesArg) throws IllegalArgumentException |
594 | |
{ |
595 | |
try |
596 | |
{ |
597 | 14 | List<String> dimensionNames = Util.tokeniseCommaSeparatedString(dimensionNamesArg); |
598 | 14 | StringBuffer strBuf = new StringBuffer(); |
599 | 40 | for (String dimensionName : dimensionNames) |
600 | |
{ |
601 | 12 | strBuf.append(dimensionName + " "); |
602 | |
} |
603 | 14 | return strBuf.toString(); |
604 | |
} |
605 | 0 | catch (PatternSyntaxException pse) |
606 | |
{ |
607 | 0 | throw new IllegalArgumentException(NcDefineVariable.DIMENSION_NAMES |
608 | 0 | + " value is not a comma separated String: " + dimensionNamesArg); |
609 | |
} |
610 | |
} |
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
|
620 | |
|
621 | |
private static DataType mapStringToDataType(String variableDataType) throws IllegalArgumentException |
622 | |
{ |
623 | 12 | DataType dataType = DataType.getType(variableDataType); |
624 | 12 | if (dataType != null && NcDefineVariable.netCDF3DataTypes.contains(dataType)) |
625 | |
{ |
626 | 10 | return dataType; |
627 | |
} |
628 | 4 | throw new IllegalArgumentException(NcDefineVariable.VARIABLE_DATA_TYPE + " value is not a valid data type: " |
629 | 2 | + variableDataType + ". Allowed data types are: " + NcDefineVariable.netCDF3DataTypes); |
630 | |
} |
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
public static Set<DataType> getNetCDF3DataTypes() |
636 | |
{ |
637 | 0 | return netCDF3DataTypes; |
638 | |
} |
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
public static void setNetCDF3DataTypes(Set<DataType> netCDF3DataTypes) |
644 | |
{ |
645 | 0 | NcDefineVariable.netCDF3DataTypes = netCDF3DataTypes; |
646 | 0 | } |
647 | |
} |