if ldisk: if not Disk: Disk = Root + disk if not ( os.path.isdir(Disk) or os.path.islink(Disk[:-1]) ): # create new destination folder os.mkdir(Disk) ## remove directory if already there #shutil.rmtree(Disk) #os.mkdir(Disk) # directory shortcuts Meta = Tmp + meta # parse namelist parameters imd, maxdom, isd, startdates, ied, enddates = time.readNamelist(nmlstwps) # translate start/end dates into numerical tuples starts = [time.splitDateWRF(sd) for sd in startdates] ends = [time.splitDateWRF(ed) for ed in enddates] # figure out domains doms = range(1,maxdom+1) # list of domain indices # copy meta data to temporary folder shutil.copytree(meta,Meta) shutil.copy(metgrid_exe, Tmp) shutil.copy(nmlstwps, Tmp) for i in doms: # loop over all geogrid domains shutil.copy(geopfx.format(i)+ncext, Tmp) # N.B.: shutil.copy copies the actual file that is linked to, not just the link # change working directory to tmp folder os.chdir(Tmp) # create dataset instance
# no next step if stepline == 0: # reached end of file sys.stdout.write('') sys.exit(0) elif stepline == -1: # last/current step not found sys.exit(currentstep+' not found in '+stepfile) else: # unknown error sys.exit(127) else: # extract information nextstep = linesplit[0] # next step name startdatestr = linesplit[1] # next start date startdate = time.splitDateWRF(startdatestr[1:-1]) enddatestr = linesplit[2] # next end date enddate = time.splitDateWRF(enddatestr[1:-1]) # screen for leap days (treat Feb. 29th as 28th) if lly == False: # i.e. if we don't use leap-years in WRF if calendar.isleap(startdate[0]) and startdate[2]==29 and startdate[1]==2: startdate = (startdate[0], startdate[1], 28, startdate[3]) if calendar.isleap(enddate[0]) and enddate[2]==29 and enddate[1]==2: enddate = (enddate[0], enddate[1], 28, enddate[3]) # create next step folder StepFolder = IniDir + '/' + nextstep + '/' if not os.path.isdir(StepFolder): #shutil.rmtree(StepFolder) # remove directory if already there os.mkdir(StepFolder) # create new step folder # copy namelist templates shutil.copy(IniDir+'/'+nmlstwps, StepFolder)