lpz%ocu.DECnet@STC10.CTD.ORNL.GOV ("OCU::LPZ") (06/21/88)
In response to several requests, I am posting some code in Fortran to parse ranges in a fashion similar to the Authorize does it: This routine sets bits in a mask depending on whether the respective hour is supposed to be prime. Lawrence ~ ----------------------------------------------------------------------------- ARPA: LPZ@STC10.CTD.ORNL.GOV LPZ%OCU.DECNET@STC10.CTD.ORNL.GOV MFE: MACINTYRE@ORN BITNET: LPZ@ORNLSTC Bell-South: 615.576.0824 US-Snail: Lawrence MacIntyre Martin Marietta Energy Systems Bldg 9201-5 MS 8 P O Box Y Oak Ridge, TN 37831 ! Abstract: ! ! This routine will set any designated hour or day as prime or nonprime. ! The command looks like Set /[No]Prime Day[=(1,12-14,23)] or similar. ! If the list of hours is not there, the whole day is set. Midnight is ! hour 0 and 11:00 pm is hour 23, just like military time. ! Subroutine Set_Day(Day_Number,Status) Implicit None Include 'Sphinx_Device:[Sphinx.Source]Sphinx_Control_Data.Include' Include '($Ssdef)' !System service definitions Include '($Syssrvnam)' !System service names Integer*4 Ots$Cvt_Tu_L !Convert text to longword Integer*4 Cli$Get_Value !Get value from DCL Integer*4 Cli$Present !Is the command there? Character*1 Dash !The - Integer*4 Day_Number !This day (1 is Monday, 7 is Sunday) Integer*4 First !Set this bit as a prime hour Integer*4 Loop !Counter inside range loop Character*13 Keyword !Which day is this Integer*4 Keyword_Length !# of chars. in Keyword Integer*4 Hour_Bit !Set this bit as a prime hour Character*80 Hours !Hours to be prime or not-prime Integer*4 Hours_Length !How many Chars. in Hours Integer*4 Position !Where the - was Integer*4 Status !Status from system routines Integer*4 Status_Cvt !Status from Ots$Cvt_Tu_L External Cli$_Absent !The list is through External Cli$_Comma !He followed this item with a comma External Cli$_IvValu !He typed an invalid value External Cli$_Negated !He typed No<whatever> Parameter Convert_Flag=17 !Bits 0 and 4 lit Dash='-' If(Day_Number .EQ. 1)Then Keyword='Set_Monday' Keyword_Length=10 Else If(Day_Number .EQ. 2)Then Keyword='Set_Tuesday' Keyword_Length=11 Else If(Day_Number .EQ. 3)Then Keyword='Set_Wednesday' Keyword_Length=13 Else If(Day_Number .EQ. 4)Then Keyword='Set_Thursday' Keyword_Length=12 Else If(Day_Number .EQ. 5)Then Keyword='Set_Friday' Keyword_Length=10 Else If(Day_Number .EQ. 6)Then Keyword='Set_Saturday' Keyword_Length=12 Else If(Day_Number .EQ. 7)Then Keyword='Set_Sunday' Keyword_Length=10 EndIf Status=Cli$Get_Value( !Get a value from DCL 1 Keyword(1:Keyword_Length), !Set prime and nonprime hours 2 Hours, !The hours 3 Hours_Length) !# of chars. in Hours If(Status .EQ. %Loc(Cli$_Absent))Then If(Cli$Present('Set_Prime'))Then Control.Day(Day_Number)='FFFFFF'x !Prime all day Else If(Cli$Present('Set_NonPrime'))Then Control.Day(Day_Number)=0 !Nonprime all day EndIf Status=Ss$_Normal Return Else If(.NOT. Status)Then Return EndIf Position=Index(Hours(1:Hours_Length),Dash) !Is there a dash? If(Position .EQ. 1 .OR. Position .EQ. Hours_Length)Then Status=%Loc(Cli$_IvValu) Return EndIf If(Position .NE. 0)Then Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours(1:Position-1), !This is the text 2 First, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf If(First .LT. 0 .OR. First .GT. 22)Then Status=%Loc(Cli$_IvValu) Return EndIf Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours(Position+1:Hours_Length), !This is the text 2 Hour_Bit, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf If(Hour_Bit .LE. First .OR. Hour_Bit .GT. 23)Then !There are only 24 Status=%Loc(Cli$_IvValu) Return EndIf Do 30 Loop=First,Hour_Bit-1 If(Cli$Present('Set_Prime'))Then Control.Day(Day_Number)=JibSet(Control.Day(Day_Number),Loop) Else If(Cli$Present('Set_NonPrime'))Then Control.Day(Day_Number)=JibClr(Control.Day(Day_Number),Loop) EndIf 30 Continue Else Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours, !This is the text 2 Hour_Bit, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf If(Hour_Bit .LT. 0 .OR. Hour_Bit.GT. 23)Then !There are only 24 Status=%Loc(Cli$_IvValu) Return EndIf EndIf If(Cli$Present('Set_Prime'))Then Control.Day(Day_Number)=JibSet(Control.Day(Day_Number),Hour_Bit) Else If(Cli$Present('Set_Prime'))Then Control.Day(Day_Number)=JibClr(Control.Day(Day_Number),Hour_Bit) EndIf Do While (Status .EQ. %Loc(Cli$_Comma)) !Get them all... Status=Cli$Get_Value( !Get a value from DCL 1 Keyword(1:Keyword_Length), !Set prime and nonprime hours 2 Hours, !The hours 3 Hours_Length) !# of chars. in Hours If(.NOT. Status)Then Return EndIf Position=Index(Hours(1:Hours_Length),Dash) If(Position .EQ. 1 .OR. Position .EQ. Hours_Length)Then Status=%Loc(Cli$_IvValu) Return EndIf If(Position .NE. 0)Then Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours(1:Position-1), !This is the text 2 First, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours(Position+1:Hours_Length), !This is the text 2 Hour_Bit, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf If(Hour_Bit .LE. First .OR. Hour_Bit .GT. 23)Then Status=%Loc(Cli$_IvValu) Return EndIf Do 40 Loop=First,Hour_Bit-1 If(Cli$Present('Set_Prime'))Then Control.Day(Day_Number)=JibSet(Control.Day(Day_Number),Loop) Else If(Cli$Present('Set_NonPrime'))Then Control.Day(Day_Number)=JibClr(Control.Day(Day_Number),Loop) EndIf 40 Continue Else Status_Cvt=Ots$Cvt_Tu_L( !Convert text to integer 1 Hours, !This is the text 2 Hour_Bit, !This is the integer 3 %Val(4), !Integer*4 4 %Val(Convert_Flag)) !What to do with space and tab If(.NOT. Status_Cvt)Then Status=Status_Cvt Return EndIf If(Hour_Bit .LT. 0 .OR. Hour_Bit.GT. 23)Then Status=%Loc(Cli$_IvValu) Return EndIf EndIf If(Cli$Present('Set_Prime'))Then !Set them prime Control.Day(Day_Number)=JibSet(Control.Day(Day_Number),Hour_Bit) Else If(Cli$Present('Set_NonPrime'))Then !Set them nonprime Control.Day(Day_Number)=JibClr(Control.Day(Day_Number),Hour_Bit) EndIf EndDo Return End ------