Class: FortranNamelistParser::ParamDef

Inherits:
Struct
  • Object
show all
Defined in:
ext/fortio/lib/fortio/fortran_namelist.rb,
ext/fortio/lib/fortio/fortran_namelist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#array_specObject

Returns the value of attribute array_spec

Returns:

  • (Object)

    the current value of array_spec



89
90
91
# File 'ext/fortio/lib/fortio/fortran_namelist.rb', line 89

def array_spec
  @array_spec
end

#identObject

Returns the value of attribute ident

Returns:

  • (Object)

    the current value of ident



89
90
91
# File 'ext/fortio/lib/fortio/fortran_namelist.rb', line 89

def ident
  @ident
end

#rvalObject

Returns the value of attribute rval

Returns:

  • (Object)

    the current value of rval



89
90
91
# File 'ext/fortio/lib/fortio/fortran_namelist.rb', line 89

def rval
  @rval
end

Instance Method Details

#inspectObject



141
142
143
144
145
146
147
# File 'ext/fortio/lib/fortio/fortran_namelist.rb', line 141

def inspect
  if array_spec
    return "#{ident}(#{array_spec.inspect}) = #{rval.inspect}"
  else
    return "#{ident} = #{rval}"
  end
end

#set(hash) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/fortio/lib/fortio/fortran_namelist.rb', line 91

def set (hash)
  case hash[ident]
  when CArray
    hash[ident].attach { |ca|
      if array_spec
        crv = rval.to_ca
        if crv.search(nil)
          mask = crv.ne(nil)
          ca[*array_spec][0...crv.size][mask] = crv[mask]
        elsif ca[*array_spec].is_a?(CArray)
          ca[*array_spec][0...crv.size] = crv              
        else 
          ca[*array_spec] = rval.first
        end
      else
        if rval.is_a?(Array) and rval.size == 1
          ca[0] = rval.first
        else
          ca[0...rval.size] = rval
        end
      end
    }
  when Array
    if array_spec
      if array_spec.first.is_a?(Integer) and rval.size == 1
        hash[ident][*array_spec] = rval.first
      else
        hash[ident][*array_spec] = rval.first
      end
    else
      if rval.is_a?(Array) and rval.size == 1
        hash[ident][0] = rval.first
      else
        hash[ident].clear
        hash[ident].push(*rval)
      end
    end        
  else
    if array_spec
      hash[ident] = []
      set(hash)
    else
      if rval.is_a?(Array) and rval.size == 1
        hash[ident] = rval.first
      else
        hash[ident] = rval
      end
    end
  end
end