FileWrite

Transfers data from expressions to a unit.

Declaration

Syntax

FileWrite(int label, expr? unit, expr? iomsg, expr? iostat, expr? id,
    expr* values, expr? separator, expr? end, stmt? overloaded,
    bool is_formatted, symbol? nml, expr? rec, expr? pos,
    expr? asynchronous)

Arguments

Argument

Description

label

the statement label of the Fortran statement, or -1 when it has none.

unit

the unit number to act on.

iomsg

a variable receiving the error message when the operation fails.

iostat

a variable receiving the I/O status: zero on success, non-zero otherwise. The statement does not abort when it is present.

id

the identifier of an asynchronous transfer.

values

the output list.

separator

the separator written between items.

end

the string written at the end of the record, for advance='no' style output.

overloaded

the call implementing a user-defined derived type output procedure.

is_formatted

false for an unformatted write.

nml

the Namelist group for a namelist write.

rec

the record number for a direct access write.

pos

the file position for a stream access write.

asynchronous

yes for an asynchronous transfer.

Return values

None.

Description

write and Print are different nodes because write names a unit and carries the full set of I/O specifiers, while print always writes a single formatted record to standard output.

With nml, values is empty and the variables of the group are written with their names.

Examples

(FileWrite
  :label -1
  :unit (Var
    :v (SymbolRef 1 "unit")
  )
  :iomsg nil
  :iostat nil
  :id nil
  :values [
    (Var
      :v (SymbolRef 1 "n")
    )
  ]
  :separator nil
  :end nil
  :overloaded nil
  :is_formatted true
  :nml nil
  :rec nil
  :pos nil
  :asynchronous nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "exists" (Variable
              :parent_symtab 1
              :name "exists"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "iostat" (Variable
              :parent_symtab 1
              :name "iostat"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "n" (Variable
              :parent_symtab 1
              :name "n"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "unit" (Variable
              :parent_symtab 1
              :name "unit"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (FileOpen
            :label -1
            :newunit (Var
              :v (SymbolRef 1 "unit")
            )
            :filename (StringConstant
              :s "data.txt"
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 8
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
            )
            :status (StringConstant
              :s "old"
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 3
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
            )
            :form nil
            :access nil
            :iostat (Var
              :v (SymbolRef 1 "iostat")
            )
            :iomsg nil
            :action nil
            :delim nil
            :recl nil
            :position nil
            :blank nil
            :encoding nil
            :sign nil
            :decimal nil
            :round nil
            :pad nil
            :asynchronous nil
          )
          (FileRead
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :fmt nil
            :iomsg nil
            :iostat (Var
              :v (SymbolRef 1 "iostat")
            )
            :advance nil
            :size nil
            :id nil
            :pos nil
            :values [
              (Var
                :v (SymbolRef 1 "n")
              )
            ]
            :overloaded nil
            :is_formatted true
            :nml nil
            :rec nil
            :pad nil
          )
          (FileWrite
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :iomsg nil
            :iostat nil
            :id nil
            :values [
              (Var
                :v (SymbolRef 1 "n")
              )
            ]
            :separator nil
            :end nil
            :overloaded nil
            :is_formatted true
            :nml nil
            :rec nil
            :pos nil
            :asynchronous nil
          )
          (FileBackspace
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :iostat nil
            :iomsg nil
            :err nil
          )
          (FileRewind
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :iostat nil
            :err nil
            :iomsg nil
          )
          (FileEndfile
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :iostat nil
            :iomsg nil
            :err nil
          )
          (Flush
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :err nil
            :iomsg nil
            :iostat nil
          )
          (FileInquire
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :file nil
            :iostat nil
            :err nil
            :exist (Var
              :v (SymbolRef 1 "exists")
            )
            :opened nil
            :number nil
            :named nil
            :name nil
            :access nil
            :sequential nil
            :direct nil
            :form nil
            :formatted nil
            :unformatted nil
            :recl nil
            :nextrec nil
            :blank nil
            :position nil
            :action nil
            :read nil
            :write nil
            :readwrite nil
            :delim nil
            :pad nil
            :flen nil
            :blocksize nil
            :convert nil
            :carriagecontrol nil
            :size nil
            :pos nil
            :iolength nil
            :iolength_vars []
            :decimal nil
            :sign nil
            :encoding nil
            :stream nil
            :iomsg nil
            :round nil
            :pending nil
            :asynchronous nil
          )
          (FileClose
            :label -1
            :unit (Var
              :v (SymbolRef 1 "unit")
            )
            :iostat nil
            :iomsg nil
            :err nil
            :status nil
          )
        ]
      )
    }
  )
  :items []
)

See Also

FileRead, Print, Namelist, StringFormat