The mdsupport.h & mdsupport.c


Modules

 Midas dump error code
 Midas dump support Define
 Midas dump support Macros

Functions

INT mftp_open (char *destination, FTP_CON **con)
INT md_file_ropen (char *infile, INT data_fmt)
INT md_file_rclose (INT data_fmt)
INT md_file_wopen (INT type, INT data_fmt, char *filename, INT *hDev)
INT md_file_wclose (INT handle, INT type, INT data_fmt, char *destination)
INT md_dev_os_read (INT handle, INT type, void *prec, DWORD nbytes, DWORD *readn)
INT md_dev_os_write (INT handle, INT type, void *prec, DWORD nbytes, DWORD *written)
INT md_physrec_get (INT data_fmt, void **precord, DWORD *readn)
INT md_log_write (INT handle, INT data_fmt, INT type, void *prec, DWORD nbytes)
INT md_physrec_skip (INT data_fmt, INT bl)
INT midas_event_skip (INT evtn)
INT md_physrec_display (INT data_fmt)
INT md_all_info_display (INT what)
INT md_event_swap (INT data_fmt, void *pevent)
INT md_event_get (INT data_fmt, void **pevent, DWORD *readn)
void md_event_display (void *pevent, INT data_fmt, INT dsp_mode, INT dsp_fmt, char *bn)
void md_raw_event_display (void *pevent, INT data_fmt, INT dsp_fmt)
void md_bank_event_display (void *pevent, INT data_fmt, INT dsp_fmt, INT dsp_mode, char *bn)
void md_bank_display (void *pmbh, void *pbk, INT data_fmt, INT dsp_mode, INT dsp_fmt)
void md_raw_bank_display (void *pbank, INT data_fmt, INT dsp_fmt)
INT midas_event_get (void **pevent, DWORD *readn)
INT midas_physrec_get (void *prec, DWORD *readn)
void midas_bank_display (BANK *pbk, INT dsp_fmt)
void midas_bank_display32 (BANK32 *pbk, INT dsp_fmt)


Function Documentation

INT md_all_info_display ( INT  what  ) 

Definition at line 689 of file mdsupport.c.

00691        : md_all_info_display
00692 Purpose: display on screen all the info about "what".
00693 Input:
00694 INT     what              type of display.
00695 Output:
00696 none
00697 Function value:
00698 INT                 MD_SUCCESS
00699 MD_DONE
00700 \********************************************************************/
00701 {
00702    if (my.fmt == FORMAT_YBOS) {
00703      assert(!"YBOS not supported anymore");
00704    } else if (my.fmt == FORMAT_MIDAS) {
00705      DWORD mbn, run, ser;
00706      WORD id, msk;
00707      mbn = my.evtn;
00708      run = my.runn;
00709      id = my.pmh->event_id;
00710      msk = my.pmh->trigger_mask;
00711      ser = my.pmh->serial_number;
00712      switch (what) {
00713      case D_RECORD:
00714      case D_HEADER:
00715        printf(">>> No physical record structure for Midas format <<<\n");
00716        return MD_DONE;
00717        break;
00718      case D_EVTLEN:
00719        printf("Evt#%d- ", my.evtn);
00720        printf("%irun 0x%4.4uxid 0x%4.4uxmsk %5dmevt#", run, id, msk, mbn);
00721        printf("%5del/x%x %5dserial\n", my.evtlen, my.evtlen, ser);
00722        break;
00723      }
00724    }
00725    return MD_SUCCESS;
00726 }

void md_bank_display ( void *  pmbh,
void *  pbk,
INT  data_fmt,
INT  dsp_mode,
INT  dsp_fmt 
)

Definition at line 939 of file mdsupport.c.

00941        : external md_bank_display
00942 Purpose: display on screen the given bank.
00943 Input:
00944 void * pbk          pointer to the bank
00945 INT  data_fmt       YBOS or MIDAS
00946 INT  dsp_mode       display mode (RAW/BANK)
00947 INT  dsp_fmt        display format (DSP_DEC/HEX)
00948 Output:             
00949 none
00950 Function value:
00951 none
00952 \********************************************************************/
00953 {
00954    if (dsp_mode == DSP_RAW)
00955       md_raw_bank_display(pbk, data_fmt, dsp_fmt);
00956    else {
00957       if (data_fmt == FORMAT_MIDAS) {
00958          if (bk_is32(pmbh))
00959             midas_bank_display32((BANK32 *) pbk, dsp_fmt);
00960          else
00961             midas_bank_display((BANK *) pbk, dsp_fmt);
00962       } else if (data_fmt == FORMAT_YBOS)
00963       assert(!"YBOS not supported anymore");
00964    }
00965    return;
00966 }

void md_bank_event_display ( void *  pevent,
INT  data_fmt,
INT  dsp_fmt,
INT  dsp_mode,
char *  bn 
)

Definition at line 850 of file mdsupport.c.

Referenced by md_event_display().

00852        : md_bank_event_display
00853 Purpose: display on screen the event header, bank list and bank content
00854 for midas format.)
00855 Input:
00856 void * pevent          points to either plrl or pheader
00857 INT     data_fmt       uses the YBOS or MIDAS event structure
00858 INT     dsp_fmt        display format (DSP_DEC/HEX)
00859 Output:
00860 none
00861 Function value:
00862 none
00863 \********************************************************************/
00864 {
00865    char banklist[MD_STRING_BANKLIST_MAX + STRING_BANKLIST_MAX];
00866    DWORD *pdata, *pdata1;
00867    BANK_HEADER *pbh = NULL;
00868    BANK *pmbk;
00869    BANK32 *pmbk32;
00870    EVENT_HEADER *pheader;
00871    INT status, single = 0;
00872 
00873    if (data_fmt == FORMAT_YBOS) {
00874      assert(!"YBOS not supported anymore");
00875    } else if (data_fmt == FORMAT_MIDAS) {
00876      /* skip these special events (NO bank structure) */
00877      pheader = (EVENT_HEADER *) pevent;
00878      if (pheader->event_id == EVENTID_BOR ||
00879          pheader->event_id == EVENTID_EOR || pheader->event_id == EVENTID_MESSAGE)
00880        return;
00881      
00882      /* check if format is MIDAS or FIXED */
00883      pbh = (BANK_HEADER *) (pheader + 1);
00884      
00885      /* Check for single bank display request */
00886      if (dsp_mode == DSP_BANK_SINGLE) {
00887        bk_locate(pbh, bn, &pdata1);
00888        single = 1;
00889      }
00890      /* event header (skip it if in single bank display) */
00891      if (!single)
00892        printf
00893          ("Evid:%4.4x- Mask:%4.4x- Serial:%i- Time:0x%x- Dsize:%i/0x%x",
00894           (WORD) pheader->event_id, (WORD) pheader->trigger_mask,
00895           pheader->serial_number, pheader->time_stamp, pheader->data_size, pheader->data_size);
00896      
00897      if ((pbh->data_size + 8) == pheader->data_size) {
00898        /* bank list */
00899        if (!single) {
00900          /* Skip list if in single bank display */
00901          status = bk_list((BANK_HEADER *) (pheader + 1), banklist);
00902          printf("\n#banks:%i - Bank list:-%s-\n", status, banklist);
00903        }
00904        
00905        /* display bank content */
00906        if (bk_is32(pbh)) {
00907          pmbk32 = NULL;
00908          do {
00909            bk_iterate32(pbh, &pmbk32, &pdata);
00910            if (pmbk32 != NULL)
00911              if (single && (pdata == pdata1))
00912                midas_bank_display32(pmbk32, dsp_fmt);
00913            if (!single)
00914              if (pmbk32 != NULL)
00915                midas_bank_display32(pmbk32, dsp_fmt);
00916          } while (pmbk32 != NULL);
00917        } else {
00918          pmbk = NULL;
00919          do {
00920            bk_iterate(pbh, &pmbk, &pdata);
00921            if (pmbk != NULL)
00922              if (single && (pdata == pdata1))
00923                midas_bank_display(pmbk, dsp_fmt);
00924            if (!single)
00925              if (pmbk != NULL)
00926                midas_bank_display(pmbk, dsp_fmt);
00927          } while (pmbk != NULL);
00928        }
00929      } else {
00930        printf("\nFIXED event with Midas Header\n");
00931        md_raw_event_display(pevent, data_fmt, dsp_fmt);
00932      }
00933    }
00934    
00935    return;
00936 }

