Shrew CCK computed field

A sample chunk of CCK computed field code for use with my Shrew module for Drupal. Shrew is a PHP library to interact with Innovative Interface online library catalog systems. You can see how this code snippet evolved over time in the revisions.

<?php
if (!$node->nid) {
node_save($node);
}
$delta = 0;
$node_field = array();
if ($bnum = $node->field_iii_single[0]['value']) {
  $record = shrew_record_get($bnum);
  if ($fields = shrew_field_get($record[$bnum]->bibliographicRecord, '520')) {
    foreach ($fields as $field) {
      $node_field[$delta]['value'] = $field;
      $delta++;
    }
  }
  else $node_field[0]['value'] = NULL;
}