def make_mfnwt(): # Note, this script does not work yet due to some non-standard Fortran # in one or more of the source files. # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Remove the existing directory if it exists dirname = 'MODFLOW-NWT_1.0.9' if os.path.isdir(dirname): shutil.rmtree(dirname) # Download the MODFLOW-NWT distribution url = "http://water.usgs.gov/ogw/modflow-nwt/MODFLOW-NWT-v1.0.9/MODFLOW-NWT_1.0.9.zip" download_and_unzip(url) # Remove the parallel and serial folders from the source directory srcdir = os.path.join('MODFLOW-NWT_1.0.9', 'src') target = 'mfnwt' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Clean up dirname = 'MODFLOW-NWT_1.0.9' if os.path.isdir(dirname): shutil.rmtree(dirname)
def make_mt3d(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MT3D distribution url = "http://hydro.geo.ua.edu/mt3d/mt3dms_530.exe" download_and_unzip(url) # Set srcdir and remove unneeded files srcdir = os.path.join('src', 'true-binary') dlist = ['automake.fig', 'mt3dms5b.exe'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isfile(dname): print('Removing ', dname) os.remove(dname) # Replace the getcl command with getarg f1 = open(os.path.join(srcdir, 'mt3dms5.for'), 'r') f2 = open(os.path.join(srcdir, 'mt3dms5.for.tmp'), 'w') for line in f1: f2.write(line.replace('CALL GETCL(FLNAME)', 'CALL GETARG(1,FLNAME)')) f1.close() f2.close() os.remove(os.path.join(srcdir, 'mt3dms5.for')) shutil.move(os.path.join(srcdir, 'mt3dms5.for.tmp'), os.path.join(srcdir, 'mt3dms5.for')) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' fn = os.path.join(srcdir, 'filespec.inc') f = open(fn, 'w') f.write(l) f.close() target = 'mt3dms' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) # Clean up unneeded folders dlist = ['bin', 'doc', 'examples', 'src', 'utility'] for d in dlist: dname = d if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(dname) # Clean up unneeded files for f in ['ReadMe_MT3DMS.pdf', 'upgrade.pdf']: print('Removing {}'.format(f)) os.remove(f)
def make_swtv4(): # To compile SEAWAT on mac or linux: # 1. The starting source folder should not have the parallel and serial folders # 3. The program needs to be compiled in double precision. # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Remove the existing directory if it exists dirname = 'swt_v4_00_05' if os.path.isdir(dirname): shutil.rmtree(dirname) # Download the SEAWAT distribution url = "http://water.usgs.gov/ogw/seawat/swt_v4_00_05.zip" download_and_unzip(url) # Remove the parallel and serial folders from the source directory srcdir = os.path.join(dirname, 'source') dlist = ['parallel', 'serial'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' fn = os.path.join(srcdir, 'FILESPEC.INC') f = open(fn, 'w') f.write(l) f.close() target = 'swtv4' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Remove the existing directory if it exists dirname = 'swt_v4_00_05' if os.path.isdir(dirname): shutil.rmtree(dirname) return
def make_mfusg(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Remove the existing mfusg.1_2 directory if it exists dirname = 'mfusg.1_2' if os.path.isdir(dirname): shutil.rmtree(dirname) url = 'http://water.usgs.gov/ogw/mfusg/mfusg.1_2_00.zip' download_and_unzip(url) # Set src and target srcdir = os.path.join('mfusg.1_2', 'src') target = 'mfusg' # Remove extraneous source directories dlist = ['zonebudusg', 'serial'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Remove the existing mfusg.1_2 directory if it exists dirname = 'mfusg.1_2' if os.path.isdir(dirname): shutil.rmtree(dirname)
def make_mflgr(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-LGR distribution url = "http://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip" download_and_unzip(url) dirname = 'mflgr.2_0' srcdir = os.path.join(dirname, 'src') target = 'mflgrdbl' print('Present working directory: ', os.getcwd()) # pymake.main(srcdir, target, 'ifort', 'gcc', makeclean=True, # expedite=False, dryrun=False, double=True, debug=False) pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.'
def make_mf2005(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "http://water.usgs.gov/ogw/modflow/MODFLOW-2005_v1.11.00/mf2005v1_11_00_unix.zip" download_and_unzip(url) # Rename Unix to a more reasonable name dirname = 'MF2005.1_11u' if os.path.isdir(dirname): shutil.rmtree(dirname) os.rename('Unix', 'MF2005.1_11u') # Remove two src folders srcdir = os.path.join(dirname, 'src') dlist = ['hydprograms', 'mnw1to2'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) target = 'mf2005dbl' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.' dirname = 'MF2005.1_11u' if os.path.isdir(dirname): shutil.rmtree(dirname)
def make_mflgr(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-LGR distribution url = "https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip" download_and_unzip(url) dirname = 'mflgr.2_0' srcdir = os.path.join(dirname, 'src') target = 'mflgrdbl' print('Present working directory: ', os.getcwd()) # pymake.main(srcdir, target, 'ifort', 'gcc', makeclean=True, # expedite=False, dryrun=False, double=True, debug=False) pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.'
def make_modpath6(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "http://water.usgs.gov/ogw/modpath/modpath.6_0_01.zip" download_and_unzip(url) dirname = 'modpath.6_0' dwpath = os.path.join(dstpth, dirname) if os.path.isdir(dwpath): shutil.rmtree(dwpath) # Name src folders srcdir = os.path.join(dirname, 'src') fname1 = os.path.join(srcdir, 'MP6Flowdata.for') f = open(fname1, 'r') fname2 = os.path.join(srcdir, 'MP6Flowdata_mod.for') f2 = open(fname2, 'w') for line in f: line = line.replace('CD.QX2', 'CD%QX2') f2.write(line) f.close() f2.close() os.remove(fname1) target = 'mp6' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.'
def make_modpath6(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "https://water.usgs.gov/ogw/modpath/archive/modpath_v6.0.01/modpath.6_0_01.zip" download_and_unzip(url) dirname = 'modpath.6_0' dwpath = os.path.join(dstpth, dirname) if os.path.isdir(dwpath): shutil.rmtree(dwpath) # Name src folders srcdir = os.path.join(dirname, 'src') # start of edit a few files so it can compile with gfortran # file 1 fname1 = os.path.join(srcdir, 'MP6Flowdata.for') f = open(fname1, 'r') bigline = 'CB%BALANCE = ABS(100.0*CB%QRESIDUAL/CB%QAVE)' newline = ' IF (ABS(CB%QAVE) > 0.) THEN\n' + \ ' CB%BALANCE = ABS(100.0*CB%QRESIDUAL/CB%QAVE)\n' + \ ' ELSE\n' + \ ' CB%BALANCE = 0.\n' + \ ' END IF\n' fname2 = os.path.join(srcdir, 'MP6Flowdata_mod.for') f2 = open(fname2, 'w') for line in f: line = line.replace('CD.QX2', 'CD%QX2') if bigline in line: line = newline f2.write(line) f.close() f2.close() os.remove(fname1) # file 2 fname1 = os.path.join(srcdir, 'MP6MPBAS1.for') f = open(fname1, 'r') fname2 = os.path.join(srcdir, 'MP6MPBAS1_mod.for') f2 = open(fname2, 'w') for line in f: line = line.replace('MPBASDAT(IGRID)%NCPPL=NCPPL', 'MPBASDAT(IGRID)%NCPPL=>NCPPL') f2.write(line) f.close() f2.close() os.remove(fname1) # end of edit a few files so it can compile with gfortran target = 'mp6' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) assert os.path.isfile(target), 'Target does not exist.'
def make_mt3d(): # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MT3D distribution url = "https://hydro.geo.ua.edu/mt3d/mt3dms_530.exe" download_and_unzip(url, verify=False, timeout=15) # Set srcdir and remove unneeded files srcdir = os.path.join('src', 'true-binary') dlist = ['automake.fig', 'mt3dms5b.exe'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isfile(dname): print('Removing ', dname) os.remove(dname) # Replace the getcl command with getarg f1 = open(os.path.join(srcdir, 'mt3dms5.for'), 'r') f2 = open(os.path.join(srcdir, 'mt3dms5.for.tmp'), 'w') for line in f1: f2.write(line.replace('CALL GETCL(FLNAME)', 'CALL GETARG(1,FLNAME)')) f1.close() f2.close() os.remove(os.path.join(srcdir, 'mt3dms5.for')) shutil.move(os.path.join(srcdir, 'mt3dms5.for.tmp'), os.path.join(srcdir, 'mt3dms5.for')) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' fn = os.path.join(srcdir, 'FILESPEC.INC') f = open(fn, 'w') f.write(l) f.close() target = 'mt3dms' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) # Clean up unneeded folders dlist = ['bin', 'doc', 'examples', 'src', 'utility'] for d in dlist: dname = d if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(dname) # Clean up unneeded files for f in ['ReadMe_MT3DMS.pdf', 'upgrade.pdf']: print('Removing {}'.format(f)) os.remove(f)
def make_modpath7(): # get current directory srcpth = os.getcwd() dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "https://water.usgs.gov/ogw/modpath/Modpath_7_1_000.zip" download_and_unzip(url) dirname = 'Modpath_7_1_000' dwpath = os.path.join(dstpth, dirname) if os.path.isdir(dwpath): shutil.rmtree(dwpath) # Name src folders srcdir = os.path.join(dirname, 'source') # modify source files that prevent compiling with gfortran pth = os.path.join(srcdir, 'utl7u1.f') if os.path.isfile(pth): os.remove(pth) fname1 = os.path.join(srcdir, 'ModpathSubCellData.f90') f = open(fname1, 'r') fname2 = os.path.join(srcdir, 'ModpathSubCellData_mod.f90') f2 = open(fname2, 'w') for line in f: line = line.replace('location.', 'location%') f2.write(line) f.close() f2.close() os.remove(fname1) os.rename(fname2, fname1) fname1 = os.path.join(srcdir, 'ModpathCellData.f90') f = open(fname1, 'r') fname2 = os.path.join(srcdir, 'ModpathCellData_mod.f90') f2 = open(fname2, 'w') for line in f: line = line.replace('dimension(grid%GetCellCount())', 'dimension(:)') line = line.replace('dimension(grid%GetReducedConnectionCount())', 'dimension(:)') f2.write(line) f.close() f2.close() os.remove(fname1) os.rename(fname2, fname1) fname1 = os.path.join(srcdir, 'MPath7.f90') f = open(fname1, 'r') fname2 = os.path.join(srcdir, 'MPath7_mod.f90') f2 = open(fname2, 'w') for line in f: line = line.replace("form='binary', access='stream'", "form='unformatted', access='stream'") f2.write(line) f.close() f2.close() os.remove(fname1) os.rename(fname2, fname1) # allow line lengths greater than 132 columns fflags='ffree-line-length-512' # make modpath 7 in starting directory target = os.path.join('..', 'mp7') pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False, fflags=fflags) assert os.path.isfile(target), 'Target does not exist.' # change back to the original path os.chdir(srcpth) # remove temporary directory if os.path.isdir(dstpth): shutil.rmtree(dstpth)
print('Copying documentation') for din, dout in doclist: dst = os.path.join(fd['doc'], dout) print(' copying {} ===> {}'.format(din, dst)) shutil.copy(din, dst) print('\n') print('Downloading published reports for inclusion in distribution') for url in [ 'https://pubs.usgs.gov/tm/06/a57/tm6a57.pdf', 'https://pubs.usgs.gov/tm/06/a55/tm6a55.pdf', 'https://pubs.usgs.gov/tm/06/a56/tm6a56.pdf', 'https://github.com/MODFLOW-USGS/modflow6-examples/releases/download/6.1.0/csubexamples.pdf', ]: print(' downloading {}'.format(url)) download_and_unzip(url, pth=fd['doc'], delete_zip=False, verify=False) print('\n') # Prior to zipping, enforce os line endings on all text files windows_line_endings = True convert_line_endings(distfolder, windows_line_endings) # Zip the distribution uflag = 'u' if win_target_os: uflag = '' zipname = version + uflag + '.zip' if os.path.exists(zipname): print('Removing existing file: {}'.format(zipname)) os.remove(zipname) print('Creating zipped file: {}'.format(zipname))
def make_mf2000(): # get current directory dstpth = os.path.join('temp') if os.path.exists(dstpth): shutil.rmtree(dstpth) os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "http://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz" download_and_unzip(url) dirname = 'mf2k.1_19' # Set source directory srcdir = os.path.join(dirname, 'src') # Remove six src folders dlist = ['beale2k', 'hydprgm', 'mf96to2k', 'mfpto2k', 'resan2k', 'ycint2k'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) # Move src files and serial src file to src directory tpth = os.path.join(srcdir, 'mf2k') files = [ f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f)) ] for f in files: shutil.move(os.path.join(tpth, f), srcdir) tpth = os.path.join(srcdir, 'mf2k', 'serial') files = [ f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f)) ] for f in files: shutil.move(os.path.join(tpth, f), srcdir) # Remove mf2k directory in source directory tpth = os.path.join(srcdir, 'mf2k') shutil.rmtree(tpth) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' fn = os.path.join(srcdir, 'openspec.inc') f = open(fn, 'w') f.write(l) f.close() target = 'mf2000' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Remove MODFLOW-2000 files if os.path.isdir(dirname): shutil.rmtree(dirname)
def make_swtv4(): # To compile SEAWAT on mac or linux: # 1. The starting source folder should not have the parallel and serial folders # 3. The program needs to be compiled in double precision. # get current directory dstpth = os.path.join('temp') if not os.path.exists(dstpth): os.makedirs(dstpth) os.chdir(dstpth) # Remove the existing directory if it exists dirname = 'swt_v4_00_05' if os.path.isdir(dirname): shutil.rmtree(dirname) # Download the SEAWAT distribution url = "https://water.usgs.gov/ogw/seawat/{0}.zip".format(dirname) download_and_unzip(url) # Remove the parallel and serial folders from the source directory srcdir = os.path.join(dirname, 'source') dlist = ['parallel', 'serial'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' try: os.remove(os.path.join(srcdir, 'FILESPEC.INC')) except: pass fn = os.path.join(srcdir, 'filespec.inc') f = open(fn, 'w') f.write(l) f.close() # rename all source files to lower case so compilation doesn't # bomb on case-sensitive operating systems srcfiles = os.listdir(srcdir) for filename in srcfiles: src = os.path.join(srcdir, filename) dst = os.path.join(srcdir, filename.lower()) os.rename(src, dst) # make target target = 'swtv4' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=True, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Remove the existing directory if it exists #if os.path.isdir(dirname): # shutil.rmtree(dirname) return
def make_mf2000(): # get current directory dstpth = os.path.join('temp') if os.path.exists(dstpth): shutil.rmtree(dstpth) os.makedirs(dstpth) os.chdir(dstpth) # Download the MODFLOW-2005 distribution url = "http://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz" download_and_unzip(url) dirname = 'mf2k.1_19' # Set source directory srcdir = os.path.join(dirname, 'src') # Remove six src folders dlist = ['beale2k', 'hydprgm', 'mf96to2k', 'mfpto2k', 'resan2k', 'ycint2k'] for d in dlist: dname = os.path.join(srcdir, d) if os.path.isdir(dname): print('Removing ', dname) shutil.rmtree(os.path.join(srcdir, d)) # Move src files and serial src file to src directory tpth = os.path.join(srcdir, 'mf2k') files = [f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f))] for f in files: shutil.move(os.path.join(tpth, f), srcdir) tpth = os.path.join(srcdir, 'mf2k', 'serial') files = [f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f))] for f in files: shutil.move(os.path.join(tpth, f), srcdir) # Remove mf2k directory in source directory tpth = os.path.join(srcdir, 'mf2k') shutil.rmtree(tpth) # Replace filespec with standard fortran l = ''' CHARACTER*20 ACCESS,FORM,ACTION(2) DATA ACCESS/'STREAM'/ DATA FORM/'UNFORMATTED'/ DATA (ACTION(I),I=1,2)/'READ','READWRITE'/ ''' fn = os.path.join(srcdir, 'openspec.inc') f = open(fn, 'w') f.write(l) f.close() target = 'mf2000' pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True, expedite=False, dryrun=False, double=False, debug=False) assert os.path.isfile(target), 'Target does not exist.' # Remove MODFLOW-2000 files if os.path.isdir(dirname): shutil.rmtree(dirname)