INT md_dev_os_read ( INT  handle,
INT  type,
void *  prec,
DWORD  nbytes,
DWORD readn 
)

Definition at line 424 of file mdsupport.c.

Referenced by midas_physrec_get().

00426        : md_dev_os_read
00427 Purpose: read nbytes from the type device.
00428 Input:
00429 INT  handle        file handler
00430 INT  type          Type of device (TAPE or DISK)
00431 void * prec        pointer to the record
00432 DWORD nbytes       # of bytes to read
00433 Output:
00434 DWORD *readn       # of bytes read
00435 Function value:
00436 MD_DONE            No more record to read
00437 MD_SUCCESS         Ok
00438 \********************************************************************/
00439 {
00440    INT status;
00441    if (type == LOG_TYPE_DISK)
00442       /* --------- DISK ---------- */
00443    {
00444       *readn = read(handle, prec, nbytes);
00445       if (*readn <= 0)
00446          status = SS_FILE_ERROR;
00447       else
00448          status = SS_SUCCESS;
00449       return status;
00450    }
00451    /* --------- TAPE ---------- */
00452 #ifdef OS_UNIX
00453    else if (type == LOG_TYPE_TAPE) {
00454       *readn = read(handle, prec, nbytes);
00455       if (*readn <= 0)
00456          status = SS_FILE_ERROR;
00457       else
00458          status = SS_SUCCESS;
00459       return status;
00460    }
00461 #endif
00462 
00463 #ifdef OS_WINNT
00464    else if (type == LOG_TYPE_TAPE) {
00465       if (!ReadFile((HANDLE) handle, prec, nbytes, readn, NULL))
00466          status = GetLastError();
00467       else
00468          status = SS_SUCCESS;
00469       if (status == ERROR_NO_DATA_DETECTED)
00470          status = SS_END_OF_TAPE;
00471 
00472       return status;
00473    }
00474 #endif                          /* OS_WINNT */
00475    else
00476       return SS_SUCCESS;
00477 }

INT md_dev_os_write ( INT  handle,
INT  type,
void *  prec,
DWORD  nbytes,
DWORD written 
)

Definition at line 480 of file mdsupport.c.

Referenced by md_log_write().

00482        : md_dev_os_write
00483 Purpose: write nbytes to the device.
00484 Input:
00485 INT  handle        file handler
00486 INT  type          Type of device (TAPE or DISK)
00487 void * prec        pointer to the record
00488 DWORD   nbytes     record length to be written
00489 Output:
00490 DWORD *written     # of written bytes
00491 Function value:
00492 INT status           # of written bytes or ERROR
00493 SS_FILE_ERROR      write error
00494 SS_SUCCESS         Ok
00495 \********************************************************************/
00496 {
00497    INT status;
00498    if (type == LOG_TYPE_DISK)
00499 #ifdef OS_WINNT
00500    {                            /* --------- DISK ---------- */
00501       WriteFile((HANDLE) handle, (char *) prec, nbytes, written, NULL);
00502       status = *written == nbytes ? SS_SUCCESS : SS_FILE_ERROR;
00503       return status;            /* return for DISK */
00504    }
00505 #else
00506    {                            /* --------- DISK ---------- */
00507      status = *written = write(handle, (char *) prec, nbytes) == (INT) nbytes ? SS_SUCCESS : SS_FILE_ERROR;
00508       return status;            /* return for DISK */
00509    }
00510 #endif
00511    else if (type == LOG_TYPE_TAPE) {    /* --------- TAPE ---------- */
00512 #ifdef OS_UNIX
00513       do {
00514          status = write(handle, (char *) prec, nbytes);
00515       } while (status == -1 && errno == EINTR);
00516       *written = status;
00517       if (*written != nbytes) {
00518          cm_msg(MERROR, "any_dev_os_write", strerror(errno));
00519          if (errno == EIO)
00520             return SS_IO_ERROR;
00521          if (errno == ENOSPC)
00522             return SS_NO_SPACE;
00523          else
00524             return SS_TAPE_ERROR;
00525       }
00526 #endif                          /* OS_UNIX */
00527 
00528 #ifdef OS_WINNT
00529       WriteFile((HANDLE) handle, (char *) prec, nbytes, written, NULL);
00530       if (*written != nbytes) {
00531          status = GetLastError();
00532          cm_msg(MERROR, "any_dev_os_write", "error %d", status);
00533          return SS_IO_ERROR;
00534       }
00535       return SS_SUCCESS;        /* return for TAPE */
00536 #endif                          /* OS_WINNT */
00537    } else if (type == LOG_TYPE_FTP)
00538 #ifdef HAVE_FTPLIB
00539    {
00540       *written = status = ftp_send(ftp_con->data, (char *) prec,
00541                                    (int) nbytes) == (int) nbytes ? SS_SUCCESS : SS_FILE_ERROR;
00542       return status;
00543    }
00544 #else
00545    {
00546       cm_msg(MERROR, "mdsupport", "FTP support not included");
00547       return SS_IO_ERROR;
00548    }
00549 #endif
00550    return SS_SUCCESS;
00551 }

void md_event_display ( void *  pevent,
INT  data_fmt,
INT  dsp_mode,
INT  dsp_fmt,
char *  bn 
)

Definition at line 785 of file mdsupport.c.

00787        : external md_event_display
00788 Purpose: display on screen the event data in either Decimal or Hexadecimal.
00789 Input:
00790 void *  pevent     pointer to either plrl or pheader.
00791 INT     data_fmt   uses the YBOS or MIDAS event structure
00792 INT     dsp_mode   display in RAW or Bank mode
00793 INT     dsp_fmt    display format (DSP_DEC/HEX)
00794 Output:
00795 none
00796 Function value:
00797 none
00798 \********************************************************************/
00799 {
00800    if (dsp_mode == DSP_RAW)
00801       md_raw_event_display(pevent, data_fmt, dsp_fmt);
00802    else if ((dsp_mode == DSP_BANK) || (dsp_mode == DSP_BANK_SINGLE))
00803       md_bank_event_display(pevent, data_fmt, dsp_fmt, dsp_mode, bn);
00804    else
00805       printf("mdsupport- Unknown format:%i\n", dsp_fmt);
00806    return;
00807 }

