check
Cotton2K Source Code | Plant Sciences and Genetics in Agriculture
Avishalom Marani

Prof. Avishalom Marani

In Memoriam
Plant Science and Genetics

IN MEMORY OF

Prof. Avishalom Marani

1924 - 2020

Cotton physiology and breeding; Moisture stress in field crops; Quantitative genetics in plant breeding; Heterosis in cotton.

Contact Us

 

Mailing Address:
The Robert H. Smith Institute of
Plant Sciences and Genetics
in Agriculture
Herzl 229, Rehovot 7610001, Israel

Administrator: 
Neomi Maimon 
Tel: 972-8-948-9251,
Fax: 972-8-948-9899,
E-mail: neomim@savion.huji.ac.il

Secretary of teaching program:
Ms. Iris Izenshtadt
Tel: 972-8-9489333
E-mail: Iris.Izenshtadt@mail.huji.ac.il

Director: 
Prof. Naomi Ori
Tel: 972-8-948-9605
E-mail: naomi.ori@mail.huji.ac.il

 

Cotton2K Source Code

Cotton2K Model Open Source Code

 

Introduction

The source code of Cotton2K is hereby made available for research and education purposes. As many other crop simulation models, this model simulates processes involving weather elements, soil water, soil nitrogen, soil temperature, root growth, plant growth, plant phenology, plant water relations, plant nitrogen, etc. Some of these simulated processes are unique to the cotton crop, but most of them can be used (unchanged, or with some modifications) in simulation models of other crops.

Scientists who try to develop crop simulation models often spend a lot of their time in developing the framework of the model, and in repeating tasks that have already been done by other scientists. Programming is a very time - consuming effort (if done by scientists or graduate students), or expensive (if done by hired programmers). Progress in crop modeling would therefore be greatly enhanced if some modelers will be willing to share their efforts, and other modelers will be able to use some existing "building blocks" and add to them their own contribution. The concept of "object oriented programming", which is now used in all modern programming languages, makes it easy to transfer code segments from one model to another.

For general information about the cotton2Kmodel see: Description of Cotton2K

I hope some segments of this code will be found useful by members of the crop modelling community. Please do not hesitate to write me if you have any questions, comments or criticism.

The code is written in C++, and compiled by Microsoft Visual C++.Net 2003. Microsoft Foundation Classes (MFC) are used for deriving the framework of the model, but most of the functions are class-free and may probably be compiled by any C++ compiler. The code is commented to add explanations for most of the code segments. Local variables are defined when declared in each function. The 'file scope' variables are defined at the beginning of each file. The 'global' variables are defined in file 'global.cpp'.

Back to Top

Copyright Information

This program (version 4.0) has been written in 2004 by

Avishalom Marani
Professor Emeritus at the Institute of Plant Science
School of Agriculture of the Hebrew University of Jerusalem
P.O.Box 12
Rehovoth 76100
Israel

Email address: Avshalom.Marani@mail.huji.ac.il

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. To receive a copy of the GNU General Public License write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, or contact http://www.gnu.org/licenses/gpl.txt

The following is adapted from parts of the document created by the Free Software Foundation.

You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work, provided that you also meet all of these conditions:

  • a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
  • b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties.
These requirements apply to the modified work as a whole, and also to sections of the code. You may copy and distribute the Program (or a work based on it) in object code or executable form under the above terms, provided that you also do one of the following:
  • a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the above terms on a medium customarily used for software interchange; or,
  • b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the above terms on a medium customarily used for software interchange; or,
  • c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer.)
You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.

Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.

If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.

If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission.

BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

List of Files and Functions

The code of program CottonModel includes the following files and functions:

