This README describes two software packages which are the following:
1) Best Prediction Software - 2024
2) Age-Parity-Season-PreviousDaysOpen Adjustment Factors Software - 2023 and 2024
Both packages above call aiplage2.c.  README and software updates by Gary Fok,
Animal Genomics and Improvement Laboratory (AGIL), USDA Agricultural Research Service

The user has two options.  The first option is to run the "Best Prediction Software"
to standardize lactation yields to 305 days and then apply the "Age-Parity-Season-PreviousDaysOpen
Adjustment Factors".  The other option is to run newfactors.f90 to only apply the
"Age-Parity-Season-PreviousDaysOpen Adjustment Factors".  Therefore, the "Best
Prediction Software" is a superset of the "Age-Parity-Season-PreviousDaysOpen
Adjustment Factors Software".

Cole, J. B., and P. M. VanRaden. 2008. A Manual for Use of BESTPRED: A Program
for Estimation of Lactation Yield and Persistency Using Best Prediction.
Please read the Best Prediction Manual PDF located at
https://github.com/wintermind/bestpred/blob/master/Best%20Prediction%20Manual.pdf

U.S. Department of Agriculture, Agricultural Research Service, Animal Genomics
and Improvement Laboratory.

This manual describes how to obtain, install, and run a Fortran 90 program for
calculating lactation yields and persistencies using best prediction
methodology. Chapters also present the theory underlying best prediction,
describe the methodology used to calculate covariances among pairs of days in
milk for any combination of traits, and discuss implementation details important
to anyone considering modifications to the programs. The purpose is to provide
both background material and step-by-step instructions for successful use of the
software.

The Best Prediction Software package starts with bestpred_main.f90.  Program
bestpred_main.f90 prepares format 4 data for subroutine bestpred_fmt4() which
calls bestpred() and aiplage2().  In bestpred.par, "source = 10" enables the
above use of format 4 data (format4.dat).  It starts with test days to calculate
actual yield and standardizes them to 305 days.  C function aiplage2.c is the
heart of the "Age-Parity-Season-PreviousDaysOpen Adjustment Factors Software".

bestpred_main.f90:
INPUTS: format4.dat  - Input for bestpred_main.f90
        bestpred.par - Input for subroutine bestpred_parm.f90
        ageparityfactors1     - Input for aiplage2.c
        SeasonFactors2023.txt - Input for aiplage2.c
        PrevDOfactorsHO       - Input for aiplage2.c
        ClimateRegions        - Input for aiplage2.c
        adjust.scs - Input for ageadjs.c
OUTPUTS: bestpred_main.screen.output - Prints to the screen saved to bestpred_main.f90.screen.output
         cowcurve.ST.20240715
         cowdata.ST.20240715
         lctcurve.dat
         results_v2.dcr
SUBROUTINES: bestpred_log.f90
             aiplage2.c - Yield
             ageadjs.c - SCS
             bestpred_fmt4.f90
             bestpred_parm.f90
             bestpred.f90
#include: ageadj.h - for ageadjs.c
          adjscs.h - for ageadjs.c
          aiplage.h - for aiplage.c

To run the bestpred_main.f90 executable, type 'bestpred_main |tee bestpred_main.screen.output' and hit return:
bestpred_main |tee bestpred_main.screen.output <return>

See "MAKEFILE AND PROGRAM DOWNLOADS:" below to make a bestpred_main executable and three '.o' files (aiplage2.o, aiplage.o, ageadjs.o).

------------------------------------------------------------------------------

PURPOSE of Age-Parity-Season-PreviousDaysOpen Adjustment Factors Software:
Apply new factors for age, parity, season, and previous days open to compare cows more fairly within herds.

INPUT FILES for aiplage2.c, aiplage.c, and the calling program newfactors.f90:
ageparityfactors1     - from Jana Hutchison's ageparityfactors.sas as input for aiplage2.c.
SeasonFactors2023.txt - from Paul VanRaden's agefactor.sas as input for aiplage2.c.
PrevDOfactorsHO       - from Paul VanRaden's maindcr.f90 as input for aiplage2.c.
ClimateRegions        - defined by Asha Miles as input for aiplage2.c.
aiplage.h             - arrays used by the old aiplage.c (1994).
examples.yld.oldME    - mature equivalent milk, fat, and protein examples using the 1994 factors as input for newfactors.f90.

The above input files should be in the same directory where newfactors.f90 will be run.