INT md_event_get ( INT  data_fmt,
void **  pevent,
DWORD readn 
)

Definition at line 761 of file mdsupport.c.

00763        : external md_event_get
00764 Purpose: Retrieve an event from the given data format.
00765 Input:
00766 INT data_fmt :  YBOS or MIDAS 
00767 void ** pevent : either plrl or pheader
00768 Output:
00769 DWORD * readn : number of bytes read
00770 Function value:
00771 status : from lower function
00772 \********************************************************************/
00773 {
00774    INT status = 0;
00775 
00776    *pevent = NULL;
00777    if (data_fmt == FORMAT_MIDAS)
00778      status = midas_event_get(pevent, readn);
00779    else if (data_fmt == FORMAT_YBOS)
00780      assert(!"YBOS not supported anymore");
00781    return (status);
00782 }

INT md_event_swap ( INT  data_fmt,
void *  pevent 
)

Definition at line 729 of file mdsupport.c.

00731        : external md_event_swap
00732 Purpose: Swap an event from the given data format.
00733 Input:
00734 INT data_fmt  : YBOS or MIDAS 
00735 void * pevent : pointer to either plrl or pheader
00736 Output:
00737 none
00738 Function value:
00739 status :  from the lower function
00740 \********************************************************************/
00741 {
00742    INT status;
00743    BANK_HEADER *pbh;
00744 
00745    if (data_fmt == FORMAT_MIDAS) {
00746       if ((((EVENT_HEADER *) pevent)->event_id == EVENTID_BOR) ||
00747           (((EVENT_HEADER *) pevent)->event_id == EVENTID_EOR) ||
00748           (((EVENT_HEADER *) pevent)->event_id == EVENTID_MESSAGE))
00749          return SS_SUCCESS;
00750       pbh = (BANK_HEADER *) (((EVENT_HEADER *) pevent) + 1);
00751       status = bk_swap(pbh, FALSE);
00752       return status == CM_SUCCESS ? MD_EVENT_NOT_SWAPPED : MD_SUCCESS;
00753    } else if (data_fmt == FORMAT_YBOS) {
00754      assert(!"YBOS not supported anymore");
00755    }
00756 
00757    return MD_UNKNOWN_FORMAT;
00758 }

INT md_file_rclose ( INT  data_fmt  ) 

Definition at line 257 of file mdsupport.c.

Referenced by lazy_copy().

00259        : external md_any_file_rclose
00260 Purpose: Close a data file used for replay for the given data format
00261 Input:
00262 INT data_fmt :  YBOS or MIDAS 
00263 Output:
00264 none
00265 Function value:
00266 status : from lower function
00267 *******************************************************************/
00268 {
00269    int i;
00270 
00271    i = data_fmt;                /* avoid compiler warning */
00272 
00273    switch (my.type) {
00274    case LOG_TYPE_TAPE:
00275    case LOG_TYPE_DISK:
00276       /* close file */
00277       if (my.zipfile) {
00278 #ifdef HAVE_ZLIB
00279          gzclose(filegz);
00280 #endif
00281       } else {
00282          if (my.handle != 0)
00283             close(my.handle);
00284       }
00285       break;
00286    }
00287    if (ptopmrd != NULL)
00288       free(ptopmrd);
00289    if (my.pmp != NULL)
00290       free(my.pmp);
00291    my.pmp = NULL;
00292    my.pmh = NULL;
00293    ptopmrd = NULL;
00294    my.pmrd = NULL;              /* ptopmrd and my.pmrd point to the same place. K.O. 25-FEB-2005 */
00295    return (MD_SUCCESS);
00296 }

INT md_file_ropen ( char *  infile,
INT  data_fmt 
)

Definition at line 172 of file mdsupport.c.

Referenced by lazy_copy().

00174        : external md_any_file_ropen
00175 Purpose: Open data file for replay for the given data format.
00176 It uses the local "my" structure.
00177 Input:
00178 INT data_fmt :  YBOS or MIDAS 
00179 char * infile : Data file name
00180 Output:
00181 none
00182 Function value:
00183 status : from lower function
00184 \********************************************************************/
00185 {
00186    INT status;
00187 
00188    /* fill up record with file name */
00189    strcpy(my.name, infile);
00190 
00191    /* find out what dev it is ? : check on /dev */
00192    my.zipfile = FALSE;
00193    if ((strncmp(my.name, "/dev", 4) == 0) || (strncmp(my.name, "\\\\.\\", 4) == 0)) {
00194       /* tape device */
00195       my.type = LOG_TYPE_TAPE;
00196    } else {
00197       /* disk device */
00198       my.type = LOG_TYPE_DISK;
00199       if (strncmp(infile + strlen(infile) - 3, ".gz", 3) == 0)
00200         my.zipfile = TRUE;        // FALSE; // PAA Nov/07 ignore zip, copy blindly blocks
00201    }
00202 
00203    /* open file */
00204    if (!my.zipfile) {
00205       if (my.type == LOG_TYPE_TAPE) {
00206          status = ss_tape_open(my.name, O_RDONLY | O_BINARY, &my.handle);
00207       } else if ((my.handle = open(my.name, O_RDONLY | O_BINARY | O_LARGEFILE, 0644)) == -1) {
00208          printf("dev name :%s Handle:%d \n", my.name, my.handle);
00209          return (SS_FILE_ERROR);
00210       }
00211    } else {
00212 #ifdef HAVE_ZLIB
00213       if (my.type == LOG_TYPE_TAPE) {
00214          printf(" Zip on tape not yet supported \n");
00215          return (SS_FILE_ERROR);
00216       }
00217       filegz = gzopen(my.name, "rb");
00218       my.handle = 0;
00219       if (filegz == NULL) {
00220          printf("dev name :%s gzopen error:%d \n", my.name, my.handle);
00221          return (SS_FILE_ERROR);
00222       }
00223 #else
00224       cm_msg(MERROR, "mdsupport", "Zlib not included ... gz file not supported");
00225       return (SS_FILE_ERROR);
00226 #endif
00227    }
00228 
00229    if (data_fmt == FORMAT_YBOS) {
00230       assert(!"YBOS support not supported anymore");
00231    } else if (data_fmt == FORMAT_MIDAS) {
00232       my.fmt = FORMAT_MIDAS;
00233       my.size = TAPE_BUFFER_SIZE;
00234       my.pmp = (char *) malloc(my.size);
00235       if (my.pmp == NULL)
00236          return SS_NO_MEMORY;
00237       my.pme = (EVENT_HEADER *) my.pmp;
00238 
00239       /* allocate memory for one full event */
00240       if (my.pmrd != NULL)
00241          free(my.pmrd);
00242       my.pmrd = (char *) malloc(5 * MAX_EVENT_SIZE);    /* in bytes */
00243       ptopmrd = my.pmrd;
00244       if (my.pmrd == NULL)
00245          return SS_NO_MEMORY;
00246       memset((char *) my.pmrd, -1, 5 * MAX_EVENT_SIZE);
00247       my.pmh = (EVENT_HEADER *) my.pmrd;
00248    }
00249 
00250    /* initialize pertinent variables */
00251    my.recn = -1;
00252    my.evtn = 0;
00253    return (MD_SUCCESS);
00254 }

