Bij onze vrienden van Siemens kun je deze downloaden. Maar wel pas nadat je betaald hebt
(CWD_EU) Dus heb ik ‘m zelf maar geschreven in SCL.
FUNCTION FC370_DAYOFYEAR : INT TITLE= 'FC370_DAYOFYEAR' NAME : DAYOFYR FAMILY : PROCESS AUTHOR : VMI_JFO VERSION : '1.0' //Jfo - 29 juni 2011: This function calculates the number of the day of the year. // This will generate 1-365 for normal years, and 1-366 for leap years. // NOTE: this will work until year 2100! Year 2100, 2200, 2300... are NOT leap years! VAR_INPUT END_VAR VAR_TEMP Err_ReadDate : INT; // error code return tmpDATE : DT; // time structure current_DT AT tmpDATE: ARRAY[1..8] OF BYTE; // array for access to time structures zdn : INT; // help variable year : INT; // year, format: ?? (19XX - 20XX) num_of_month : INT; // number of month, jan -1, feb -2,... day_of_month : INT; // no commentsday_of_week : INT; // !!! sun -1, mon -2, tus -3,..., . days : ARRAY[1..12] OF INT; // array with number of days of all months i : INT; numberofdays : INT; result_INT : INT; result_REAL : REAL; END_VAR BEGIN Err_ReadDate := READ_CLK( CDT := tmpDATE); // Getting of current date year := WORD_TO_INT(SHR(IN:=current_DT[1],N:=4))*10 + WORD_TO_INT(current_DT[1] AND 16#0F); // calculation of year num_of_month := WORD_TO_INT(SHR(IN:=current_DT[2],N:=4))*10 + WORD_TO_INT(current_DT[2] AND 16#0F); // calculation numb of month day_of_month := WORD_TO_INT(SHR(IN:=current_DT[3],N:=4))*10 + WORD_TO_INT(current_DT[3] AND 16#0F); // calculation of day day_of_week := WORD_TO_INT(current_DT[8] AND 16#0F); // calculation day of week //--------------------------------------------------------------------------- // Fill in the number of days of the months //--------------------------------------------------------------------------- days[1] := 31; //jan days[2] := 28; //feb (note: leap year day will be added further...) days[3] := 31; //mrt days[4] := 30; //apr days[5] := 31; //may days[6] := 30; //jun days[7] := 31; //jul days[8] := 31; //aug days[9] := 30; //sep days[10] := 31; //oct days[11] := 30; //nov days[12] := 31; //dec //--------------------------------------------------------------------------- // Leap year? If it is a leap year then we have to add 1 extra day for month february. //--------------------------------------------------------------------------- result_INT := year / 4; result_REAL := INT_TO_REAL(year) / 4; IF result_REAL - INT_TO_REAL(result_INT) = 0 THEN days[2] := days[2] + 1; //feb END_IF; //--------------------------------------------------------------------------- // Calculate number days of previous months. //--------------------------------------------------------------------------- numberofdays := 0; FOR i:= 1 TO num_of_month - 1 BY 1 DO numberofdays := numberofdays + days[i]; END_FOR; //--------------------------------------------------------------------------- // Calculate number days of current months. //--------------------------------------------------------------------------- numberofdays := numberofdays + day_of_month; //--------------------------------------------------------------------------- // Move result to the output. //--------------------------------------------------------------------------- FC370_DAYOFYEAR := numberofdays; END_FUNCTION
Category: NL, Siemens PLC