// TryOps is a subroutine to test an ops scenario through a specified number of switchlists. // It's purpose is to check that the Ops data makes a viable Train Sequence. // If any of the switchlists can't be completed the process terminates to highlight the problem. // ENSURE OPS CENTRAL AND SCHEDULE ARE HIDDEN AT START call $view(hide,"ops central") call $view(hide,schedule) // DEFINE CR CHARACTER FOR USE IN DISPLAY NOTES. let cr=" " // SET UP THE NOTE WINDOW SIZE AND POSITION. call noteprops 53 894 20 123 1 L // SET NOTE COLOR note color=220,220,220 // DISPLAY OPENING NOTE let layout = $layout(name) note " TRYOPS SUBROUTINE > Layout = @layout > The current layout situation will be saved to disk for recovery at the end of the testing process. > TryOps will not make any changes to the layout file during switchlist testing. > The train Sequence will reiterate five times to test the viability of the supplied ops data. > The subroutine will report on the number of cars which were respotted in each switchlist. > If any errors are found the process will terminate immediately to enable them to be investigated. > The existing layout file and current settings will be recovered at the end of the process. Press the F1 key to continue. ....or press the ESC key twice to abandon the TryOps process. " // WAIT FOR F1 KEY TO PROCEED // permit ESC ESC to clear note and cancel script while waiting for F1 key. // ESC1 closes the note and ESC2 cancels active script. set notedownonesc 1 on key 112 set notedownonesc 0 // ABORT THE PROCESS IF THE RRW FILE DOES NOT CONTAIN ANY ADVANCED OPS DATA if ($ops(find,sequence.startat,all)="") if ($ops(find,industries.location,all)="") set notewndtextpos C note @cr TRYOPS PROCESS ABORTED @cr @cr This copy of @layout has no ops data to test. @cr after 0:0:05 note exit endif endif // UPDATE NOTE let message = "TESTING ADVANCED OPS SEQUENCE@cr" note @message // SAVE THE CURRENT FILE TO DISK PRIOR TO REWINDING SO THAT IT CAN BE RECOVERED LATER. let pathname = $layout(path) file "save as" @pathname // shorten the pathname for the displayed message note let x = $findstr(layouts,@pathname) let tempname = $substr(@x,-1,@pathname) // UPDATE NOTE let message = "TESTING ADVANCED OPS SEQUENCE@cr" let message = @message + "> Layout = @layout @cr" let message = @message + "> Recovery file saved to disk as @tempname@.@cr" note @message // GET THE USERS CURRENT "ADVOPSDEVMODE" SETTING let AOmode = $setting(AdvOpsDevMode) // SWITCH OFF ADVOPSDEVMODE TO ENABLE CONCISE SCHEDULE WINDOW OUTPUT. set AdvOpsDevMode 0 // REWIND THE LAYOUT TO THE START OF SWITCHLIST #1 call $ao_dev(dev,Reset trains to start) // ====================================================================== // COUNT THE NUMBER OF ROWS IN THE TRAIN SEQUENCE GRID let allrows = $ops(find,sequence.trainname,all) let rowcount = $set(@allrows,count) let repeat = 5 let firstrow = 1 let switchlist = 1 let error = 0 // OUTER LOOP = SWITCHLISTS let outer = 1 let inner = 1 let zerocars = 0 //INNER LOOP = SEQUENCE ROWS while (outer <= @repeat) while (inner <= @rowcount) call $ops(show,switchlist) // update variables call $ao_dev(init) // refresh switchlist grid view refresh // count the rows in the switchlist let slrows = $ops(find,switchlist.car,all) let tospot = $set(@slrows,count) // count the instances of zero cars to spot if (tospot = 0) let zerocars = @zerocars + 1 endif call $ao_dev(ccs) // update switchlist grid view refresh call $ao_dev(reset) // should be able to detect errors here. let errortest = $ao_dev(getset,Cstilltospot) if (errortest <> "") let error = 1 break endif let spotted = @tospot let trainname = $ops(get,sequence.trainname,@inner) // display result let message = @message + "> Row: @inner@, Switchlist: @switchlist@ - @spotted cars were respotted by the @trainname@.@cr@" note @message endif // generate next switchlist call $ao_dev(gnsl) // advance switchlist and row numbers let switchlist = @switchlist + 1 let inner = @inner + 1 endwhile if (error = 1) ; break ; endif // advance/adjust counts for next iteration of outer loop let outer = @outer + 1 if (inner > @rowcount) let inner = 1 endif endwhile // ERROR MESSAGE if (error = 1) // update switchlist grid view refresh let car = $ops(get,switchlist.car,1) let errorlocation = $ops(get,switchlist.spotat,1) let message = @message + "@cr@ERROR DETECTED - UNABLE TO COMPLETE SWITCHLIST @switchlist @cr@" let message = @message + "> Insufficient space for @car at @errorlocation@.@cr@" let message = @message + "> If @errorlocation is an Industry then use the FixOps subroutine to adjust the vacant spots value. @cr" let message = @message + "> If @errorlocation is any Yard type you should enlarge the yard or reduce the 'CarsToPull' value for Sequence Row @inner@.@cr@" let message = @message + @cr + "Close the Switchlist grid to terminate the test and click OK to reload the layout for editing.@cr@" note @message endif // REPORT A CLEAN BILL OF HEALTH if (error = 0) let test = @rowcount * @repeat let test = @test + 1 if (switchlist = @test) if (zerocars = 0) let message = @message + @cr + "ADVANCED OPS SEQUENCE IS VIABLE" + @cr else let message = @message + @cr + "WARNING: @zerocars SWITCHLISTS COULD NOT BE CREATED." + @cr endif note @message endif endif // CONFIRM CLOSURE OF MESSAGES AND COMPLETE THE PROCESS call $msgbox("Click OK to clear the report and reload the original layout.") // RESTORE THE USERS ORIGINAL ADVOPSDEVMODE SETTING set AdvOpsDevMode @AOmode // CLOSE SWITCHLIST GRID call $ops(hide,switchlist) // RESTORE THE ORIGINAL SAVED LAYOUT FILE file revert // FOCUS THE DISPLAY ON THE SELECTED TRAIN train $train;train car 1;car "zoom to" // SEND THE MESSAGE CONTENTS TO THE SCHEDULE WINDOW echo echo COPY OF TRY OPS REPORT FOR ANALYSIS echo echo @message // End of subroutine TryOps RF240311