Skip to content

Commit b577fc7

Browse files
committed
Add v20 folder
1 parent 0f3b157 commit b577fc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+20918
-0
lines changed

SourceCode/socket/utilSocket.c

+870
Large diffs are not rendered by default.

SourceCode/socket/utilSocket.h

+361
Large diffs are not rendered by default.

SourceCode/utility/stack.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* -------------------------------------------------------------------------
2+
* stack.c
3+
* A stack of pointers.
4+
* Copyright 2010 QTronic GmbH. All rights reserved.
5+
* -------------------------------------------------------------------------*/
6+
7+
8+
#include <stdio.h>
9+
#include <assert.h>
10+
#include "stack.h"
11+
#include <stdlib.h>
12+
13+
Stack* stackNew(int initialSize, int inc){
14+
Stack* s = (Stack*)malloc(sizeof(Stack));
15+
s->stack = NULL;
16+
s->stackSize = 0;
17+
s->stackPos = -1;
18+
s->initialSize = initialSize;
19+
s->inc = inc;
20+
return s;
21+
}
22+
23+
int stackIsEmpty(Stack* s) {
24+
return s->stackPos == -1;
25+
}
26+
27+
// add an element to stack and grow stack if required
28+
// returns 1 to indicate success and 0 for error
29+
int stackPush(Stack* s, void* e) {
30+
s->stackPos++;
31+
if (s->stackPos==s->stackSize){
32+
s->stackSize += (s->stack ? s->inc: s->initialSize);
33+
s->stack = (void**) realloc(s->stack, s->stackSize * sizeof(void*));
34+
if (!s->stack) return 0; // error;
35+
}
36+
s->stack[s->stackPos] = e;
37+
return 1; // success
38+
}
39+
40+
// return top element (possibly NULL), if stack not empty
41+
// runtime error if stack is empty
42+
void* stackPeek(Stack* s){
43+
assert(!stackIsEmpty(s));
44+
return s->stack[s->stackPos];
45+
}
46+
47+
// remove top element (possibly NULL) from stack and return it
48+
// runtime error if stack is empty
49+
void* stackPop(Stack* s){
50+
assert(!stackIsEmpty(s));
51+
return s->stack[s->stackPos--];
52+
}
53+
54+
// return the last n elements as null terminated array,
55+
// or NULL if memory allocation fails
56+
void** stackLastPopedAsArray0(Stack* s, int n){
57+
int i;
58+
void** array = (void**)malloc((n + 1)*sizeof(void*));
59+
if (! array) return NULL; // failure
60+
for (i=0; i<n; i++) {
61+
array[i] = s->stack[i+ s->stackPos + 1];
62+
}
63+
array[n]=NULL; // terminating NULL
64+
return array;
65+
}
66+
67+
// return stack as possibly empty array, or NULL if memory allocation fails
68+
// On sucessful return, the stack is empty.
69+
void** stackPopAllAsArray(Stack* s, int *size) {
70+
int i;
71+
void** array = (void**)malloc((s->stackPos + 1)*sizeof(void*));
72+
if (! array) return NULL; // failure
73+
*size = s->stackPos + 1;
74+
for (i=0; i<*size; i++)
75+
array[i] = s->stack[i];
76+
s->stackPos = -1;
77+
return array;
78+
}
79+
80+
// release the given stack
81+
void stackFree(Stack* s){
82+
if (s->stack) free(s->stack);
83+
free(s);
84+
}
85+
86+

SourceCode/utility/stack.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* -------------------------------------------------------------------------
2+
* stack.c
3+
* A stack of pointers.
4+
* Copyright 2010 QTronic GmbH. All rights reserved.
5+
* -------------------------------------------------------------------------*/
6+
7+
#ifndef STACK_H
8+
#define STACK_H
9+
10+
typedef struct {
11+
void** stack;
12+
int stackSize; // allocated size of stack
13+
int stackPos; // array index of top element, -1 if stack is empty.
14+
int initialSize; // how many element to allocate initially
15+
int inc; // how many elements to allocate when stack gets full
16+
} Stack;
17+
18+
Stack* stackNew(int initialSize, int inc);
19+
int stackIsEmpty(Stack* s);
20+
int stackPush(Stack* s, void* e);
21+
void* stackPeek(Stack* s);
22+
void* stackPop(Stack* s);
23+
void** stackPopAllAsArray(Stack* s, int *size);
24+
void** stackLastPopedAsArray0(Stack* s, int n);
25+
void stackFree(Stack* s);
26+
27+
#endif // STACK_H
28+

SourceCode/utility/util.c