Package A. General Framework:
  • File CottonModel.cpp
    • Class C2KApp:
      • Message map and constructor
      • InitInstance()
      • ExitInstance()
      • GetJobFile()
      • GetProfilesList()
      • RunTheModel()
      • DailySimulation()
      • DoAdjustments()
      • SimulateThisDay()
      • OnAppAbout()
    • Class CAoutDlg
  • File CottonModel.rc
    • Resource script for menu, dialogs, etc.
  • File MainFrm.cpp
    • Class CMainFrame
  • File Dialogs.cpp
    • Class InputDatesDlg
    • Class COpenDlg
    • Class CProgCtrlDlg
  • File GeneralFunctions.cpp (functions which are used in several places in the model)
    • String handling -
      • GetLineData()
    • Date conversions -
      • DateToDoy()
      • DoyToDate()
      • LeapYear()
    • Soil functions -
      • psiq()
      • qpsi()
      • wcond()
      • PsiOsmotic()
    • Extracting climate data -
      • GetFromClim()
  • File global.cpp
    • Defines all global ("common") variables. (This file also serves as a "dictionary" for these variables.)
  • File InitializeGlobal.cpp
    • InitializeGlobal()
  • File PlantAdjustment.cpp
    • WriteStateVariables()
    • PlantAdjustments()
    • GoBack()
  • File stdafx.cpp
  • Header files:
    • CottonModel.h
    • CottonSimulation.h
    • Dialogs.h
    • GeneralFunctions.h
    • Global.h
    • MainFrame.h
    • Resource.h
    • StdAfx.h

Package B. Input Routines:

  • File GettingInput_1.cpp
    • ReadInput()
    • ReadProfileFile()
    • ReadCalibrationData()
    • InitializeGrid()
    • WriteInitialInputData()
  • File GettingInput_2.cpp
    • ReadSoilImpedance()
    • InitSoil()
    • InitializeSoilData()
    • ReadSoilHydraulicData()
    • InitializeRootData()
    • InitializeSoilTemperature()
    • form()
  • File GettingInput_3.cpp
    • OpenClimateFile()
    • ReadClimateData()
    • tdewest()
    • ReadAgriculturalInput()
    • SlabLoc()
    • ReadPlantMapInput()

Package C. Climate:

  • File DailyClimate.cpp
    • DayClim()
    • ComputeDayLength()
    • dayrad()
    • daytmp()
    • tdewhour()
    • dayrh()
    • daywnd()
    • AverageAirTemperatures()
    • VaporPressure()
    • EvapoTranspiration()
    • clearskyemiss()
    • cloudcov()
    • clcor()
    • del()
    • gam()
    • refalbed()
    • sunangle()
    • SimulateRunoff()
Package D. Soil:
  • File SoilProcedures_1.cpp
    • SoilProcedures()
    • RootsCapableOfUptake()
    • ApplyFertilizer()
    • ComputeIrrigation()
    • GetTargetStress()
    • PredictDripIrrigation()
    • PredictSurfaceIrrigation()
    • OutputPredictedIrrigation()
    • AveragePsi()
    • WaterTable()
  • File SoilProcedures_2.cpp
    • CapillaryFlow()
    • Drain()
    • DripFlow()
    • CellDistance()
  • File SoilProcedures_3.cpp
    • GravityFlow()
    • WaterUptake()
    • PsiOnTranspiration()
    • NitrogenUptake()
    • WaterFlux()
    • WaterBalance()
    • NitrogenFlow()
    • SoilSum()
  • File SoilNitrogen.cpp
    • SoilNitrogen()
    • UreaHydrolysis()
    • SoilWaterEffect()
    • MineralizeNitrogen()
    • SoilTemperatureEffect()
    • Nitrification()
    • Denitrification()
    • SoilNitrogenBal()
    • SoilNitrogenAverage()

Package E. Soil Temperature:

  • File SoilTemperature_1.cpp
    • ColumnShading()
    • SoilTemperature()
    • SoilTemperatureInit()
  • File SoilTemperature_2.cpp
    • EnergyBalance()
    • SensibleHeatTransfer()
    • SoilSurfaceBalance()
    • SoilMulchBalance()
  • File SoilTemperature_3.cpp
    • CanopyBalance()
    • MulchSurfaceBalance()
    • SoilHeatFlux()
    • ThermalCondSoil()
    • HeatBalance()
    • PredictEmergence()

Package F. The Root System:

  • File RootGrowth_1.cpp
    • PotentialRootGrowth()
    • RootImpedance()
    • SoilTemOnRootGrowth()
    • SoilMechanicResistance()
    • SoilAirOnRootGrowth()
    • SoilNitrateOnRootGrowth()
    • SoilWaterOnRootGrowth()
    • ComputeActualRootGrowth()
  • File RootGrowth_2.cpp
    • RedistRootNewGrowth()
    • TapRootGrowth()
    • InitiateLateralRoots()
    • LateralRootGrowthLeft()
    • LateralRootGrowthRight()
    • RootAging()
    • RootDeath()
    • RootCultivation()
    • RootSummation()

Package G.The Cotton Plant:

  • File PlantGrowth_1.cpp
    • PhysiologicalAge()
    • Stress()
    • LeafWaterPotential()
    • LeafResistance()
    • GetNetPhotosynthesis()
    • PlantGrowth()
  • File PlantGrowth_2.cpp
    • PotentialStemGrowth()
    • PotentialLeafGrowth()
    • TemperatureOnLeafGrowthRate()
    • PotentialFruitGrowth()
    • TemperatureOnFruitGrowthRate()
  • File PlantGrowth_3.cpp
    • DryMatterBalance()
    • ActualFruitGrowth()
    • ActualLeafGrowth()
    • AddPlantHeight()
    • CheckDryMatterBal()
    • To be added Defoliate()
  • File CottonPhenology.cpp
    • CottonPhenology()
    • PreFruitingNode()
    • DaysToFirstSquare()
    • CreateFirstSquare()
    • AddVegetativeBranch()
    • AddFruitingBranch()
    • AddFruitingNode()
    • FruitingSite{}
    • NewBollFormation()
    • BollOpening()
  • File FruitAbscission.cpp
    • FruitingSitesAbscission()
    • SiteAbscissionRatio()
    • SquareAbscission()
    • BollAbscission()
    • AdjustAbscission()
    • AdjustSquareAbscission()
    • AdjustYoungBollAbscission()
    • AdjustSetBollAbscission()
    • AdjustBollAbscission()
    • ComputeSiteNumbers()
  • File LeafAbscission.cpp
    • LeafAbscission()
    • PreFruitLeafAbscission()
    • MainStemLeafAbscission()
    • FruitNodeLeafAbscission()
    • DefoliationLeafAbscission()
    • SortArray()
  • File PlantNitrogen.cpp
    • PlantNitrogen()
    • NitrogenRequirement()
    • NitrogenSupply()
    • PetioleNitrateN()
    • NitrogenAllocation()
    • ExtraNitrogenAllocation()
    • PlantNitrogenContent()
    • GetNitrogenStress()
    • NitrogenUptakeRequirement()
    • PlantNitrogenBal()

Package H. Output Routines:

  • File WriteOutput_1.cpp
    • OpenOutputFiles()
    • DailyOutput{}
    • output1()
    • DataOutput()
    • WriteLine22()
  • File WriteOutput_2.cpp
    • cotplt()
    • sitecode()
    • bollsize()
  • File WriteOutput_3.cpp
    • outputplt()
    • output2()
    • output3()
    • output4()
    • output5()
    • output6()
    • output7()
    • OutputForSoilMaps()

All the source code files can be downloaded at once (file size 208 KB). Another option is to download each or some of the packages separately . To get the list of files in each package see List of files and functions . In this case, it is recommended not to exclude Section A, which contains the header files and the dictionary of global variables.Downloading Information

The downloaded files are stored as *.zip files. Unzip before attempting to read these files. Read these files by any text editor (like Notepad) or any C++ compiler.

Section A contains some files, specific for the compiler, which are needed for compilation. If compilation is not needed, only files of type *.cpp, *.h, or *.rc have to be read.

To download All the files of the source code: Download Source Code of Cotton2K

To download individual sections of the source code:

Package A - Download General Framework

Package B - Download Input Routines

Package C - Download Climate Routines

Package D - Download Soil Routines

Package E - Download Soil Temperature Routines

Package F - Download Root System Routines

Package G - Download Cotton Plant Routines

Package H - Download Output Routines

sourcecotton2kver40.zip201 KB
a.zip42 KB
b.zip19 KB
c.zip13 KB
d.zip29 KB
e.zip22 KB
f.zip13 KB
g.zip45 KB
h.zip15 KB