def do_edit(self, context, name=''): "usage: edit [<config>]" if not name and not self.curr_conf: common_err("please load a config first") return False if name: if not self.config_exists(name): return False utils.edit_file("%s/%s" % (userdir.CRMCONF_DIR, name)) else: utils.edit_file("%s/%s" % (userdir.CRMCONF_DIR, self.curr_conf))
def run_upp(work_root, upp_root, config, args): start_time = config['custom']['start_time'] end_time = config['custom']['end_time'] max_dom = config['domains']['max_dom'] start_time_str = start_time.format('YYYY-MM-DD_HH:mm:ss') end_time_str = end_time.format('YYYY-MM-DD_HH:mm:ss') wrf_work_dir = work_root + '/wrf' if not os.path.isdir(wrf_work_dir): cli.error('WRF is not run successfully!') upp_work_dir = work_root + '/upp' if not os.path.isdir(upp_work_dir): os.makedirs(upp_work_dir) os.chdir(upp_work_dir) if not os.path.isdir(f'{upp_work_dir}/parm'): run(f'mkdir {upp_work_dir}/parm') if not os.path.isdir(f'{upp_work_dir}/postprd'): run(f'mkdir {upp_work_dir}/postprd') run(f'cp {upp_root}/parm/postxconfig-NT-WRF.txt {upp_work_dir}/parm') run(f'cp {upp_root}/parm/postcntrl.xml {upp_work_dir}/parm') run(f'cp {upp_root}/parm/post_avblflds.xml {upp_work_dir}/parm') run(f'cp {upp_root}/parm/wrf_cntrl.parm {upp_work_dir}/parm') run(f'cp {upp_root}/scripts/run_unipost {upp_work_dir}/postprd') edit_file('./postprd/run_unipost', [ ['/bin/ksh', '/bin/bash'], ['TOP_DIR=.*', f'TOP_DIR={upp_root}'], ['DOMAINPATH=.*', f'DOMAINPATH={upp_work_dir}'], ['UNIPOST_HOME=.*', f'UNIPOST_HOME={upp_root}'], ['modelDataPath=.*', f'modelDataPath={wrf_work_dir}'], ['startdate=.*', f'startdate={start_time.format("YYYYMMDDHH")}'], ['lastfhr=.*', f'lastfhr={(end_time - start_time).hours}'], ['incrementhr=.*', f'incrementhr=01'], ['domain_list=.*', f'domain_list="d02"'] ]) run(f'./postprd/run_unipost') cli.notice('Succeeded.')
def build_nceplibs(nceplibs_root, args): if not 'HDF5' in os.environ: res = subprocess.run(['which', 'h5dump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['HDF5'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set HDF5 to {os.environ["HDF5"]}') if not 'HDF5' in os.environ: cli.warning('HDF5 environment variable is not set') if not 'NETCDF' in os.environ: res = subprocess.run(['which', 'ncdump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['NETCDF'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set NETCDF to {os.environ["NETCDF"]}') if not 'NETCDF' in os.environ: cli.warning('NETCDF environment variable is not set!') if not 'JASPER_INC' in os.environ or not 'JASPER_LIB' in os.environ: if 'JASPER_ROOT' in os.environ: os.environ['JASPER_INC'] = os.environ['JASPER_ROOT'] + '/include' os.environ['JASPER_LIB'] = os.environ['JASPER_ROOT'] + '/lib' cli.notice(f'Set JASPER_INC to {os.environ["JASPER_INC"]}.') cli.notice(f'Set JASPER_LIB to {os.environ["JASPER_LIB"]}.') else: cli.error( 'JASPERINC and JASPERLIB environment variables are not set!') if not 'PNG_INC' in os.environ or not 'PNG_LIB' in os.environ: if 'LIBPNG_ROOT' in os.environ: os.environ['PNG_INC'] = os.environ['LIBPNG_ROOT'] + '/include' os.environ['PNG_LIB'] = os.environ['LIBPNG_ROOT'] + '/lib' else: os.environ['PNG_INC'] = '/usr/include' os.environ['PNG_LIB'] = '/usr/lib64' cli.notice(f'Set PNG_INC to {os.environ["PNG_INC"]}.') cli.notice(f'Set PNG_LIB to {os.environ["PNG_LIB"]}.') os.chdir(nceplibs_root) if args.compiler_suite == 'gnu': # Fix for gfortran 9.1.0. edit_file('src/g2/v3.1.0/src/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_8)/=0']], return_on_first_match=True) edit_file('src/g2/v3.1.0/src/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_4)/=0']], return_on_first_match=True) edit_file('src/g2/v3.1.0/src/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_2)/=0']], return_on_first_match=True) edit_file('src/g2/v3.1.0/src/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_1)/=0']], return_on_first_match=True) edit_file('make_ncep_libs.sh', [['read -p "Proceed\? \(y/n\) " yn', 'yn=y']]) run(f'./make_ncep_libs.sh -s linux -c {args.compiler_suite} -d {args.nceplibs_root} -o 0 -a upp' )
def build_gsi(wrf_root, gsi_root, args): # Check environment. if not 'HDF5' in os.environ: res = subprocess.run(['which', 'h5dump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['HDF5'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set HDF5 to {os.environ["HDF5"]}') if not 'HDF5' in os.environ: cli.warning('HDF5 environment variable is not set') if not 'NETCDF' in os.environ: res = subprocess.run(['which', 'ncdump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['NETCDF'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set NETCDF to {os.environ["NETCDF"]}') if not 'NETCDF' in os.environ: cli.warning('NETCDF environment variable is not set!') if not os.getenv('LAPACK_PATH') and args.compiler_suite != 'intel': cli.error('Shell variable LAPACK_PATH is not set!') version = gsi_version(args.gsi_root) if version <= Version('3.6'): # 3.7 changes: Added wrf interface as a library (wrflib). No need to compile WRF with GSI and EnKF. if not os.path.isdir(args.wrf_root): cli.error(f'WRF directory {args.wrf_root} does not exist!') os.chdir(args.wrf_root) expected_exe_files = ('main/wrf.exe') if not check_files(expected_exe_files): cli.error('WRF has not been built! Build it first.') os.chdir(args.gsi_root) if args.force: run('rm -rf build') if not os.path.isdir('build'): os.mkdir('build') os.chdir('build') if version == Version('3.6'): expected_exe_files = ('bin/gsi.x', 'lib/libbacio_v2.0.1.a', 'lib/libbufr_v10.2.5.a', 'lib/libcrtm_v2.2.3.a', 'lib/libenkfdeplib.a', 'lib/libenkflib.a', 'lib/libgsilib_shrd.a', 'lib/libgsilib_wrf.a', 'lib/libnemsio_v2.2.1.a', 'lib/libsfcio_v1.1.0.a', 'lib/libsigio_v2.0.1.a', 'lib/libsp_v2.0.2.a', 'lib/libw3emc_v2.2.0.a', 'lib/libw3nco_v2.0.6.a') elif version == Version('3.7'): expected_exe_files = ('bin/enkf_wrf.x', 'bin/gsi.x', 'lib/libbacio_v2.0.1.a', 'lib/libbufr_v10.2.5.a', 'lib/libcrtm_v2.2.3.a', 'lib/libenkfdeplib.a', 'lib/libenkflib.a', 'lib/libgsilib_shrd.a', 'lib/libgsilib_wrf.a', 'lib/libnemsio_v2.2.1.a', 'lib/libsfcio_v1.1.0.a', 'lib/libsigio_v2.0.1.a', 'lib/libsp_v2.0.2.a', 'lib/libw3emc_v2.2.0.a', 'lib/libw3nco_v2.0.6.a') if not check_files(expected_exe_files): cmake_args = f'-DBUILD_ENKF=ON -DBUILD_CORELIBS=ON -DUSE_WRF=ON -DBUILD_WRF=ON -DBUILD_GFS=OFF ' if version == Version('3.6'): cli.notice('Fix GSI 3.6!') edit_file('../cmake/Modules/FindCORELIBS.cmake', [[ '\${CMAKE_SOURCE_DIR}/libsrc', '${CMAKE_SOURCE_DIR}/lib/libsrc' ]]) if args.compiler_suite == 'gnu': edit_file('../cmake/Modules/setCompilerFlags.cmake', [[ 'set\(BACIO_Fortran_FLAGS " -O3 -fconvert=big-endian -ffree-form', 'set(BACIO_Fortran_FLAGS " -O3 -fconvert=big-endian' ]]) elif args.compiler_suite == 'intel': edit_file('../cmake/Modules/setCompilerFlags.cmake', [[ 'set \(BACIO_Fortran_FLAGS "-O3 -free -assume nocc_omp', 'set(BACIO_Fortran_FLAGS " -O3 -assume nocc_omp' ]]) edit_file('../core-libs/sigio/CMakeLists.txt', [['\*\.f\)', '*.f90)']]) edit_file('../src/hybrid_ensemble_isotropic.F90', [['stop\(123\)', 'stop 123']]) edit_file('../src/setupoz.f90', [[ 'my_head%ij\(1\),my_head%wij\(1\)\)', 'my_head%ij,my_head%wij)' ]]) cmake_args += f'-DWRFPATH={args.wrf_root}' if version == Version('3.7'): cli.notice('Fix GSI 3.7!') edit_file('../src/setuplight.f90', [['my_head%wij\(1\)\)', 'my_head%wij)']]) cli.warning( 'GSI 3.7 has bug when rerun cmake, so clean all build files.') run('rm -rf ../build/*') cmake_args += '-DBUILD_UTIL_COM=ON' # Fix not-found -lnetcdf -lnetcdff. edit_file('../cmake/Modules/setCompilerFlags.cmake', [['-lnetcdf -lnetcdff', '']]) cli.notice('Configure GSI ...') if args.compiler_suite == 'gnu': cc = 'gcc' cxx = 'g++' fc = 'gfortran' elif args.compiler_suite == 'intel': cc = 'mpiicc' cxx = 'mpiicpc' fc = 'mpiifort' if args.verbose: run(f'CC={cc} CXX={cxx} FC={fc} cmake .. {cmake_args}') else: run(f'CC={cc} CXX={cxx} FC={fc} cmake .. {cmake_args} &> cmake.out' ) cli.notice('Compile GSI ...') if args.verbose: run('make') else: run('make &> make.out') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed') else: cli.error(f'Failed! Check {args.gsi_root}/build/make.out') else: cli.notice('GSI has already been built.') if version == Version('3.6'): os.chdir(f'{args.gsi_root}/util/bufr_tools') if args.force: run('make clean') expected_exe_files = ( 'bufr_append_sample.exe', 'bufr_decode_radiance.exe', 'bufr_decode_sample.exe', 'bufr_encode_sample.exe', 'prepbufr_append_retrieve.exe', 'prepbufr_append_surface.exe', 'prepbufr_append_upperair.exe', 'prepbufr_decode_all.exe', 'prepbufr_encode_surface.exe', 'prepbufr_encode_upperair.exe', 'prepbufr_inventory.exe') if not check_files(expected_exe_files): edit_file('makefile', [['^\s*FC\s*=.*$', f'FC = {fc}'], ['-I\.\./\.\./dtc', '-I../../build'], ['-L\.\./\.\./dtc', '-L../../build'], ['-lbufr_i4r8', '-lbufr_v10.2.5']]) cli.notice('Compile bufr_tools ...') if args.verbose: run('make') else: run('make &> make.out') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed!') else: cli.error( f'Failed! Check {args.gsi_root}/util/bufr_tools/make.out' ) else: cli.notice('GSI bufr_tools has been built.') os.chdir(f'{args.gsi_root}/util/Analysis_Utilities/read_diag/') expected_exe_files = ('read_diag_conv.exe', 'read_diag_conv_ens.exe', 'read_diag_rad.exe') if not check_files(expected_exe_files): edit_file('makefile', [[ 'include \.\./\.\./\.\./dtc/configure.gsi', '' ], ['\$\(SFC\)', fc], ['-I\.\./\.\./\.\./dtc', '-I../../../build'], [ '-L\.\./\.\./\.\./src -lgsi', '-L../../../build/lib -lgsilib_shrd' ], [ 'FLAGS= \$\(FFLAGS_DEFAULT\)', 'FLAGS = -fconvert=big-endian' ]]) cli.notice('Compile read_diag ...') if args.verbose: run('make') else: run('make &> make.out') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed') else: cli.error( f'Failed! Check {args.gsi_root}/util/Analysis_Utilities/read_diag/make.out' ) else: cli.notice('GSI read_diag has been built.')
def edit_setting(self, item: QListWidgetItem): utils.edit_file(item.text())
def build_upp(wrf_root, upp_root, args): if wrf_root != None: os.environ['WRF_DIR'] = wrf_root if not 'HDF5' in os.environ: res = subprocess.run(['which', 'h5dump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['HDF5'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set HDF5 to {os.environ["HDF5"]}') if not 'HDF5' in os.environ: cli.warning('HDF5 environment variable is not set') if not 'NETCDF' in os.environ: res = subprocess.run(['which', 'ncdump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['NETCDF'] = os.path.dirname( os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set NETCDF to {os.environ["NETCDF"]}') if not 'NETCDF' in os.environ: cli.warning('NETCDF environment variable is not set!') if not 'JASPERINC' in os.environ or not 'JASPERLIB' in os.environ: if 'JASPER_ROOT' in os.environ: os.environ['JASPERINC'] = os.environ['JASPER_ROOT'] + '/include' os.environ['JASPERLIB'] = os.environ['JASPER_ROOT'] + '/lib' cli.notice(f'Set JASPERINC to {os.environ["JASPERINC"]}.') cli.notice(f'Set JASPERLIB to {os.environ["JASPERLIB"]}.') else: cli.error( 'JASPERINC and JASPERLIB environment variables are not set!') version = upp_version(args.upp_root) if version < Version('4.1'): expected_exe_files = ('bin/copygb.exe', 'bin/ndate.exe', 'bin/unipost.exe') else: expected_exe_files = ('exec/unipost.exe') if not check_files(expected_exe_files): if not args.nceplibs_root: args.nceplibs_root = f'{os.path.dirname(args.upp_root)}/NCEPLIBS' if not os.path.isdir(args.nceplibs_root): cli.error('NCEPLIBS is not ready!') os.environ['NCEPLIBS_DIR'] = args.nceplibs_root if not check_files(expected_exe_files): os.chdir(upp_root) if args.force: run('./clean -a &> /dev/null') cli.notice('Configure UPP ...') child = pexpect.spawn('./configure') child.expect('Enter selection.*') if args.compiler_suite == 'intel': child.sendline('4') # Linux x86_64, Intel compiler (dmpar) elif args.compiler_suite == 'gnu': child.sendline('8') # Linux x86_64, gfortran compiler (dmpar) elif args.compiler_suite == 'pgi': child.sendline( '14') # Linux x86_64, PGI compiler: -f90=pgf90 (dmpar) child.wait() if args.compiler_suite == 'intel': edit_file('./configure.upp', [['mpif90', 'mpiifort'], ['mpicc', 'mpiicc']]) if 'LIBPNG_ROOT' in os.environ: edit_file('./configure.upp', [ ['-lpng', f'-L{os.environ["LIBPNG_ROOT"]}/lib -lpng'], [ 'GRIB2SUPT_INC\s*=\s*(.*)', f'GRIB2SUPT_INC = \\1 -I{os.environ["LIBPNG_ROOT"]}/include' ] ]) cli.notice('Compile UPP ...') run('./compile &> compile.out') if check_files(expected_exe_files): cli.notice('Succeeded.') else: cli.error(f'Failed! Check {upp_root}/compile.out') else: cli.notice('UPP is already built.')
def build_wrf(wrf_root, wps_root, wrfplus_root, wrfda_root, args): if not 'HDF5' in os.environ: res = subprocess.run(['which', 'h5dump'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['HDF5'] = os.path.dirname(os.path.dirname(res.stdout.decode('utf-8'))) cli.notice(f'Set HDF5 to {os.environ["HDF5"]}') if not 'HDF5' in os.environ: cli.warning('HDF5 environment variable is not set') if not 'NETCDF' in os.environ: res = subprocess.run(['which', 'nf-config'], stdout=subprocess.PIPE) if res.returncode == 0: os.environ['NETCDF'] = os.path.dirname(os.path.dirname(res.stdout.decode('utf-8'))) res = subprocess.run(['nf-config', '--includedir'], stdout=subprocess.PIPE) os.environ['NETCDF_INC'] = res.stdout.decode('utf-8').strip() res = subprocess.run(['nf-config', '--flibs'], stdout=subprocess.PIPE) os.environ['NETCDF_LIB'] = re.search(r'-L([^ ]*)', res.stdout.decode('utf-8'))[1] cli.notice(f'Set NETCDF_INC to {os.environ["NETCDF_INC"]}') cli.notice(f'Set NETCDF_LIB to {os.environ["NETCDF_LIB"]}') if not 'NETCDF' in os.environ: cli.warning('NETCDF environment variable is not set!') if not 'JASPERINC' in os.environ or not 'JASPERLIB' in os.environ: if 'JASPER_ROOT' in os.environ: os.environ['JASPERINC'] = os.environ['JASPER_ROOT'] + '/include' os.environ['JASPERLIB'] = os.environ['JASPER_ROOT'] + '/lib' cli.notice(f'Set JASPERINC to {os.environ["JASPERINC"]}.') cli.notice(f'Set JASPERLIB to {os.environ["JASPERLIB"]}.') else: cli.error('JASPERINC and JASPERLIB environment variables are not set!') if not 'LIBPNG_ROOT' in os.environ: cli.warning('LIBPNG_ROOT environment variable is not set. Library PNG may not be found!') if not 'WRFIO_NCD_LARGE_FILE_SUPPORT' in os.environ: os.environ['WRFIO_NCD_LARGE_FILE_SUPPORT'] = '1' cli.notice('Set WRFIO_NCD_LARGE_FILE_SUPPORT to 1.') if args.rttov: os.environ['RTTOV'] = args.rttov cli.notice(f'Use RTTOV in {args.rttov}.') # --------------------------------------------------------------------------------- # WRF os.chdir(wrf_root) version = wrf_version(wrf_root) if version <= Version('3.6.1'): os.environ['BUFR'] = '1' # Fix possible code bugs. if Version('3.6.1') <= version <= Version('3.8.1'): edit_file('phys/module_cu_g3.F', [['integer, dimension \(12\) :: seed', 'integer, dimension (33) :: seed']]) if args.force: run('./clean -a 1> /dev/null 2>&1') expected_exe_files = ('main/wrf.exe', 'main/real.exe', 'main/ndown.exe', 'main/tc.exe') if not check_files(expected_exe_files): cli.notice('Configure WRF ...') if args.use_grib: cli.notice('Set GRIB2 flag.') edit_file('./arch/Config.pl', [ ['\$I_really_want_to_output_grib2_from_WRF = "FALSE"', '$I_really_want_to_output_grib2_from_WRF = "TRUE"'] ]) if args.use_hyb: child = pexpect.spawn('./configure -hyb', encoding='utf-8') else: child = pexpect.spawn('./configure', encoding='utf-8') child.expect('Enter selection.*') if platform.system() == 'Darwin': if args.compiler_suite == 'gnu': child.sendline('15') else: if args.compiler_suite == 'intel': if args.openmp: child.sendline('16') # INTEL (ifort/icc) dm+sm else: child.sendline('15') # INTEL (ifort/icc) dmpar elif args.compiler_suite == 'gnu': if args.openmp: child.sendline('35') # GNU (gfortran/gcc) dm+sm else: child.sendline('34') # GNU (gfortran/gcc) dmpar elif args.compiler_suite == 'pgi': if args.openmp: child.sendline('55') # PGI (pgf90/pgcc) dm+sm else: child.sendline('54') # PGI (pgf90/pgcc) dmpar child.expect('Compile for nesting.*:') child.sendline('1') if platform.system() == 'Darwin': child.expect('This build of WRF will use NETCDF4 with HDF5 compression') child.wait() if args.compiler_suite == 'intel': edit_file('./configure.wrf', [ ['mpif90', 'mpiifort'], ['mpicc', 'mpiicc'] ]) elif args.compiler_suite == 'pgi': edit_file('./configure.wrf', [ ['pgf90', 'pgfortran'], ['mpif90', 'mpifort'] ]) # Fix for OpenMPI. edit_file('./configure.wrf', [ ['DM_CC\s*=\s*mpicc\s*$', 'DM_CC = mpicc -DMPI2_SUPPORT\n'] ]) cli.notice('Compile WRF ...') if args.debug: if args.compiler_suite == 'intel': debug_options = '-O0 -g -traceback' elif args.compiler_suite == 'gnu': debug_options = '-O0 -g -fbacktrace' edit_file('configure.wrf', [ ['FCFLAGS\s*=\s*\$\(FCOPTIM\)\s*\$\(FCBASEOPTS\)', f'FCFLAGS = {debug_options} $(FCBASEOPTS)'] ]) if args.verbose: run(f'./compile em_real') else: run(f'./compile em_real 1> compile.out 2>&1') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed!') else: cli.error(f'Failed! Check {wrf_root}/compile.out') else: cli.notice('WRF is already built.') # --------------------------------------------------------------------------------- # WPS os.chdir(wps_root) if args.force: run('./clean -a 1> /dev/null 2>&1') expected_exe_files = ('geogrid/src/geogrid.exe', 'metgrid/src/metgrid.exe', 'ungrib/src/ungrib.exe') if not check_files(expected_exe_files): cli.notice('Configure WPS ...') child = pexpect.spawn('./configure') child.expect('Enter selection.*') if args.compiler_suite == 'intel': child.sendline('19') # Linux x86_64, Intel compiler (dmpar) elif args.compiler_suite == 'gnu': child.sendline('3') # Linux x86_64, gfortran (dmpar) elif args.compiler_suite == 'pgi': child.sendline('7') child.wait() if args.compiler_suite == 'intel': edit_file('./configure.wps', [ ['mpif90', 'mpiifort'], ['mpicc', 'mpiicc'] ]) elif args.compiler_suite == 'pgi': edit_file('./configure.wps', [ ['pgf90', 'pgfortran'], ['mpif90', 'mpifort'] ]) else: run('sed -i "s/mpicc -cc=.*/mpicc/" configure.wps') run('sed -i "s/mpif90 -f90=.*/mpif90/" configure.wps') run('sed -i "s/WRF_DIR\s*=.*/WRF_DIR = ..\/WRF/" configure.wps') if 'LIBPNG_ROOT' in os.environ: run(f'sed -i "s@COMPRESSION_LIBS\s*=\(.*\)@COMPRESSION_LIBS = \\1 -L{os.environ["LIBPNG_ROOT"]}/lib@" configure.wps') run(f'sed -i "s@COMPRESSION_INC\s*=\(.*\)@COMPRESSION_INC = \\1 -I{os.environ["LIBPNG_ROOT"]}/include@" configure.wps') if args.compiler_suite == 'gnu': # Fix for gfortran 9.1.0. edit_file('ungrib/src/ngl/g2/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_8)/=0']], return_on_first_match=True) edit_file('ungrib/src/ngl/g2/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_4)/=0']], return_on_first_match=True) edit_file('ungrib/src/ngl/g2/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_2)/=0']], return_on_first_match=True) edit_file('ungrib/src/ngl/g2/intmath.f', [['iand\(i,i-1\)/=0', 'iand(i,i-1_1)/=0']], return_on_first_match=True) # Fix for OpenMPI. edit_file('./configure.wps', [ ['DM_CC\s*=\s*mpicc\s*$', 'DM_CC = mpicc -DMPI2_SUPPORT\n'] ]) cli.notice('Compile WPS ...') if args.verbose: run('./compile') else: run('./compile 1> compile.out 2>&1') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed!') else: cli.error(f'Failed! Check {wps_root}/compile.out') else: cli.notice('WPS is already built.') # --------------------------------------------------------------------------------- # WRFPLUS os.chdir(wrfplus_root) if args.force: run('./clean -a 1> /dev/null 2>&1') if Version('3.6.1') <= version <= Version('3.9.1'): edit_file('phys/module_cu_g3.F', [['integer, dimension \(12\) :: seed', 'integer, dimension (33) :: seed']]) if version == Version('3.6.1'): line_number = 841 elif version == Version('3.8.1'): line_number = 855 elif version == Version('3.9.1'): line_number = 856 else: error('Find out the wrong OpenMP directive in WRFPLUS/main/module_wrf_top.F!') edit_file('main/module_wrf_top.F', [[line_number, ' !$OMP DEFAULT (SHARED) PRIVATE ( ij )\n']]) if version >= Version('4.0'): expected_exe_files = ('main/wrfplus.exe') else: expected_exe_files = ('main/wrf.exe') if not check_files(expected_exe_files): cli.notice('Configure WRFPLUS ...') if args.use_grib: cli.notice('Set GRIB2 flag.') edit_file('./arch/Config.pl', [ ['\$I_really_want_to_output_grib2_from_WRF = "FALSE"', '$I_really_want_to_output_grib2_from_WRF = "TRUE"'] ]) child = pexpect.spawn('./configure wrfplus') child.expect('Enter selection.*') if args.compiler_suite == 'intel': if version <= Version('3.6.1'): child.sendline('8') else: child.sendline('34') elif args.compiler_suite == 'gnu': child.sendline('18') elif args.compiler_suite == 'pgi': child.sendline('28') child.wait() if args.compiler_suite == 'intel': edit_file('./configure.wrf', [ ['mpif90', 'mpiifort'], ['mpicc', 'mpiicc'], ['override-limits', 'qoverride-limits'] ]) # Fix for OpenMPI. edit_file('./configure.wrf', [ ['DM_CC\s*=\s*mpicc\s*$', 'DM_CC = mpicc -DMPI2_SUPPORT\n'] ]) cli.notice('Compile WRFPLUS ...') if args.debug: if args.compiler_suite == 'intel': debug_options = '-O0 -g -traceback' elif args.compiler_suite == 'gnu': debug_options = '-O0 -g -fbacktrace' edit_file('configure.wrf', [ ['FCFLAGS\s*=\s*\$\(FCOPTIM\)\s*\$\(FCBASEOPTS\)', f'FCFLAGS = {debug_options} $(FCBASEOPTS)'] ]) if version >= Version('4.0'): build_target = 'wrfplus' else: build_target = 'wrf' if args.verbose: run(f'./compile {build_target}') else: run(f'./compile {build_target} 1> compile.out 2>&1') if check_files(expected_exe_files): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed!') else: cli.error(f'Failed! Check {wrfplus_root}/compile.out') else: cli.notice('WRFPLUS is already built.') # --------------------------------------------------------------------------------- # WRFDA os.chdir(wrfda_root) os.environ['WRFPLUS_DIR'] = wrfplus_root if args.force: run('./clean -a 1> /dev/null 2>&1') if Version('3.6.1') <= version <= Version('3.9.1'): cli.warning(f'Fix {wrfda_root}/var/da/da_define_structures/da_zero_y.inc') edit_file('var/da/da_define_structures/da_zero_y.inc', [ [', value \)', ', value_ )'], [':: value$', ':: value_\nreal value'], ['if \(.not.\(present\(value\)\)\) value = 0.0', ''' if (.not.(present(value_))) then value = 0.0 else value = value_ end if '''] ]) if version == Version('4.1.1'): cli.warning(f'Fix {wrfda_root}/share/input_wrf.F') edit_file('share/input_wrf.F', [ ['FUNCTION check_which_switch', 'FUNCTION check_which_switch1'] ]) expected_exe_files = [ 'var/build/da_advance_time.exe', 'var/build/da_bias_airmass.exe', 'var/build/da_bias_scan.exe', 'var/build/da_bias_sele.exe', 'var/build/da_bias_verif.exe', 'var/build/da_rad_diags.exe', 'var/build/da_tune_obs_desroziers.exe', 'var/build/da_tune_obs_hollingsworth1.exe', 'var/build/da_tune_obs_hollingsworth2.exe', 'var/build/da_update_bc_ad.exe', 'var/build/da_update_bc.exe', 'var/build/da_verif_grid.exe', 'var/build/da_verif_obs.exe', 'var/build/da_wrfvar.exe', 'var/build/gen_be_addmean.exe', 'var/build/gen_be_cov2d3d_contrib.exe', 'var/build/gen_be_cov2d.exe', 'var/build/gen_be_cov3d2d_contrib.exe', 'var/build/gen_be_cov3d3d_bin3d_contrib.exe', 'var/build/gen_be_cov3d3d_contrib.exe', 'var/build/gen_be_cov3d.exe', 'var/build/gen_be_diags.exe', 'var/build/gen_be_diags_read.exe', 'var/build/gen_be_ensmean.exe', 'var/build/gen_be_ensrf.exe', 'var/build/gen_be_ep1.exe', 'var/build/gen_be_ep2.exe', 'var/build/gen_be_etkf.exe', 'var/build/gen_be_hist.exe', 'var/build/gen_be_stage0_gsi.exe', 'var/build/gen_be_stage0_wrf.exe', 'var/build/gen_be_stage1_1dvar.exe', 'var/build/gen_be_stage1.exe', 'var/build/gen_be_stage1_gsi.exe', 'var/build/gen_be_stage2_1dvar.exe', 'var/build/gen_be_stage2a.exe', 'var/build/gen_be_stage2.exe', 'var/build/gen_be_stage2_gsi.exe', 'var/build/gen_be_stage3.exe', 'var/build/gen_be_stage4_global.exe', 'var/build/gen_be_stage4_regional.exe', 'var/build/gen_be_vertloc.exe', 'var/build/gen_mbe_stage2.exe', 'var/obsproc/src/obsproc.exe'] if not check_files(expected_exe_files): cli.notice('Configure WRFDA ...') if args.use_grib: cli.notice('Set GRIB2 flag.') edit_file('./arch/Config.pl', [ ['\$I_really_want_to_output_grib2_from_WRF = "FALSE"', '$I_really_want_to_output_grib2_from_WRF = "TRUE"'] ]) child = pexpect.spawn('./configure 4dvar') child.expect('Enter selection.*') if args.compiler_suite == 'intel': child.sendline('8') elif args.compiler_suite == 'gnu': child.sendline('18') elif args.compiler_suite == 'pgi': child.sendline('28') child.wait() if args.compiler_suite == 'intel': edit_file('./configure.wrf', [ ['mpif90', 'mpiifort'], ['mpicc', 'mpiicc'] ]) # Fix for OpenMPI. edit_file('./configure.wrf', [ ['DM_CC\s*=\s*mpicc\s*$', 'DM_CC = mpicc -DMPI2_SUPPORT\n'] ]) cli.notice('Compile WRFDA ...') if args.debug: if args.compiler_suite == 'intel': debug_options = '-O0 -g -traceback' elif args.compiler_suite == 'gnu': debug_options = '-O0 -g -fbacktrace' edit_file('configure.wrf', [ ['FCFLAGS\s*=\s*\$\(FCOPTIM\)\s*\$\(FCBASEOPTS\)', f'FCFLAGS = {debug_options} $(FCBASEOPTS)'] ]) if args.verbose: run(f'./compile all_wrfvar') else: run(f'./compile all_wrfvar 1> compile.out 2>&1') if check_files(expected_exe_files, fatal=True): cli.notice('Succeeded.') else: if args.verbose: cli.error('Failed!') else: cli.error(f'Failed! Check {wrfda_root}/compile.out') else: cli.notice('WRFDA is already built.')
def gen_be(wrf_root, wrfda_root, work_dir, config, args): wrf_work_dir = args.work_dir + '/fc' wrfda_work_dir = args.work_dir + '/da' da_config = config['da'] if da_config['cv_options'] != 'cv3' and not os.path.isdir(wrf_work_dir): cli.notice(f'Create directory {wrf_work_dir}.') os.makedirs(wrf_work_dir) if not os.path.isdir(wrfda_work_dir): cli.notice(f'Create directory {wrfda_work_dir}.') os.makedirs(wrfda_work_dir) if da_config['cv_options'] == 'cv3': os.chdir(wrfda_work_dir) cli.notice('Use cv3 option.') run(f'cp -p {wrfda_root}/var/run/be.dat.cv3 {wrfda_work_dir}/be.dat') cli.notice('Edit namelist.input for WRFDA.') namelist_input = f90nml.read( f'{wrfda_root}/var/test/tutorial/namelist.input') namelist_input['wrfvar7']['cv_options'] = 3 namelist_input['wrfvar7']['as1'] = [0.25, 1.0, 1.5] namelist_input['wrfvar7']['as2'] = [0.25, 1.0, 1.5] namelist_input['wrfvar7']['as3'] = [0.25, 1.0, 1.5] namelist_input['wrfvar7']['as4'] = [0.25, 1.0, 1.5] namelist_input['wrfvar7']['as5'] = [0.25, 1.0, 1.5] namelist_input.write('namelist.input', force=True) elif da_config['cv_options'] == 'cv5': os.chdir(wrfda_work_dir) cli.notice('Use cv5 option.') cli.notice('Edit namelist.input for WRFDA.') namelist_input = f90nml.read( f'{wrfda_root}/var/test/tutorial/namelist.input') namelist_input['wrfvar7']['cv_options'] = 5 namelist_input.write('namelist.input', force=True) os.chdir(wrf_work_dir) cli.notice('Edit namelist.input for WRF.') namelist_input = f90nml.read(f'{wrf_root}/run/namelist.input') namelist_input['time_control'][ 'history_interval'] = da_config['nmc']['short_forecast_hours'] * 60 namelist_input['time_control']['frames_per_outfile'] = 1 namelist_input.write('namelist.input', force=True) config['common']['start_time'] = da_config['nmc']['start_time'] config['common']['forecast_hours'] = da_config['nmc'][ 'short_forecast_hours'] cli.notice(f'Edit {wrfda_root}/var/scripts/gen_be/gen_be_wrapper.ksh') edit_file( f'{wrfda_root}/var/scripts/gen_be/gen_be_wrapper.ksh', [['^\s*export WRFVAR_DIR=.*$', f'export WRFVAR_DIR={wrfda_root}'], ['^\s*export NL_CV_OPTIONS=.*$', f'export NL_CV_OPTIONS=5'], [ '^\s*export START_DATE=.*$', f'export START_DATE={da_config["nmc"]["start_time"]}' ], [ '^\s*export END_DATE=.*$', f'export END_DATE={da_config["nmc"]["end_time"]}' ], ['^\s*export FC_DIR=.*$', f'export FC_DIR={wrf_work_dir}'], [ '^\s*export RUN_DIR=.*$', f'export RUN_DIR={wrfda_work_dir}/gen_be' ]]) elif da_config['cv_options'] == 'cv6': pass elif da_config['cv_options'] == 'cv7': pass
def edit(self): if self.path != "": utils.edit_file(self.path)