Read Search Terms from a Data File

Scripts can read values out of data files to streamline creating queries with large numbers of known search terms (such as CAS Registry Numbers, patent numbers or common chemical names). This example reads CAS Registry Numbers from a file and parses them into workable groups.

 

\* This script provided without warranty

\* Example script reads data file and groups search terms

 

=> FILE REGISTRY

 

_maxRNs = 15

_innerCount = 0

_storeSearch = “S”

_storeFinal = “S”

This script uses variables and counters to include hundreds of CAS RNs in a search query by creating groups of 15 values.

ECHO "OPEN Solvent RN file"

OPEN <SOLVENTRNS> /R

 

@MAINLOOP

 READ _searchterm

 ECHO “Read _searchterm”

 

 IF _searchterm = “*****” THEN

The data file has a string used to signal the end of reading search terms.

 GOTO @FINALSEARCH

 

 _join = “”

 IF _innercount > 0 _join = “OR”

 

 _storeSearch = _storeSearch + _join

 _storeSearch = _storeSearch + _searchterm

 

 _innerCount = _innerCount + 1

 IF _innerCount = _maxRNs THEN

 BEGIN

   => _storeSearch

   _innerCount = 0

   _storeSearch = “S”

   IF _storeFinal <> “S” THEN

   BEGIN

   _storeFinal = _storeFinal + “OR

   END

   _storeFinal = _storeFinal + _$LNUM

 END

 GOTO @MAINLOOP

Here we are programmatically adding the “OR” operator between L-numbers.

@FINALSEARCH

 IF _storeSearch <> “S” THEN

 BEGIN

   => _storeSearch

   IF _storeFinal <> “S” THEN

   BEGIN

   _storeFinal = _storeFinal+ “OR”

   END

   _storeFinal = _storeFinal + _$LNUM

 END

 

 => _storeFinal

 => D CN 1-

 :Y

 

 CLOSE

 ECHO "Script complete"

 EXIT