rclimdex2climatol: Convert RClimDex daily data files to 'climatol' input format

View source: R/clihomog.R

rclimdex2climatolR Documentation

Convert RClimDex daily data files to climatol input format

Description

This function can be useful to prepare the climatol input files when the user have their daily data in RClimDex format.

Usage

rclimdex2climatol(stfile, kvar, chrcod=c(6,10), varcli='', sep='\t', anyi=NA,
anyf=NA, mis=-99.9, mindat=365, header=TRUE)

Arguments

stfile

Name of the file with the list of data file names and station coordinates, codes and names.

kvar

RClimDex variable to extract: 1 (RR), 2 (TX), 3 (TN).

chrcod

Initial and final characters of data file names to be used as station codes. c(6,10) by default.

varcli

(Short) name of the studied climatic variable. Defaults to 'RR', 'TX' or 'TN', depending on kvar.

sep

Field separator in stfile and data files (Tab by default).

anyi

First year to study. (Defaults to the first year of available data.)

anyf

Last year to study. (Defaults to the last year of available data.)

mis

Missing data code. (Defaults to -99.9.)

mindat

Minimum required number of data per station. (Defaults to 365 daily data.)

header

Set to TRUE (the default) if files have a header)

Details

Users of the RClimDex program can convert their daily data files to the climatol format. All files listed in stfile will be read, and the selected variable (precipitation, maximum or minimum temperature) will be stored in a unique *.dat file, with its companion *.est station file. Therefore, if you want to convert all three variables, you must run this function three times.

If data files do not provide station names in their 9th column, station codes will be used also as station names.

See Also

homogen, climatol2rclimdex

Examples

## Set a temporal working directory:
wd <- tempdir()
wd0 <- setwd(wd)

## Prepare a few files in RClimDex format:
data(climatol_data)
gY=c(46,46,46); mY=c(06,15,14); sY=c(42,25,53)
gX=c(14,15,14); mX=c(03,09,50); sX=c(05,06,05)
df=data.frame(File=c('p064.txt','p084.txt','p082.txt'),
LatDeg=gY,LatMin=mY,LatSec=sY,LonDeg=gX,LonMin=mX,LonSec=sX,
elev=SIstations[,3],name=SIstations[,5])
write.table(df,'stations.txt',sep='\t',row.names=FALSE)
write.table(p064.df,'p064.txt',sep='\t',row.names=FALSE,quote=FALSE)
write.table(p084.df,'p084.txt',sep='\t',row.names=FALSE,quote=FALSE)
write.table(p082.df,'p082.txt',sep='\t',row.names=FALSE,quote=FALSE)

## Now run the example:
rclimdex2climatol('stations.txt',3,chrcod=c(1,4))

## Return to user's working directory:
setwd(wd0)

## Input and output files can be found in directory:
print(wd)

climatol documentation built on April 20, 2023, 5:08 p.m.