P
Paul van Delst
Hello,
I've written some ruby code that creates Fortran95 code to define and manipulate derived
types (aka structures) as well as perform "regular" (what I ambiguously refer to as
"Binary") and netCDF I/O. Via a driver script, I provide a text file with the simple
structure definition to my ruby code and out pops three modules (fortran95 modules, not
ruby ones) that I can compile.
The way I do this currently is like so:
f=FDefMod.new
f.read(def_file) # Parse the file containing an f95 structure definition
f.createDefModule # Create the structure definition f95 module
f.createBinIOModule # Create the binary I/O f95 module
f.createNCIOModule # Create the netCDF I/O f95 module
This creates three compilable f95 modules. (It's all very cool, really
)
The problem I'm facing is that my ruby class definition file, fdefmod.rb, has grown
unmanageably large and I want to split the code up into more manageable pieces but I can't
figure out how best to do it.
I would like all the methods used to create the f95 definition code (i.e. the public
createDefModule and about 20 private methods) to reside in one file, the methods to create
the f95 binary I/O in another, and similarly for the methods to create the f95 netCDF I/O
code. E.g.
fdefmod.rb : contains the FDefMod class definition and associated methods
fdefmod_def.rb : contains the instance methods that create the f95 structure
definition module
fdefmod_binio.rb: contains the instance methods that create the f95 binary I/O module
fdefmod_ncio.rb : contains the instance methods that create the f95 netCDF I/O module
The last three files would be included (in the C sense) in the FDefMod class definition
file. All of the methods in the three "functional categories" (def, binio, and ncio) are,
of course, instance methods. Currently, the monolithic fdefmod.rb file contains everything
and it's a nightmare to organise the code itself and associated unit tests -- to say
nothing of adding new features.
So: how to split up the code? Module mixins? Subclasses?
The way I see it, the above type of organisational structure, while logical, is opposite
to how one would typically use modules to mixin methods since the methods in question
aren't generic, they're very specific.
And inheritance doesn't seem right either since each code component I'm trying to separate
aren't really classes in their own right; they're just a bunch of methods operating on a
class to create a particular format of output.
In addition, there are a number of class methods that are used by all three "functional
categories" of code. These class methods are just little utilities for formatting the
output f95 code are all private to the FDefMod class.
I've been thinking myself in circles for a while now, so my explanation may be malformed.
If so, I apologise.
Any ideas, suggestions, hints, etc much appreciated.
cheers,
paulv
I've written some ruby code that creates Fortran95 code to define and manipulate derived
types (aka structures) as well as perform "regular" (what I ambiguously refer to as
"Binary") and netCDF I/O. Via a driver script, I provide a text file with the simple
structure definition to my ruby code and out pops three modules (fortran95 modules, not
ruby ones) that I can compile.
The way I do this currently is like so:
f=FDefMod.new
f.read(def_file) # Parse the file containing an f95 structure definition
f.createDefModule # Create the structure definition f95 module
f.createBinIOModule # Create the binary I/O f95 module
f.createNCIOModule # Create the netCDF I/O f95 module
This creates three compilable f95 modules. (It's all very cool, really
The problem I'm facing is that my ruby class definition file, fdefmod.rb, has grown
unmanageably large and I want to split the code up into more manageable pieces but I can't
figure out how best to do it.
I would like all the methods used to create the f95 definition code (i.e. the public
createDefModule and about 20 private methods) to reside in one file, the methods to create
the f95 binary I/O in another, and similarly for the methods to create the f95 netCDF I/O
code. E.g.
fdefmod.rb : contains the FDefMod class definition and associated methods
fdefmod_def.rb : contains the instance methods that create the f95 structure
definition module
fdefmod_binio.rb: contains the instance methods that create the f95 binary I/O module
fdefmod_ncio.rb : contains the instance methods that create the f95 netCDF I/O module
The last three files would be included (in the C sense) in the FDefMod class definition
file. All of the methods in the three "functional categories" (def, binio, and ncio) are,
of course, instance methods. Currently, the monolithic fdefmod.rb file contains everything
and it's a nightmare to organise the code itself and associated unit tests -- to say
nothing of adding new features.
So: how to split up the code? Module mixins? Subclasses?
The way I see it, the above type of organisational structure, while logical, is opposite
to how one would typically use modules to mixin methods since the methods in question
aren't generic, they're very specific.
And inheritance doesn't seem right either since each code component I'm trying to separate
aren't really classes in their own right; they're just a bunch of methods operating on a
class to create a particular format of output.
In addition, there are a number of class methods that are used by all three "functional
categories" of code. These class methods are just little utilities for formatting the
output f95 code are all private to the FDefMod class.
I've been thinking myself in circles for a while now, so my explanation may be malformed.
If so, I apologise.
Any ideas, suggestions, hints, etc much appreciated.
cheers,
paulv