#!/opt/ohpc/Taiwania3/pkg/local/python/3.9.7/bin/python3
importnumpyasnpimportnetCDF4importos,sys,datetimefname=[sys.argv[i+1]foriinrange(3)]rw=['r','r','r+']nc0=netCDF4.Dataset(fname[0],rw[0])V=[list(filter(lambdax:nc0.variables[x].ndim==j,[iforiinnc0.variables]))forjin[1,2,3,4]]nt0,nlay,nrow,ncol=nc0.variables[V[3][0]].shapenc1=netCDF4.Dataset(fname[1],rw[1])#V=[list(filter(lambda x:nc1.variables[x].ndim==j, [i for i in nc1.variables])) for j in [1,2,3,4]]
nt1,nlay,nrow,ncol=nc1.variables[V[3][0]].shapeifnt1<nt0:fname[0]=fname[1]os.system('cp '+fname[0]+' '+fname[2])nc2=netCDF4.Dataset(fname[2],rw[2])v4=V[3]nt=min(nt1,nt0)forvinv4:nc2[v][:,:,:,:]=nc0[v][:nt,:,:,:]-nc1[v][:nt,:,:,:]nc2.close()
Reference
Community Modeling and Analysis System (CMAS), I/O API,