INT md_file_wclose ( INT  handle,
INT  type,
INT  data_fmt,
char *  destination 
)

Definition at line 354 of file mdsupport.c.

Referenced by lazy_copy().

00356        : external md_file_wclose
00357 Purpose: Close a data file used for replay for the given data format
00358 Input:
00359 INT data_fmt :  YBOS or MIDAS 
00360 Output:
00361 none
00362 Function value:
00363 status : from lower function
00364 *******************************************************************/
00365 {
00366    INT status;
00367 
00368    status = SS_SUCCESS;
00369    switch (type) {
00370    case LOG_TYPE_TAPE:
00371       /* writing EOF mark on tape Fonly */
00372       status = ss_tape_write_eof(handle);
00373       ss_tape_close(handle);
00374       break;
00375    case LOG_TYPE_DISK:
00376       /* close file */
00377       if (handle != 0)
00378 #ifdef OS_WINNT
00379          CloseHandle((HANDLE) handle);
00380 #else
00381          close(handle);
00382 #endif
00383       break;
00384    case LOG_TYPE_FTP:
00385 #ifdef HAVE_FTPLIB
00386       {
00387       char *p, filename[256];
00388       int  i;
00389 
00390       ftp_close(ftp_con);
00391 
00392       /* 
00393          destination should have the form:
00394          host, port, user, password, directory, run%05d.mid, file_mode, command, ...
00395       */
00396       p = destination;
00397       for (i=0 ; i<5 && p != NULL ; i++) {
00398          p = strchr(p, ',');
00399          if (*p == ',')
00400             p++;
00401       }
00402       if (p != NULL) {
00403          strlcpy(filename, p, sizeof(filename));
00404          if (strchr(filename, ','))
00405             *strchr(filename, ',') = 0;
00406       } else
00407          strlcpy(filename, destination, sizeof(filename));
00408 
00409       /* if filename starts with a '.' rename it */
00410       if (filename[0] == '.')
00411          ftp_move(ftp_con, filename, filename+1);
00412 
00413       ftp_bye(ftp_con);
00414       }
00415 #endif
00416       break;
00417    }
00418    if (status != SS_SUCCESS)
00419       return status;
00420    return (MD_SUCCESS);
00421 }

INT md_file_wopen ( INT  type,
INT  data_fmt,
char *  filename,
INT hDev 
)

Definition at line 299 of file mdsupport.c.

Referenced by lazy_copy().

00301        : external md_file_wopen
00302 Purpose: Open a data file for the given data format
00303 Input:
00304 INT type     :  Tape or Disk
00305 INT data_fmt :  YBOS or MIDAS
00306 char * filename : file to open
00307 Output:
00308 INT * hDev      : file handle
00309 Function value:
00310 status : from lower function
00311 *******************************************************************/
00312 {
00313    INT status = 0;
00314 
00315    if (type == LOG_TYPE_DISK)
00316       /* takes care of TapeLX/NT under ss_tape_open , DiskLX/NT here */
00317    {
00318       if (data_fmt == FORMAT_YBOS) {
00319          assert(!"YBOS not supported anymore");
00320       } else if (data_fmt == FORMAT_MIDAS) {
00321 #ifdef OS_WINNT
00322          *hDev =
00323            (int) CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ,
00324                             NULL, CREATE_ALWAYS,
00325                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, 0);
00326 #else
00327          *hDev = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644);
00328 #endif
00329          status = *hDev < 0 ? SS_FILE_ERROR : SS_SUCCESS;
00330       }
00331    } else if (type == LOG_TYPE_TAPE) {
00332      if (data_fmt == FORMAT_YBOS) {
00333          assert(!"YBOS not supported anymore");
00334       } else if (data_fmt == FORMAT_MIDAS)
00335          status = ss_tape_open(filename, O_WRONLY | O_CREAT | O_TRUNC, hDev);
00336    } else if (type == LOG_TYPE_FTP) {
00337 #ifdef HAVE_FTPLIB
00338       status = mftp_open(filename, (FTP_CON **) & ftp_con);
00339       if (status != SS_SUCCESS) {
00340          *hDev = 0;
00341          return status;
00342       } else
00343          *hDev = 1;
00344 #else
00345       cm_msg(MERROR, "mdsupport", "FTP support not included");
00346       return SS_FILE_ERROR;
00347 #endif
00348    }
00349 
00350    return status;
00351 }

INT md_log_write ( INT  handle,
INT  data_fmt,
INT  type,
void *  prec,
DWORD  nbytes 
)

Definition at line 575 of file mdsupport.c.

Referenced by lazy_copy().

00577        : external md_log_write
00578 Purpose: Write a physical record to the out device.
00579 
00580 Input:
00581 void handle   : file handle
00582 INT data_fmt  : YBOS or MIDAS 
00583 INT type      : Tape or disk 
00584 void *prec    : record pointer
00585 DWORD nbytes  : record length to be written
00586 Output:
00587 none
00588 Function value:
00589 status : from lower function  SS_SUCCESS, SS_FILE_ERROR
00590 \********************************************************************/
00591 {
00592    INT status;
00593    DWORD written;
00594 
00595    status = data_fmt;           /* avoid compiler warning */
00596    /* write record */
00597    status = md_dev_os_write(handle, type, prec, nbytes, &written);
00598    return status;
00599 }

INT md_physrec_display ( INT  data_fmt  ) 

Definition at line 663 of file mdsupport.c.

00665        : external md_physrec_display
00666 Purpose: Display the physical record of the current record 
00667 for the given data format.
00668 Not possible for MIDAS as no physical record structure
00669 Input:
00670 INT data_fmt :  YBOS or MIDAS 
00671 Output:
00672 none
00673 Function value:
00674 status          Lower function
00675 \********************************************************************/
00676 {
00677 
00678    if (data_fmt == FORMAT_MIDAS) {
00679       printf(">>> No physical record structure for Midas format <<<\n");
00680       return MD_DONE;
00681    } else if (data_fmt == FORMAT_YBOS) {
00682      assert(!"YBOS not supported anymore");
00683      return (MD_SUCCESS);
00684    } else
00685      return MD_UNKNOWN_FORMAT;
00686 }

INT md_physrec_get ( INT  data_fmt,
void **  precord,
DWORD readn 
)

Definition at line 554 of file mdsupport.c.

Referenced by lazy_copy().

00556        : external md_physrec_get
00557 Purpose: Retrieve a physical record for the given data format
00558 Input:
00559 INT data_fmt :  YBOS or MIDAS 
00560 Output:
00561 void ** precord     pointer to the record
00562 DWORD * readn       record length in bytes
00563 Function value:
00564 status : from lower function
00565 \********************************************************************/
00566 {
00567    *precord = my.pmp;
00568    if (data_fmt == FORMAT_MIDAS) {
00569       return midas_physrec_get(*precord, readn);
00570    } else
00571      return MD_UNKNOWN_FORMAT;
00572 }

INT md_physrec_skip ( INT  data_fmt,
INT  bl 
)

Definition at line 602 of file mdsupport.c.

