/*
* EasyWave - A realtime tsunami simulation program with GPU support.
* Copyright (C) 2014 Andrey Babeyko, Johannes Spazier
* GFZ German Research Centre for Geosciences (http://www.gfz-potsdam.de)
*
* Parts of this program (especially the GPU extension) were developed
* within the context of the following publicly funded project:
* - TRIDEC, EU 7th Framework Programme, Grant Agreement 258723
* (http://www.tridec-online.eu)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
// last modified 11.07.2012
#ifndef UTIL_H
#define UTIL_H
#include
#define MaxFileRecordLength 16384
#define RealMax 1.e+30
#define RealMin 1.e-30
#define My_PI 3.14159265358979
#define g2r(x) (((double)(x))*My_PI/180)
#define r2g(x) (((double)(x))/My_PI*180)
#define cosdeg(x) cos(g2r(x))
#define sindeg(x) sin(g2r(x))
#define tandeg(x) tan(g2r(x))
#define My_max(a,b) (((a) > (b)) ? (a) : (b))
#define My_min(a,b) (((a) < (b)) ? (a) : (b))
// Class Message
#define MSG_OUTSCRN 1
#define MSG_OUTFILE 2
class cMsg
{
protected:
int enabled;
int channel;
char fname[64];
public:
cMsg();
~cMsg();
void enable();
void disable();
void setchannel( int newchannel );
void setfilename( const char* newfilename );
int print( const char* fmt, ... );
};
extern cMsg Msg;
// Class Error message
class cErrMsg : public cMsg
{
public:
cErrMsg();
~cErrMsg();
int post( const char* fmt, ... );
char* msgAllocateMem();
char* msgOpenFile( const char *fname );
char* msgReadFile( const char *fname, int line, const char *expected );
};
extern cErrMsg Err;
// Class Log
class cLog : public cMsg
{
private:
int timestamp_enabled;
public:
cLog();
~cLog();
void start( const char* filename );
void timestamp_enable();
void timestamp_disable();
int print( const char* fmt, ... );
};
extern cLog Log;
/*** Error messages and logging ***/
char *utlCurrentTime();
// Following error functions are outdated. Use global Err object instead.
int utlPostError( const char* message );
char *utlErrMsgMemory();
char *utlErrMsgOpenFile( const char *fname );
char *utlErrMsgEndOfFile( const char *fname );
char *utlErrMsgReadFile( const char *fname, int line, const char *expected );
/*** Command-line processing ***/
int utlCheckCommandLineOption( int argc, char **argv, const char *option, int letters_to_compare );
/*** String handling ***/
int utlStringReadOption( char *record, char *option_name, char *contents );
int utlReadSequenceOfInt( char *line, int *value );
int utlReadSequenceOfDouble( char *line, double *value );
int utlPickUpWordFromString( char *string, int n, char *word );
char *utlPickUpWordFromString( char *string, int n );
char *utlPickUpWordFromString( char *string, char *pos, char *word );
int utlCountWordsInString( char *record );
char *utlWords2String( int nwords, char **word );
int utlSubString( char *logstr, int p1, int p2, char *substr );
void utlPrintToString( char *string, int position, char *insert );
/*** File handling ***/
int utlFindNextInputField( FILE *fp );
int utlReadNextRecord( FILE *fp, char *record, int *line );
int utlReadNextDataRecord( FILE *fp, char *record, int *line );
char *utlFileFindRecord( char *fname, char *pattern, char *record );
int utlFileParceToString( FILE *fp, char *pattern );
int utlGetNumberOfRecords( const char *fname );
int utlGetNumberOfDataRecords( const char *fname );
int utlFileReadOption( char *fname, char *option_name, char *contents );
char *utlFileChangeExtension( const char *fname, const char *newext );
char *utlFileRemoveExtension( const char *fname );
int utlFileRemoveExtension( char *newname, const char *fname );
char *utlFileAddExtension( const char *fname, const char *addext );
int utlReadXYdata( char *fname, double **x, double **y );
/*** MATH & GEOMETRY ***/
double utlRandom( int& seed );
double utlRandom( double avg, double err );
double utlNormal( int& seed, double avg, double stdev );
int utlPointInPolygon( int nvrtx, double *xvrtx, double *yvrtx, double x, double y );
/*** O T H E R S ***/
void utlTimeSplit( double ctime, int& nHour, int& nMin, int& nSec, int& nMsec );
char *utlTimeSplitString( double ctime );
char *utlTimeSplitString( int ctime );
int utlTimeHour( double timesec );
int utlTimeHour( int timesec );
int utlTimeMin( double timesec );
int utlTimeMin( int timesec );
int utlTimeSec( double timesec );
int utlTimeSec( int timesec );
#endif // UTIL_H