FORMAT of examples.yld.oldME (input), examples.yld.actual (output), and examples.yld.newadj (output):
Animal_Key
          State
             Age
               Fresh_Year
                    Parity
                       Breed
                         Fresh_Month
                            Milk   Fat   Protein
 89606611 93 1 2020  1 5 11 18685. 1047.  731.
 89998174 93 1 2020  1 5 10 19745.  849.  732.
 92150366 93 2 2020  1 5 12 20338.  949.  687.
 15653856 11 3 1990  1 4 12 17780.  630.  554.
  5412866 11 2 1990  1 3  8  9120.  385.  304.
  5412865 11 1 1990  2 3  6 15049.  601.  490.
 33550309 11 1 1990  3 5 12 13793.  662.  473.

OUPUTS from newfactors.f90:
examples.yld.actual
examples.yld.newadj

MAKEFILE AND PROGRAM DOWNLOADS:
makefile is used to compile aiplage2.c, aiplage.c, ageadjs.c, newfactors.f90, and bestpred_main.f90 (Fortran subroutines: bestpred_log.f90, bestpred_fmt4.f90, bestpred_parm.f90, and bestpred.f90).
Put makefile, aiplage2.c, aiplage.c, ageadjs.c, ageadj.h, adjscs.h, aiplage.h, newfactors.f90, bestpred_main.f90, bestpred_log.f90, bestpred_fmt4.f90, bestpred_parm.f90, and bestpred.f90 into the same directory.
Type 'make' and hit return.
make <return>
The compile generates aiplage2.o, aiplage.o, ageadjs.o, a bestpred_main executable, and a newfactors executable.

New C function - 2023:
aiplage2.c - Obtain age, season, previous days open adjustments
             agebase = 0 adjusts to mature equivalent.  agebase = 36
             adjusts to 36 month equivalent.  Factors differ by breed,
             region, and time period.  Removes age, season, and
             regional climate biases.  Reads four input files instead
             of using arrays from aiplage.h like aiplage.c does.
             Standardizes 305-day yields by multiplying milk, fat,
             and protein by updated milk, fat, and protein age factors.
             Adjusting for the nongenetic advantages and disadvantages
             for each cow or bull improves the genetic selection
             process for the best dairy animals.

Old C function - 1994:
aiplage.c -  Obtain age, season, previous days open adjustments
             agebase = 0 adjusts to mature equivalent.  agebase = 36
             adjusts to 36 month equivalent.  Factors differ by breed,
             region, and time period.  Standardizes 305-day yields by
             multiplying milk, fat, and protein by milk, fat, and
             protein age factors.

Fortran calling program:
newfactors.f90 - Season de-adjust using aiplage.c.  Then season new
                 adjust using aiplage2.c.  Milk, fat, and protein
                 are divided by the old milk, fat, and protein
                 age factors from aiplage.c.  Next, they are
                 multiplied by the new milk, fat, and protein age
                 factors from aiplage2.c.

Program newfactors.f90 converts previous ME milk, fat, and protein to actual yields
by dividing by the previous 1994 age factors:
   ActualMilk_4F = Milk_4F / agefactor(1)
   ActualFat_4F  = Fat_4F  / agefactor(2)
   ActualPro_4F  = Pro_4F  / agefactor(3)
Writes examples.yld.actual for actual milk, fat, and protein.

Program newfactors.f90 also outputs 36-month equivalent milk, fat, and protein
after dividing by the previous age factors and multiplying by the new age factors:
   Milk_4F = (Milk_4F / agefactor(1)) * agefac(1)
   Fat_4F  = (Fat_4F  / agefactor(2)) * agefac(2)
   Pro_4F  = (Pro_4F  / agefactor(3)) * agefac(3)
Writes examples.yld.newadj for 36 month equivalent milk, fat, and protein.

Output file examples.yld.actual has actual milk, fat, and protein.
Output file examples.yld.newadj has 36-month equivalent milk, fat, and protein.
Both files have records for all breeds and regions but fresh years of either 2020 or 1990.
Records from before 1990 were converted from ME to 36-month equivalent were re-adjusted
simply by multiplying by the ratio of 36-month to ME yield for each breed from the 1990 factors.

To run the newfactors.f90 executable, type 'newfactors' and hit return:
newfactors <return>

------------------------------------------------------------------------------

