Gems3k  3.1
GEMS3K standalone solver for geochemical equilibria
 All Classes Files Functions Variables Enumerations Enumerator
/Users/kulik/DevGEMS/trunk/standalone/GEMS3K/v_user.h
Go to the documentation of this file.
00001 //-------------------------------------------------------------------
00002 // $Id: v_user.h 724 2012-10-02 14:25:25Z kulik $
00005 //
00006 // Copyright (C) 1996,2001,2012 A.Rysin, S.Dmytriyeva
00007 // <GEMS Development Team, mailto:gems2.support@psi.ch>
00008 //
00009 // This file is part of the GEMS3K code for thermodynamic modelling
00010 // by Gibbs energy minimization <http://gems.web.psi.ch/GEMS3K/>
00011 //
00012 // GEMS3K is free software: you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation, either version 3 of
00015 // the License, or (at your option) any later version.
00016 
00017 // GEMS3K is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU Lesser General Public License for more details.
00021 
00022 // You should have received a copy of the GNU General Public License
00023 // along with GEMS3K code. If not, see <http://www.gnu.org/licenses/>.
00024 //-------------------------------------------------------------------
00025 
00026 #ifndef _v_user_h_
00027 #define _v_user_h_
00028 
00029 #include <algorithm>
00030 #include <iostream>
00031 using namespace std;
00032 
00033 #include "string.h"
00034 #include "verror.h"
00035 
00036 #ifdef __APPLE__
00037 
00038 #ifndef __unix
00039 #define __unix
00040 #endif
00041 #ifndef __FreeBSD
00042 #define __FreeBSD
00043 #endif
00044 
00045 typedef unsigned int uint;
00046 #endif
00047 
00048 const int MAXKEYWD = 6+1;
00049 
00050 #ifndef  __unix
00051 
00052 typedef unsigned int uint;
00053 
00054 #endif //  __noborl
00055 
00056 void Gcvt(double number, size_t ndigit, char *buf);
00057 double NormDoubleRound(double aVal, int digits);
00058 void NormDoubleRound(double *aArr, int size, int digits);
00059 void NormFloatRound(float *aArr, int size, int digits);
00060 
00061 inline
00062 int ROUND(double x )
00063 {
00064     return int((x)+.5);
00065 }
00066 
00067 template <class T>
00068 inline
00069 void fillValue( T* arr, T value, int size )
00070 {
00071   if( !arr )
00072     return;
00073   for(int ii=0; ii<size; ii++)
00074     arr[ii] = value;
00075 }
00076 
00077 template <class T>
00078 inline
00079 void copyValues( T* arr, T* data, int size )
00080 {
00081   if( !arr || !data )
00082     return;
00083   for(int ii=0; ii<size; ii++)
00084     arr[ii] = data[ii];
00085 }
00086 
00087 inline
00088 void copyValues( double* arr, float* data, int size )
00089 {
00090   if( !arr || !data )
00091     return;
00092   for(int ii=0; ii<size; ii++)
00093     arr[ii] = (double)data[ii];
00094 }
00095 
00096 inline
00097 void copyValues( float* arr, double* data, int size )
00098 {
00099   if( !arr || !data )
00100     return;
00101   for(int ii=0; ii<size; ii++)
00102     arr[ii] = (float)data[ii];
00103 }
00104 
00105 inline
00106 void copyValues( long int* arr, short* data, int size )
00107 {
00108   if( !arr || !data )
00109     return;
00110   for(int ii=0; ii<size; ii++)
00111     arr[ii] = (long int)data[ii];
00112 }
00113 
00114 #ifndef IPMGEMPLUGIN
00115 
00116 #include "array.h"
00117 
00118 inline
00119 bool
00120 IsSpace(char ch)
00121 {
00122     return ( (ch == ' ') || (ch == '\t') );
00123 }
00124 
00125 void StripLine(gstring& line);
00126 
00127 // Added by SD on 22/12/2001
00128 // Change string on templates
00129 void
00130 ChangeforTempl( gstring& data_str,  const gstring& from_templ1,
00131                 const gstring& to_templ1, uint len_ );
00132 
00133 // Returns string representation of current date in dd/mm/yyyy format
00134 gstring curDate();
00135 
00136 // Returns string representation of current date in dd/mm/yy format
00137 gstring curDateSmol(char ch = '/');
00138 
00139 // Returns string representation of current time in HH:MM  format
00140 gstring curTime();
00141 
00142 // Returns string representation of current date and time
00143 inline
00144 gstring curDateTime()
00145 {
00146     return curDate() + curTime();
00147 }
00148 
00149 // reads line to gstring class from istream with a delimiter
00150 istream& u_getline(istream& instream, gstring& dst_string, char delimit = '\n');
00151 istream& f_getline(istream& is, gstring& str, char delim);
00152 
00153 /* returns pointer after spaces in gstring 's'*/
00154 /*
00155 inline
00156 const char* fastLeftStrip(const char* s)
00157 { while(*s==' ') s++;
00158   return s;
00159 }
00160 */
00161 
00162 /* returns length of fgstring without right blanks*/
00163 /*
00164 inline
00165 unsigned int lenWithRightStrip(const char* s)
00166 {
00167   const char* pp = s+strlen(s)-1;
00168   while(*pp==' ') pp--;
00169   return pp-s+1;
00170 }
00171 */
00172 
00173 #ifdef __FreeBSD
00174 // replacement for missing function in FreeBSD
00175 inline char* gcvt(double num, int digit, char* buf)
00176 {
00177     sprintf(buf, "%*g", digit, num);
00178     return buf;
00179 }
00180 
00181 #endif  // __FreeBSD
00182 
00183 #ifdef __APPLE__
00184 #include <algobase.h>
00185 #endif
00186 
00187 
00188 // dynamically allocates temporary 'char*'
00189 // for simple string manipulations
00190 // (used instead of stack char[] allocation to avoid stack problems)
00191 struct vstr
00192 {
00193     char* p;
00194     vstr(int ln): p(new char[ln+1])
00195     { }
00196 
00197     vstr(int ln, const char* s): p(new char[ln+1])    {
00198         strncpy(p, s, ln);
00199         p[ln]='\0';
00200     }
00201 
00202     vstr(const char* s): p(new char[strlen(s)+1])    {
00203        strcpy(p, s);
00204     }
00205 
00206     ~vstr()    {
00207         delete[] p;
00208     }
00209 
00210     operator char* ()    {
00211         return p;
00212     }
00213 
00214 private:
00215     vstr (const vstr&);
00216     const vstr& operator= (const vstr&);
00217 
00218 };
00219 
00220 #else
00221 
00222 //#define max( a, b )  ( (a) >( b) ? (a) : (b) )
00223 //#define min( a, b )  ( (a) <( b) ? (a) : (b) )
00224 
00225 
00226 #endif    // IPMGEMPLUGIN
00227 
00229 gstring
00230 u_makepath(const gstring& dir,
00231            const gstring& name, const gstring& ext);
00232 
00234 void
00235 u_splitpath(const gstring& Path, gstring& dir,
00236             gstring& name, gstring& ext);
00237 
00238 #define fileNameLength 64
00239 
00240 char  (* f_getfiles(const char *f_name, char *Path, 
00241                 long int& nElem, char delim ))[fileNameLength];
00242 
00243 
00244 
00245 #endif
00246 // _v_user_h_
00247