00604        : external md_physrec_skip
00605 Purpose: Skip physical record until block = bl for the given data
00606 format, Under midas the skip is an event as no physical 
00607 record is present under that format,
00608 Input:
00609 INT data_fmt :  YBOS or MIDAS 
00610 INT bl:         block number (-1==all, 0 = first block)
00611 in case of MIDAS the bl represent an event
00612 Output:
00613 none
00614 Function value:
00615 status : from lower function
00616 \********************************************************************/
00617 {
00618    INT status;
00619 
00620    if (data_fmt == FORMAT_MIDAS) {
00621       status = midas_event_skip(bl);
00622       return MD_SUCCESS;
00623    } else
00624       return MD_UNKNOWN_FORMAT;
00625 }

void md_raw_bank_display ( void *  pbank,
INT  data_fmt,
INT  dsp_fmt 
)

Definition at line 969 of file mdsupport.c.

Referenced by md_bank_display().

00971        : md__raw_bank_display
00972 Purpose: display on screen the RAW data of a given YBOS/MIDAS bank.
00973 Input:
00974 void  * pbank          pointer to the bank name
00975 INT     data_fmt       uses the YBOS or MIDAS event structure
00976 INT     dsp_fmt        display format (DSP_DEC/HEX)
00977 Output:
00978 none
00979 Function value:
00980 none
00981 \********************************************************************/
00982 {
00983    DWORD *pdata = NULL, lrl = 0, j, i;
00984 
00985    if (data_fmt == FORMAT_YBOS) {
00986      assert(!"YBOS not supported any ore");
00987    } else if (data_fmt == FORMAT_MIDAS) {
00988       lrl = ((BANK *) pbank)->data_size >> 2;   /* in DWORD */
00989       pdata = (DWORD *) ((BANK *) (pbank) + 1);
00990    }
00991 
00992    for (i = 0; i < lrl; i += NLINE) {
00993       j = 0;
00994       printf("\n%4i-> ", i + j + 1);
00995       for (j = 0; j < NLINE; j++) {
00996          if ((i + j) < lrl) {
00997             if (dsp_fmt == DSP_DEC)
00998                printf("%8.i ", *((DWORD *) pdata));
00999             if (dsp_fmt == DSP_ASC)
01000                printf("%8.8x ", *((DWORD *) pdata));
01001             if (dsp_fmt == DSP_HEX)
01002                printf("%8.8x ", *((DWORD *) pdata));
01003             pdata++;
01004          }
01005       }
01006    }
01007 }

void md_raw_event_display ( void *  pevent,
INT  data_fmt,
INT  dsp_fmt 
)

Definition at line 810 of file mdsupport.c.

Referenced by md_bank_event_display(), and md_event_display().

00812        : md_raw_event_display
00813 Purpose: display on screen the RAW data of MIDAS format.
00814 Input:
00815 DWORD *  pevent         points to either plrl or pheader
00816 INT     data_fmt        uses the YBOS or MIDAS event structure
00817 INT      dsp_fmt        display format (DSP_DEC/HEX)
00818 Output:
00819 none
00820 Function value:
00821 none
00822 \********************************************************************/
00823 {
00824    DWORD lrl = 0, *pevt = NULL, j, i, total = 0;
00825 
00826    if (data_fmt == FORMAT_YBOS) {
00827       assert(!"YBOS not supported anymore");
00828    } else if (data_fmt == FORMAT_MIDAS) {
00829       lrl = ((((EVENT_HEADER *) pevent)->data_size) + sizeof(EVENT_HEADER)) / sizeof(DWORD);    /* in I*4 for raw including the header */
00830       pevt = (DWORD *) pevent;  /* local copy starting from the pheader */
00831    }
00832 
00833    for (i = 0; i < lrl; i += NLINE) {
00834       printf("%6.0d->: ", total);
00835       for (j = 0; j < NLINE; j++) {
00836          if ((i + j) < lrl) {
00837             if (dsp_fmt == DSP_DEC)
00838                printf("%8.i ", *pevt);
00839             else
00840                printf("%8.8x ", *pevt);
00841             pevt++;
00842          }
00843       }
00844       total += NLINE;
00845       printf("\n");
00846    }
00847 }

INT mftp_open ( char *  destination,
FTP_CON **  con 
)

dox

Definition at line 92 of file mdsupport.c.

Referenced by md_file_wopen().

00093 {
00094    INT status;
00095    short port = 0;
00096    char *token, host_name[HOST_NAME_LENGTH],
00097        user[256], pass[256], directory[256], file_name[256], file_mode[256];
00098 
00099    /* 
00100       destination should have the form:
00101       host, port, user, password, directory, run%05d.mid, file_mode, command, ...
00102     */
00103 
00104    /* break destination in components */
00105    token = strtok(destination, ",");
00106    if (token)
00107       strcpy(host_name, token);
00108 
00109    token = strtok(NULL, ",");
00110    if (token)
00111       port = atoi(token);
00112 
00113    token = strtok(NULL, ",");
00114    if (token)
00115       strcpy(user, token);
00116 
00117    token = strtok(NULL, ",");
00118    if (token)
00119       strcpy(pass, token);
00120 
00121    token = strtok(NULL, ",");
00122    if (token)
00123       strcpy(directory, token);
00124 
00125    token = strtok(NULL, ",");
00126    if (token)
00127       strcpy(file_name, token);
00128 
00129    token = strtok(NULL, ",");
00130    file_mode[0] = 0;
00131    if (token)
00132       strcpy(file_mode, token);
00133 
00134    status = ftp_login(con, host_name, port, user, pass, "");
00135    if (status >= 0)
00136       return status;
00137 
00138    status = ftp_chdir(*con, directory);
00139    if (status >= 0) {
00140       /* directory does not exist -> create it */
00141       ftp_mkdir(*con, directory);
00142       status = ftp_chdir(*con, directory);
00143    }
00144    if (status >= 0)
00145       return status;
00146    status = ftp_binary(*con);
00147    if (status >= 0)
00148       return status;
00149 
00150    if (file_mode[0]) {
00151       status = ftp_command(*con, "umask %s", file_mode, 200, 250, EOF);
00152       if (status >= 0)
00153          return status;
00154    }
00155 
00156    while (token) {
00157       token = strtok(NULL, ",");
00158       if (token) {
00159          status = ftp_command(*con, token, NULL, 200, 250, EOF);
00160          if (status >= 0)
00161             return status;
00162       }
00163    }
00164 
00165    if (ftp_open_write(*con, file_name) >= 0)
00166       return (*con)->err_no;
00167 
00168    return SS_SUCCESS;
00169 }

void midas_bank_display ( BANK pbk,
INT  dsp_fmt 
)

Definition at line 1146 of file mdsupport.c.

Referenced by md_bank_display(), and md_bank_event_display().

