⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slog_irec_read.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#ifdef HAVE_SLOGCONF_H#include "slog_config.h"#endif#ifdef HAVE_SLOG_WINCONFIG_H#include "slog_winconfig.h"#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_UNISTD_H )#include <unistd.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDARG_H )#include <stdarg.h>#endif#include "slog_fileio.h"#include "slog_bbuf.h"#include "slog_header.h"#include "slog_preview.h"#include "slog_pstat.h"#include "slog_ttable.h"#include "slog_profile.h"#include "slog_recdefs.h"#include "slog_impl.h"               /*I  "slog_impl.h"  I*//*@C    SLOG_OpenInputStream - Returns Input SLOG_STREAM associcated with                           the given filename.  Unmodified Input Variables :. filename - constant char pointer to the filename.  Modified Output Variables :. returned value - pointer to newly allocated SLOG_STREAM.                   it is NULL when the routine encounters error.  Include File Needed :  slog.h.N SLOG_RETURN_STATUS@*/SLOG_STREAM *SLOG_OpenInputStream( const char *filename ){    SLOG_STREAM  *slog;    SLOG_InitGlobalData();    /*  memory for slog is allocated by SLOG_OpenStream()  */    if ( ( slog = SLOG_OpenStream( filename, "rb" ) ) == NULL )        return NULL;    if ( SLOG_ReadHeader( slog ) != SLOG_SUCCESS )        return NULL;    if ( SLOG_PSTAT_Read( slog ) != SLOG_SUCCESS )        return NULL;    if ( SLOG_PVIEW_Read( slog ) != SLOG_SUCCESS )        return NULL;    if ( SLOG_TTAB_ReadThreadInfos( slog ) != SLOG_SUCCESS )        return NULL;    if ( SLOG_PROF_ReadIntvlInfos( slog ) != SLOG_SUCCESS )        return NULL;    if ( SLOG_RDEF_ReadRecDefs( slog ) != SLOG_SUCCESS )        return NULL;    return slog;}/*@C    SLOG_Irec_FromInputStream - Return a pointer to the next interval                                 record in the given SLOG_STREAM.                                The interval record returned can be real                                or pseudo record.  Modified Input Variables :. slog - pointer to the SLOG_STREAM where interval record is retrieved.. irc  - pointer to the returned integer status code.  Modified Output Variables :. returned value - pointer to the next interval record of type                    SLOG_intvlrec_t in the frame buffer.  The "const"                    qualifier indicates that user should NOT modify the                   content.  The pointer is NULL when the routine                    encounters error or end of file.  Usage Notes on this subroutine :    The routine returns a pointer to the interval record of the various    Bbuf in current frame buffer in the SLOG_STREAM given.  The     routine does NOT create new node/irec.  It just simply returns a pointer    to the existing one in the bi-directional linked list( an internal data    structure ).  If one wants to modify the content of the interval record     without modification of the specified bi-directional linked node, one     should use SLOG_Irec_Copy() to copy the returned record content to a new    record.  The routine also ADVANCES the internal pointer of the specified    linked list buffer.  Also, the routine does NOT gurantee the memory    associated with previously _returned_ interval record be retained in the    next call of the routine.  So if one wants to keep interval record for    future reference, one need to use SLOG_Irec_Copy() to copy    the content of the interval record to another memory location __BEFORE__    calling SLOG_Irec_FromInputStream() again.  The example program,    slog_readtest.c shows the typical way of using this subroutine.  Include File Needed :  slog.h.N SLOG_RETURN_STATUS@*/const SLOG_intvlrec_t *SLOG_Irec_FromInputStream( SLOG_STREAM *slog, int *irc ){    const SLOG_intvlrec_t *src_irec;    int                    ierr;    if ( slog->HasIrec2IOStreamBeenUsed == SLOG_FALSE ) {        /*  Make sure this block is executed once for each SLOG_STREAM  */        slog->HasIrec2IOStreamBeenUsed = SLOG_TRUE;         if ( SLOG_STM_CreateBbufs( slog ) != SLOG_SUCCESS ) {            *irc = SLOG_FAIL;            return NULL;        }        /*  Temporary put slog_fseek( fptr2framedata ) here  */        if ( slog->hdr->fptr2framedata == SLOG_fptr_NULL ) {            fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - \n" );            fprintf( errfile, "\t""slog->hdr->fptr2framedata is NULL \n" );            fprintf( errfile, "\t""SLOG_Irec_ToOutputStream() has NOT been "                              "called\n" );            fflush( errfile );            *irc = SLOG_EOF;            return NULL;        }        ierr = slog_fseek( slog->fd, slog->hdr->fptr2framedata, SEEK_SET );        if ( ierr != 0 ) {            fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - "                              "slog_fseek( fptr2framedata ) fails\n" );            fflush( errfile );            *irc = SLOG_FAIL;            return NULL;        }        /*           It is necessary to call SLOG_STM_Init() _BEFORE_ SLOG_ReadFrameDir().           SLOG_STM_Init() initializes the Frame_Dir components and various           Bbufs in the SLOG_STREAM.  Then SLOG_ReadFrameDir() can update           Frame_Dir compoents afterward.        */        SLOG_STM_Init( slog );        if ( SLOG_ReadFrameDir( slog ) != SLOG_SUCCESS )            return NULL;    }   /*  Endof { if ( slog->HasIrec2IOStreamBeenUsed == SLOG_FALSE ) }  */    /*        Since SLOG_Bbuf_GetIntvlRec() advances internal pointer at the end        of the routine before returning.  In stead of checking        (slog->cur_bbuf)->lptr == (slog->cur_bbuf)->ltail,  one checks for        (slog->cur_bbuf)->lptr == NULL.    */    if (    SLOG_Bbuf_IsPointerAtNULL( slog->inc_bbuf )          && SLOG_Bbuf_IsPointerAtNULL( slog->pas_bbuf )         && SLOG_Bbuf_IsPointerAtNULL( slog->cur_bbuf )         && SLOG_Bbuf_IsPointerAtNULL( slog->out_bbuf ) ) {        /*            Reinitialize all the Bbufs & cleanup memory used in Bbufs            before Reading the frame buffer        */        SLOG_Bbuf_DelAllNodes( slog->cur_bbuf );        SLOG_Bbuf_DelAllNodes( slog->inc_bbuf );        SLOG_Bbuf_DelAllNodes( slog->pas_bbuf );        SLOG_Bbuf_DelAllNodes( slog->out_bbuf );        SLOG_Bbuf_Init( slog->cur_bbuf );        SLOG_Bbuf_Init( slog->inc_bbuf );        SLOG_Bbuf_Init( slog->pas_bbuf );        SLOG_Bbuf_Init( slog->out_bbuf );        ierr = SLOG_STM_ReadFRAME( slog );        if ( ierr == SLOG_FAIL ) {            fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - "                              "Unexpected termination of "                              "SLOG_STM_ReadFRAME()\n" );            fflush( errfile );            *irc = SLOG_FAIL;            return NULL;        }        if ( ierr == SLOG_EOF ) {            *irc = SLOG_EOF;            return NULL;        }        /*  Set the cur_bbuf's pointer to point at the head of the blist  */        if (    SLOG_Bbuf_IsPointerAtNULL( slog->inc_bbuf )             && SLOG_Bbuf_IsPointerAtNULL( slog->pas_bbuf )             && SLOG_Bbuf_IsPointerAtNULL( slog->cur_bbuf )             && SLOG_Bbuf_IsPointerAtNULL( slog->out_bbuf ) ) {            SLOG_Bbuf_SetPointerAtHead( slog->inc_bbuf );            SLOG_Bbuf_SetPointerAtHead( slog->pas_bbuf );            SLOG_Bbuf_SetPointerAtHead( slog->cur_bbuf );            SLOG_Bbuf_SetPointerAtHead( slog->out_bbuf );        }        slog->ptr2bbuf = slog->inc_bbuf;    }  /*  endof if ( SLOG_Bbuf_IsPointerAtNULL( slog->ALL_bbufs ) )  */    /*        The above IF statement guarantees that there should exist        at least one non-returned irec among all bbufs in the frame        So the following WHILE statement tries to return a non-empty        bbuf which still has one non-returned irec.    */    while ( SLOG_Bbuf_IsPointerAtNULL( slog->ptr2bbuf ) ) {        if ( slog->ptr2bbuf == slog->inc_bbuf )            slog->ptr2bbuf = slog->pas_bbuf;        else if ( slog->ptr2bbuf == slog->pas_bbuf )             slog->ptr2bbuf = slog->cur_bbuf;        else if ( slog->ptr2bbuf == slog->cur_bbuf )             slog->ptr2bbuf = slog->out_bbuf;        else if ( slog->ptr2bbuf == slog->out_bbuf ) {            fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - "                              "Unexpected NULL pointer at "                              "SLOG_Bbuf_IsPointerAtNULL( _ptr_ )\n" );            fflush( errfile );            *irc = SLOG_FAIL;            return NULL;        }    }    /*        An extra IF statement to guarantee to return any interval record        ( pointer ) if there is any left in the SLOG_STREAM/disk.    */    if ( ! SLOG_Bbuf_IsPointerAtNULL( slog->ptr2bbuf ) ) {        src_irec = SLOG_Bbuf_GetIntvlRec( slog->ptr2bbuf );        if ( src_irec == NULL ) {            fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - "                              "SLOG_Bbuf_GetIntvlRec() return FAIL\n" );            fflush( errfile );            *irc = SLOG_FAIL;            return NULL;        }        *irc = SLOG_SUCCESS;        return src_irec;    }   /*  endof ( NOT IsSLOG_Bbuf_PointerAtNULL( slog->ptr2bbuf ) )  */    fprintf( errfile, __FILE__":SLOG_Irec_FromInputStream() - "                      "something goes wrong\n" );    fflush( errfile );    *irc = SLOG_FAIL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -