#!/usr/bin/env python # # Copyright (c) 2005-2006 The ABINIT Group (Yann Pouillon) # All rights reserved. # # This file is part of the ABINIT software package. For license information, # please see the COPYING file in the top-level directory of the ABINIT source # distribution. # from time import gmtime,strftime import commands import os import re import sys # ---------------------------------------------------------------------------- # # # Main program # # Initial setup my_name = "etsf-make-module" my_configs = ["config/etsf/specs.cf", "config/etsf/library.cf", "config/etsf/abinit.cf"] # Check if we are in the top of the ABINIT source tree if ( not os.path.exists("configure.ac") or not os.path.exists("src/main/abinit.F90") ): print "%s: You must be in the top of an ABINIT source tree." % my_name print "%s: Aborting now." % my_name sys.exit(1) # Read config file(s) for cnf in my_configs: if ( os.path.exists(cnf) ): execfile(cnf) else: print "%s: Could not find config file (%s)." % (my_name,cnf) print "%s: Aborting now." % my_name sys.exit(2) # Global attributes ead = " ! Global attributes" for att in etsf_attributes: if ( att[0] in etsf_properties ): specs = etsf_properties[att[0]] else: specs = ETSF_PRO_NONE if ( ((specs & ETSF_PRO_ATT_GLOBAL) != 0) and (len(att) > 2) ): if ( re.match("character",att[1]) ): spc = "&\n & " else: spc = "" ead += "\n %s,parameter :: etsf_%s = %s%s" % \ (att[1],att[0].lower(),spc,att[2]) # Data type for dimensions edt = "\n\n ! Data type for dimensions\n type etsf_dims\n" for dim in etsf_dimensions: edt += " integer :: %s\n" % (dim) edt += " end type etsf_dims" # Data structures for each group of variables egc = "\n\n ! Constants for groups of variables" egv = 1 egn = 0 for grp in etsf_group_list: egc += "\n integer,parameter :: etsf_grp_%-16s = %d" % (grp,egv) egv *= 2 egn += 1 edt += "\n\n ! Data type for %s\n type etsf_%s\n" % (grp,grp) for var in etsf_groups[grp]: dsc = etsf_variables[var] if ( len(dsc) > 1 ): dim = ":" for i in range(len(dsc)-2): dim += ",:" edt += " %s,pointer :: %s(%s)\n" % (dsc[0],var,dim) else: edt += " %s :: %s\n" % (dsc[0],var) edt += " end type etsf_%s" % (grp) # Number of groups egc += "\n integer,parameter :: etsf_%-20s = %d" % ("ngroups",egn) # Import template src = file("config/etsf/template.%s" % (etsf_modules["io_etsf"]),"r").read() src = re.sub("@SCRIPT@",my_name,src) src = re.sub("@CODE@",ead+egc+edt,src) # Write module mod = file(etsf_file_module,"w") mod.write(src) mod.close()