;can also put all forward functions here FUNCTION ed_globals,pref=pref ;global vars - copy to system struct IF !version.os_family EQ 'Windows' THEN BEGIN base = 'c:/data/ed/run1/' ENDIF ELSE BEGIN ; base = '/eddy/s1/adesai/data/ed/run1/' base = '/data/projects/synthesis/ed/run1/' ENDELSE IF n_elements(pref) EQ 0 THEN pref = '' ed = {basedir:base,$ outdir:'output/restart/'+pref,$ plotdir:'output/plots/'+pref,$ model:1b, $ n_climate:12.d,$ n_sub:12.d,$ timestep:1.d/12.d,$ patch_freq:12.,$ cohort_freq:1.,$ landuse:1b,$ num_lu_trans:3,$ water_competition:1b,$ max_surface_soil_depth:0.,$ water_hard:1.,$ n_hard:0b,$ recruitment:1b,$ internal_recruitment:1b,$ n_dist_types:3,$ mortality:1b,$ cold_mortality:1b,$ lag:5,$ n_pft:5,$ pt:2,$ ncmpt:6,$ hgtmin:1.5,$ c2b:2.,$ growth_resp:0.533,$ ;was 375 was 433 mass_OF_water:1.,$ sapling_mortality:0.0,$ patch_termination:1b,$ patch_fusion:1b,$ patch_termifusion:0b,$ patch_reduction:1b,$ patch_reduction_tailsize:1b,$ cohort_fusion:1b,$ cohort_fission:1b,$ cohort_termination:1b,$ f_area:0.02d,$ btol:0.001d,$ profile_tol:0.5,$ dbhmax:100.,$ n_dbh_bins:10,$ ntol:0.001,$ fusetol:0.4,$ fusetol_h:0.5,$ lai_tol:4.0,$ lai_fuse_tol:1.0,$ cohort_shading:0.5,$ self_shading:0.5,$ n_init_patches:6l,$ area:10000.d,$ ;*1e3*1e3 n_light:41,$ n_vm0:12,$ init_density:0.1d,$ resolution:1.0,$ half_res:1.0/2.0,$ imposed_mortality:1b,$ mort_int:1,$ cwd_fract:1.0,$ min_rho:0.1,$ min_cwd_dbh:10.0,$ n_cwd_classes:5,$ tmax:354l,$ winter_decay:1b,$ theta_crit:0.5d,$ l_fract:0.,$ tp_fract:0.5,$ precip_multiplier_start_year:0.0,$ precip_multiplier:1.0,$ cwd_on:1b,$ fire_on:1b,$ forestry_on:1b,$ forestry_rate_factor:1.0,$ treefall_age_threshold:25.,$ forestry_interval:1.0,$ hwa:0b,$ n_competition:1b,$ n_decomp_limitation:1b,$ external_recruitment:1b,$ initial_mineralized_soil_n:0.,$ initial_fast_soil_N:0.,$ reduce_cohorts:1b,$ max_patches:50l,$ ;500l,$ ;for now max_cohorts_per_patch:10l,$ ;1000l,$ ;for now restart:0b,$ restart_dir:'',$ restart_filename:''} return,ed END FUNCTION ed_cohort_str cohort = {pft:0,$ pt:1,$ n:0.d,$ dbh:0.d,$ avgRg:0.d,$ pastDbh:fltarr(!ed.lag),$ pastI:0l,$ hite:0.d,$ b:0.d,$ babove:0.d,$ bbelow:0.d,$ balive:0.d,$ mortality:0.d,$ bdead:0.d,$ bsw:0.d,$ bl:0.d,$ bls:0.d,$ bs:0.d,$ bstem:0.d,$ br:0.d,$ root_layer:0b,$ leaf_area:0.,$ lai:0.d,$ lite:0.d,$ gpp:0.d,$ npp:0.d,$ npp2:0.d,$ carbon_gain:0.d,$ carbon_gain_max:0.d,$ gpp_max:0.d,$ npp_max:0.d,$ resp:0.d,$ stemresp:0.d,$ gr_resp:0.d,$ md:0.d,$ An_o_max:0.,$ An_c_max:0.,$ An_o:0.,$ An_c:0.,$ fs_open:0.,$ fsn:0.,$ fsw:0.,$ carbon_balance:0.,$ cb:fltarr(!ed.n_climate),$ cb_full_light:fltarr(!ed.n_climate),$ cbr_bar:0.,$ payment_to_Nfixers:0.,$ p:fltarr(2),$ leaves_off:0b,$ ; density:0.,$ water_uptake:0.,$ E_o:0.,$ E_c:0.,$ dndt:0.d,$ ; dhdt:0.d,$ ddbhdt:0.d,$ dbalivedt:0.d,$ dbdeaddt:0.d,$ ; dbswdt:0.d,$ ; dbsdt:0.d,$ ; dbldt:0.d,$ ; dblsdt:0.d,$ ; dbrdt:0.d,$ nitrogen_uptake:0.,$ N_uptake_pot:0.,$ N_uptake_shut:0.,$ Vm0_index:0.,$ patchid:0l,$ ploc:(-1l)} return,cohort END FUNCTION ed_patch_str patch = {patchid:0l,$ age:0.,$ area:0.d,$ dist_type:0,$ ncohorts:0l,$ total_plant_nitrogen_uptake:0.,$ water:dblarr(2),$ theta:dblarr(2),$ theta_avg:0.,$ plant_water_uptake:fltarr(2),$ plant_water_uptake_total:0.,$ plant_water_demand_total:0.,$ perc:fltarr(2),$ soil_evap:0.,$ interception:0.,$ pft_biomass:fltarr(!ed.n_pft),$ pft_ag_biomass:fltarr(!ed.n_pft),$ pft_lai:fltarr(!ed.n_pft),$ plant_ag_biomass:0.d,$ plant_biomass:0.d,$ basal_area:0.d,$ pft_basal_area:fltarr(!ed.n_pft),$ delta_tagb:0.d,$ past_tagb:fltarr(!ed.n_sub),$ lai:0.d,$ gpp:0.d,$ npp:0.d,$ npp2:0.d,$ nep:0.d,$ pft_gpp:fltarr(!ed.n_pft),$ pft_npp:fltarr(!ed.n_pft),$ pft_npp2:fltarr(!ed.n_pft),$ pft_nep:fltarr(!ed.n_pft),$ aa_gpp:0.d,$ aa_npp:0.d,$ aa_npp2:0.d,$ aa_nep:0.d,$ soil_c:0.d,$ total_c:0.d,$ rh:0.d,$ aa_rh:0.d,$ litter:0.d,$ flushlitter:0.d,$ flushlittern:0.d,$ repro:fltarr(!ed.n_pft),$ seedbank:fltarr(!ed.n_pft),$ plantation:0b,$ fuel:0.,$ floorlite:0.,$ ignition_rate:0.,$ lambda1:fltarr(!ed.n_sub),$ pft_density_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_basal_area_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_agb_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ fuse_flag:0b,$ mineralized_soil_N:0.d,$ fast_soil_N:0.d,$ fast_soil_C:0.d,$ structural_soil_C:0.d,$ slow_soil_C:0.d,$ passive_soil_C:0.d,$ structural_soil_L:0.d,$ A:0.d,$ fstd:0.d,$ ssc_in:0.d,$ ssl_in:0.d,$ fsc_in:0.d,$ fsn_in:0.d,$ okint:0,$ cwd_resp:fltarr(!ed.n_cwd_classes),$ cwd:fltarr(!ed.n_cwd_classes),$ cwd_vol:fltarr(!ed.n_cwd_classes),$ cwd_in:fltarr(!ed.n_cwd_classes),$ cwd_total:0.,$ cwd_resp_total:0.,$ cwd2ssc_flux:0.,$ Td:0.,$ Wd:0.} return,patch END FUNCTION ed_sitedata_str sdata = {area:0.,$ pet:fltarr(12),$ pet_average:0.,$ precip:fltarr(12),$ precip_average:0.,$ snow:fltarr(12),$ snowmelt:fltarr(12),$ snowevap:fltarr(12),$ snowdepth:fltarr(12),$ runoff:fltarr(12),$ netprecip:fltarr(12),$ temp:fltarr(12),$ dgd:fltarr(12),$ chd:fltarr(12),$ dl:fltarr(12),$ temp_average:0.,$ sum_dgd:fltarr(12),$ sum_chd:fltarr(12),$ L_top:1.,$ Rn_top:1.,$ soil_type:intarr(2),$ soil_depth:fltarr(2),$ soil_depth_fract:fltarr(2),$ soil_lowerbound:fltarr(2),$ soil_temp:fltarr(12),$ soil_temp_average:0.,$ min_temp:fltarr(12),$ min_temp_min:0.,$ loss_fraction:fltarr(!ed.n_dist_types),$ theta_max:fltarr(2),$ k_sat:dblarr(2),$ tau:dblarr(2),$ Nfact:1.,$ light_levels:fltarr(!ed.n_light,!ed.pt),$ Ao:fltarr(!ed.n_light,!ed.n_climate,!ed.pt,!ed.n_vm0),$ Eo:fltarr(!ed.n_light,!ed.n_climate,!ed.pt,!ed.n_vm0),$ Ac:fltarr(!ed.n_light,!ed.n_climate,!ed.pt,!ed.n_vm0),$ Ec:fltarr(!ed.n_light,!ed.n_climate,!ed.pt,!ed.n_vm0),$ landuse:fltarr(!ed.num_lu_trans,1000),$ landuse_years:fltarr(1000),$ num_landuse_years:0.,$ plantation:0b,$ lambda_primary:0.d,$ lambda_secondary:0.d,$ plantation_species:intarr(3),$ plantation_stocking:dblarr(3),$ imposed_mortality_year:0.} return,sdata END FUNCTION ed_site_str,np=np,nc=nc IF n_elements(np) EQ 0 THEN np = !ed.max_patches IF n_elements(nc) EQ 0 THEN nc = !ed.max_cohorts_per_patch site = {lat:0.,$ lon:0.,$ npatches:0l,$ ncohorts:0l,$ integration_flag:0b,$ patches:temporary(replicate(ed_patch_str(),np)),$ cohorts:temporary(replicate(ed_cohort_str(),np*nc)),$ sdata:ed_sitedata_str(),$ lu_dist_area:fltarr(!ed.n_dist_types),$ plant_biomass:0.d,$ plant_ag_biomass:0.d,$ basal_area:0.d,$ pft_biomass:fltarr(!ed.n_pft),$ pft_ag_biomass:fltarr(!ed.n_pft),$ pft_basal_area:fltarR(!ed.n_pft),$ pft_lai:fltarr(!ed.n_pft),$ total_c:0.d,$ soil_c:0.d,$ lai:0.d,$ flush_month:intarr(!ed.n_pft)+13,$ leaf_drop_month:intarr(!ed.n_pft)-1,$ avg_stand_age:0.,$ gpp:0.d,$ npp:0.d,$ npp2:0.d,$ nep:0.d,$ rh:0.d,$ pft_gpp:fltarr(!ed.n_pft),$ pft_npp:fltarr(!ed.n_pft),$ pft_npp2:fltarr(!ed.n_pft),$ pft_nep:fltarr(!ed.n_pft),$ aa_gpp:0.d,$ aa_npp:0.d,$ aa_npp2:0.d,$ aa_nep:0.d,$ aa_rh:0.d,$ litter:0.d,$ water:dblarr(2),$ theta:dblarr(2),$ plant_water_uptake:0.d,$ plant_water_demand:0.d,$ perc:0.d,$ soil_evap:0.d,$ disturbance_rates:dblarr(!ed.n_dist_types,!ed.n_dist_types),$ treefall_disturbance_rate:0.d,$ fire_disturbance_rate:0.d,$ lambda1:dblarr(!ed.n_sub),$ nat_dist_type:0b,$ disturbance_memory:dblarr(!ed.n_dist_types,!ed.n_dist_types),$ fire_memory:0.d,$ treefall_memory:0.d,$ primary_harvest_memory:0.d,$ secondary_harvest_memory:0.d,$ nat_disturbance_rate:0.d,$ disturbance_rate:0.d,$ fire_flag:0b,$ fuel:0.d,$ ignition_rate:0.d,$ pft_density_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_basal_area_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_agb_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ density_profile:fltarr(!ed.n_dbh_bins),$ basal_area_profile:fltarr(!ed.n_dbh_bins),$ agb_profile:fltarr(!ed.n_dbh_bins),$ create_patch:0b,$ mineralized_soil_N:0.d,$ fast_soil_C:0.d,$ fast_soil_N:0.d,$ structural_soil_C:0.d,$ slow_soil_C:0.d,$ passive_soil_C:0.d,$ structural_soil_L:0.d,$ harvested_biomass:0.d,$ removed_biomass:0.d,$ planted_trees:0.,$ c_loss_term:0.d,$ cwd_resp:fltarr(!ed.n_cwd_classes),$ cwd:fltarr(!ed.n_cwd_classes),$ cwd_total:0.,$ cwd_resp_total:0.,$ cwd_in:fltarr(!ed.n_cwd_classes),$ cwd2ssc_flux:0.,$ initpatcharea:fltarr(!ed.n_init_patches),$ initpatchco:fltarr(!ed.n_init_patches,3),$ initpatchage:fltarr(!ed.n_init_patches)} return,site END FUNCTION ed_userdata_str data = {first_year:0l,$ first_year_projection:0l,$ year_lu_BEGIN:0l,$ current_year:0l,$ num_lu_trans_val:fltarr(!ed.num_lu_trans),$ num_mech_years:0l,$ mech_years:intarr(1000),$ mechyp:(-1l),$ deltat:0.,$ current_patch:0l,$ ok:0l,$ tt:0.,$ time_period:0l,$ gpp_max:0.,$ pft_names:strarr(!ed.n_pft),$ L_extinct:fltarr(!ed.n_pft),$ Rn_extinct:0.,$ M1:fltarr(!ed.n_pft),$ M2:fltarr(!ed.n_pft),$ M3:fltarr(!ed.n_pft),$ min_temp:fltarr(!ed.n_pft),$ frost_mort:0.,$ sd_mort:0.,$ wup_max:0.,$ water1:0.,$ nitrogen1:0.,$ nitrogen2:0.,$ patch_freq:0l,$ seed_rain:fltarr(!ed.n_pft),$ germination:fltarr(!ed.n_pft),$ sap_min_lite:fltarr(!ed.n_pft),$ sap_max_lite:fltarr(!ed.n_pft),$ sap_min_theta:fltarr(!ed.n_pft),$ seedlingsize:fltarr(!ed.n_pft),$ sapling_mortality:fltarr(!ed.n_pft),$ sapwood_Fraction:0.,$ leaf_life_span:fltarr(!ed.n_pft),$ specific_leaf_area:fltarr(!ed.n_pft),$ repro_min_h:fltarr(!ed.n_pft),$ treefall_hite_threshold:0.,$ treefall_s_gtht:fltarr(!ed.n_pft),$ treefall_s_ltht:fltarr(!ed.n_pft),$ treefall_disturbance_rate:0.,$ max_patch_age:0.,$ fp1:0.,$ k_fw:0.,$ b1Bl:dblarr(!ed.n_pft),$ b2Bl:dblarr(!ed.n_pft),$ b1BS:dblarr(!ed.n_pft),$ b2BS:dblarr(!ed.n_pft),$ b1Ht:dblarr(!ed.n_pft),$ b2Ht:dblarr(!ed.n_pft),$ bsw_m:dblarr(!ed.n_pft),$ bsw_b:dblarr(!ed.n_pft),$ imposed_mortality:dblarr(!ed.n_pft),$ Vm0_pft:fltarr(!ed.n_pft),$ Nfixer:fltarr(!ed.n_pft),$ fraction_OF_gpp_to_nfixers:0.,$ phenology:fltarr(!ed.n_pft),$ dl_tr:fltarr(!ed.n_pft),$ st_tr1:fltarr(!ed.n_pft),$ st_tr2:fltarr(!ed.n_pft),$ phen_a:fltarr(!ed.n_pft),$ phen_b:fltarr(!ed.n_pft),$ phen_c:fltarr(!ed.n_pft),$ pt:fltarr(!ed.n_pft),$ m:fltarr(!ed.n_pft),$ q:fltarr(!ed.n_pft),$ root_depth_max:fltarr(!ed.n_pft),$ qsw:dblarr(!ed.n_pft),$ agf_bs:fltarr(!ed.n_pft),$ rho:fltarr(!ed.n_pft),$ alpha:fltarr(!ed.n_pft,!ed.ncmpt),$ beta:fltarr(!ed.n_pft,!ed.ncmpt),$ max_dbh:fltarr(!ed.n_pft),$ max_dbh_s:fltarr(!ed.n_pft),$ max_bs:fltarr(!ed.n_pft),$ min_dbh:fltarr(!ed.n_pft),$ max_hite:fltarr(!ed.n_pft),$ r_fract:fltarr(!ed.n_pft),$ c_fract:fltarr(!ed.n_pft),$ hgt_min:fltarr(!ed.n_pft),$ init_dens:dblarr(!ed.n_pft),$ l2n_stem:0.,$ l2n_root:0.,$ l2n_leaf:0.,$ l2n_sd:0.,$ c2n_leaf:fltarr(!ed.n_pft),$ c2n_recruit:fltarr(!ed.n_pft),$ c2n_sd:fltarr(!ed.n_pft),$ c2n_stem:0.,$ c2n_root:0.,$ c2n_structural:0.,$ c2n_slow:0.,$ c2n_passive:0.,$ Vm0_levels:fltarr(!ed.n_vm0,!ed.pt),$ cwd_rho_classes:fltarr(!ed.n_cwd_classes),$ delta_rho:fltarr(!ed.n_cwd_classes),$ pft_cwd_class:fltarr(!ed.n_pft),$ wood_den:fltarr(!ed.n_pft),$ init_seed_bank:fltarr(!ed.n_pft)} return,data END FUNCTION ed_monout_str monout = {year:0l,$ mo:0l,$ tm:0.d,$ area:0.,$ pet:0.,$ temp:0.,$ precip:0.,$ snow:0.,$ snowmelt:0.,$ snowevap:0.,$ snowdepth:0.,$ dl:0.,$ dgd:0.,$ chd:0.,$ soil_temp:0.,$ min_temp:0.,$ lambda_primary:0.,$ lambda_secondary:0.,$ plantation_species:intarr(3),$ plantation_stocking:dblarr(3),$ npatches:0l,$ ncohorts:0l,$ lu_dist_area:fltarr(!ed.n_dist_types),$ plant_biomass:0.d,$ plant_ag_biomass:0.d,$ basal_area:0.d,$ pft_biomass:fltarr(!ed.n_pft),$ pft_ag_biomass:fltarr(!ed.n_pft),$ pft_basal_area:fltarR(!ed.n_pft),$ pft_lai:fltarr(!ed.n_pft),$ total_c:0.d,$ soil_c:0.d,$ lai:0.d,$ flush_month:intarr(!ed.n_pft),$ leaf_drop_month:intarr(!ed.n_pft),$ avg_stand_age:0.,$ gpp:0.d,$ npp:0.d,$ npp2:0.d,$ nep:0.d,$ rh:0.d,$ er:0.d,$ pft_gpp:fltarr(!ed.n_pft),$ pft_npp:fltarr(!ed.n_pft),$ pft_npp2:fltarr(!ed.n_pft),$ pft_nep:fltarr(!ed.n_pft),$ pft_er:fltarr(!ed.n_pft),$ aa_gpp:0.d,$ aa_npp:0.d,$ aa_npp2:0.d,$ aa_nep:0.d,$ aa_rh:0.d,$ litter:0.d,$ water:dblarr(2),$ theta:dblarr(2),$ plant_water_uptake:0.d,$ plant_water_demand:0.d,$ perc:0.d,$ soil_evap:0.d,$ disturbance_rates:dblarr(!ed.n_dist_types,!ed.n_dist_types),$ treefall_disturbance_rate:0.d,$ fire_disturbance_rate:0.d,$ lambda1:dblarr(!ed.n_sub),$ nat_dist_type:0b,$ disturbance_memory:dblarr(!ed.n_dist_types,!ed.n_dist_types),$ fire_memory:0.d,$ treefall_memory:0.d,$ primary_harvest_memory:0.d,$ secondary_harvest_memory:0.d,$ nat_disturbance_rate:0.d,$ disturbance_rate:0.d,$ fire_flag:0b,$ fuel:0.d,$ ignition_rate:0.d,$ pft_density_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_basal_area_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ pft_agb_profile:fltarr(!ed.n_pft,!ed.n_dbh_bins),$ density_profile:fltarr(!ed.n_dbh_bins),$ basal_area_profile:fltarr(!ed.n_dbh_bins),$ agb_profile:fltarr(!ed.n_dbh_bins),$ mineralized_soil_N:0.d,$ fast_soil_C:0.d,$ fast_soil_N:0.d,$ structural_soil_C:0.d,$ slow_soil_C:0.d,$ passive_soil_C:0.d,$ structural_soil_L:0.d,$ harvested_biomass:0.d,$ removed_biomass:0.d,$ planted_trees:0.,$ c_loss_term:0.d,$ cwd_resp:fltarr(!ed.n_cwd_classes),$ cwd:fltarr(!ed.n_cwd_classes),$ cwd_total:0.,$ cwd_resp_total:0.,$ cwd_in:fltarr(!ed.n_cwd_classes),$ cwd2ssc_flux:0.} return,monout END FUNCTION ed_yrout_str,np=np,nc=nc yrout ={year:0l,$ temp:0.d,$ precip:0.d,$ snow:0.d,$ plant_biomass:0.d,$ plant_ag_biomass:0.d,$ basal_area:0.d,$ pft_biomass:fltarr(!ed.n_pft),$ pft_ag_biomass:fltarr(!ed.n_pft),$ pft_basal_area:fltarR(!ed.n_pft),$ pft_lai:fltarr(!ed.n_pft),$ total_c:0.d,$ soil_c:0.d,$ lai:0.d,$ flush_month:0,$ leaf_drop_month:0,$ avg_stand_age:0.,$ gpp:0.d,$ npp:0.d,$ npp2:0.d,$ nep:0.d,$ rh:0.d,$ er:0.d,$ pft_gpp:fltarr(!ed.n_pft),$ pft_npp:fltarr(!ed.n_pft),$ pft_npp2:fltarr(!ed.n_pft),$ pft_nep:fltarr(!ed.n_pft),$ pft_er:fltarr(!ed.n_pft),$ litter:0.d,$ plant_water_uptake:0.d,$ mineralized_soil_N:0.d,$ fast_soil_C:0.d,$ fast_soil_N:0.d,$ structural_soil_C:0.d,$ slow_soil_C:0.d,$ passive_soil_C:0.d,$ structural_soil_L:0.d,$ harvested_biomass:0.d,$ removed_biomass:0.d,$ planted_trees:0.,$ c_loss_term:0.d,$ cwd_total:0.,$ cwd_resp_total:0.} return,yrout END PRO ed_define,site,data,hardwood=hardwood,pine=pine,wetland=wetland,nocc=nocc,nofor=nofor,test=test,opt=opt,conyr=conyr,nodyn=nodyn ;setup structures pref = 'hw_' IF keyword_set(pine) THEN pref = 'pn_' IF keyword_set(wetland) THEN pref = 'wl_' IF keyword_set(nocc) THEN pref+='nocc_' IF keyword_set(nofor) THEN pref+='nofor_' IF keyword_set(nodyn) THEN pref+='nodyn_' IF keyword_set(conyr) THEN pref+='conyr_' IF keyword_set(test) THEN pref+='test_' IF keyword_set(opt) THEN pref+='opt_' ed = ed_globals(pref=pref) defsysv,'!ed',ed site = ed_site_str() data = ed_userdata_str() END