Transfer state variable values to initialize worldfile - RHESSys/RHESSys GitHub Wiki
Extract values from a spun-up worldfile to initialize another worldfile
If you have just one type of veg, use format_init.awk, if you have different veg types use format_init2.awk.
If you have just one veg (or soil) type:
- From your spun up worldfile (i.e. a single patch worldfile), extract the lines for all the state variables and associated values of interest and save them as a text file:
veg = C&N stores (cs.cpool through ns.retransn)
soil = soil_cs.soil1c through soil_cs.soil4c (note, zero out any values for soil_ns.sminn & soil_ns.nitrate before transferring to full worldfile)
litter = litter_cs.litr1c through litter_cs.litr4c
For example, use a text editor – or you can do this in the terminal with vi by:
vi the spun up worldfile and set numbers on the lines by typing:
:set number
(that is the colon : followed by the words set number)
extract appropriate lines and write to a text file, i.e.
:75,118 w veg_vals.txt
then quit out of vi.
this will have written a new text file to your directory called veg_vals.txt that will just consist of the state variable names and the values.
-
Run the format_init.awk script, using the text file containing the extracted lines (i.e. veg_vals.txt) as input:
awk -f format_init.awk < veg_vals.txt > init_veg.awk -
Edit init_veg.awk.
add this text to the first line of the file:
{a = 0;}
You can do this by reading firstline.txt into init_veg.awk:
If using vi, read the line in by opening init_veg.awk,, leave cursor at the top line and type:
:r firstline.txt
Add this text to the last line of the file:
(a == 0) {printf("%s %s\n",$1,$2);}
or in vi - move cursor to the bottom of the file and type:
:r lastline.txt
- Apply init_veg.awk to your full worldfile to get those new values into it:
awk -f init_veg.awk < world.name > world.name.initialized
If you have more than one veg (or soil) type:
-
Extract values for each veg type, same as above.
i.e. if you have 3 veg types, you'll end up with 3 text files, one for each veg type, i.e.
conifer.txt, deciduous.txt, grass.txt -
Run format_init2.awk 3 times, using each of text files, i.e.
awk -f format_init2.awk < conifer.txt > initialize_conifer.awk
awk -f format_init2.awk < deciduous.txt > initialize_deciduous.awk
akw -f format_init2.awk < grass.txt > initialize_grass.awk -
edit each of these.
add these 3 lines to the top of each file:
BEGIN {h=0;}
{a = 0;}
($2 == "veg_default_ID") && ($1==XX) {h=1;}
You can do this by reading firstline2.txt into each of the initialize_X.awk files:
vi initialize_X.awk, leave cursor at the top and type:
:r firstline2.txt
❗ CHANGE THE ID TO MATCH THE APPROPRIATE VEG TYPE ID FOR THAT FILE (i.e. if you are working on the initialize_conifer.awk file and the definition ID for conifer is 7, make sure you edit $1==XX to $1==7)
❗ On the last line of the file, at the end of the line add h=0;
so it looks like this:
($2 == "ns_retransn") && (h==1) {printf("%f %s\n",$1=0.00124073,$2); a=1; h=0;}
❗ Add this as the last line of the file:
(a == 0) {printf("%s %s\n",$1,$2);}
- Run each of the initialize awk files on your full worldfile to get the values into it for the applicable veg types.
Make sure that you used the corresponding veg type ID.