import numpy as np import os import math import struct #This version will adjust pCO2, but makes no effort to model large changes, instead #using a constant maximum timestep of 500 years, rate-limited by ice change. This focuses #on modeling glacial response to external forcings like CO2 and orbital parameters. def getmaxdsnow(filename1,filename2): f1=open(filename1,'rb') r1=f1.read() f1.close() f2=open(filename2,'rb') r2=f2.read() f2.close() dd1=np.array(struct.unpack('2048d',r1[4:-4])).reshape((32,64)) dd2=np.array(struct.unpack('2048d',r2[4:-4])).reshape((32,64)) dsnow = dd2-dd1 maxdsnow = np.amax(np.abs(dsnow)) return maxdsnow def changeCO2(pCO2): nl=open("radmod_namelist","r") nltxt=nl.read().split('\n') nl.close() l=0 while lburnout "+dataname+" "+dataname+".nc") os.system("[ -e "+dataname+" ] && cp "+dataname+" "+EXP+"_OUT.%04d"%n) os.system("[ -e "+dataname+".nc ] && rm "+dataname) relaxed=isflat("weathering.pso") os.system("cp "+dataname+".nc "+EXP+"_OUT.%04d.nc"%n) os.system("cp "+restname+" "+EXP+"_REST.%04d"%n) os.system("cp "+snowname+" "+EXP+"_SNOW.%04d"%n) ct=getct('weathering.pso') co2s=getndco2('weathering.pso') dco2=getdco2('weathering.pso') etemps.append(ct) eCO2s.append(co2s[1]) os.system("mv weathering.pso weathering"+str(n)+".pso") oldCO2 = pCO2 #Adjust snowpack sfile1 = EXP+"_SNOW_0" sfile2 = EXP+"_SNOW_1" sfile3 = EXP+"_SNOW_2" sfile4 = EXP+"_SNOW_3" sfile5 = EXP+"_SNOW_4" os.system("cp newdsnow newdsnow_old") os.system("cp newxsnow newxsnow_old") deltat = 100.0 os.system("./newsnow.x "+sfile1+" "+sfile2+" "+sfile3+" "+sfile4+" "+sfile5+" "+str(deltat)) maxdsnow = getmaxdsnow("newdsnow_old","newdsnow") hmax = 300.0 rhoglac = 0.85 nudt = deltat*rhoglac*hmax/maxdsnow #maxdsnow/100 years = 300 meters/t years; solve for t new_co2 = max(oldCO2 + dco2*nudt, 1.0e-7) os.system("cp newdsnow_old newdsnow") os.system("cp newxsnow_old newxsnow") os.system("./newsnow.x "+sfile1+" "+sfile2+" "+sfile3+" "+sfile4+" "+sfile5+" "+str(nudt)) pCO2 = new_co2 psurf = p0+pCO2 changep(psurf*0.1) changeCO2(pCO2/psurf*1e6) f=open('cyclelog.txt','a') f.write('Adjusted to '+str(pCO2)+'ubars CO2 and '+str(psurf*0.1)+' Pa atmosphere. dco2 was '+str(dco2)+", end co2 was "+str(co2s[1])+". Maximum snow change was "+str(maxdsnow)+".\n") f.close() os.system("mv newdsnow restart_dsnow") os.system("mv newxsnow restart_xsnow") n+=1 #changeCO2(2.0e5)