/*:>-------------------------------------------------------------------- **: FILE: mMvdIo.c **: HISTORY: **: 00jan93-v000a-hpl- Created by stic Version **: Id: idl.y,v 1.2 1998/02/03 22:21:05 dave Exp **:<------------------------------------------------------------------*/ #include "mMvdIo.h" #include void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...); #define NO_ERROR 0 /* used for message output with no error */ #define ERROR_NO_INIT 1 /* initialization call skipped */ #define LOUD 2 /* messages which are usually output */ #define QUIET 1 /* used for messages which are output at default setting */ #define SILENT 0 /* for messages which are usually not output */ #define DEFAULT_LEVEL 2 /* the default setting of LevelIo */ long mMvdIo_( TABLE_HEAD_ST *Io_h, DMVDIO_ST *Io ) { /*:>-------------------------------------------------------------------- **: ROUTINE: mMvdIo_ **: DESCRIPTION: Physics Analysis Module ANSI C template. **: This is an ANSI C Physics Analysis Module template **: automatically generated by stic from mMvdMess.idl. **: This is a simple messaging interface which allows the **: I/O from the MVD code to be increased or decreased **: using control parameters. **: AUTHOR: JPS -- John P. Sullivan, sullivan@lanl.gov **: ARGUMENTS: **: IN: **: dMvdIo - contains a control parameter to specify **: the amount of I/O which is desired. **: dMvdIo_h - header Structure for dMvdIo **: INOUT: **: OUT: **: RETURNS: STAF Condition Value **: Revision History **: Name Date Comment **: J.P.Sullivan 29-Jul-98 remove use of STAFCV_BAD return **:>------------------------------------------------------------------*/ short ierr,level; short itest; int jtest; float ftest; unsigned int unsignedi; char ctest; /* Sanity check of header for table "Io"... */ if( ( Io_h->maxlen <= 0 ) || ( Io_h->nok > Io_h->maxlen ) ){ /* we come here is the input table containing the "verbose" */ /* variable has not been filled before calling this routine. */ /* In that case, do the initialization to the default */ /* verbosity level=2. */ ierr=ERROR_NO_INIT; MvdMess_("mMvdIo",ierr,LOUD,"initialize"); return STAFCV_OK; /* should be STAFCV_BAD, but that crashes */ /* on linux */ } /*************************************************************/ /* If the input table contains some data, use this to */ /* set the output verbosity level via a call to MvdMess with */ /* the message set to "initialize". */ level = Io->verbose; MvdMess_("dMvdIo",NO_ERROR,level,"initialize"); return STAFCV_OK; } void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...) { /*:>-------------------------------------------------------------------- **: ROUTINE: MvdMess_ **: DESCRIPTION: This routine sends a message to the standard output **: if the "level" of the message is greater than or equal **: to the IoLevel which is set when this routine is **: initialized. **: This routine should be called once with the message **: "initialize" to set LevelIo before any other calls. **: WARNING: This routine will not work properly for messages **: containing a "%". **: **: AUTHOR: JPS -- John P. Sullivan, sullivan@lanl.gov **: **: ARGUMENTS: **: IN: **: name_of_function = should contain the name of the function **: which called this function. This is used **: as part of the output string to help **: identify the source of the message. This **: code does not check this this string is **: really the name of the calling function. **: **: ierror = the error code from the calling routine. **: If ierror=0, it is assumed that there is **: no "error", so its value is not output. **: Instead, the function assumes that some **: "informative" message is to be output and **: just sends the message without an error code. **: For the initialization call, this is ignored. **: **: level = The "level" of the message. A higher number **: means a more important message. The message **: is only send if level>=LevelIo. **: LevelIo is set by calling this routine with **: a message "initialize". **: **: message = a character string containing the message. **: The message can contain format strings like **: those used in printf (%f, %d, %s, %i). If **: The message contains these format strings, **: the a corresponding string of arguements **: (i.e. just like printf) is expected to **: follows. **: **: (optional) = there can be any number (including zero) **: of arguements which follow the message **: string. These should match the in number **: and type the format specifiers in the **: message. **: INOUT: **: OUT: **: RETURNS: nothing **:>------------------------------------------------------------------*/ static short LevelIo; /* Set at initialization, controls */ /* amount of output, a higher number */ /* means less output. */ static short FirstCall = 0; /* Used to see if this is the first */ /* call to this routine. */ size_t string_size; /* size of message string */ va_list arg_ptr; /* used in retrieving arguements from*/ /* the (variable length) series of */ /* arguements which follow "message" */ int num; /* the number of arguements following*/ /* message */ short i; /* loop index */ double temp; /* dummy variable */ char twochar[2]; /* for /n type commands */ /* check the length of the input string */ string_size = strlen(message); if ( string_size==10 && message[0]=='i' && message[1]=='n' && message[2]=='i' && message[3]=='t' && message[4]=='i' && message[5]=='a' && message[6]=='l' && message[7]=='i' && message[8]=='z' && message[9]=='e' ) { /* The following did not work on the pentium pro's, it worked on */ /* the hp's. The messier formulation above seems more robust */ /* if ( message=='initialize') { */ LevelIo=level; FirstCall=1; printf("\nMvdMess: Initialized via call from %s\n",name_of_function); printf("\t LevelIo=%d\n",LevelIo); return; } if (FirstCall==0) { LevelIo=DEFAULT_LEVEL; FirstCall=1; printf("\nMvdMess: called without being initialized from %s\n",name_of_function); printf("\t LevelIo set to default value= %d\n",LevelIo); } /***********************************************/ /* only print the message if level>=LevelIo */ /* only write the error code if it is non-zero */ if ( level 0 ) { va_end ( arg_ptr ); /* terminates access to variable length */ /* arguement list */ } printf ( "\n" ); /* end on a new line */ return; }