Пример #1
0
int lemonReaderNextRecord(LemonReader *reader)
{
  int err = 0;

  if (reader == (LemonReader *)NULL)
  {
    fprintf(stderr, "[LEMON] Node %d reports in lemonReaderNextRecord:\n"
                    "        NULL pointer or uninitialized reader provided.\n", reader->my_rank);
    return LEMON_ERR_PARAM;
  }

  if (!reader->is_awaiting_header)
    lemonReaderCloseRecord(reader);

  err = readAndParseHeader(reader);

  /* readAndParseHeader will produce debug output */
  if (err != LEMON_SUCCESS)
    return err;

  reader->is_last = reader->curr_header->ME_flag;
  reader->is_awaiting_header = 0;

  return LEMON_SUCCESS;
}
Пример #2
0
int limeReaderNextRecord(LimeReader *r)
{
  int status;
  char myname[] = "limeReaderNextRecord";

  if( r == (LimeReader *)NULL ) { 
    printf("%s LIME_ERR_PARAM\n",myname);
    return LIME_ERR_PARAM;
  }
  
  if( r->first_read == 0 ) { 
    /* We haven't yet read the first record */
    /* Call an auxiliary function to read and parse the header 
       -- this call may allocate memory */
    status = readAndParseHeader(r);

    /* We allow the caller to handle the error condition. */
    /* An EOF condition could be normal here. */
    if ( status < 0 ) { 
      if( status != LIME_EOF )
	printf("%s returning %d\n",myname,status);
      return status;
    }
    r->first_read = 1;
  }
  else { 
    /* We have read the first record -- so presumably we have 
       already got a header in the reader.*/

    /* In this case what we must do is skip to the end of the current
       record */
    status = skipReaderBytes(r, r->bytes_total - r->rec_ptr);
    if ( status < 0 ) { 
      if( status != LIME_EOF )
	printf("%s returns %d\n",myname,status);
      return status;
    }
    
    /* Right we have now skipped to the end of the previous 
       record and we believe it not to be the last record 
       so we can now safely destroy the current record header 
       and try to read the next header */
    status = readAndParseHeader(r);
    if ( status < 0 ){
      if( status != LIME_EOF )
	printf("%s returns %d\n",myname,status);
      return status;
    }
  }

  if(r->curr_header == NULL) {
    printf("%s No header info on this node\n",myname);
    return LIME_ERR_PARAM;
  }

  r->is_last = r->curr_header->ME_flag;
  r->bytes_left = r->curr_header->data_length;
  r->bytes_total = r->curr_header->data_length;
  r->rec_ptr = 0;
  r->rec_start = DCAPL(ftello)(r->fp);
  r->bytes_pad = lime_padding(r->bytes_total);

  return status;
}