};
siglen=0;
int i=0;
char k=0;
while(siglen!=0x21&&siglen!=schname_len&&!feof(f)&&siglen==0)
fread(&siglen,sizeof(char),1,f);
for(;i<siglen;i++){
fread(&k,sizeof(char),1,f);
value[i]=k;
}
value[i]=0;
ff_counter+=1;
signals[signal_counter].SetOneFF(ff_counter,val,value);
fseek(f,1,SEEK_CUR);
}
fseek(f,-1,SEEK_CUR);
break;
};
}
}
}
//-----------------------------------------------
void SaveHeader(FILE *f)
{
long x1=0x1,x2=0x4,x3=num_signals;
fwrite(&x1,sizeof(long),1,f);
fwrite(&x2,sizeof(long),1,f);
fwrite(&x3,sizeof(long),1,f);
}
//-----------------------------------------------
void SaveAll(FILE *f)
{
SaveHeader(f);
for(int i=0;i<num_signals;i++)
signals[i].Save(f);
}
//--------------------
void signal::SetSignalInfo(int _ff, int _dim,char *_name) //Установка информ. о сигнале
{
this->num_ff=_ff;
this->dim=_dim;
strcpy(this->name,_name);
}
//-----------------------------------------------
char *signal::GetName() //Считать имя файла
{
return this->name;
}
//-------------------------------------------------
void signal::SetOneFF(int index,int _time, char *val) //Уст. инф. об одном переключении
{
if (index<N)
{
this->times[index]=_time;
int i;
strcpy(v[index],val);
}
}
//------------------------------------------------------------------
void signal::InsertFF(int _time, char *val) //вставить переключение
{
int i,j;
//add
if (_time>this->times[this->num_ff-1])
{
this->times[this->num_ff]=_time;
strcpy(this->v[this->num_ff],val);
this->num_ff++;
return;
}
//insert
for(i=0;i<this->num_ff;i++)
if(_time<this->times[i])
{
for(j=this->num_ff;j>=i;j--)
{
this->times[j+1]=this->times[j];
strcpy(this->v[j+1],this->v[j]);
}
break;
}
this->times[i]=_time;
strcpy(this->v[i],val);
this->num_ff++;
}
//---------------------------------------
char *signal::GetValAtTime(int _time) //вернуть значение по времени
{
int i;
if (this->times[this->num_ff-1]<_time)
return v[this->num_ff-1];
for(i=1;i<this->num_ff;i++)
if(_time<this->times[i])
return v[i-1];
return "Z";
}
//------------------------------------------------
int signal::GetFFAtTime(int _time) //Возвращает номер переключения
{
int i;
if (this->times[this->num_ff-1]<_time)
return this->num_ff-1;
for(i=1;i<this->num_ff;i++)
if(_time<this->times[i]&&_time>this->times[i-1])
return i-1;
return num_ff-1;
}
//------------------------------------------------
int signal::FindNearest(int _time)//ищет индекс ближайшего переключения
{
int i;
for(i=0;i<this->num_ff;i++)
if(_time<this->times[i])
{
if((this->times[i]-_time)<(_time-this->times[i-1]))
return i;
else return i-1;
}
return i-1;
}
//------------------------------------------------
void signal::delFF(int index)//удаляет переключение по индексу
{
int i;
if (this->num_ff<=1) return;
if (index==num_ff-1)
{
times[index]=0;
v[index][0]='0';
num_ff--;
return;
}
for(i=index+1;i<this->num_ff;i++)
{
this->times[i-1]=this->times[i];
strcpy(this->v[i-1],this->v[i]);
}
this->num_ff--;
}
//------------------------------------------------
int GetSchLen(char *s)
{
int i;
for(i=0;i<strlen(s)&&s[i]!='.';i++);
return i;
}
//------------------------------------------------
void signal::Save(FILE *f) //сохранть сигнал
{
char *c=this->name,type;
schname_len=GetSchLen(schname);
char l=(char)schname_len;
char ff=(char)this->num_ff,czero=0x0,type_basic,var=0x1;
long zero=0,time_ff,maxlong=0xFFFFFFFF,start_time,t_one,t_two;
int i;
fwrite(&l,sizeof(char),1,f);
fwrite(c,sizeof(char),l,f);
c+=l;
c++;
l=strlen(c);
fwrite(&l,sizeof(char),1,f);
fwrite(c,sizeof(char),l,f);
if (dim!=3)
fwrite(&ff,sizeof(char),1,f);
else
fwrite(&var,sizeof(char),1,f);
fwrite(&zero,sizeof(long),1,f);
if(this->dim==3)
{
fseek(f,-1,SEEK_CUR);
fwrite(&var,sizeof(char),1,f);
type=0x24;
fwrite(&type,sizeof(char),1,f);
start_time=0;
t_one=long(this->times[0]);
t_two=long(this->times[1]);
fwrite(&start_time,sizeof(long),1,f);
fwrite(&czero,sizeof(char),1,f);
if (v[0][0]=='0') var=0x2;
if (v[0][0]=='1') var=0x3;
if (v[0][0]=='Z') var=0x4;
if (v[0][0]=='H') var=0x5;
if (v[0][0]=='L') var=0x6;
fwrite(&var,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&t_one,sizeof(long),1,f);
if (v[1][0]=='0') var=0x2;
if (v[1][0]=='1') var=0x3;
if (v[1][0]=='Z') var=0x4;
if (v[1][0]=='H') var=0x5;
if (v[1][0]=='L') var=0x6;
fwrite(&var,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&czero,sizeof(char),1,f);
fwrite(&t_two,sizeof(long),1,f);
fwrite(&maxlong,sizeof(long),1,f);
var=0x1;
fwrite(&var,sizeof(char),1,f);
fwrite(&v[0][0],sizeof(char),1,f);
fwrite(&var,sizeof(char),1,f);
fwrite(&v[1][0],sizeof(char),1,f);
}
if(this->dim==1||this->dim==2)
{
type=0x21;
if (this->dim==1)
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.