macroWriteBin-methods: Write bin file for the SOIL and MACRO models.

macroWriteBinR Documentation

Write bin file for the SOIL and MACRO models.

Description

Write bin file for the SOIL and MACRO models. Original code by Kristian Persson. R code vectorisation by Julien Moeys.

Usage

macroWriteBin(x, ...)

## S3 method for class 'macroTimeSeries'
macroWriteBin(x, ...)

## S3 method for class 'macroTimeSeriesList'
macroWriteBin(x, f, ...)

## S3 method for class 'list'
macroWriteBin(x, f, ...)

## S3 method for class 'data.frame'
macroWriteBin(x, f, header = TRUE, dateMethod = 1L, tz = "GMT", ...)

Arguments

x

A data.frame. Table of data to be written in file. The table must contain one column named "Date" containing POSIXct dates, and thus must have column names. All columns but "Date" must be of type numerical (integer or double), and will be written as double. The "Date" will be converted into integers, representing minutes since 2 days before the 1st of Januray of year 0001 at 00:00. Missing values are not allowed.

...

Additional options passed to writeBin

f

Single character string or connection to a binary file. If a character string, it should be the name of the binary file which the data are to be written from. The path of the file may be provided as well, if f is not in the working directory.

header

If codeTRUE, the column header is written in the bin-file.

dateMethod

See help page for macroReadBin.

tz

See help page for macroReadBin.

Examples


library( "macroutils2" )


# ====== Write a binary file in SOIL or MACRO style ======

# 1.1. Read a table, that will then be written back


#   Path to the file to be read
( filenm <- system.file( 
    "bintest/chat_winCer_GW-D_1kgHa_d298_annual_output.bin", 
    package = "macroutils2", mustWork = TRUE ) )

#   Read the file
tmp1 <- macroReadBin( f = filenm, rmRunID = FALSE ) 


# 1.2. Generate a dummy temporary file where the table will be 
#   written

( filenm <- tempfile(  ) )


# 1.3. Write this table in SOIL or MACRO bin style 

#   NB: This table is NOT a standard SOIL or MACRO input file!

macroWriteBin( f = filenm, x = tmp1 ) 

#   NB: When writing the bin file, time zones are ignored!



# 1.4. Read that file again and check that it is the same:

tmp1.b <- macroReadBin( f = filenm, rmRunID = FALSE ) 

# Maximum difference (small numerical differences)
unlist( lapply(
    X      = colnames(tmp1), 
    FUN    = function(X){ 
        max( tmp1[,X] - tmp1.b[,X] ) 
    }   
) ) 



# Remove the temporary file
file.remove( filenm ) 

julienmoeys/macroutils2 documentation built on Feb. 28, 2024, 2:17 a.m.