DrylandEcology / STEPWAT2

folder
4 stars 5 forks source link

Compress sxw.c local variables into struct. #267

Closed chaukap closed 5 years ago

chaukap commented 5 years ago

sxw.c has a lot of local variables of primitive types. Here's a snippet:

     /* rgroup by layer, ie, group-level values */
RealD * _roots_max,     /* read from root distr. file */
      * _roots_active_sum, /* used in sxw_resource */

     /* rgroup by period */
      * _phen;          /* phenology read from file */

/* simple vectors hold the resource information for each group */
/* curr/equ gives the available/required ratio */
RealF _resource_cur[MAX_RGROUPS],  /* current resource availability for each STEPPE functional type */
      _resource_pr[MAX_RGROUPS];

To make the gridded overhaul easier it would be nice to create a struct that holds all of these variables. The code would not only look less cluttered, but also make adding these variables to CellType much easier.

kpalmqui commented 5 years ago

@chaukap I am fine with this as long as code readability remains. For instance I find this rather clear (in terms of understanding how _roots_active_sum gets calculated):

/* Calculate the active roots in each month and soil layer for each STEPPE
         * functional group based on the functional group biomass this year */
    ForEachGroup(g)
    {
        t = RGroup[g]->veg_prod_type-1;
        nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type);
        for (l = 0; l < nLyrs; l++) {
            ForEachTrPeriod(p)
            {
                x = _rootsXphen[Iglp(g, l, p)] * sizes[g];
                _roots_active[Iglp(g, l, p)] = x;
                _roots_active_sum[Itlp(t, l, p)] += x;
            }
        }
    }
chaukap commented 5 years ago

@kpalmqui absolutely. I'll explain on our call, but this change shouldn't affect any of the functions, where the structs are defined.

chaukap commented 5 years ago

The struct has been created, but right now it is called TempType. I will update the name as soon as we come up with a more descriptive one.

kpalmqui commented 5 years ago

@chaukap how about SXW_resource?

chaukap commented 5 years ago

@kpalmqui sounds good!

chaukap commented 5 years ago

@kpalmqui since we have a file called sxw_resource.c I'll call the type SXW_resourceType so there is no confusion does that sound alright?

kpalmqui commented 5 years ago

@chaukap not sure what Type is referring to, but I guess it is OK.