01148        : midas_bank_display
01149 Purpose: display on screen the pointed MIDAS bank data using MIDAS Bank structure.
01150 Input:
01151 BANK *  pbk            pointer to the BANK
01152 INT     dsp_fmt        display format (DSP_DEC/HEX)
01153 Output:
01154 none
01155 Function value:
01156 none
01157 \********************************************************************/
01158 {
01159    char bank_name[5], strbktype[32];
01160    char *pdata, *pendbk;
01161    DWORD length_type = 0, lrl;
01162    INT type, i, j;
01163 
01164    lrl = pbk->data_size;        /* in bytes */
01165    type = pbk->type & 0xff;
01166    bank_name[4] = 0;
01167    memcpy(bank_name, (char *) (pbk->name), 4);
01168    pdata = (char *) (pbk + 1);
01169 
01170    j = 64;                      /* elements within line */
01171    i = 1;                       /* data counter */
01172    strcpy(strbktype, "Unknown format");
01173    if (type == TID_DOUBLE) {
01174       length_type = sizeof(double);
01175       strcpy(strbktype, "double*8");
01176    }
01177    if (type == TID_FLOAT) {
01178       length_type = sizeof(float);
01179       strcpy(strbktype, "Real*4 (FMT machine dependent)");
01180    }
01181    if (type == TID_DWORD) {
01182       length_type = sizeof(DWORD);
01183       strcpy(strbktype, "Unsigned Integer*4");
01184    }
01185    if (type == TID_INT) {
01186       length_type = sizeof(INT);
01187       strcpy(strbktype, "Signed Integer*4");
01188    }
01189    if (type == TID_WORD) {
01190       length_type = sizeof(WORD);
01191       strcpy(strbktype, "Unsigned Integer*2");
01192    }
01193    if (type == TID_SHORT) {
01194       length_type = sizeof(short);
01195       strcpy(strbktype, "Signed Integer*2");
01196    }
01197    if (type == TID_BYTE) {
01198       length_type = sizeof(BYTE);
01199       strcpy(strbktype, "Unsigned Bytes");
01200    }
01201    if (type == TID_SBYTE) {
01202       length_type = sizeof(BYTE);
01203       strcpy(strbktype, "Signed Bytes");
01204    }
01205    if (type == TID_BOOL) {
01206       length_type = sizeof(DWORD);
01207       strcpy(strbktype, "Boolean");
01208    }
01209    if (type == TID_CHAR) {
01210       length_type = sizeof(char);
01211       strcpy(strbktype, "8 bit ASCII");
01212    }
01213    if (type == TID_STRUCT) {
01214       length_type = sizeof(char);
01215       strcpy(strbktype, "STRUCT (not supported->8 bits)");
01216    }
01217    if (type == TID_STRING) {
01218       length_type = sizeof(char);
01219       strcpy(strbktype, "String 8bit ASCII");
01220    }
01221 
01222    printf("\nBank:%s Length: %i(I*1)/%i(I*4)/%i(Type) Type:%s",
01223           bank_name, lrl, lrl >> 2, lrl / (length_type == 0 ? 1 : length_type), strbktype);
01224 
01225    pendbk = pdata + lrl;
01226    while (pdata < pendbk) {
01227       switch (type) {
01228       case TID_DOUBLE:
01229          if (j > 3) {
01230             printf("\n%4i-> ", i);
01231             j = 0;
01232             i += 4;
01233          }
01234          printf("%15.5le    ", *((double *) pdata));
01235          pdata = (char *) (((double *) pdata) + 1);
01236          j++;
01237          break;
01238       case TID_FLOAT:
01239          if (j > 7) {
01240             printf("\n%4i-> ", i);
01241             j = 0;
01242             i += 8;
01243          }
01244          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01245             printf("%8.3e ", *((float *) pdata));
01246          if (dsp_fmt == DSP_HEX)
01247             printf("0x%8.8x ", *((DWORD *) pdata));
01248          pdata = (char *) (((DWORD *) pdata) + 1);
01249          j++;
01250          break;
01251       case TID_DWORD:
01252          if (j > 7) {
01253             printf("\n%4i-> ", i);
01254             j = 0;
01255             i += 8;
01256          }
01257          if (dsp_fmt == DSP_DEC)
01258             printf("%8.1i ", *((DWORD *) pdata));
01259          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01260             printf("0x%8.8x ", *((DWORD *) pdata));
01261          pdata = (char *) (((DWORD *) pdata) + 1);
01262          j++;
01263          break;
01264       case TID_INT:
01265          if (j > 7) {
01266             printf("\n%4i-> ", i);
01267             j = 0;
01268             i += 8;
01269          }
01270          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01271             printf("%8.1i ", *((DWORD *) pdata));
01272          if (dsp_fmt == DSP_HEX)
01273             printf("0x%8.8x ", *((DWORD *) pdata));
01274          pdata = (char *) (((DWORD *) pdata) + 1);
01275          j++;
01276          break;
01277       case TID_WORD:
01278          if (j > 7) {
01279             printf("\n%4i-> ", i);
01280             j = 0;
01281             i += 8;
01282          }
01283          if (dsp_fmt == DSP_DEC)
01284             printf("%5.1i ", *((WORD *) pdata));
01285          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01286             printf("0x%4.4x ", *((WORD *) pdata));
01287          pdata = (char *) (((WORD *) pdata) + 1);
01288          j++;
01289          break;
01290       case TID_SHORT:
01291          if (j > 7) {
01292             printf("\n%4i-> ", i);
01293             j = 0;
01294             i += 8;
01295          }
01296          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01297             printf("%5.1i ", *((short *) pdata));
01298          if (dsp_fmt == DSP_HEX)
01299             printf("0x%4.4x ", *((short *) pdata));
01300          pdata = (char *) (((short *) pdata) + 1);
01301          j++;
01302          break;
01303       case TID_BYTE:
01304       case TID_STRUCT:
01305          if (j > 15) {
01306             printf("\n%4i-> ", i);
01307             j = 0;
01308             i += 16;
01309          }
01310          if (dsp_fmt == DSP_DEC)
01311             printf("%4.i ", *((BYTE *) pdata));
01312          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01313             printf("0x%2.2x ", *((BYTE *) pdata));
01314          pdata++;
01315          j++;
01316          break;
01317       case TID_SBYTE:
01318          if (j > 15) {
01319             printf("\n%4i-> ", i);
01320             j = 0;
01321             i += 16;
01322          }
01323          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01324             printf("%4.i ", *((BYTE *) pdata));
01325          if (dsp_fmt == DSP_HEX)
01326             printf("0x%2.2x ", *((BYTE *) pdata));
01327          pdata++;
01328          j++;
01329          break;
01330       case TID_BOOL:
01331          if (j > 15) {
01332             printf("\n%4i-> ", i);
01333             j = 0;
01334             i += 16;
01335          }
01336          (*((BOOL *) pdata) != 0) ? printf("Y ") : printf("N ");
01337          pdata = (char *) (((DWORD *) pdata) + 1);
01338          j++;
01339          break;
01340       case TID_CHAR:
01341       case TID_STRING:
01342          if (j > 15) {
01343             printf("\n%4i-> ", i);
01344             j = 0;
01345             i += 16;
01346          }
01347          if (dsp_fmt == DSP_DEC)
01348             printf("%3.i ", *((BYTE *) pdata));
01349          if ((dsp_fmt == DSP_ASC) || (dsp_fmt == DSP_UNK))
01350             printf("%1.1s ", (char *) pdata);
01351          if (dsp_fmt == DSP_HEX)
01352             printf("0x%2.2x ", *((BYTE *) pdata));
01353          pdata++;
01354          j++;
01355          break;
01356       default:
01357          printf("bank type not supported (%d)\n", type);
01358          return;
01359          break;
01360       }
01361    }                            /* end of bank */
01362    printf("\n");
01363    return;
01364 }

void midas_bank_display32 ( BANK32 pbk,
INT  dsp_fmt 
)

Definition at line 1367 of file mdsupport.c.