The authors of this software do not make any warranty, express or implied, or
assume any liability or responsibility for the accuracy, completeness, or
usefulness of any information, apparatus, product, or process disclosed, or
represent that its use would not infringe privately-owned rights. Reference
herein to any specific commercial products, processes, or services by trade
name, trademark, manufacturer, or otherwise, does not necessarily constitute
or imply its endorsement, recommendation, or favoring by the United States
Government or the author. The views and opinions of authors expressed herein
do not necessarily state or reflect those of the United States Government
and shall not be used for advertising or product endorsement purposes.

Permission to use, copy, modify, and distribute this software for any purpose
without fee is hereby granted, provided that this entire notice is included
in all copies of any software which is or includes a copy or modification of
this software and in all copies of the supporting documentation for such
software.

7-Zip is copyrighted 2007 by Igor Pavlov. Absoft is a registered trademark and
Absoft Fortran v10 is a trademark of Absoft Corporation, Rochester Hills, MI.
DB2 is a registered trademark of International Business Machines Corporation,
Armonk, NY. G95 is copyrighted 2004 by the Free Software Foundation, Boston, MA.
GCC, the GNU Compiler Collection, is copyrighted 2007 by the Free Software
Foundation, Boston, MA. Kubuntu is a registered trademark of Canonical Ltd.
Linux is copyrighted 2007 by Linus Torvalds. Microsoft is a registered trademark
and Windows is a trademark of Microsoft Corporation, Redmond, WA. Red Hat and
Red Hat Enterprise Linux are registered trademarks of Red Hat, Inc., Raleigh, NC.

======================================================================================

REFERENCES for Best Prediction Software
Original projects - 1997, 1999, 2007 and 2008:
   Cole, J.B., Null, D.J., and VanRaden, P.M. 2008. Best prediction of yields for long lactations. J. Dairy Sci. (Accepted)
      https://aipl.arsusda.gov/publish/jds/submit/jdsabstr_bestprediction_jbc.html
   Cole, J.B., and VanRaden, P.M. 2007. A Manual for Use of BESTPRED: A Program for Estimation of Lactation Yield and Persistency Using Best Prediction. Available: http://aipl.arsusda.gov/software/bestpred/docs/html/index.html. Accessed:
      https://github.com/wintermind/bestpred/blob/master/Best%20Prediction%20Manual.pdf
   Cole, J.B., VanRaden, P.M., and Dematawewa, C.M.B. 2007. Estimation of yields for long lactations using best prediction. Journal of Dairy Science 90(Suppl. 1), 421(abstr. 558).
      https://www.journalofdairyscience.org/article/S0022-0302(09)70493-X/fulltext
   Norman, H.D., VanRaden, P.M., Wright, J.R., and Clay, J.S. 1999. Comparison of test interval and best prediction methods for estimation of lactation yield from monthly, a.m.-p.m., and trimonthly testing. J. Dairy Sci. 82(2):438-444.
      https://www.journalofdairyscience.org/article/S0022-0302(99)75250-1/fulltext
   VanRaden, P.M. 1997. Lactation yields and accuracies computed from test day yields and (co)variances by best prediction. J. Dairy Sci. 80(11):3015-3022.
      https://www.journalofdairyscience.org/article/S0022-0302(97)76268-4/fulltext

Project team members - 2024:
   John Cole     - research geneticist
   Paul VanRaden - research geneticist
   Gary Fok      - programmer

REFERENCES for Age-Parity-Season-PreviousDaysOpen Adjustment Factors and Software:
   Miles, A.M., Van Raden, P.M., Hutchison, J.L., Fok, G.C., Schutz, M.M. 2023. Standardizing lactation yields from national data with age-parity-season-region corrections for fair comparisons across individual cows and environments. Journal of Dairy Science. 106(Suppl. 1):189-190(abstr. 2716).
Original projects - 1994 and 1995:
   Duane Norman et al. (1995)
      https://www.researchgate.net/publication/14417143_Age_and_Seasonal_Effects_on_Holstein_Yield_for_Four_Regions_of_the_United_States_Over_Time
   Mike Schutz - post doctoral research geneticist (1994)
      https://www.researchgate.net/publication/265195434_Age-Season_Standardization
   George Wiggans - research geneticist

Project team members - 2023 and 2024:
   Asha Miles     - research geneticist - Asha.Miles@usda.gov
   Paul VanRaden  - research geneticist - paul.vanraden@usda.gov
   Jana Hutchison - animal scientist    - jana.hutchison@usda.gov
   John Cole      - research geneticist - john.cole@uscdcb.com
   Gary Fok       - programmer          - gary.fok@usda.gov