+260
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
// Methods for Functional Mock-up Unit Export of EnergyPlus.
2+
3+
///////////////////////////////////////////////////////
4+
/// \file util.c
5+
///
6+
/// \brief utility functions
7+
///
8+
/// \author Wangda Zuo, Thierry S. Nouidui, Michael Wetter
9+
/// Simulation Research Group,
10+
/// LBNL,
11+
/// WZuo@lbl.gov
12+
///
13+
/// \date 2011-11-02
14+
///
15+
///
16+
/// This file provides utility functions for fmus
17+
///
18+
/// Copyright (c) 2012, The Regents of the University of California,
19+
/// through Lawrence Berkeley National Laboratory
20+
/// subject to receipt of any required approvals from the U.S. Dept. of Energy.
21+
/// All rights reserved.
22+
///////////////////////////////////////////////////////
23+
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <sys/stat.h>
28+
#include "util.h"
29+
30+
int debug; // Control for debug information
31+
32+
///////////////////////////////////////////////////////////////////////////////
33+
/// Translate the double variable to string variable.
34+
///
35+
///\param buffer String variable.
36+
///\param r Double variable.
37+
///////////////////////////////////////////////////////////////////////////////
38+
void doubleToCommaString(char* buffer, double r){
39+
char* comma;
40+
sprintf(buffer, "%.16g", r);
41+
comma = strchr(buffer, '.');
42+
if (comma) *comma = ',';
43+
}
44+
45+
//////////////////////////////////////////////////////////////////////////
46+
/// Delete the temporary folder
47+
///
48+
///\param tmpPat The path of the temporary folder
49+
///\return 0 if no error occurred
50+
/////////////////////////////////////////////////////////////////////////
51+
int deleteTmpDir(char* tmpPat){
52+
char* cmd;
53+
struct stat st;
54+
55+
// Ceck if the folder present
56+
if(stat(tmpPat,&st) != 0){
57+
printfError("Folder \"%s\" is not existing.\n", tmpPat);
58+
return -1;
59+
}
60+
61+
cmd = (char *)calloc(sizeof(char), strlen(tmpPat) +18);
62+
if (cmd == NULL){
63+
printfError("Fail to allocate memory for cmd.\n", tmpPat);
64+
return -1;
65+
}
66+
67+
if (WINDOWS)
68+
sprintf(cmd, "rd %s /S/Q", tmpPat); // Command in windows
69+
else
70+
sprintf(cmd, "rm -r %s", tmpPat); // Command in Linux
71+
72+
73+
printf("Generated cmd: \"%s\".\n", cmd);
74+
if ( system(cmd) != 0 ){
75+
printError("Fail to delete the temporary files");
76+
return -1;
77+
}
78+
printDebug("Deleted temporary files");
79+
return 0;
80+
}
81+
82+
//////////////////////////////////////////////////////////////////////////////
83+
/// Get temporary path
84+
///
85+
///\param nam Name to be used for temporary path
86+
///\param length Number of characters to be copied from \c nam.
87+
///\return Point of tmpPat if there is no error occurred.
88+
/////////////////////////////////////////////////////////////////////////////
89+
char *getTmpPath(const char *nam, int length)
90+
{
91+
char *tmpPat;
92+
93+
tmpPat = (char *)calloc(sizeof(char), length+2);
94+
95+
// Define the temporary folder
96+
if(strncpy(tmpPat, nam, length) == NULL){
97+
printError("Fail to allocate memory for temp dir.\n");
98+
return NULL;
99+
}
100+
if(WINDOWS) strcat(tmpPat, "\\");
101+
else strcat(tmpPat, "/");
102+
103+
return tmpPat;
104+
}
105+
106+
107+
108+
//////////////////////////////////////////////////////////////////////////////
109+
/// Set the mode in debug so that the debug information will be printed
110+
///
111+
//////////////////////////////////////////////////////////////////////////////
112+
void setDebug(int value)
113+
{
114+
debug = 1;
115+
}
116+
117+
//////////////////////////////////////////////////////////////////////////////
118+
/// Print debug message
119+
///
120+
///\param msg Message to be printed for debugging
121+
//////////////////////////////////////////////////////////////////////////////
122+
void printDebug(const char* msg){
123+
if (debug == 1)
124+
{
125+
fprintf(stdout, "Debug: ");
126+
fprintf(stdout, "%s\n", msg);
127+
}
128+
}
129+
130+
////////////////////////////////////////////////////////////////////////////////
131+
///// Print formatted debug message
132+
/////
133+
/////\param str1 Message to be printed for debugging
134+
/////\param str2 String variable to be printed for debugging
135+
////////////////////////////////////////////////////////////////////////////////
136+
//void printfDebug(const char* str1, const char* str2){
137+
// if (debug == 1)
138+
// {
139+
// fprintf(stdout, "Debug: ");
140+
// fprintf(stdout, str1, str2);
141+
// }
142+
//}
143+
144+
//////////////////////////////////////////////////////////////////////////////
145+
/// Print formatted debug message with Integer
146+
///
147+
///\param str1 Message to be printed for debugging
148+
///\param integer Integer variable to be printed for debugging
149+
//////////////////////////////////////////////////////////////////////////////
150+
void printfIntDebug(const char* str1, const int integer){
151+
if (debug == 1)
152+
{
153+
fprintf(stdout, "Debug: ");
154+
fprintf(stdout, str1, integer);
155+
}
156+
}
157+
158+
//////////////////////////////////////////////////////////////////////////////
159+
/// Print error message
160+
///
161+
///\param msg Error message to be printed
162+
//////////////////////////////////////////////////////////////////////////////
163+
void printError(const char* msg){
164+
fprintf(stderr, "*** Error: ");
165+
fprintf(stderr, "%s\n", msg);
166+
}
167+
168+
//////////////////////////////////////////////////////////////////////////////
169+
/// Print formatted error message
170+
///
171+
///\param str1 Error message to be printed
172+
///\param str2 String variable to be printed
173+
//////////////////////////////////////////////////////////////////////////////
174+
void printfError(const char* str1, const char* str2){
175+
fprintf(stderr, "*** Error: ");
176+
fprintf(stderr, str1, str2);
177+
}
178+
179+
/*
180+
181+
***********************************************************************************
182+
Copyright Notice
183+
----------------
184+
185+
Functional Mock-up Unit Export of EnergyPlus ©2013, The Regents of
186+
the University of California, through Lawrence Berkeley National
187+
Laboratory (subject to receipt of any required approvals from
188+
the U.S. Department of Energy). All rights reserved.
189+
190+
If you have questions about your rights to use or distribute this software,
191+
please contact Berkeley Lab's Technology Transfer Department at
192+
TTD@lbl.gov.referring to "Functional Mock-up Unit Export
193+
of EnergyPlus (LBNL Ref 2013-088)".
194+
195+
NOTICE: This software was produced by The Regents of the
196+
University of California under Contract No. DE-AC02-05CH11231
197+
with the Department of Energy.
198+
For 5 years from November 1, 2012, the Government is granted for itself
199+
and others acting on its behalf a nonexclusive, paid-up, irrevocable
200+
worldwide license in this data to reproduce, prepare derivative works,
201+
and perform publicly and display publicly, by or on behalf of the Government.
202+
There is provision for the possible extension of the term of this license.
203+
Subsequent to that period or any extension granted, the Government is granted
204+
for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable
205+
worldwide license in this data to reproduce, prepare derivative works,
206+
distribute copies to the public, perform publicly and display publicly,
207+
and to permit others to do so. The specific term of the license can be identified
208+
by inquiry made to Lawrence Berkeley National Laboratory or DOE. Neither
209+
the United States nor the United States Department of Energy, nor any of their employees,
210+
makes any warranty, express or implied, or assumes any legal liability or responsibility
211+
for the accuracy, completeness, or usefulness of any data, apparatus, product,
212+
or process disclosed, or represents that its use would not infringe privately owned rights.
213+
214+
215+
Copyright (c) 2013, The Regents of the University of California, Department
216+
of Energy contract-operators of the Lawrence Berkeley National Laboratory.
217+
All rights reserved.
218+
219+
1. Redistribution and use in source and binary forms, with or without modification,
220+
are permitted provided that the following conditions are met:
221+
222+
(1) Redistributions of source code must retain the copyright notice, this list
223+
of conditions and the following disclaimer.
224+
225+
(2) Redistributions in binary form must reproduce the copyright notice, this list
226+
of conditions and the following disclaimer in the documentation and/or other
227+
materials provided with the distribution.
228+
229+
(3) Neither the name of the University of California, Lawrence Berkeley
230+
National Laboratory, U.S. Dept. of Energy nor the names of its contributors
231+
may be used to endorse or promote products derived from this software without
232+
specific prior written permission.
233+
234+
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
235+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
236+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
237+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
238+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
239+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
240+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
241+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
242+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
243+
POSSIBILITY OF SUCH DAMAGE.
244+
245+
3. You are under no obligation whatsoever to provide any bug fixes, patches,
246+
or upgrades to the features, functionality or performance of the source code
247+
("Enhancements") to anyone; however, if you choose to make your Enhancements
248+
available either publicly, or directly to Lawrence Berkeley National Laboratory,
249+
without imposing a separate written license agreement for such Enhancements,
250+
then you hereby grant the following license: a non-exclusive, royalty-free
251+
perpetual license to install, use, modify, prepare derivative works, incorporate
252+
into other computer software, distribute, and sublicense such enhancements or
253+
derivative works thereof, in binary and source code form.
254+
255+
NOTE: This license corresponds to the "revised BSD" or "3-clause BSD"
256+
License and includes the following modification: Paragraph 3. has been added.
257+
258+
259+
***********************************************************************************
260+
*/

0 commit comments

Comments
 (0)