8
8
import matplotlib .pyplot as plt
9
9
import numpy as np
10
10
import matplotlib .cm as cm
11
- from netCDF4 import Dataset
12
- from h5py import File
13
11
import argparse
14
12
import os
15
13
import json
@@ -36,6 +34,9 @@ def parse_args():
36
34
parser .add_argument ('-oned' , \
37
35
help = 'strip 1d files of ghostcells and store in one file' , \
38
36
action = "store_true" )
37
+ parser .add_argument ('-dir' , default = None , type = str ,
38
+ help = "Directory to find Aether files in. Will look in current"
39
+ " directory & $PWD/UA/output/" )
39
40
40
41
args = parser .parse_args ()
41
42
@@ -544,6 +545,13 @@ def get_base_files():
544
545
IsFound , item = if_unique (ensembleFiles , fileInfo ['ensembleFile' ])
545
546
if (IsFound ):
546
547
filesInfo [i ]['ensembleMembers' ] = ensembleCounter [item ]
548
+
549
+ if len (filesInfo ) == 0 :
550
+ try :
551
+ os .chdir ("UA/output" )
552
+ get_base_files ()
553
+ except :
554
+ print ("No input files found!!" )
547
555
548
556
return filesInfo
549
557
@@ -948,18 +956,33 @@ def write_and_plot_data(dataToWrite,
948
956
# main code
949
957
#----------------------------------------------------------------------------
950
958
951
- if __name__ == '__main__' : # main code block
959
+ def main ( args ):
952
960
953
- args = parse_args ()
954
961
isVerbose = args .v
962
+
963
+ if args .dir :
964
+ if isVerbose :
965
+ print ("changing directory to: " , args .dir )
966
+ os .chdir (args .dir )
955
967
956
968
filesInfo = get_base_files ()
969
+
970
+ if len (filesInfo ) == 0 :
971
+ return
957
972
958
973
iVar = 3
959
974
iAlt = args .alt
960
975
961
976
output_netcdf = False if args .hdf5 else True
962
-
977
+
978
+ if filesInfo [0 ]['isNetCDF' ]:
979
+ try :
980
+ from netCDF4 import Dataset
981
+ from h5py import File
982
+ except InputError :
983
+ raise InputError (
984
+ "Attempting to postprocess NetCDF files, but NetCDF is not installed for Python" )
985
+
963
986
for iFile , fileInfo in enumerate (filesInfo ):
964
987
coreFile = fileInfo ['coreFile' ]
965
988
isNetCDF = fileInfo ['isNetCDF' ]
@@ -1004,4 +1027,12 @@ def write_and_plot_data(dataToWrite,
1004
1027
if (isVerbose ):
1005
1028
print (' ' , command )
1006
1029
os .system (command )
1007
-
1030
+
1031
+ # call main:
1032
+ if __name__ == '__main__' :
1033
+
1034
+ args = parse_args ()
1035
+
1036
+ # This allows code to cleanly exit on error
1037
+ main (args )
1038
+
0 commit comments