(ATCScript "Listing Script - by property" (' Lists time series from a file that have certain properties) (Arg "PropertiesString") (Arg "CriteriaString") (Arg "TimeStep") (LoadLibrary "ATCScriptData") (Set CR (+ (Chr 13) (Chr 10))) (Set TSused "Locations:") (' Parse out and set the properties used as criteria) (Set propCnt 0) (Set propLength (Len arg1)) (If (> propLength 0) (Set parsePos 0) (Set spacePos 1) (While (< parsePos propLength) (Increment parsePos) (If (= (Mid arg1 parsePos 1) " ") (Set propCnt (+ propCnt 1)) (RunScript (+ "(Set prop_" propCnt " (Mid arg1 spacePos (- parsePos spacePos)))")) (' Skip spaces til next string) (While (= (Mid arg1 parsePos 1) " ") (Increment parsePos) ) (Set spacePos parsePos) ) ) (Set propCnt (+ propCnt 1)) (Increment parsePos) (RunScript (+ "(Set prop_" propCnt " (Mid arg1 spacePos (- parsePos spacePos)))")) ) (' Loop thru each data set in file) (Set DataCnt (DataFile TSerFile DataCount)) (For DataIndex = 1 to DataCnt (Set DataSet (DataFile TSerFile Data Index DataIndex)) (' Set values of properties) (For i 1 to propCnt (Set propName (+ "prop_" i)) (RunScript (+ "(Set tmpVal (DataTSer DataSet Attrib " propName "))")) (Set thisVal (+ "prop" i)) (If (= (Len tmpVal) 0) (' The following Warn interrupts the run. Perhaps aggregate message and show at end.) (' RunScript (Warn (+ "prop_" i) " has not been set for " (DataTSer DataSet Attribute "Location") "Missing Data")) (Else (RunScript (+ "(Set " thisVal " " tmpVal ")"))) ) ) (' Check to see if the data set meets the criteria) (Set UseTS 0) (RunScript (+ "(If " arg2 " (Set UseTS 1))")) (If (= UseTS 1) (' Include this data set in the listing) (Increment TSCount) (Set thisLocation (Trim (Mid (DataTSer DataSet Attribute "Location") 1 10))) (Set TSused (+ TSused (* " " (- 10 (Len thisLocation))) thisLocation)) (' Aggregate data according to specified time step) (Set DataSetAgg (DataTSer DataSet Aggregate TimeStep 1 "Sum")) (If (And (> sDate 0) (> eDate 0)) (' Create incremental data subset based on dates in main script) (RunScript (+ "(Set " (+ FinalDataSet TSCount) " (DataTSer DataSetAgg SubSetByDate sDate eDate))")) (Else (RunScript (+ "(Set " (+ FinalDataSet TSCount) " DataSetAgg)")) ) ) (' Create array with all values in DataSubSet) (RunScript (+ "(Set " (+ dataValues TSCount) " (DataTSer " (+ FinalDataSet TSCount) " values))")) ) (For i 1 to propCnt (Unset (+ "prop" i)) ) ) (' Print out names of locations) (Set oStr (+ TSused CR)) (' Print out values for relevant TS) (Set thisJDate SDate) (For dataCnt 1 to (JDateDiff sDate edate TimeStep) (Set oStr (+ oStr (Format thisJDate "yyyy/mm/dd") ": ")) (For TSIndex = 1 to TSCount (RunScript (+ "(If (> dataCnt (Len " (+ dataValues TSIndex) ")) (Set haveVal 1) (Else (Set haveVal 0)))")) (If (= haveVal 1) (Set curVal "-999") (Else (RunScript (+ "(Set curVal (ArrayItem " (+ dataValues TSIndex) " dataCnt))")) ) ) (Set oStr (+ oStr curVal)) (Set oStr (+ oStr (* " " (- 10 (Len curVal))))) ) (Set oStr (+ oStr CR)) (Increment thisJDate) ) (Set header (+ "Time series listing for " (Format SDate "yyyy-mmm-dd") " through " (Format EDate "yyyy-mmm-dd"))) (Set oStr (+ header CR CR oStr)) (Set outFile (+ OutputDir "SortedByProp" ".lst")) (SaveFile outFile oStr) )