Referenced by md_bank_display(), and md_bank_event_display().

01369        : midas_bank_display32
01370 Purpose: display on screen the pointed MIDAS bank data using MIDAS Bank structure.
01371 for 32bit length banks
01372 Input:
01373 BANK32 *  pbk            pointer to the BANK
01374 INT     dsp_fmt        display format (DSP_DEC/HEX)
01375 Output:
01376 none
01377 Function value:
01378 none
01379 \********************************************************************/
01380 {
01381    char bank_name[5], strbktype[32];
01382    char *pdata, *pendbk;
01383    DWORD length_type = 0, lrl;
01384    INT type, i, j;
01385 
01386    lrl = pbk->data_size;        /* in bytes */
01387    type = pbk->type & 0xff;
01388    bank_name[4] = 0;
01389    memcpy(bank_name, (char *) (pbk->name), 4);
01390    pdata = (char *) (pbk + 1);
01391 
01392    j = 64;                      /* elements within line */
01393    i = 1;                       /* data counter */
01394    strcpy(strbktype, "Unknown format");
01395    if (type == TID_DOUBLE) {
01396       length_type = sizeof(double);
01397       strcpy(strbktype, "double*8");
01398    }
01399    if (type == TID_FLOAT) {
01400       length_type = sizeof(float);
01401       strcpy(strbktype, "Real*4 (FMT machine dependent)");
01402    }
01403    if (type == TID_DWORD) {
01404       length_type = sizeof(DWORD);
01405       strcpy(strbktype, "Unsigned Integer*4");
01406    }
01407    if (type == TID_INT) {
01408       length_type = sizeof(INT);
01409       strcpy(strbktype, "Signed Integer*4");
01410    }
01411    if (type == TID_WORD) {
01412       length_type = sizeof(WORD);
01413       strcpy(strbktype, "Unsigned Integer*2");
01414    }
01415    if (type == TID_SHORT) {
01416       length_type = sizeof(short);
01417       strcpy(strbktype, "Signed Integer*2");
01418    }
01419    if (type == TID_BYTE) {
01420       length_type = sizeof(BYTE);
01421       strcpy(strbktype, "Unsigned Bytes");
01422    }
01423    if (type == TID_SBYTE) {
01424       length_type = sizeof(BYTE);
01425       strcpy(strbktype, "Signed Bytes");
01426    }
01427    if (type == TID_BOOL) {
01428       length_type = sizeof(DWORD);
01429       strcpy(strbktype, "Boolean");
01430    }
01431    if (type == TID_CHAR) {
01432       length_type = sizeof(char);
01433       strcpy(strbktype, "8 bit ASCII");
01434    }
01435    if (type == TID_STRUCT) {
01436       length_type = sizeof(char);
01437       strcpy(strbktype, "STRUCT (not supported->8 bits)");
01438    }
01439    if (type == TID_STRING) {
01440       length_type = sizeof(char);
01441       strcpy(strbktype, "String 8bit ASCI");
01442    }
01443 
01444    printf("\nBank:%s Length: %i(I*1)/%i(I*4)/%i(Type) Type:%s",
01445           bank_name, lrl, lrl >> 2, lrl / (length_type == 0 ? 1 : length_type), strbktype);
01446 
01447    pendbk = pdata + lrl;
01448    while (pdata < pendbk) {
01449       switch (type) {
01450       case TID_DOUBLE:
01451          if (j > 3) {
01452             printf("\n%4i-> ", i);
01453             j = 0;
01454             i += 4;
01455          }
01456          printf("%15.5e    ", *((double *) pdata));
01457          pdata = (char *) (((double *) pdata) + 1);
01458          j++;
01459          break;
01460       case TID_FLOAT:
01461          if (j > 7) {
01462             printf("\n%4i-> ", i);
01463             j = 0;
01464             i += 8;
01465          }
01466          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01467             printf("%8.3e ", *((float *) pdata));
01468          if (dsp_fmt == DSP_HEX)
01469             printf("0x%8.8x ", *((DWORD *) pdata));
01470          pdata = (char *) (((DWORD *) pdata) + 1);
01471          j++;
01472          break;
01473       case TID_DWORD:
01474          if (j > 7) {
01475             printf("\n%4i-> ", i);
01476             j = 0;
01477             i += 8;
01478          }
01479          if (dsp_fmt == DSP_DEC)
01480             printf("%8.1i ", *((DWORD *) pdata));
01481          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01482             printf("0x%8.8x ", *((DWORD *) pdata));
01483          pdata = (char *) (((DWORD *) pdata) + 1);
01484          j++;
01485          break;
01486       case TID_INT:
01487          if (j > 7) {
01488             printf("\n%4i-> ", i);
01489             j = 0;
01490             i += 8;
01491          }
01492          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01493             printf("%8.1i ", *((DWORD *) pdata));
01494          if (dsp_fmt == DSP_HEX)
01495             printf("0x%8.8x ", *((DWORD *) pdata));
01496          pdata = (char *) (((DWORD *) pdata) + 1);
01497          j++;
01498          break;
01499       case TID_WORD:
01500          if (j > 7) {
01501             printf("\n%4i-> ", i);
01502             j = 0;
01503             i += 8;
01504          }
01505          if (dsp_fmt == DSP_DEC)
01506             printf("%5.1i ", *((WORD *) pdata));
01507          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01508             printf("0x%4.4x ", *((WORD *) pdata));
01509          pdata = (char *) (((WORD *) pdata) + 1);
01510          j++;
01511          break;
01512       case TID_SHORT:
01513          if (j > 7) {
01514             printf("\n%4i-> ", i);
01515             j = 0;
01516             i += 8;
01517          }
01518          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01519             printf("%5.1i ", *((short *) pdata));
01520          if (dsp_fmt == DSP_HEX)
01521             printf("0x%4.4x ", *((short *) pdata));
01522          pdata = (char *) (((short *) pdata) + 1);
01523          j++;
01524          break;
01525       case TID_BYTE:
01526       case TID_STRUCT:
01527          if (j > 15) {
01528             printf("\n%4i-> ", i);
01529             j = 0;
01530             i += 16;
01531          }
01532          if (dsp_fmt == DSP_DEC)
01533             printf("%4.i ", *((BYTE *) pdata));
01534          if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
01535             printf("0x%2.2x ", *((BYTE *) pdata));
01536          pdata++;
01537          j++;
01538          break;
01539       case TID_SBYTE:
01540          if (j > 15) {
01541             printf("\n%4i-> ", i);
01542             j = 0;
01543             i += 16;
01544          }
01545          if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
01546             printf("%4.i ", *((BYTE *) pdata));
01547          if (dsp_fmt == DSP_HEX)
01548             printf("0x%2.2x ", *((BYTE *) pdata));
01549          pdata++;
01550          j++;
01551          break;
01552       case TID_BOOL:
01553          if (j > 15) {
01554             printf("\n%4i-> ", i);
01555             j = 0;
01556             i += 16;
01557          }
01558          (*((BOOL *) pdata) != 0) ? printf("Y ") : printf("N ");
01559          pdata = (char *) (((DWORD *) pdata) + 1);
01560          j++;
01561          break;
01562       case TID_CHAR:
01563       case TID_STRING:
01564          if (j > 15) {
01565             printf("\n%4i-> ", i);
01566             j = 0;
01567             i += 16;
01568          }
01569          if (dsp_fmt == DSP_DEC)
01570             printf("%3.i ", *((BYTE *) pdata));
01571          if (dsp_fmt == DSP_ASC || (dsp_fmt == DSP_UNK))
01572             printf("%1.1s ", (char *) pdata);
01573          if (dsp_fmt == DSP_HEX)
01574             printf("0x%2.2x ", *((BYTE *) pdata));
01575          pdata++;
01576          j++;
01577          break;
01578       default:
01579          printf("bank type not supported (%d)\n", type);
01580          return;
01581          break;
01582       }
01583    }                            /* end of bank */
01584    printf("\n");
01585    return;
01586 }

