#!/usr/bin/env python """This script creates html views of all available vcs templates, If a file is passed then removes everything from the initial_attributes first """ import vcs,sys,cdms,os x=vcs.init() ## Load exmaple file and set it up f=cdms.open('clt.nc') s=f('clt') iso=x.createisofill('new') for a in ['id','name','function','source','comment1','comment2','comment3','comment4','file','long_name','units', 'file', 'function', 'logicalmask', 'transformation', 'dataname', 'title', 'crdate', 'crtime', 'xname', 'yname', 'zname', 'tname', 'xunits', 'yunits', 'zunits', 'tunits', 'xvalue', 'yvalue', 'zvalue', 'tvalue', ]: setattr(s,a,a) ## Retrieve the original templates tinit=x.listelements('template') if len(sys.argv)>1: fscr=sys.argv[1] print fscr x.scriptrun(fscr) tfile=x.listelements('template') templates=[] for t2 in tfile: if t2 in tinit: pass else: templates.append(t2) else: templates=tinit try: os.mkdir('gif') except: pass try: os.mkdir('html') except: pass try: os.mkdir('scr') except: pass bg=1 for t in templates: print 'Processing:',t,s.shape tmpl=x.gettemplate(t) x.portrait() x.plot(s,tmpl,iso,bg=bg) x.gif('gif/template_'+t+'_portrait.gif',merge='r',orientation='p') x.clear() x.landscape() x.plot(s,tmpl,iso,bg=bg) x.gif('gif/template_'+t+'_landscape.gif',merge='r',orientation='l') x.clear() tmpl.script('scr/template_'+t+'.py','w') tmpl.script('scr/template_'+t+'.scr','w') f=open('html/template_'+t+'.html','w') f.write('VCS TEMPLATE:'+t+'\n\n') f.write('

VCS TEMPLATE
-- '+t+' --

\n') f.write('Downloads:
Python script
\n') f.write('VCS script
\n') f.write('\n') f.write('\n') f.write('
landscapeportrait

\n') f.write('') os.popen('tar -cvf template.tar scr gif html ; gzip template.tar').readlines()