[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: standard units in software
But you do get much more readable code, which make upkeep
a lot easier .. curtis
On Mon November 24 2008, Eugene Chudakov wrote:
> I see now. You are right, only the header file should be defined,
> and it defines the basic units. The only downside
> is nearly twice more typing everywhere and more
> CPU cycles.
>
> Thanks,
> Eugene
>
>
> On Mon, 24 Nov 2008, Matthew Shepherd wrote:
>
> >
> > Hi Eugene,
> >
> > Other routines can use the same global constants. For example:
> >
> > suppose showerEnergy is some energy expressed internally in an object in
> > standard units. Then:
> >
> > if( checkEnergy( showerEnergy ) ){
> > ...
> > }
> >
> > bool checkEnergy( double energy ){
> >
> > return( energy*k_MeV > 30*k_MeV );
> > }
> >
> > One just needs to be sure:
> >
> > #include "units.h"
> >
> > exists wherever the global constants need to be used.
> >
> > In other words, the numbers are always expressed in standard units. Having
> > the constants just helps alleviate keeping track of what the units are. If
> > the standard units are MeV then k_MeV == 1, k_GeV == 0.001, etc..
> >
> > -Matt
> >
> >
> > On Nov 24, 2008, at 9:53 AM, Eugene Chudakov wrote:
> >
> >> Hi Matt,
> >>
> >> the scheme you suggest is convenient for local
> >> calculations, but how do you transfer variables to another
> >> routines? You still seem to need a convention or another call
> >> parameter to define the unit...
> >>
> >> Regards,
> >> Eugene
> >>
> >>
> >> On Mon, 24 Nov 2008, Matthew Shepherd wrote:
> >>
> >>>
> >>> In CLEO we had a set of constants defined in a file called units.h
> >>>
> >>> One would then write things like:
> >>>
> >>> 0.25*k_GeV, 120*k_MeV, 15*k_m, ...
> >>>
> >>> The constants were multiplicative factors to convert the numbers to
> >>> standard units. This was very nice since one never had to think about
> >>> what the standard units were and the code looks much nicer:
> >>>
> >>> if( energy > 30*k_MeV ){
> >>> ...
> >>> }
> >>>
> >>> I would advocate a similar approach for us.
> >>>
> >>> -Matt
> >>>
> >>>
> >>> On Nov 24, 2008, at 9:13 AM, David Lawrence wrote:
> >>>
> >>>> Hi Mark,
> >>>>
> >>>> I distinctly remember discussing this at a software meeting a long time
> >>>> ago. However, it does not appear to have made it into the coding
> >>>> conventions and a quick scan of meeting minutes was none too fruitful.
> >>>>
> >>>> I think we should add this to the coding conventions with the exact units
> >>>> you suggest using Tesla for the magnetic field. Would you mind adding the
> >>>> entry to the coding conventions wiki page? Then, we can discuss it and
> >>>> ratify it at the software meeting next week.
> >>>> Regards,
> >>>> -David
> >>>> Mark M. Ito wrote:
> >>>>> Folks,
> >>>>> Do we have an official set of standard units written down somewhere? I
> >>>>> am talking about things like
> >>>>> centimeters
> >>>>> nanoseconds
> >>>>> GeV
> >>>>> Tesla? kilogauss?
> >>>>> where one can assume a given quantity in the software is in standard
> >>>>> units unless stated otherwise explicitly.
> >>>>> -- Mark
> >>>> --
> >>>> ------------------------------------------------------------------------
> >>>> David Lawrence Ph.D.
> >>>> Staff Scientist Office: (757)269-5567 [[[ [ [ [
> >>>> Jefferson Lab Pager: (757)584-5567 [ [ [ [ [ [
> >>>> http://www.jlab.org/~davidl davidl@jlab.org [[[ [[ [[ [[[
> >>>> ------------------------------------------------------------------------
> >>>
> >>
> >
>
--
Professor Curtis A. Meyer Department of Physics
Phone: (412) 268-2745 Carnegie Mellon University
Fax: (412) 681-0648 Pittsburgh PA 15213-3890
cmeyer@ernest.phys.cmu.edu http://www.curtismeyer.com/