00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdlib.h>
00010 #include "itablefunct.h"
00011 #include "intools.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 itablefunct::itablefunct()
00025 {
00026 asize=0; x=NULL; y=NULL;
00027 }
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 itablefunct::~itablefunct()
00038 {
00039 delete[] x; delete[] y;
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 void itablefunct::read(XFILE *in)
00062 {
00063 long i;
00064 xfscanf (in,"%k%ld","nitab_items",&asize);
00065 x=new double[asize];
00066 y=new long[asize];
00067 for (i=0;i<asize;i++){
00068 xfscanf (in,"%lf",&x[i]);
00069 xfscanf (in,"%ld",&y[i]);
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 void itablefunct::print(FILE *out)
00084 {
00085 long i;
00086 fprintf (out,"\n%ld",asize);
00087 for (i=0;i<asize;i++){
00088 fprintf (out,"\n%le ",x[i]);
00089 fprintf (out,"%ld",y[i]);
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void itablefunct::read_prop(FILE *in)
00102 {
00103 long i;
00104 getlong(in, asize);
00105 x=new double[asize];
00106 y=new long[asize];
00107
00108 for (i=0;i<asize;i++)
00109 {
00110 getdouble (in, x[i]);
00111 getlong (in, y[i]);
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 long itablefunct::getval (double temp)
00130 {
00131 long i,ret;
00132
00133 if (temp<x[0]){
00134 return y[0];
00135 }
00136 if (x[asize-1]<=temp){
00137 return y[asize-1];
00138 }
00139
00140 for (i=0;i<asize-1;i++){
00141 if (x[i]<=temp && temp<x[i+1]){
00142 ret = y[i];
00143 break;
00144 }
00145 }
00146
00147 return ret;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 void itablefunct::copy (itablefunct &tf)
00162 {
00163 long i;
00164
00165
00166 asize = tf.asize;
00167
00168 if (x!=NULL)
00169 delete [] x;
00170 x = new double [asize];
00171
00172 if (y!=NULL)
00173 delete [] y;
00174 y = new long [asize];
00175
00176 for (i=0;i<asize;i++){
00177 x[i]=tf.x[i];
00178 y[i]=tf.y[i];
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 long itablefunct::compare(itablefunct &tf)
00195 {
00196 long i;
00197
00198
00199 if (asize != tf.asize)
00200 return 1;
00201
00202 for (i=0;i<asize;i++){
00203 if (x[i] != tf.x[i])
00204 return 1;
00205 if (y[i] != tf.y[i])
00206 return 1;
00207 }
00208 return 0;
00209 }