CVecCl& CVecCl::operator=(const CMatrCl &mat) { int Dx,Dy;mat.DimMN(Dx,Dy); if (Dx!=Dy) { cout<<" CVecCl::operator=(CMatrCl &mat) - mat is not square, cannot get diag\n";Dx=min(Dx,Dy);} SetDim(Dx); for (int k=1;k<=Dx;k++) Ptr[k]=mat(k,k); return (*this); };
// scan the model config and save the tag positions in the "VecPos"-structure void FileTag::ScanConfigFile() { int pos,spos,epos; pos=0; while (pos<bufsize) { if (bufmodelconfig[pos]=='%') // tag-found { spos=epos=pos+1; while (epos<bufsize && bufmodelconfig[epos]!='%') epos++; int len=epos-spos; if (len==0) fprintf(stderr," warning: empty tag!\n"); else if (len>=MAX_STR) fprintf(stderr," warning: tag-name too long!\n"); else { char strtmp[MAX_STR]; strncpy(strtmp,bufmodelconfig+spos,len); strtmp[len]='\0'; // find the tag unsigned int i; for (i=0;i<Tags.size();i++) { // tag-names are case sensitive! if (strcmp(strtmp,Tags[i].name)==0) { if (verbose>0) fprintf(stdout,"tag number %i at %i\n",i,spos); tTagPos TPos; TPos.pos=spos; TPos.tag=&Tags[i]; Tags[i].active=true; TagPos.push_back(TPos); break; } } if (i==Tags.size()) { char strlmt[MAX_STR]; MiscUtils::StrLimit(strlmt,strtmp,10); fprintf(stderr," warning: definition for tag '%s' not found!\n",strlmt); } }; pos=epos+1; } else pos++; } SetDim(); }
/* * copy matrix */ FMatrix& FMatrix::operator=( const FMatrix &M ) { if( this == &M ) return( *this ); if( M.XDim() > 0 && M.YDim() > 0 ) { if( SetDim( M.XDim(), M.YDim() ) == 0 ) crash( "Out of memory in FMatrix assignment operator" ); for( int iy = 0; iy < ydim; iy++ ) for( int ix = 0; ix < xdim; ix++ ) elem[ iy*xdim + ix ] = M.rElem( iy, ix ); } else { xdim = M.XDim(); ydim = M.YDim(); elem = NULL; } return( *this ); }
void Vec::SetFromArray(int dim, float array [] ) { SetDim( dim ); for( int i = 0; i < dim; i++ ){ _vec[i] = array[i]; } }
// --- Check if there is something to do --- void PollAlarm( uint8_t hour, uint8_t min, uint8_t sec, uint8_t wsound ) { uint8_t status_temp; uint8_t i; // New alarm or some status change? if(alarm>0) { for(i=0; i<4; i++) // Compare alarm mask for all alarms { if(alarm&(1<<i)&&alrm[i].hour==hour&&alrm[i].min==min&&sec==0) { if(alarmstatus==ALARM_STATUS_OFF) { alarmstatus = ALARM_STATUS_INIT; predelay = 3; // Give other events 3 ticks time to initialize. } } } } else { if(alarmstatus!=ALARM_STATUS_OFF) // Should not happen { alarmstatus=ALARM_STATUS_DISABLE; } } // Handle running alarm status_temp = alarmstatus; switch(status_temp) { case ALARM_STATUS_INIT: if(predelay==0) { triescounter = tries; alarmtimer = alarmtime*60; alarmstatus=ALARM_STATUS_ON; if(wsound==0) sound = GetRandom(); else sound = wsound-1; SayTime( hour, min ); } break; case ALARM_STATUS_ON: if(alarmtimer>0) { if(!IsPlaying()) PlaySound(sound); SetDim( 0 ); } else { if(snoozetime>0) { triescounter--; if(triescounter>0) { AbortPlaying(); snoozetimer = snoozetime*60; alarmstatus=ALARM_STATUS_SNOOZE; } else { alarmstatus=ALARM_STATUS_DISABLE; } } else { alarmstatus=ALARM_STATUS_DISABLE; } } break; case ALARM_STATUS_SNOOZE: if(snoozetimer==0) { alarmtimer = alarmtime*60; alarmstatus=ALARM_STATUS_ON; SayTime( hour, min ); } break; case ALARM_STATUS_DISABLE: AbortPlaying(); alarmstatus=ALARM_STATUS_WAIT; break; case ALARM_STATUS_WAIT: for(i=0; i<4; i++) // Compare alarm mask for all alarms { if(alarm&(1<<i)&&alrm[i].hour==hour&&alrm[i].min==min&&sec==0) return; } // Nothing matched, disable wait status alarmstatus=ALARM_STATUS_OFF; break; } // Power to the leds :-) if(alarmstatus==ALARM_STATUS_ON||alarmstatus==ALARM_STATUS_INIT) { if(pwm_value<0x03FF) { pwm_value=0x03FF; OCR1A = pwm_value; OCR1B = pwm_value; } } else { if(pwm_value>0x0000) { pwm_value--; OCR1A = pwm_value; OCR1B = pwm_value; } } }