<modify-namelist>

Purpose/Function

Change, add or delete values in a namelist file. The task reads in the template (if no namelist object is set), makes the changes in memory, then writes it back out.

Deletion can be done on entire sections or individual variables; insertion or replacement can be destined for a particular section or for all sections. The task processes the operations in the following order: DELETE, REPLACE, ADD/INSERT.

Attributes

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

asXml

boolean

false

write out namelist in XML format

file

java.io.File

(required)

file to which to write namelist

namelistTemplate

java.io.File

null

file from which to read in namelist

namelistType

java.lang.String

null

identifying type for namelist, if any (used in notifications)

namelist

ncsa.tools.common.namelist.Namelist

null

reference to a namelist object in the environment to use instead of a template file

notify

boolean

false

send a "file produced" notification after executing this task

targetFile

java.io.File

(required)

same as file attribute

Elements

TAG

TYPE

COUNT

DESCRIPTION

<delete>

ncsa.tools.ogrescript.types.Delete

0:N

describes a part of the namelist to delete

<replace>

ncsa.tools.ogrescript.types.Replace

0:N

describes a part of the namelist to replace

<insert>

ncsa.tools.ogrescript.types.Insert

0:N

describes a part of the namelist to insert/add

Attributes of <delete>

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

section

java.lang.String

null

namelist section

variable

java.lang.String

null

namelist variable name

valueAtIndex

java.lang.String

null

index for subscripted variables or vectors

Attributes of <replace>

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

section

java.lang.String

null

namelist section

variable

java.lang.String

null

namelist variable name

value

java.lang.String

null

value to substitute

Attributes of <insert>

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

section

java.lang.String

null

namelist section

variable

java.lang.String

null

namelist variable name

value

java.lang.String

null

value of the variable

before

java.lang.String

null

insert before this variable

beforeIndex

java.lang.String

null

insert before this position in the vector

after

java.lang.String

null

insert after this variable

afterIndex

java.lang.String

null

insert after this position in the vector

If neither the "before" nor "after" attributes are set, the entry is appended to the end of the indicated section.

For how to use these child elements, see the commented example below.

ReturnValues

None.

Examples

<ogrescript>
        <declare name="double-value" double="-.040822"/>
	<modify-namelist namelistTemplate="/tmp/short.namelist" targetFile="/tmp/deletions.namelist">
		
		<delete section="fake_section_2"/>                                        <!-- remove section (if it doesn't exist, this is a NOP) -->
		<delete variable="fake(2,1)"/>                                            <!-- remove variable from any section -->
		<delete section="adas_kpvar" variable="kpvar(1)"/>                        <!-- remove variable -->
		<delete section="adas_zrange" variable="zrange(1)"/>                      <!-- zrange(1) is not an explicit var; this will not touch zrange -->
		<delete section="adas_zrange" variable="zrange" valueAtIndex="2"/>        <!-- this will null out the zrange value -->
		<delete section="soil_ebm" variable="tsoilint" valueAtIndex="1"/>         <!-- nulls out value of tsoilint(1), but does not remove definition -->
		<delete section="adas_sng" variable="iusesng(2)" valueAtIndex="1"/>       <!-- nulls out value of iuseng(2,1), but does not remove definition -->
		<delete section="adas_sng" variable="iusesng" valueAtIndex="1"/>          <!-- nulls out value of iuseng(1,x), but does not remove definitions -->
	</modify-namelist>
	
	<modify-namelist namelistTemplate="/tmp/short.namelist" targetFile="/tmp/insertions.namelist">
		<insert section="fake_section_X"/>	                                  <!-- appends empty section -->
		<insert section="fake_section_Y" before="fake_section_X"/>	          <!-- inserts empty section -->
		<insert section="fake_section_Z" after="fake_section_X"/>	          <!-- inserts empty section -->
		<insert section="fake_section_X" variable="newvar1" value="'NEW1'"/>      <!-- appends variable to section -->
		<insert section="fake_section_X" variable="newvar2" value="'NEW2'" after="newvar1"/>
		<insert section="fake_section_X" variable="newvar3" value="'NEW3'" before="newvar2"/>
	        <insert section="fake_section_X" variable="newvector" value=",1,2,3,4,5,6,7,," after="newvar2"/>
		<insert section="fake_section_X" variable="newvector(20)" value="20"
				  after="newvector"/>                                     <!-- a separate variable, but it shares its value (and newvector gets updated) -->
		<insert section="fake_section_X" variable="newvector" beforeIndex="20"
				  value="19"/>                                            <!-- value newvector(20) after this should be = 19 -->
		<insert section="fake_section_X" variable="newvector" afterIndex="21"
				  value="21"/>
	</modify-namelist>
		
	<modify-namelist namelistTemplate="/tmp/short.namelist" targetFile="/tmp/replacements.namelist">
		<replace variable="sfcqcrng" value="${double-value}"/>                    <!-- replaces all variables by that name in any section -->	
		<replace section="soil_ebm" variable="sfcdat" value="3"/>                 <!-- replaces variable by that name only in the section indicated -->	
		<replace section="adas_range" variable="xyrange(1)" value="99.E03"/>      <!-- replaces single value of vector -->
		<replace section="adas_typ" variable="ianxtyp" value="0,0,0,0,1,1,1,1,2"/><!-- overwrite an entire vector -->
		<replace section="adas_typ" variable="ianxtyp(9)" value="9"/>             <!-- ianxtyp(10) would fail because the 10th entry does not exist yet -->
		<replace section="adas_kpvar" variable="kpvar(1)" value="0.9, 0.9"/>      <!-- change from single to multiple values is allowed -->
		<replace section="adas_zrange" variable="zrange" value="400.,100."/>      <!-- but once a vector, always a vector (remaining values will not be overwritten) -->
		<replace section="adas_zrange" variable="zrange" value="400.,100.,,,,,,,,,"/><!-- those values can be nulled out, though -->
		<replace section="fake_section_1" variable="fake(1)" value="2.2,2.3"/>    <!-- note how the new values will appear in the individual variable entries for (1,1) and (1,2) -->
	</modify-namelist>       		
</ogrescript>
  • No labels