macroReadBin {macroutils}R Documentation

Read bin file from the Soil and MACRO models.

Description

Read bin file from the Soil and MACRO models. Adapted from an "anonymous" SLU origial code by Kristian Persson. R code vectorisation by Julien Moeys.

Usage

macroReadBin(file, ...)

## S3 method for class 'character'
macroReadBin(file, ...)

Arguments

file

Vector of character strings or a single connection to a binary file. If a vector character strings, it should be the name(s) of the binary file(s) which the data are to be read from. The path of the file(s) may be provided as well, if file(s) is (are) not in the working directory.

...

Additional options passed to specific methods and to readBin

Details

Many global arguments can be set-up and retrieved via muPar and getMuPar. Please check the help page of these functions if you need to tune macroReadBin.

Value

Returns a data.frame with the content of the bin file. If length(file) > 1, then a list of data.frame is returned instead. The Date column in the bin file is converted from "Julian Date" into POSIXct date format.

See Also

readBin.

Examples

require( "macroutils" )


# ====== Example 1: MACRO model weather file ====== 

#   Path to the file to be read
( filenm <- system.file( "bintest/METFILE.BIN", 
    package = "macroutils", mustWork = TRUE ) )
## [1] "C:/Users/julienm/Documents/R/win-library/3.2/macroutils/bintest/METFILE.BIN"
#   Read the file
tmp1 <- macroReadBin( file = filenm ) 

#   Using different settings
muPar( alphaNumOnly = FALSE, removeSpace = FALSE ) 

tmp3 <- macroReadBin( file = filenm ) 

colnames( tmp1 ) 
## [1] "Date"                                       
## [2] "Max_air_temperature_oC_Sutton_Bonington"    
## [3] "Min_air_temperature_oC_Sutton_Bonington"    
## [4] "Solar_radiation_W_m_2_Sutton_Bonington_TRS1"
## [5] "Vapour_pressure_kPa_Sutton_Bonington_TRS1"  
## [6] "Wind_speed_m_s_1_Sutton_Bonington_TRS1"
colnames( tmp3 ) 
## [1] "Date"                                                
## [2] "Max. air temperature oC      Sutton Bonington"       
## [3] "Min. air temperature oC      Sutton Bonington"       
## [4] "Solar radiation      W m-2   Sutton Bonington   TRS1"
## [5] "Vapour pressure      kPa     Sutton Bonington   TRS1"
## [6] "Wind speed           m s-1   Sutton Bonington   TRS1"
dim( tmp1 ) 
## [1] 731   6
dim( tmp3 ) 
## [1] 731   6
#   Reset settings
muPar( reset = TRUE ) 


# ====== Example 2: SOIL model input file ====== 

#   Path to the file to be read
( filenm <- system.file( "bintest/soiln001.BIN", 
    package = "macroutils", mustWork = TRUE ) ) 
## [1] "C:/Users/julienm/Documents/R/win-library/3.2/macroutils/bintest/soiln001.BIN"
#   Read the file
tmp1 <- macroReadBin( file = filenm ) 

#   Using different settings
muPar( alphaNumOnly = FALSE, removeSpace = FALSE ) 

tmp3 <- macroReadBin( file = filenm ) 

colnames( tmp1 ) 
##  [1] "Date"                                   
##  [2] "Nitrogen_g_m_0_25NNO3_A_13"             
##  [3] "Nitrogen_g_m_25_50NNO3_A_38"            
##  [4] "Nitrogen_g_m_50_75NNO3_A_63"            
##  [5] "Nitrogen_g_m_75_100NNO3_A_88"           
##  [6] "Nitrogen_g_m_100_150NNO3_A_125"         
##  [7] "Nitrogen_g_m_Nt_Plant_N_A"              
##  [8] "Cumulated_Nitrogen_g_m_Denitrified_NO_A"
##  [9] "Cumulated_Nitrogen_g_m_Leached_NO3_N_A" 
## [10] "Nitrogen_g_m_0_25NNH4_A_13"             
## [11] "Nitrogen_g_m_25_50NNH4_A_38"            
## [12] "Nitrogen_g_m_50_75NNH4_A_63"            
## [13] "Nitrogen_g_m_75_100NNH4_A_88"           
## [14] "Nitrogen_g_m_100_150NNH4_A_125"         
## [15] "Nitrogen_g_m_Harvest_residu_A"          
## [16] "Nitrogen_flow_g_mdayDeposition_to_A"    
## [17] "Nitrogen_flow_g_mday_75_100_A_88"       
## [18] "Nitrogen_flow_g_mday_0_25_Man_fa_A_13"  
## [19] "Nitrogen_flow_g_mdayHarvest_export_A"   
## [20] "Nitrogen_flow_g_mday_0_25_Man_NH_A_13"  
## [21] "Nitrate_N_mg_l_0_25_water_A_13"         
## [22] "Nitrogen_flow_g_mdayNO3_N_tile_dra_A"   
## [23] "Nitrogen_flow_g_mdayNO3_N_stream_Q_A"   
## [24] "Nitrogen_g_m_Litter_tot_pro_A"          
## [25] "Nitrogen_g_m_Faeces_tot_pro_A"          
## [26] "Nitrogen_g_m_Humus_tot_prof_A"          
## [27] "Nitrogen_g_m_NH4_N_tot_prof_A"          
## [28] "Nitrogen_g_m_NO3_N_tot_prof_A"          
## [29] "Depth_m_zr_RootDepth_A"                 
## [30] "Nitrogen_flow_g_mdayXNd_PotPlant_A"     
## [31] "Nitrogen_flow_g_mdayAct_denitrific_A"   
## [32] "Nitrogen_flow_g_mdayXNu_ActPlant_A"     
## [33] "Water_flow_mm_day_In_drainage_ti_A"     
## [34] "Water_flow_mm_day_In_stream_A"          
## [35] "Nitrogen_flow_g_mdayLitter_NH4_A"       
## [36] "Nitrogen_flow_g_mdayFaeces_NH4_A"       
## [37] "Nitrogen_flow_g_mdayOrg_NH4_A"          
## [38] "C_N_ratio_0_25_Litter_A_13"             
## [39] "C_N_ratio_25_50_Litter_A_38"            
## [40] "C_N_ratio_50_75_Litter_A_63"            
## [41] "C_N_ratio_75_100_Litter_A_88"           
## [42] "C_N_ratio_100_150_Litter_A_125"         
## [43] "C_N_ratio_0_25_Faeces_A_13"             
## [44] "Nitrogen_mg_l_NO3_N_stream_A"           
## [45] "Nitrogen_mg_l_NO3_N_tile_dra_A"         
## [46] "Water_flow_mm_day_Surface_runoff_A"     
## [47] "Water_flow_mm_day_Surface_runoff_A"     
## [48] "Water_flow_mm_day_Percolation_A"
colnames( tmp3 ) 
##  [1] "Date"                                                
##  [2] "Nitrogen            g m²      0- 25(NNO3)  A 001  13"
##  [3] "Nitrogen            g m²     25- 50(NNO3)  A 001  38"
##  [4] "Nitrogen            g m²     50- 75(NNO3)  A 001  63"
##  [5] "Nitrogen            g m²     75-100(NNO3)  A 001  88"
##  [6] "Nitrogen            g m²    100-150(NNO3)  A 001 125"
##  [7] "Nitrogen            g m²    (Nt) Plant-N   A 001"    
##  [8] "Cumulated Nitrogen  g m²    Denitrified NO A 001"    
##  [9] "Cumulated Nitrogen  g m²    Leached NO3-N  A 001"    
## [10] "Nitrogen            g m²      0- 25(NNH4)  A 001  13"
## [11] "Nitrogen            g m²     25- 50(NNH4)  A 001  38"
## [12] "Nitrogen            g m²     50- 75(NNH4)  A 001  63"
## [13] "Nitrogen            g m²     75-100(NNH4)  A 001  88"
## [14] "Nitrogen            g m²    100-150(NNH4)  A 001 125"
## [15] "Nitrogen            g m²    Harvest residu A 001"    
## [16] "Nitrogen flow       g m²day Deposition (to A 001"    
## [17] "Nitrogen flow       g m²day  75-100        A 001  88"
## [18] "Nitrogen flow       g m²day   0- 25 Man-fa A 001  13"
## [19] "Nitrogen flow       g m²day Harvest export A 001"    
## [20] "Nitrogen flow       g m²day   0- 25 Man-NH A 001  13"
## [21] "Nitrate-N           mg l      0- 25 water  A 001  13"
## [22] "Nitrogen flow       g m²day NO3-N tile dra A 001"    
## [23] "Nitrogen flow       g m²day NO3-N stream Q A 001"    
## [24] "Nitrogen            g m²    Litter tot pro A 001"    
## [25] "Nitrogen            g m²    Faeces tot pro A 001"    
## [26] "Nitrogen            g m²    Humus tot prof A 001"    
## [27] "Nitrogen            g m²    NH4-N tot prof A 001"    
## [28] "Nitrogen            g m²    NO3-N tot prof A 001"    
## [29] "Depth               m       (zr) RootDepth A 001"    
## [30] "Nitrogen flow       g m²day (XNd) PotPlant A 001"    
## [31] "Nitrogen flow       g m²day Act denitrific A 001"    
## [32] "Nitrogen flow       g m²day (XNu) ActPlant A 001"    
## [33] "Water flow          mm day  In drainage ti A 001"    
## [34] "Water flow          mm day  In stream      A 001"    
## [35] "Nitrogen flow       g m²day Litter-NH4     A 001"    
## [36] "Nitrogen flow       g m²day Faeces-NH4     A 001"    
## [37] "Nitrogen flow       g m²day Org-NH4        A 001"    
## [38] "C-N ratio           -         0- 25 Litter A 001  13"
## [39] "C-N ratio           -        25- 50 Litter A 001  38"
## [40] "C-N ratio           -        50- 75 Litter A 001  63"
## [41] "C-N ratio           -        75-100 Litter A 001  88"
## [42] "C-N ratio           -       100-150 Litter A 001 125"
## [43] "C-N ratio           -         0- 25 Faeces A 001  13"
## [44] "Nitrogen            mg l    NO3-N stream   A 001"    
## [45] "Nitrogen            mg l    NO3-N tile dra A 001"    
## [46] "Water flow          mm day  Surface runoff A 001"    
## [47] "Water flow          mm day  Surface runoff A 001"    
## [48] "Water flow          mm day  Percolation    A 001"
dim( tmp1 ) 
## [1] 7121   48
dim( tmp3 ) 
## [1] 7121   48
# Reset settings
muPar( reset = TRUE ) 

[Package macroutils version 1.8.2 Index]