INT midas_event_get ( void **  pevent,
DWORD readn 
)

Definition at line 1010 of file mdsupport.c.

Referenced by md_event_get(), and midas_event_skip().

01012        : midas_event_get
01013 Purpose: read one MIDAS event.
01014 Will detect:
01015 The first pass in getting the record number being -1
01016 The last pass in checking the midas_physrec_get() readn
01017 being different then the my.size then flushing the current
01018 buffer until pointer goes beyond last event.
01019 Input:
01020 void ** pevent     points to MIDAS HEADER 
01021 Output:
01022 DWORD * readn      event size in bytes (MIDAS)
01023 Function value:
01024 MD_DONE           No more record to read
01025 MD_SUCCESS        Ok
01026 \********************************************************************/
01027 {
01028    INT status, leftover;
01029    DWORD fpart;
01030    static DWORD size = 0;
01031 
01032    /* save pointer */
01033    *pevent = (char *) my.pmh;
01034    if (size == 0)
01035       size = my.size;
01036 
01037    /* first time in get physrec once */
01038    if ((int) my.recn == -1) {
01039       status = midas_physrec_get((void *) my.pmp, &size);
01040       if (status != MD_SUCCESS)
01041          return (MD_DONE);
01042    }
01043 
01044   /*-PAA- Jul 12/2002
01045     if (((my.pmp+size) - (char *)my.pme) == 0)
01046         return (MD_DONE);
01047   */
01048 
01049    /* copy header only */
01050    if (((my.pmp + size) - (char *) my.pme) < (int) sizeof(EVENT_HEADER)) {
01051       fpart = (my.pmp + my.size) - (char *) my.pme;
01052       memcpy(my.pmh, my.pme, fpart);
01053       my.pmh = (EVENT_HEADER *) (((char *) my.pmh) + fpart);
01054       leftover = sizeof(EVENT_HEADER) - fpart;
01055       status = midas_physrec_get((void *) my.pmp, &size);
01056       if (status != MD_SUCCESS)
01057          return (MD_DONE);
01058       memset(my.pmp + size, -1, my.size - size);
01059       my.pme = (EVENT_HEADER *) my.pmp;
01060       memcpy(my.pmh, my.pme, leftover);
01061       my.pme = (EVENT_HEADER *) (((char *) my.pme) + leftover);
01062       my.pmh = (EVENT_HEADER *) * pevent;
01063    } else {
01064       memcpy(my.pmh, my.pme, sizeof(EVENT_HEADER));
01065       my.pme = (EVENT_HEADER *) (((char *) my.pme) + sizeof(EVENT_HEADER));
01066    }
01067    /* leave with pmh  to destination header
01068       pmrd to destination event (pmh+1)
01069       pme  to source event
01070     */
01071    my.pmrd = (char *) (my.pmh + 1);
01072 
01073    /* check for end of file */
01074    if (my.pmh->event_id == -1)
01075       return MD_DONE;
01076 
01077    /* copy event (without header) */
01078    leftover = my.pmh->data_size;
01079 
01080    /* check for block crossing */
01081    while (((my.pmp + size) - (char *) my.pme) < leftover) {
01082       fpart = (my.pmp + my.size) - (char *) my.pme;
01083       memcpy(my.pmrd, my.pme, fpart);
01084       my.pmrd += fpart;
01085       leftover -= fpart;
01086       status = midas_physrec_get((void *) my.pmp, &size);
01087       if (status != MD_SUCCESS)
01088          return (MD_DONE);
01089       memset(my.pmp + size, -1, my.size - size);
01090       my.pme = (EVENT_HEADER *) my.pmp;
01091    }
01092 
01093    /* copy left over or full event if no Xing */
01094    *readn = my.evtlen = my.pmh->data_size + sizeof(EVENT_HEADER);
01095    memcpy(my.pmrd, my.pme, leftover);
01096    my.pme = (EVENT_HEADER *) (((char *) my.pme) + leftover);
01097    my.evtn++;
01098    return MD_SUCCESS;
01099 }

INT midas_event_skip ( INT  evtn  ) 

Definition at line 628 of file mdsupport.c.

Referenced by md_physrec_skip().

00630        : midas_event_skip
00631 Purpose: skip event on a MIDAS file.
00632 Input:
00633 INT     evtn          event record number. (start at 0)
00634 if evt = -1 : skip skiping
00635 Output:
00636 none
00637 Function value:
00638 MD_SUCCESS        Ok
00639 \********************************************************************/
00640 {
00641    void *pevent;
00642    DWORD size;
00643 
00644    size = MAX_EVENT_SIZE;
00645    if (evtn == -1) {
00646       /*    if(midas_event_get(&pevent, &size) == MD_SUCCESS) */
00647       return MD_SUCCESS;
00648    }
00649    while (midas_event_get(&pevent, &size) == MD_SUCCESS) {
00650       if ((INT) my.evtn < evtn) {
00651          printf("Skipping event_# ... ");
00652          printf("%d \r", my.evtn);
00653          fflush(stdout);
00654       } else {
00655          printf("\n");
00656          return MD_SUCCESS;
00657       }
00658    }
00659    return MD_DONE;
00660 }

INT midas_physrec_get ( void *  prec,
DWORD readn 
)

Definition at line 1102 of file mdsupport.c.

Referenced by md_physrec_get(), and midas_event_get().

01104        : midas_physrec_get
01105 Purpose: read one physical record.from a MIDAS run
01106 This is a "fake" physical record as Midas is
01107 not block structured. This function is used for
01108 reading a my.size record size. The return readn if different
01109 then my.size, will indicate a end of run. An extra read will
01110 indicate an eof.
01111 
01112 Input:
01113 void * prec        pointer to the record
01114 Output:
01115 DWORD *readn       retrieve number of bytes
01116 Function value:
01117 MD_DONE            No more record to read
01118 MD_SUCCESS         Ok
01119 \********************************************************************/
01120 {
01121    INT status = 0;
01122 
01123    /* read one block of data */
01124    if (!my.zipfile) {
01125       status = md_dev_os_read(my.handle, my.type, prec, my.size, readn);
01126    } else {
01127 #ifdef HAVE_ZLIB
01128       *readn = gzread(filegz, (char *) prec, my.size);
01129       if (*readn <= 0)
01130          status = SS_FILE_ERROR;
01131       else
01132          status = SS_SUCCESS;
01133 #endif
01134    }
01135 
01136    if (status != SS_SUCCESS) {
01137       return (MD_DONE);
01138    } else {
01139       /* count blocks */
01140       my.recn++;
01141       return (MD_SUCCESS);
01142    }
01143 }


Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk