File: Z1-BasicsTools.R

package info (click to toggle)
fbasics 200.10058-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,644 kB
  • ctags: 189
  • sloc: fortran: 1,709; ansic: 116; sh: 29; makefile: 12
file content (206 lines) | stat: -rw-r--r-- 5,686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General 
# Public License along with this library; if not, write to the 
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA 02111-1307 USA

# Copyrights (C)
# for this R-port: 
#   1999 - 2004, Diethelm Wuertz, GPL
#   Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
#   info@rmetrics.org
#   www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
#   see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
#   see Rmetrics's copyright file


################################################################################
# FUNCTION:		   		DESCRIPTION:
#  myFinCenter 			 My financial Center
#  currentYear           Date of the Current Year
#  myUnits               Date Units
#  xmpBasics             Sets prompt
#  xmpfBasics            Popups the example menu
# FUNCTION:             DESCRIPTION:
#  modify                Modify a 'timeSeries' object
#  modify.default        S3 Default Method
#  atoms                 Extract atoms from 'timeSeries' object
#  atoms.default         S3 Default Method
################################################################################


# Requires:

    require(methods)
    
    
# Default Parameters:
	
	myFinCenter =  "Zurich"
	currentYear = as.POSIXlt(Sys.time())$year + 1900
	myUnits = "days"
	
	
# Set a timezone if none found in environment variables or options()
# ... as suggested by Dirk Eddelbuettel, thanks Dirk.

    if (Sys.getenv("TZ") == "") {
		if (is.null(getOption("TZ"))) {
			cat("No timezone information found, using default of GMT\n")
          	Sys.putenv("TZ" = "GMT") }
       	else {
          	cat("No timezone information found, applying option() value of",
             	getOption("TZ"), "\n")
       		Sys.putenv("TZ" = getOption("TZ")) } }


# ------------------------------------------------------------------------------


xmpBasics = 
function(prompt = "") 
{
	invisible(prompt)
}

	
# ------------------------------------------------------------------------------


xmpfBasics = 
function() 
{ 	# A function implemented by Diethelm WUertz

	# Description:
	#	Popups the example menu
	
	# FUNCTION:
	
	# Popup:
	path = paste(.Library,"/fBasics", sep = "") 
	entries = .read.fBasics.00Index (file.path(path, "demoIndex"))    
	example = select.list(entries[,1])
	selected = 0
	for (i in 1:length(entries[,1])) {
		if (example == entries[i,1]) selected = i
	}
	if (example == "") {
    	cat("\nNo demo selected\n")
    } else {
     	cat("\nLibrary: ", "fBasics", "\nExample: ", 
       		entries[selected, 1], "\nTitle:   ", entries[selected, 2], "\n")
        source(paste(path, "/demo/", example, ".R", sep = ""))
    }
    if (TRUE) {
	    cat("\n") 
	}
    
    # Return Value:
    invisible()
}


# ------------------------------------------------------------------------------


.read.fBasics.00Index = 
function (file) 
{
    if (is.character(file)) {
        if (file == "") {
            file <- stdin()
    	} else {
            file <- file(file, "r")
            on.exit(close(file))
        }
    }
    if (!inherits(file, "connection")) 
        stop(paste("argument", 
        	sQuote("file"), "must be a character string or connection"))
    y <- matrix("", nr = 0, nc = 2)
    x <- paste(readLines(file), collapse = "\n")
    for (chunk in unlist(strsplit(x, "\n[       \n]*\n"))) {
        entries <- try({
            if (regexpr("(   |  )", chunk) == -1) 
                NULL
            else {
                chunk <- gsub("\n[      ]+", "  ", chunk)
                x <- strsplit(unlist(strsplit(chunk, "\n")), "[    ]")
                cbind(unlist(lapply(x, "[[", 1)), unlist(lapply(x, 
                  	function(t) {
                    	paste(t[-c(1, which(nchar(t) == 0))], collapse = " ")
                  	})))
            }
        })
        if (!inherits(entries, "try-error") && NCOL(entries) == 2) 
            y <- rbind(y, entries)
    }
    colnames(y) <- c("Item", "Description")
    y
}

 

# ******************************************************************************
# R - Modifications and Problems:


modify =
function(x, method, units) 
{
	UseMethod("modify")	
}


# ------------------------------------------------------------------------------


modify.default =
function(x, method = c("sort", "round", "trunc"), units = NULL )
{	
	# Modify:
	ans = NA
	if (method[1] == "sort") return(sort(x))
	if (method[1] == "round") return(round(x))
	if (method[1] == "trunc") return(trunc(x))
	
	# Return Value:
	ans
}	


# ------------------------------------------------------------------------------


atoms = 
function(x, ...) 
{
	UseMethod("atoms")
}


# ------------------------------------------------------------------------------


atoms.default = 
function(x, ...) 
{
	invisible(x)
}


# ------------------------------------------------------------------------------