set iaurl = `$GREP -oE '//.+' "$WI_TEMP""tmpO" | $AWK '{gsub(/'\''/,"%27",$1); print $1}'`

set urllength = `$AWK -v s="$iaurl" 'BEGIN{print length(s)}'`
echo "URL ""$urllength"" = ""$iaurl"
if($urllength > 2000) then
  # Ring bell 
  source "$WI_PATH""bell.csh"
  set pausetext = "Long URL. Press the <ENTER> key to continue..."
  printf "\n$pausetext" > /dev/stderr
  if(! "$internetarchive7" && ! "$internetarchive9" ) then
    set junk = ($<)
  endif
endif

set cname = `$AWK -v s="$cname" 'BEGIN{split(s, b, "|"); print b[1]}'`
set cnameunder = `$AWK -v s="$cname" 'BEGIN{gsub(/ /,"_",s); print s}'`

@ tmpoc++

set iaOfilename = "tmpO@""$cnameunder""@""$sopt""@""$tmpoc"
set iaIfilename = "$WI_TEMP""tmpI@""$cnameunder""@""$sopt"

set noglob
set iaurln = `$AWK -v s="$iaurl" 'BEGIN{sub(/\/search[.]php/,"/advancedsearch.php",s); sub(/[?]query=/,"?q=", s); s = s "&fl%5B%5D=identifier&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=100&page=1&output=json&callback=callback&save=yes"; print s}'`

echo "$iaIfilename"'|'"$iaurln" >> "$WI_TEMP""ia-check.debug"

$MV "$WI_TEMP""tmpO" "$WI_TEMP""$iaOfilename"
$WGET -q -O "$iaIfilename" http:"$iaurln"

# Change from extended-ascii-single-quote -> ascii-single-quote (deprecated - keep in case needed again)
# set cnameplain = `$AWK -v s="$cname" 'BEGIN{ gsub(/'\’'/,"'\''",s) ; print s }'`

set numberofbooks = `$AWK -v datafile="$iaIfilename" -f "$WI_PATH""getIAcount.awk"`

if("$numberofbooks" > 0) then
  echo "$sopt"'|'"$numberofbooks"'|'"$cname"'|'"$iaOfilename" >> "$WI_TEMP""ia-results"
else
  echo 'none|0|'"$cname"'|'"$iaOfilename" >> "$WI_TEMP""ia-results"
endif


