TABLE OF CONTENTS


::pwtk::nebi::load_fromNEBI

SYNOPSIS

proc ::pwtk::nebi::load_fromNEBI {nebi {clear_existing 1}} {

PURPOSE

Load the input data from existing neb.x input file.

If clear_existing == 1, then the current input will be cleared, but otherwise the data will be simply added to the existing data.

ARGUMENTS

SOURCE

    ::pwtk::fileMustExist $nebi "neb.x input"

    if { [::pwtk::is_true $clear_existing] } {
        # clear the current neb.x input data ...
        ::pwtk::nebi::clear
    }

    # neb.x input file must contain the PATH namelist

    if { [catch {::pwtk::readNamelists $nebi PATH 1}] } {
        ::pwtk::error "input file \"$nebi\" does not appear to be a neb.x input file" 1
    }

    # parse namelists
    
    set output [::pwtk::readNamelists $nebi \
                    [concat $::pwtk::pwi::namelist_flow_list PATH]]

    # parse cards
    
    set pwi_cards [regsub ATOMIC_POSITIONS $::pwtk::pwi::card_flow_list {}]
    set card_re [join [concat $pwi_cards CLIMBING_IMAGES] |^]

    set inside_nml  0
    set inside_card 0
    
    foreach line [split [::pwtk::readFile $nebi] \n] {

        set word [::pwtk::firstWord $line]
        
        if { [regexp "^$card_re" $word] } {
            if { $inside_card } {
                append output "\}\n"
            }
            append output "$word [lrange $line 1 end] \{\n"
            set inside_card 1       
            continue
        }
        
        if { [regexp ^END_PATH_INPUT $word] } {
            if { $inside_card } {
                # close the CLIMBING_IMAGES card
                append output "\}\n"
            }
            set inside_card 0
            continue
        }

        # POSITIONS supercard
        
        if { [regexp ^BEGIN_POSITIONS $word] } {
            if { $inside_card } {
                append output "\}\n"
            }
            append output "POSITIONS \{\n"
            set inside_card 1
            continue
        }
        if { [regexp ^END_POSITIONS $word] } {
            append output "\}\n"
            set inside_card 0
            continue
        }
        
        if { [regexp {^(BEGIN|END)} $word] } {
            # strip the BEGIN & END keywords
            if { $inside_card } {
                append output "\}\n"
                set inside_card 0
            }
            continue
        }

        if { $inside_card && ! [regexp {^#|^!} $word] } {
            append output $line\n
        }
    }

    eval $output
    ::pwtk::input::namelists_ityp2atmSymb_ [concat $::pwtk::pwi::namelist_flow_list $::pwtk::nebi::input_flow_list]
}