Esempio n. 1
0
static void semis_dbg(void)
{
    struct debug_xt *debug_xt_item, *debug_xt_up = NULL;

    /* If current semis is in our debug xt list, disable debug mode */
    debug_xt_item = debug_xt_list;
    while (debug_xt_item->next) {
        if (debug_xt_item->xt_semis == PC) {
            if (debug_xt_item->mode != DEBUG_MODE_STEPUP) {
                /* Handle the normal case */
                fstrncpy(xtname, lfa2nfa(debug_xt_item->xt_docol - sizeof(cell)), MAXNFALEN);
                printf_console("\n[ Finished %s ] ", xtname);

                /* Reset to step mode in case we were in trace mode */
                debug_xt_item->mode = DEBUG_MODE_STEP;
            } else {
                /* This word requires execution of the debugger "Up"
                 * semantics. However we can't do this here since we
                 * are iterating through the debug list, and we need
                 * to change it. So we do it afterwards.
                 */
                debug_xt_up = debug_xt_item;
            }
        }

        debug_xt_item = debug_xt_item->next;
    }

    /* Execute debugger "Up" semantics if required */
    if (debug_xt_up) {
        /* Only add the parent word if it is not within the trampoline */
        if (rstack[rstackcnt] != (cell)pointer2cell(&trampoline[1])) {
            del_debug_xt(debug_xt_up->xt_docol);
            add_debug_xt(findxtfromcell(rstack[rstackcnt]));

            fstrncpy(xtname, lfa2nfa(findxtfromcell(rstack[rstackcnt]) - sizeof(cell)), MAXNFALEN);
            printf_console("\n[ Up to %s ] ", xtname);
        } else {
            fstrncpy(xtname, lfa2nfa(findxtfromcell(debug_xt_up->xt_docol) - sizeof(cell)), MAXNFALEN);
            printf_console("\n[ Finished %s (Unable to go up, hit trampoline) ] ", xtname);

            del_debug_xt(debug_xt_up->xt_docol);
        }

        debug_xt_up = NULL;
    }

    PC = POPR();
}
Esempio n. 2
0
/** 
 * Get information about the alphanumeric characteristics of the active
 *   graphics device.
 *
 * This routine get the number of lines in the current terminal window
 *
 * @param nlines
 *   Number of text lines per screen
 *   Default output is 23 lines
 * @param erase
 *   Text to send to erase the terminal screen
 *   Set to all blanks if terminal can scroll
 * @param erase_s
 *   Length of \p erase
 *
 * @date   870217:  Changed name from getscreenatr.
 * @date   861020:  Original version.
 *
 */
void 
getalphainfo(int *nlines, char *erase, int erase_s)
{

        int nerr;
        int ncols;
        int i, n;
        display_t **dev;
        n   = gdm_get_ndevices();
        dev = gdm_get_devices();

	/* - Inquire about text values from appropriate graphics devies. */

        *nlines = -1;
        fstrncpy( erase, erase_s-1, " ", 1 );
        for(i = 0; i < n; i++) {
          if(dev[i]->on && dev[i]->get_alpha_info) {
            dev[i]->get_alpha_info(nlines, erase, erase_s);
          }
        }

        if(*nlines == -1) {
          zgwindowsize_(nlines, &ncols, &nerr);
          if(nerr) {
            *nlines = 23;
          }
        }
        return;

}
Esempio n. 3
0
// Strip a full filename of its filename, returning the path
fstring FUFileManager::StripFileFromPath(const fstring& filename)
{
	fchar fullPath[MAX_PATH + 1];
	fstrncpy(fullPath, filename.c_str(), MAX_PATH);
	fullPath[MAX_PATH] = 0;
	fchar* lastSlash = fstrrchr(fullPath, FC('/'));
	fchar* lastBackslash = fstrrchr(fullPath, FC('\\'));
	lastSlash = max(lastSlash, lastBackslash);
	if (lastSlash != NULL) *(lastSlash + 1) = 0;
	return fstring(fullPath);
}
Esempio n. 4
0
/** 
 * Get current graphics text justification
 *
 * @param khorz
 *    Horizontal text justificiation
 *    - 'LEFT' for left justification.
 *    - 'CENTER' for centered justification.
 *    - 'RIGHT' for right justification.
 * @param khorz_s
 *    Length of \p khorz and \p kvert
 * @param kvert
 *    Vertical text justificiation
 *    - 'BOTTOM' for bottom justification.
 *    - 'CENTER' for centered justification.
 *    - 'TOP' for TOP justification.
 *
 * @date   861017:  Original version.
 *
 */
void 
gettextjust(char *khorz,
            int khorz_s,
            char *kvert,
	    int kvert_s)
{
	if( cmgdm.ihjust == 1 ){
		fstrncpy( khorz, khorz_s-1, "LEFT", 4 );
	}
	else if( cmgdm.ihjust == 2 ){
		fstrncpy( khorz, khorz_s-1, "CENTER", 6 );
	}
	else{
		fstrncpy( khorz, khorz_s-1, "RIGHT", 5 );
	}

	if( cmgdm.ivjust == 1 ){
		fstrncpy( kvert, kvert_s-1, "BOTTOM", 6 );
	}
	else if( cmgdm.ivjust == 2 ){
		fstrncpy( kvert, kvert_s-1, "CENTER", 6 );
	}
	else{
		fstrncpy( kvert, kvert_s-1, "TOP", 3 );
	}

}
Esempio n. 5
0
/** 
 * Append alphanumberic string \p kalpha to current message
 *
 * \param kalpha
 *    Alphanumberic string to append to current message
 * \param kalpha_s
 *    Length of string \p kalpha
 *
 * \return Nothing
 *
 * \see indexb outmsg clrmsg
 * \see t_cmmsg.nlimsg
 * \see t_cmmsg.nchmsg
 * \see t_cmmsg.autoout
 * \see t_cmmsg.itpmsg
 * \see t_kmmsg.klimsg
 *
 * \date   900518:  Added logic to test for an empty string. 
 *                    This corrects a problem with VAX VMS version.
 * \date   890104:  Added automatic output mode coding.
 * \date   830916:  Original version.
 * \date   890104:  Documented/Reviewed
 */
void 
apcmsg(char *kalpha, 
       int   kalpha_s)
{
	int isave, nalpha, nchmax;
        char *s1;

	/* - Determine length of string without trailing blanks. */
	nalpha = indexb( kalpha,kalpha_s );

	/* - Decrease maximum length of first line of message to
	 *   allow room for a prefix to be added later when written. */

	nchmax = MCMSG;
	if( cmmsg.nlimsg == 1 )
	     nchmax = nchmax - 10;

	/* - Start new line of message if there is not enough room. */

	if( (cmmsg.nchmsg + nalpha + 1) > nchmax ){
	     if( cmmsg.nlimsg < MLIMSG ){
		cmmsg.nlimsg = cmmsg.nlimsg + 1;
	     }
	     else if( cmmsg.autoout ){
		outmsg();
		isave = cmmsg.itpmsg;
		clrmsg();
		cmmsg.itpmsg = isave;
	     }
	     else{
		fstrncpy( kmmsg.klimsg[cmmsg.nlimsg - 1], MCMSG, " ", 1 );
	     }
	     cmmsg.nchmsg = 0;
	}

	/* - Append alphanumeric string to current message line.
	 *   Include one trailing blank.  Update character counter. */


	if( nalpha > 0 ){
        s1 = strcut(kalpha, 1, nalpha);
	    subscpy( kmmsg.klimsg[cmmsg.nlimsg - 1], cmmsg.nchmsg,
		     cmmsg.nchmsg + nalpha + 1, MCMSG, s1);
        free(s1);
	}
	cmmsg.nchmsg = cmmsg.nchmsg + nalpha + 1;

	return;
}
Esempio n. 6
0
// Extract the file extension out of a filename
fstring FUFileManager::GetFileExtension(const fstring& _filename)
{
	fchar filename[MAX_PATH];
	fstrncpy(filename, _filename.c_str(), MAX_PATH);
	filename[MAX_PATH - 1] = 0;

	fchar* lastPeriod = fstrrchr(filename, '.');
	if (lastPeriod == NULL) return emptyFString;

	fchar* lastSlash = fstrrchr(filename, '/');
	fchar* lastBackslash = fstrrchr(filename, '\\');
	lastSlash = max(lastSlash, lastBackslash);
	if (lastSlash > lastPeriod) return emptyFString;

	fstrlower(lastPeriod + 1);	// [claforte] Untested on __PPU__, refer to definition of fstrlower.
	return fstring(lastPeriod + 1);
}
Esempio n. 7
0
static void docol_dbg(void)
{                               /* DOCOL */
    struct debug_xt *debug_xt_item;

    PUSHR(PC);
    PC = read_ucell(cell2pointer(PC));

    /* If current xt is in our debug xt list, display word name */
    debug_xt_item = debug_xt_list;
    while (debug_xt_item->next) {
        if (debug_xt_item->xt_docol == PC) {
            fstrncpy(xtname, lfa2nfa(PC - sizeof(cell)), MAXNFALEN);
            printf_console("\n: %s ", xtname);

            /* Step mode is the default */
            debug_xt_item->mode = DEBUG_MODE_STEP;
        }

        debug_xt_item = debug_xt_item->next;
    }

    dbg_interp_printk("docol_dbg: %s\n", cell2pointer(lfa2nfa(PC - sizeof(cell))));
}
Esempio n. 8
0
/** 
 * Convert an integer \p intgr into its ASCII equivalent
 * 
 * @param intgr 
 *    Integer to convert into a string
 * @param kintgr 
 *    Returned string
 *     If number cannot be converted then string is set to 'BADINPUT'
 * @param kintgr_s 
 *    Length of \p kintgr
 *
 * @date   800102:  Original version.
 *
 */
void 
cnvita(int  intgr, 
       char     *kintgr, 
       int       kintgr_s)
{
	char kfmt[9];
	int ncf, nck;

	/* - Determine length of character variable. */
	nck = (kintgr_s - 1);

	/* - Create format statement. */

	strcpy( kfmt, "%" );
        ncf = 1;
	if( nck <= 9 ){
                sprintf(kfmt+ncf,"%1d",nck);
                ncf++;
                		}
	else if( nck <= 99 ){
                sprintf(kfmt+ncf,"%2d",nck);
                ncf += 2;
		}
	else{
                sprintf(kfmt+ncf,"%3d",nck);
                ncf += 3;
		}
        strcpy(kfmt+ncf,"d");

	/* - Encode integer into string. */

        if( sprintf(kintgr,kfmt,intgr) < 0 ) {
           fstrncpy(kintgr, kintgr_s - 1,"BADINPUT",8);
	}
	return;
} 
Esempio n. 9
0
/* not necessary anymore because of truename */
COUNT ParseDosPath(BYTE * lpszFileName,
                   COUNT * pnDrive,
                   BYTE * pszDir,
                   BYTE * pszCurPath)
{
    COUNT nDirCnt,
          nPathCnt;
    BYTE *lpszLclDir,
         *pszBase = pszDir;

    /* Initialize the users data fields                             */
    *pszDir = '\0';
    lpszLclDir = 0;
    nDirCnt = nPathCnt = 0;

    /* Start by cheking for a drive specifier ...                   */
    if (DriveChar(*lpszFileName) && ':' == lpszFileName[1])
    {
        /* found a drive, fetch it and bump pointer past drive  */
        /* NB: this code assumes ASCII                          */
        if (pnDrive)
        {
            *pnDrive = *lpszFileName - 'A';
            if (*pnDrive > 26)
                *pnDrive -= ('a' - 'A');
        }
        lpszFileName += 2;
    }
    else
    {
        if (pnDrive)
        {
            *pnDrive = -1;
        }
    }

    lpszLclDir = lpszFileName;
    if (!PathSep(*lpszLclDir))
    {
        fstrncpy(pszDir, pszCurPath, PARSE_MAX - 1);        /*TE*/
        nPathCnt = fstrlen(pszCurPath);
        if (!PathSep(pszDir[nPathCnt - 1]) && nPathCnt < PARSE_MAX - 1) /*TE*/
            pszDir[nPathCnt++] = '\\';
        if (nPathCnt > PARSE_MAX)
            nPathCnt = PARSE_MAX;
        pszDir += nPathCnt;
    }

    /* Now see how long a directory component we have.              */
    while (NameChar(*lpszFileName)
            || PathSep(*lpszFileName)
            || '.' == *lpszFileName)
    {
        ++nDirCnt;
        ++lpszFileName;
    }

    /* Fix lengths to maximums allowed by MS-DOS.                   */
    if ((nDirCnt + nPathCnt) > PARSE_MAX - 1)     /*TE*/
        nDirCnt = PARSE_MAX - 1 - nPathCnt;

    /* Finally copy whatever the user wants extracted to the user's */
    /* buffers.                                                     */
    if (pszDir)
    {
        bcopy(lpszLclDir, pszDir, nDirCnt);
        pszDir[nDirCnt] = '\0';
    }

    /* Clean up before leaving                              */
    DosTrimPath(pszBase);

    /* Before returning to the user, eliminate any useless          */
    /* trailing "\\." since the path prior to this is sufficient.   */
    nPathCnt = strlen(pszBase);
    if (2 == nPathCnt)            /* Special case, root           */
    {
        if (!strcmp(pszBase, "\\."))
            pszBase[1] = '\0';
    }
    else if (2 < nPathCnt)
    {
        if (!strcmp(&pszBase[nPathCnt - 2], "\\."))
            pszBase[nPathCnt - 2] = '\0';
    }

    return SUCCESS;
}
Esempio n. 10
0
static void
do_source_dbg(struct debug_xt *debug_xt_item)
{
    /* Forth source debugger implementation */
    char k, done = 0;

    /* Display current dstack */
    display_dbg_dstack();
    printf_console("\n");

    fstrncpy(xtname, lfa2nfa(read_ucell(cell2pointer(PC)) - sizeof(cell)), MAXNFALEN);
    printf_console("%p: %s ", cell2pointer(PC), xtname);

    /* If in trace mode, we just carry on */
    if (debug_xt_item->mode == DEBUG_MODE_TRACE) {
        return;
    }

    /* Otherwise in step mode, prompt for a keypress */
    k = getchar_console();

    /* Only proceed if done is true */
    while (!done) {
        switch (k) {

        case ' ':
        case '\n':
            /* Perform a single step */
            done = 1;
            break;

        case 'u':
        case 'U':
            /* Up - unmark current word for debug, mark its caller for
             * debugging and finish executing current word */

            /* Since this word could alter the rstack during its execution,
             * we only know the caller when (semis) is called for this xt.
             * Hence we mark the xt as a special DEBUG_MODE_STEPUP which
             * means we run as normal, but schedule the xt for deletion
             * at its corresponding (semis) word when we know the rstack
             * will be set to its final parent value */
            debug_xt_item->mode = DEBUG_MODE_STEPUP;
            done = 1;
            break;

        case 'd':
        case 'D':
            /* Down - mark current word for debug and step into it */
            done = add_debug_xt(read_ucell(cell2pointer(PC)));
            if (!done) {
                k = getchar_console();
            }
            break;

        case 't':
        case 'T':
            /* Trace mode */
            debug_xt_item->mode = DEBUG_MODE_TRACE;
            done = 1;
            break;

        case 'r':
        case 'R':
            /* Display rstack */
            display_dbg_rstack();
            done = 0;
            k = getchar_console();
            break;

        case 'f':
        case 'F':
            /* Start subordinate Forth interpreter */
            PUSHR(PC - sizeof(cell));
            PC = findword("outer-interpreter") + sizeof(ucell);

            /* Save rstack position for when we return */
            dbgrstackcnt = rstackcnt;
            done = 1;
            break;

        default:
            /* Display debug banner */
            printf_console(DEBUG_BANNER);
            k = getchar_console();
        }
    }
}
Esempio n. 11
0
/** 
 * Get the current text output wait mode 
 * 
 * @param mode 
 *    - "ON" causes sac to pause and wait for the user to respond
 *             after a screen full of output has been generated
 *    - "OFF" causes sac to not pause
 * @param mode_s 
 *    Length of \p mode
 *
 * @bug Change \p mode to an int / enum
 *
 * @date   900410:  Original version.
 *
 */
void 
gettextwait (char *mode, 
             int mode_s) {
  fstrncpy( mode, mode_s-1, kmexm.ktextwait, strlen(kmexm.ktextwait));
  return;
}
Esempio n. 12
0
// Fill a cell with text - coltype can be title, text or combo
// returns TRUE if operation successful
BOOL ContainerFillTextCell(HWND hwndCnt, int linenum, int colnum, int type, int align, char *txt)
{
  LPFIELDINFO     lpFld;
  GENCNTR_COLUMN  column;
  LPRECORDCORE    hLine;

  //First column management
  DWORD           dwAlign;

  hLine = MakeHLineFromLineNum(hwndCnt, linenum);

  // check parameters
  if (type != CONT_COLTYPE_TEXT && type != CONT_COLTYPE_TITLE)
    return FALSE;

  // query lpFld from hline and colnum
  lpFld = QueryLpFld(hwndCnt, hLine, colnum);
  if (!lpFld)
    return FALSE;

  // special management for caption line
  if (hLine == CONT_FIRSTLINE_HANDLE) {

    // prepare align parameter
    switch (align) {
      case CONT_ALIGN_LEFT:
        dwAlign = CA_TA_LEFT;
        break;
      case CONT_ALIGN_RIGHT:
        dwAlign = CA_TA_RIGHT;
        break;
      default:
        dwAlign = CA_TA_HCENTER;
        break;
    }
    if (IsLastColumn(hwndCnt, colnum))
      dwAlign = CA_TA_LEFT;   //Force to left if last column
    CntFldTtlAlnSet(hwndCnt, lpFld, dwAlign);
    CntFldTtlSet(hwndCnt, lpFld, txt, x_strlen(txt)+1);
    return TRUE;
  }

  // extract data from cell
  if (!CntFldDataGet(hLine, lpFld, 0, (LPVOID)&column))
    return FALSE;

  // Update the data
  column.type = type;
  if (IsLastColumn(hwndCnt, colnum))
    column.align = CONT_ALIGN_LEFT;   //Force to left if last column
  else
    column.align = align;

  fstrncpy(column.ucol.s, txt, sizeof(column.ucol.s));

  // Load back data into the record.
  if (!CntFldDataSet(hLine, lpFld, 0, (LPVOID)&column))
    return FALSE;

  // Make the record being dispayed again
  // TO BE FINISHED

  return TRUE;
}
Esempio n. 13
0
/** 
 * Get an enumerated header value from the current SAC file
 * 
 * @param kname 
 *    Name of the header field to get
 * @param kvalue 
 *    Value of heade field from the current SAC data file
 *    Each value represents a specific condition
 * @param nerr 
 *    Error Return Flag
 *    - 0 on Success
 *    - ERROR_UNDEFINED_HEADER_FIELD_VALUE
 *    - 1337
 * @param kname_s 
 *    Length of \p kname
 * @param kvalue_s 
 *    Length of \p kvalye
 *
 * @date   870902:  Original version.
 *
 */
void 
getihv(char *kname, 
       char *kvalue, 
       int  *nerr, 
       int   kname_s, 
       int   kvalue_s) {

	char ktest[9];
	int index, ivalue, ntest;

	char *kname_c;
	int callFromC = 0;

	if(kname_s < 0) {
	  callFromC = 1;
	}

	kname_c = fstrdup(kname, kname_s);
	kname_s = strlen(kname_c) + 1;
	

	*nerr = 0;

	/* - Convert input name to uppercase and 
	 *   check versus list of legal names. */
	ntest = min( indexb( kname_c,kname_s ), SAC_HEADER_STRING_LENGTH_FILE );
	strcpy( ktest, "        " );
	modcase( TRUE, kname_c, ntest, ktest );
	index = nequal( ktest, (char*)kmlhf.kihdr,9, SAC_HEADER_ENUMS );

	/* - If legal name, return current value.
	 *   Otherwise, set error condition. */

	if( index > 0 ){
	    ivalue = Ihdr[index];
	    if( ivalue == cmhdr.iundef ){
    	        fstrncpy( kvalue, kvalue_s-1, "UNDEFINED", 9);
		*nerr = ERROR_UNDEFINED_HEADER_FIELD_VALUE;
	    }
	    else{
    	        fstrncpy( kvalue, kvalue_s-1, kmlhf.kiv[ivalue - 1],
                          strlen(kmlhf.kiv[ivalue - 1]) );
	    }
	}
	else{
    	    fstrncpy( kvalue, kvalue_s-1, "ILLEGAL", 7);
	    *nerr = 1337;
	}

	/* - Create error message and write to terminal. */

	if( *nerr != 0 ){
	    setmsg( "WARNING", *nerr );
	    apcmsg( kname_c,kname_s );
	    outmsg();
      clrmsg();
	}

	if(callFromC) { /* C String Termination */
        kvalue[ max(0,min(kvalue_s,8))] = 0;
        } else {        /* Fortran String Non-Termination by Spaces */
          if(kvalue_s > 8) {
            memset(kvalue + 8, ' ', kvalue_s - 8);
          }
        }

	free(kname_c);

	return;

}
Esempio n. 14
0
void 
xlinax() {
	char ktemp[9];
	int lpower;
	int ia, ib, igdlog, jdiv, jpower, jstep, jtick, 
	 mds, nds, ndsu, ntick, nxdivu;
	float divlog, divtry, factor, grdlog, power, skfudge, 
	 value, valuei, xdivu, xgrdmn, xgrdmx, xref, xrefi, xtick, xticki, 
	 xvpmax, xvpmin, yloc, ypow, yvpmax, yvpmin;
	static char kvalue[17] = "                ";
	static char kpower[9] = "        ";


	/*=====================================================================
	 * PURPOSE:  To produce a linearly-scaled axis at the bottom and/or
	 *           top of the current plot window.
	 *=====================================================================
	 * MODULE/LEVEL:  gem/4
	 *=====================================================================
	 * GLOBAL INPUT:
	 *    MACH:    VSMALL
	 *    GEM:     LXDIV, XDIV, LNXDIV, NXDIV, CHHT, CHWID, LXREV,
	 *             XPMNU, XPMXU, XIMNZ, XIMXZ,
	 *             LBOTAX, LBOTTC, LTOPAX, LTOPTC,
	 *             IHORZ, IVERT, XMPIP1, XMPIP2,
	 *             LXGRD, IXGRD, IWIDTH, ISKWIDTH, ITHIN, SKDEVFUDGE
	 *=====================================================================
	 * GLOBAL OUTPUT:
	 *    GEM:     AXWBOT, AXWTOP
	 *=====================================================================
	 * SUBROUTINES CALLED:
	 *    SACLIB:  CNVITA, LJUST, SETLINESTYLE, LINE, PLTEXT, CNVFTA, 
	 *             SETTEXTJUST, SETLINEWIDTH, GETVPORT
	 *=====================================================================
	 * LOCAL VARIABLES:
	 *    xdivu:   Divison spacing used.
	 *    lpower:  Set to .TRUE. if there is a multiplying scale factor.
	 *    power:   Multiplying scale factor.
	 *    kpower:  Character string containing formatted scale factor.
	 *    ypow:    Y location in plot coordinates of scale factor.
	 *    divtry:  Trial division spacing.
	 *    jstep:   Integer trial step size (constrained to be 10, 5 or 2).
	 *    xgrdmn:  Minimum labeled grid value (including scale factor).
	 *    xgrdmx:  Maximum labeled grid value (including scale factor).
	 *    value:   Labeled grid value excluding scale factor.
	 *    valuei:  Increment in VALUE.
	 *    kvalue:  Character string containing formatted label value.
	 *    xref:    Location of labeled grid value in plot coordinates.
	 *    xrefi:   Increment in XREF.
	 *=====================================================================
	 * ASSUMPTIONS:
	 * - plmap has set up world to plot coordiate mapping.
	 * - Text orientation is horizontal.
	 *=====================================================================
	 * MODIFICATION HISTORY:
	 *    920526:  Added line-width. TEXT is always line-width THIN!
	 *    830929:  Added secondary tick marks.
	 *    830927:  Moved grid drawing logic into its own do loop.
	 *    830223:  Fixed logic in computing annotation format.
	 *    820928:  Cleaned up and documented.
	 *    810120:  Original PRIME version.
	 *===================================================================== */
	/* PROCEDURE: */
         settextangle(TEXT_HORIZONTAL);

	/* - Determine division spacing.  There are three possibilities:
	 *   (1) The division spacing is set by user (LXDIV=.TRUE.).
	 *   (2) The (approximate) number of divsions is set (LNXDIV=.TRUE.).
	 *   (3) "Nice" division spacings are calculated. */
	if( cmgem.xdiv_spacing_on ){
          xdivu = cmgem.xdiv_spacing;
          power = log10( xdivu );
          if( power < 0. )
            power = power - 1.;
          jpower = power;
        } else {
          if( cmgem.xdiv_number_on ){
            nxdivu = cmgem.xdiv_number;
          } else {
            nxdivu = (fabs( cmgem.uplot.xmax - cmgem.uplot.xmin )/(FDIVSP*cmgem.chht)) + .001;
            if( nxdivu < 5 )
              nxdivu = 5;
          }
          divtry = (cmgem.zdata.xmax - cmgem.zdata.xmin)/nxdivu;
          if( divtry > 0. ){
            power = log10( divtry );
          } else {
            power = 0.;
          }
          if( power < 0. )
            power = power - 1.;
          jpower = power;
          
          /* -- Limit divison spacings to steps of 10, 5, or 2 [cases (2) and (3)]. */
          jstep = divtry*(powi(10.,-jpower));
          if( jstep > 5 ){
            jstep = 1;
            jpower = jpower + 1;
            /* power = power + 1.; */
          } else if( jstep > 2 ) {
            jstep = 5;
          } else {
            jstep = 2;
          }
          xdivu = jstep*(powi(10.,jpower));
        }

	/* - Determine "nice-numbered" starting and ending values. */

	ia = cmgem.zdata.xmin/xdivu;
	xgrdmn = xdivu*ia;
	if( xgrdmn < cmgem.zdata.xmin ){
		ia = ia + 1;
		xgrdmn = xgrdmn + xdivu;
		}
	ib = cmgem.zdata.xmax/xdivu;
	xgrdmx = xdivu*ib;
	if( xgrdmx > cmgem.zdata.xmax ){
		ib = ib - 1;
		xgrdmx = xgrdmx - xdivu;
		}
	nxdivu = ib - ia + 1;

	/* - Determine the format (Fn.m) of the labels.
	 *   The variable NDS assumes the role of "n" and MDS the role of "m". */

	/* - The "magic numbers" used in this algorithm  generate good division
	 *   spacings almost all of the time.  Modify them at your own risk. */

	grdlog = log10( fmax( fabs( xgrdmn ), fabs( xgrdmx ) ) + 0.001 );
	if( grdlog >= 0. ){
		grdlog = grdlog + 1.001;
		}
	else{
		grdlog = grdlog - 0.999;
		}
	divlog = log10( xdivu );
	if( divlog >= 0. ){
		divlog = divlog + 1.001;
		}
	else{
		divlog = divlog - 0.999;
		}
	lpower = FALSE;
	factor = 1.;
	if( grdlog*divlog >= 0. ){
		if( grdlog < 0. ){
			igdlog = grdlog;
			}
		else{
			igdlog = divlog;
			}
		if( labs( igdlog ) >= 3 && cmgem.lxpowr ){
			mds = 0;
			nds = max( 4, (int)( grdlog ) - (int)( divlog ) + 2 );
			cnvita( jpower, ktemp,9 );
			ljust( ktemp,9 );
			if( jpower >= 0 ){
                                fstrncpy( kpower, 8, "X 10+", 5);
                                fstrncpy( kpower+5, 8-5, ktemp, strlen(ktemp));
				}
			else{
                                fstrncpy( kpower, 8, "X 10", 4);
                                fstrncpy( kpower+4, 8-4, ktemp, strlen(ktemp));
				}
			factor = powi(10.,-jpower);
			lpower = TRUE;
			}
		else{
			mds = labs( minfi( 0., divlog ) );
			nds = maxfi( 1., grdlog );
			if( mds > 0 )
				nds = nds + mds + 2;
			}
		}
	else{
		mds = labs( minfi( 0., divlog ) );
		nds = maxfi( 0., grdlog );
		if( mds > 0 )
			nds = nds + mds + 2;
		}

	/* - Determine axes fudge factor for thick axes lines. */
	getvport( &xvpmin, &xvpmax, &yvpmin, &yvpmax );
	skfudge = cmgem.skdevfudge*((yvpmin - yvpmax)/(xvpmin - xvpmax));

	/* - Draw the bottom axis. */

	setlinestyle( LINE_STYLE_SOLID );
	setlinewidth( cmgem.iskwidth );

	if( cmgem.axis[BOTTOM].annotate || cmgem.axis[BOTTOM].ticks ){

		/* -- Bottom Axes line. */
		if( cmgem.iskwidth > LINE_WIDTH_THIN ){
			line( cmgem.uplot.xmin - cmgem.iskwidth*skfudge, cmgem.uplot.ymin, 
			 cmgem.uplot.xmax + cmgem.iskwidth*skfudge, cmgem.uplot.ymin );
			}
		else{
			line( cmgem.uplot.xmin, cmgem.uplot.ymin, cmgem.uplot.xmax, cmgem.uplot.ymin );
			}

		/* -- Label for multiplying scale factor. */
		if( lpower && cmgem.axis[BOTTOM].annotate ){
			ypow = fmax( cmgem.uplot.ymin - 2.2*cmgem.chht, 0.1*cmgem.chht );
			if( cmgem.lxrev ){
				settextjust( "RIGHT", "BOTTOM" );
				}
			else{
				settextjust( "LEFT", "BOTTOM" );
				}
			pltext( kpower,9, cmgem.uplot.xmin, ypow );
			setlinewidth( cmgem.iskwidth );
			}

		/* -- Calculate constants for labeled tick marks. */
		value = xgrdmn*factor;
		xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2;
		valuei = xdivu*factor;
		xrefi = xdivu*cmgem.xmpip1;
		strcpy( kvalue, "                " );

		/* -- Draw secondary tick marks before first labeled one. */
		ntick = 1;
		if( xrefi >= 0.10 ){
			ntick = 3;
			if( jstep == 5 )
				ntick = 4;
			}
		if( xrefi >= 0.25 )
			ntick = 9;
		xticki = xrefi/(float)( ntick + 1 );
		xtick = xref - xrefi;
		for( jtick = 1; jtick <= ntick; jtick++ ){
			xtick = xtick + xticki;
			if( xtick >= cmgem.uplot.xmin ){
				line( xtick, cmgem.uplot.ymin, xtick, cmgem.uplot.ymin + 
				 0.5*cmgem.chwid );
				}
			}

		/* -- Loop on labeled tick marks. */
		for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){
			line( xref, cmgem.uplot.ymin, xref, cmgem.uplot.ymin + 
			 cmgem.chwid );
			if( cmgem.axis[BOTTOM].annotate ){
				if( value >= 0 ){
					ndsu = nds;
					}
				else{
					ndsu = nds + 1;
					}
				cnvfta( value, ndsu, mds, kvalue,17 );
				ljust( kvalue,17 );
				yloc = cmgem.uplot.ymin - 0.1*cmgem.chht;
				settextjust( "CENTER", "TOP" );
				pltext( kvalue,17, xref, yloc );
				setlinewidth( cmgem.iskwidth );
				}
			/* --- Loop on secondary tick marks. */
			xtick = xref;
			for( jtick = 1; jtick <= ntick; jtick++ ){
				xtick = xtick + xticki;
				if( xtick <= cmgem.uplot.xmax ){
					line( xtick, cmgem.uplot.ymin, xtick, cmgem.uplot.ymin + 
					 0.5*cmgem.chwid );
					}
				}
			value = value + valuei;
			xref = xref + xrefi;
			}

		/* -- Save axes widths. */
		if( cmgem.axis[BOTTOM].annotate ){
			cmgem.axis[BOTTOM].width = 1.1*cmgem.chht;
			if( lpower )
				cmgem.axis[BOTTOM].width = cmgem.uplot.ymin - ypow;
			}
		else{
			cmgem.axis[BOTTOM].width = 0.;
			}

		}

	/* - Top axis: */

	if( cmgem.axis[TOP].annotate || cmgem.axis[TOP].ticks ){

		/* -- Top Axes line. */
		if( cmgem.iskwidth > LINE_WIDTH_THIN ){
			line( cmgem.uplot.xmin - cmgem.iskwidth*skfudge, cmgem.uplot.ymax, 
			 cmgem.uplot.xmax + cmgem.iskwidth*skfudge, cmgem.uplot.ymax );
			}
		else{
			line( cmgem.uplot.xmin, cmgem.uplot.ymax, cmgem.uplot.xmax, cmgem.uplot.ymax );
			}

		/* -- Label for multiplying scale factor. */
		if( lpower && cmgem.axis[TOP].annotate ){
			ypow = fmin( cmgem.uplot.ymax + 2.2*cmgem.chht, cmgem.view.ymax - 
			 0.1*cmgem.chht );
			if( cmgem.lxrev ){
				settextjust( "RIGHT", "TOP" );
				}
			else{
				settextjust( "LEFT", "TOP" );
				}
			pltext( kpower,9, cmgem.uplot.xmin, ypow );
			setlinewidth( cmgem.iskwidth );
			}

		/* -- Calculate constants for labeled tick marks. */
		value = xgrdmn*factor;
		xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2;
		valuei = xdivu*factor;
		xrefi = xdivu*cmgem.xmpip1;
		strcpy( kvalue, "                " );

		/* -- Draw secondary tick marks before first labeled one. */
		ntick = 1;
		if( xrefi >= 0.10 ){
			ntick = 3;
			if( jstep == 5 )
				ntick = 4;
			}
		if( xrefi >= 0.25 )
			ntick = 9;
		xticki = xrefi/(float)( ntick + 1 );
		xtick = xref - xrefi;
		for( jtick = 1; jtick <= ntick; jtick++ ){
			xtick = xtick + xticki;
			if( xtick >= cmgem.uplot.xmin ){
				line( xtick, cmgem.uplot.ymax, xtick, cmgem.uplot.ymax - 
				 0.5*cmgem.chwid );
				}
			}

		/* -- Loop on labeled tick marks. */
		for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){
			line( xref, cmgem.uplot.ymax, xref, cmgem.uplot.ymax - 
			 cmgem.chwid );
			if( cmgem.axis[TOP].annotate ){
				if( value >= 0. ){
					ndsu = nds;
					}
				else{
					ndsu = nds + 1;
					}
				cnvfta( value, ndsu, mds, kvalue,17 );
				ljust( kvalue,17 );
				yloc = cmgem.uplot.ymax + 0.1*cmgem.chht;
				settextjust( "CENTER", "BOTTOM" );
				pltext( kvalue,17, xref, yloc );
				setlinewidth( cmgem.iskwidth );
				}
			/* --- Loop on secondary tick marks. */
			xtick = xref;
			for( jtick = 1; jtick <= ntick; jtick++ ){
				xtick = xtick + xticki;
				if( xtick <= cmgem.uplot.xmax ){
					line( xtick, cmgem.uplot.ymax, xtick, cmgem.uplot.ymax - 
					 0.5*cmgem.chwid );
					}
				}
			value = value + valuei;
			xref = xref + xrefi;
			}

		/* -- Save axes widths. */
		if( cmgem.axis[TOP].annotate ){
			cmgem.axis[TOP].width = 1.1*cmgem.chht;
			if( lpower )
				cmgem.axis[TOP].width = ypow - cmgem.uplot.ymax;
			}
		else{
			cmgem.axis[TOP].width = 0.;
			}

		}

	/* - Grid lines. */

	if( cmgem.lxgrd ){
		setlinewidth( LINE_WIDTH_THIN );
		xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2;
		xrefi = xdivu*cmgem.xmpip1;
		setlinestyle( cmgem.ixgrd );
		for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){
			line( xref, cmgem.uplot.ymin, xref, cmgem.uplot.ymax );
			xref = xref + xrefi;
			}
		setlinestyle( LINE_STYLE_SOLID );
		setlinewidth( cmgem.iskwidth );
		}

       

	return;

} /* end of function */
Esempio n. 15
0
CfgError Config::ReadConfig(const char *file)
{
	FILE *fp = fopen(file, "rt");

	if (!fp)
		return Config_NoFile;

	cfghook *pHook;
	List<cfghook *>::iterator iter;

	char buffer[255];
	char section[32] = {0};
	String temp;
	size_t length = 0;
	const char *ptr;
	while (!feof(fp))
	{
		buffer[0] = '\0';
		fgets(buffer, sizeof(buffer)-1, fp);
		if (buffer[0] == '\0' || buffer[0] == '\n')
			continue;
		if (buffer[0] == ';' || (buffer[0] == '\\' || buffer[1] == '\\'))
			continue;
		length = strlen(buffer);
		if (buffer[length-1] == '\n')
			buffer[--length] = '\0';
		temp.assign(buffer);
		temp.trim();
		if (temp.size() < 1)
			continue;
		ptr = temp.c_str();
		if (ptr[0] == '[')
		{
			size_t pos = 0;
			//quick state machine!11 :o
			for (size_t i=1; i<length; i++)
			{
				if (ptr[i] == ']')
					pos = i;
			}
			if (pos < 2)
				continue;		//invalid almost-section
			if (section[0] != '\0')
			{
				for (iter=m_Hooks.begin(); iter!=m_Hooks.end(); iter++)
				{
					pHook = (*iter);
					if (pHook->section.compare(section)==0)
						MF_ExecuteForward(pHook->forward, (cell)CFG_DONE, "", section);
				}
			}
			fstrncpy(section, &(ptr[1]), pos-1);
			for (iter=m_Hooks.begin(); iter!=m_Hooks.end(); iter++)
			{
				pHook = (*iter);
				if (pHook->section.compare(section)==0)
					MF_ExecuteForward(pHook->forward, (cell)CFG_RELOAD, "", section);
			}
		} else if (section[0] != '\0') {
			for (iter=m_Hooks.begin(); iter!=m_Hooks.end(); iter++)
			{
				pHook = (*iter);
				if (pHook->section.compare(section)==0)
					MF_ExecuteForward(pHook->forward, (cell)CFG_READ, ptr, section);
			}
		}
	}

	if (section[0] != '\0')
	{
		for (iter=m_Hooks.begin(); iter!=m_Hooks.end(); iter++)
		{
			pHook = (*iter);
			if (pHook->section.compare(section)==0)
				MF_ExecuteForward(pHook->forward, (cell)CFG_DONE, "", section);
		}
	}

	fclose(fp);

	return Config_Ok;
}
Esempio n. 16
0
/** 
 * Write a File to disk
 * 
 * @param lsdd 
 *    Set the Output to be a SDD file
 * @param nerr 
 *    Error Return Flag 
 *    - 0 on Success
 *
 * @date   970702:  Changed lckey and lkchar to lckeyExact and lkcharExact
 *                  throughout xw.c.  This will allow files to begin with 
 *                  the same string as the various options (eg. sacxz.021.z)
 *                  maf.
 * @date   910731:  Bug fixed in options PREPEND, DELETE, CHANGE.
 * @date   900904:  Added SDD as a format for write.
 * @date   881228:  Added four new options for generating write file list
 *                  from data file list: APPEND, PREPEND, CHANGE, DELETE.
 * @date   880204:  Fixed logic involving use of DIR option in READ and WRITE
 *                  by adding an ON/OFF flag as well as a directory name.
 * @date   880115:  Deleted call that forced default directory to lowercase.
 * @date   870626:  Added default directory option.
 * @date   860917:  Changed to character lists for storing data file names.
 * @date   850730:  Deleted SOCKITTOME  format.
 * @date   830120:  Added SOCK and CI output formats.
 * @date   820721:  Changed to newest set of parsing and checking functions.
 * @date   810120:  Changed to output message retrieval from disk.
 * @date   810203:  Fixed bug in file overwrite option.
 *
 */
void 
xw(int  lsdd, 
   int *nerr) {

    int i;
        char delimiter[2], kcdir[9], kchange[MCPFN+1], kdirpart[MCPFN+1];
	char kfile[MCPFN+1], kpdir[9], kstring[MCPFN+1], ktemp[9];
	int lexpnd;
	int jdfl, nchange, nchar, nchg, ndx1, ndx2;
	int nlen, nstr, nstring, nwrdir;
	static int lwrdir = FALSE;
    char *cattemp;
    char *strtemp1, *strtemp2, *strtemp3;
    
    char *file;
    string_list *list, *files;

	kschan[12]='\0';
	kschdr[80]='\0';
	ksclas[4]='\0';
	kscom[40]='\0';
	ksevnm[8]='\0';
	ksfrmt[8]='\0';
	ksstnm[8]='\0';
    memset(kfile, 0, sizeof(kfile));
    memset(kdirpart, 0, sizeof(kdirpart));
    memset(kchange, 0, sizeof(kchange));
    memset(ktemp, 0, sizeof(ktemp));
    memset(kstring, 0, sizeof(kstring));
    memset(kpdir, 0, sizeof(kpdir));
    memset(kcdir, 0, sizeof(kcdir));
    memset(delimiter, 0, sizeof(delimiter));

        lexpnd = FALSE;

	*nerr = 0;

    files = string_list_init();
    list  = NULL;

	if( lsdd )
	    cmdfm.iwfmt = 3;

	/* PARSING PHASE: */
	/* - Loop on each token in command: */
	while ( lcmore( nerr ) ){

	    /* -- "SAC|ALPHA":  set format to be used in writing files. */
	    if( lckeyExact( "SAC#$",6 ) )
		cmdfm.iwfmt = 1;

	    else if( lckeyExact( "ALPHA#$",8 ) )
		cmdfm.iwfmt = 2;

	    else if( lckeyExact( "CI#$",5 ) )
		cmdfm.iwfmt = 2;

	    else if( lckeyExact( "SDD#$",6 ) )
		cmdfm.iwfmt = 3;

	    else if( lckeyExact( "XDR#$",6 ) ) {
		cmdfm.iwfmt = 4;
            }
            else if( lckeyExact( "SEGY#$", 7 ) )
                cmdfm.iwfmt = 5;

	    /* -- "OVER":  overwrite files from previous READ command. */
	    else if( lckeyExact( "OVER#$",7 ) ){
		cmdfm.lovrrq = TRUE;
		lexpnd = FALSE;
        string_list_extend(files, datafiles);
	    }

	    /* generate names from the KSTCMP header field */
	    else if( lckeyExact( "KSTCMP#$",9 ) ){
		lexpnd = FALSE;
		gennames("KSTCMP ",7,files,string_list_length(datafiles),nerr);
		if(*nerr != 0)
		    goto L_8888;
	    }

	    /* -- "APPEND string": append string to filenames from READ command. */
	    else if( lkcharExact( "APPEND#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){
        for(i = 0; i < cmdfm.ndfl; i++) {
            strtemp1 = string_list_get(datafiles, i);
		    appendstring( kstring,MCPFN+1, strtemp1, strlen(strtemp1)+2, kfile,MCPFN+1 );

            string_list_put(files, kfile, MCPFN+1);
		    if( *nerr != 0 )
                goto L_8888;
		}
		cmdfm.lovrrq = FALSE;
		lexpnd = TRUE;
	    }

	    /* -- "PREPEND string": prepend string to filenames from READ command. */
	    else if( lkcharExact( "PREPEND#$",10, MCPFN, kstring,MCPFN+1, &nstring ) ){
        for(i = 0; i < cmdfm.ndfl; i++) {
		    strtemp1 = malloc(nstring+1);
		    strncpy(strtemp1,kstring,nstring);
		    strtemp1[nstring] = '\0';
            strtemp2 = string_list_get(datafiles, i);
		    prependstring( strtemp1, nstring+1, strtemp2, strlen(strtemp2)+2, kfile,MCPFN+1);

		    free(strtemp1);
            string_list_put(files, kfile, MCPFN+1);
		    if( *nerr != 0 )
			goto L_8888;
		}
		cmdfm.lovrrq = FALSE;
		lexpnd = TRUE;
	    }

	    /* -- "DELETE string": delete string from filenames from READ command. */
	    else if( lkcharExact( "DELETE#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){
        for(i = 0; i < cmdfm.ndfl; i++) {
		    strtemp1 = malloc(nstring+1);
		    strncpy(strtemp1,kstring,nstring);
		    strtemp1[nstring] = '\0';
            strtemp2 = string_list_get(datafiles, i);

		    deletestring( strtemp1, nstring+1, strtemp2, strlen(strtemp2)+2, kfile,MCPFN+1);

		    free(strtemp1);
            string_list_put(files, kfile, MCPFN+1);
		    if( *nerr != 0 )
			goto L_8888;
		}
		cmdfm.lovrrq = FALSE;
		lexpnd = TRUE;
	    }

	    /* -- "CHANGE string1 string2": change string1 to string2 in READ filenames. */
	    else if( lkcharExact( "CHANGE#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){
		lcchar( MCPFN, kchange,MCPFN+1, &nchange );
        for(i = 0; i < cmdfm.ndfl; i++) {
		    nstr = indexb( kstring,MCPFN+1 );
		    nchg = indexb( kchange,MCPFN+1 );

		    strtemp1 = malloc(nstr+1);
		    strtemp2 = malloc(nchg+1);
		    strncpy(strtemp1,kstring,nstr);
		    strncpy(strtemp2,kchange,nchg);
		    strtemp1[nstr] = '\0';
		    strtemp2[nchg] = '\0';
            strtemp3 = string_list_get(datafiles, i);
		    changestring( strtemp1, nstr+1, strtemp2, nchg+1,
                          strtemp3, strlen(strtemp3)+2, kfile,MCPFN+1 );

		    free(strtemp1);            
		    free(strtemp2);

            string_list_put(files, kfile, MCPFN+1);
		    if( *nerr != 0 )
			goto L_8888;
		}
		cmdfm.lovrrq = FALSE;
		lexpnd = TRUE;
	    }

	    /* -- "DIR ON|OFF|CURRENT|name":  set the name of the default subdirectory. */
	    else if( lkcharExact( "DIR#$",6, MCPFN, kmdfm.kwrdir,MCPFN+1, &nchar ) ){
		modcase( TRUE, kmdfm.kwrdir, MCPW, ktemp );

		if( strncmp(ktemp,"OFF     ",8) == 0 ) {
          lwrdir = FALSE;
        } else if( strncmp(ktemp,"CURRENT ",8) == 0 ){
          lwrdir = TRUE;
          fstrncpy( kmdfm.kwrdir, MCPFN, " ", 1);
		} else if( kmdfm.kwrdir[nchar - 1] != KDIRDL ){ 
          /* If the string is mising the "/" path separator */
          lwrdir = TRUE;
          delimiter[0] = KDIRDL;
          delimiter[1] = '\0';
          subscpy( kmdfm.kwrdir, nchar, -1, MCPFN, delimiter );
		} else {
          /* Path is not OFF, CURRENT and has the "/" at the end */
          lwrdir = TRUE;
	    }
        }
	    /* -- "COMMIT|RECALLTRACE|ROLLBACK": 
	          how to treat existing data */
	    else if ( lckeyExact ( "COMMIT" , 7 ) )
		cmdfm.icomORroll = COMMIT ;
	    else if (lckeyExact ( "RECALLTRACE" , 12 ) )
		cmdfm.icomORroll = RECALL ;
	    else if ( lckeyExact ( "RECALL" , 7 ) )
		cmdfm.icomORroll = RECALL ;
	    else if ( lckeyExact ( "ROLLBACK" , 9 ) ) 
		cmdfm.icomORroll = ROLLBACK ;


	    /* -- "filelist":  write files using names in new filelist. */
	    else if( ( list = lcdfl() ) ){
		cmdfm.lovrrq = FALSE;
		lexpnd = FALSE;
	    }

	    /* -- Bad syntax. */
	    else{
		cfmt( "ILLEGAL OPTION:",17 );
		cresp();
	    }
	} /* end while ( lcmore( nerr ) ) */

	/* - The above loop is over when one of two conditions has been met:
	 *   (1) An error in parsing has occurred.  In this case NERR is > 0 .
	 *   (2) All the tokens in the command have been successfully parsed. */

	if( *nerr != 0 )
	    goto L_8888;

	/* CHECKING PHASE: */
    if(!list) {
        list = files;
    } else {
        /* List + Modifiers :: Use List */
        string_list_free(files);
        files = NULL;
    }

	/* - Check for null write filelist. */
	if( string_list_length(list) <= 0 ){
	    *nerr = 1311;
	    setmsg( "ERROR", *nerr );
	    goto L_8888;
	}

	/* - Make sure the write filelist has as many entries as read filelist. */

	if( string_list_length(list) != cmdfm.ndfl ){
	    *nerr = 1312;
        error(1312, "%d %d", string_list_length(list), cmdfm.ndfl);
	    goto L_8888;
	}

	/* EXECUTION PHASE: */

        /* - Commit or rollback data according to cmdfm.icomORroll */
	alignFiles ( nerr ) ;
	if ( *nerr )
	    return ;


	/* - Echo expanded filelist if requested. */

	if( cmdfm.lechof && lexpnd ){
	    setmsg( "OUTPUT", 0 );

        for(i = 0; i < string_list_length(list); i++) {
            file = string_list_get(list, i);

            getdir( file, strlen(file)+1, kcdir,9, kfile,MCPFN+1 );

		/* -- Echo the filename part if there is no directory part. */
            if( strcmp(kcdir,"        ") == 0 )
                apcmsg( kfile,MCPFN+1 );

		/* -- Prepend the filename part with some special characters if
         *    directory part is same as that of the previous file. */
            else if( memcmp(kcdir,kpdir,min(strlen(kcdir),strlen(kpdir)))
                     == 0 ){
                cattemp = malloc(3+strlen(kfile)+1);
                strcpy(cattemp, "...");
                strcat(cattemp,kfile);
                apcmsg( cattemp, 3+strlen(kfile)+1 );
                free(cattemp);
            }
		/* -- Echo complete pathname if directory part is different. */
            else{
                apcmsg2(file, strlen(file)+1);
                strcpy( kpdir, kcdir );
            }
	    }
	    wrtmsg( MUNOUT );
	}

	/* - Write each file in memory to disk. */

	nwrdir = indexb( kmdfm.kwrdir,MCPFN+1 );
	for( jdfl = 1; jdfl <= cmdfm.ndfl; jdfl++ ){
	    /* -- Get file from memory manager. */
        file = string_list_get(list, jdfl-1);
	    getfil( jdfl, TRUE, &nlen, &ndx1, &ndx2, nerr );
	    if( *nerr != 0 )
		goto L_8888;

	    /* isolate file name */
        file = string_list_get(list, jdfl-1);

	    /* -- Check overwrite-protect flag in header record. */
	    if( cmdfm.lovrrq && !*lovrok ){
		*nerr = 1303;
		setmsg( "ERROR", *nerr );
		apcmsg2(file, strlen(file)+1);
		outmsg () ;
		clrmsg () ;
		goto L_8888;
	    }

	    /* -- Prepare output file name:
	     * --- If directory option is ON (lwrdir=.TRUE. and nwrdir>0), 
	     *     concatenate directory name with file name part of write file list.
	     * --- If directory option is CURRENT (lwrdir=.TRUE. and nwrdir=0), 
	     *     use file name part of write file list.
	     * --- If directory option is OFF, use write file list. */
	    if( lwrdir ){
		if( nwrdir > 0 ){
		    fstrncpy( kfile, MCPFN, kmdfm.kwrdir,min(nwrdir,MCPFN));

            strtemp1 = file;
		    strtemp2 = malloc(130-(nwrdir+1));
		    strncpy(strtemp2,kfile+nwrdir,MCPFN+1-(nwrdir + 1));
		    strtemp2[MCPFN+1-(nwrdir+1)] = '\0';
		    getdir( strtemp1, strlen(strtemp1)+1, 
                    kdirpart, MCPFN+1, strtemp2,-(nwrdir+1)+130);
		    subscpy(kfile,nwrdir,-1,MCPFN,strtemp2);
		    free(strtemp2);
		}
		else{
		    fstrncpy( kfile, MCPFN, " ", 1);
		    getdir( file, strlen(file)+1, kdirpart,MCPFN+1, kfile,MCPFN+1 );
		}
	    }
	    else {
            fstrncpy( kfile, MCPFN, file, strlen(file));
        }
	    /* -- Write file in appropriate format. */
	    if( cmdfm.iwfmt == 2 )
		wrci( jdfl, kfile,MCPFN+1, "%#15.7g", nerr );

	    else if( cmdfm.iwfmt == 3 )
		wrsdd( jdfl, kfile,MCPFN+1, TRUE, nerr );

	    else if( cmdfm.iwfmt == 4 )
		wrxdr( jdfl, kfile,MCPFN+1, TRUE, nerr );

	    else if( cmdfm.iwfmt == 5 )
		wrsegy( jdfl , kfile , nerr ) ;

	    else
		wrsac( jdfl, kfile,MCPFN+1, TRUE, nerr );

	    if( *nerr != 0 )
		goto L_8888;

	} /* end for ( jdfl ) */

L_8888:
	return;
}
Esempio n. 17
0
static int  DOMNodeRefresh (
						time_t refreshtime,
						int hnodestruct,
						int iobjecttype,
						void * pstartoflist,
						int level,
						LPUCHAR * parentstrings,
						void * pdispwind,
						BOOL bParentRefreshed,
						BOOL *pbRefreshAll,
						BOOL *pbRefreshMon,
						BOOL bShouldTestOnly,
						BOOL * pbAnimRefreshRequired,
						BOOL bFromAnimation,
						HWND hwndAnimation)

{
   int   i, ires;
   void ** pptemp;
   struct ServConnectData * pdata1 = virtnode[hnodestruct].pdata;
   LPDOMREFRESHPARAMS pRefreshParams;
   UCHAR Parents[MAXPLEVEL][MAXOBJECTNAME];
   LPUCHAR Parents4Call[MAXPLEVEL];
   UCHAR bufObjectWithOwner[MAXOBJECTNAME];
   BOOL bwithsystem;
   BOOL bLocalParentRefreshed;

   bShouldTestOnly = TRUE;

   for (i=0;i<level;i++) {
      fstrncpy(Parents[i], parentstrings[i], MAXOBJECTNAME);
   }
   for (i=0;i<MAXPLEVEL;i++) {
      Parents4Call[i] = Parents[i];
   }
   
   ires = RES_SUCCESS;


   switch (iobjecttype) {

      case OT_VIRTNODE  :
         {
            int itype[]={OT_DATABASE,
                         OT_MON_SERVER,
                         OT_MON_LOCKLIST,
                         OTLL_MON_RESOURCE,
                         OT_MON_LOGPROCESS,    
                         OT_MON_LOGDATABASE,   
                         OT_MON_TRANSACTION};
            if (!pdata1)
               return RES_SUCCESS;
            for (i=0;i<sizeof(itype)/sizeof(int);i++) {
               switch (itype[i]){
                  case OT_DATABASE:
                     pRefreshParams = &(pdata1->DBRefreshParms);
                     pptemp         = (void **) &(pdata1->lpDBData);
                     bwithsystem    =  pdata1->HasSystemDB;
                     break;
                  case OT_MON_SERVER        :
                     pRefreshParams = &(pdata1->ServerRefreshParms);
                     pptemp         = (void **) &(pdata1->lpServerData);
                     bwithsystem    =  pdata1->HasSystemServers;
                     break;
                  case OT_MON_LOCKLIST      :
                     pRefreshParams = &(pdata1->LockListRefreshParms);
                     pptemp         = (void **) &(pdata1->lpLockListData);
                     bwithsystem    =  pdata1->HasSystemLockLists;
                     break;
                  case OTLL_MON_RESOURCE      :
                     pRefreshParams = &(pdata1->ResourceRefreshParms);
                     pptemp         = (void **) &(pdata1->lpResourceData);
                     bwithsystem    =  pdata1->HasSystemResources;
                     break;
                  case OT_MON_LOGPROCESS    :
                     pRefreshParams = &(pdata1->LogProcessesRefreshParms);
                     pptemp         = (void **) &(pdata1->lpLogProcessData);
                     bwithsystem    =  pdata1->HasSystemLogProcesses;
                     break;
                  case OT_MON_LOGDATABASE   :
                     pRefreshParams = &(pdata1->LogDBRefreshParms);
                     pptemp         = (void **) &(pdata1->lpLogDBData);
                     bwithsystem    =  pdata1->HasSystemLogDB;
                     break;
                  case OT_MON_TRANSACTION:
                     pRefreshParams = &(pdata1->LogTransactRefreshParms);
                     pptemp         = (void **) &(pdata1->lpLogTransactData);
                     bwithsystem    =  pdata1->HasSystemLogTransact;
                     break;
                  default:
                     return RES_ERR;
               }
               bLocalParentRefreshed=FALSE;
               if (*pptemp) {
                  if (DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
					if (bShouldTestOnly) {
						*pbAnimRefreshRequired = TRUE;
						return RES_SUCCESS;
					}
                  }
               }
               DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                               level,Parents4Call, pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
							   bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
            }
         }
         break;
      case OT_DATABASE  :
         {
            struct DBData * pDBData = (struct DBData * )pstartoflist;
            int itype[]={OT_TABLE,
						 OT_MON_REPLIC_SERVER};
            
            while (pDBData) {
               fstrncpy(Parents[0],pDBData->DBName,MAXOBJECTNAME);
               for (i=0;i<sizeof(itype)/sizeof(int);i++) {
                   switch (itype[i]){
                      case OT_TABLE:
                         pRefreshParams = &(pDBData->TablesRefreshParms);
                         pptemp         = (void **) &(pDBData -> lpTableData);
                         bwithsystem    =  pDBData->HasSystemTables;
                         break;
					  case OT_MON_REPLIC_SERVER:
                         pRefreshParams =&(pDBData->MonReplServerRefreshParms);
                         pptemp = (void **) &(pDBData -> lpMonReplServerData);
                         bwithsystem    =  pDBData->HasSystemMonReplServers;
                         break;
                      default:
                         return RES_ERR;
                  }
                  bLocalParentRefreshed=FALSE;
                  if (*pptemp) {
                     if (DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
						if (bShouldTestOnly) {
							*pbAnimRefreshRequired = TRUE;
							return RES_SUCCESS;
						}
                     }
                  }
                  DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                                  1,Parents4Call, pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
								  bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
               }
               pDBData=pDBData->pnext;
            }
         }
         break;
      case OT_MON_SESSION       :
      case OT_MON_LOCK          :
      case OT_MON_RES_LOCK      :
      case OT_MON_LOGPROCESS    :
      case OT_MON_LOGDATABASE   :
      case OT_MON_TRANSACTION   :
      case OT_MON_REPLIC_SERVER :
      case OTLL_MON_RESOURCE    :
      case OT_MON_ICE_CONNECTED_USER:
      case OT_MON_ICE_ACTIVE_USER   :
      case OT_MON_ICE_TRANSACTION   :
      case OT_MON_ICE_CURSOR        :
      case OT_MON_ICE_FILEINFO      :
      case OT_MON_ICE_DB_CONNECTION :
      case OT_ICE_ROLE:
      case OT_ICE_DBUSER:
      case OT_ICE_DBCONNECTION:
      case OT_ICE_SERVER_APPLICATION:
      case OT_ICE_SERVER_LOCATION:
      case OT_ICE_SERVER_VARIABLE:
      case OT_ICE_BUNIT_SEC_ROLE:
      case OT_ICE_BUNIT_SEC_USER:
      case OT_ICE_BUNIT_LOCATION:
      case OT_ICE_WEBUSER_ROLE:
      case OT_ICE_WEBUSER_CONNECTION:
      case OT_ICE_PROFILE_ROLE:
      case OT_ICE_PROFILE_CONNECTION:
      case OT_ICE_BUNIT_FACET_ROLE  :
      case OT_ICE_BUNIT_FACET_USER  :
      case OT_ICE_BUNIT_PAGE_ROLE   :
      case OT_ICE_BUNIT_PAGE_USER   :
         return RES_SUCCESS; // no children
         break;
      case OT_USER  :
         return RES_SUCCESS; // no children
         break;
      case OT_TABLE     :
               {
            struct TableData * pTableData = (struct TableData * )pstartoflist;
            BOOL bUsed;
            int itype[]={OT_COLUMN};

            while (pTableData) {
               fstrncpy(Parents[1],
                        StringWithOwner(pTableData->TableName,
                                        pTableData->TableOwner,
                                        bufObjectWithOwner),
                        MAXOBJECTNAME);
               for (i=0;i<sizeof(itype)/sizeof(int);i++) {
                   bUsed  =  TRUE;
                   switch (itype[i]){
                      case OT_COLUMN:
                         pRefreshParams=&(pTableData->ColumnsRefreshParms);
                         pptemp         = (void **) &(pTableData->lpColumnData);
                         bwithsystem    =  pTableData->HasSystemColumns;
                         break;
                      default:
                         return RES_ERR;
                  }
                  bLocalParentRefreshed=FALSE;
                  if (*pptemp) {
                     if (bUsed && DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
						if (bShouldTestOnly) {
							*pbAnimRefreshRequired = TRUE;
							return RES_SUCCESS;
						}
                     }
                  }
                  DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                                  1,Parents4Call, pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
								  bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
               }
               pTableData=pTableData->pnext;
            }
         }
         break;
      case OT_MON_SERVER :
         {
            struct ServerData * pServerdata = (struct ServerData * )pstartoflist;
            int itype[]={OT_MON_SESSION,
                         OT_MON_ICE_CONNECTED_USER,
                         OT_MON_ICE_ACTIVE_USER,
                         OT_MON_ICE_TRANSACTION,
                         OT_MON_ICE_CURSOR,
                         OT_MON_ICE_FILEINFO,
                         OT_MON_ICE_DB_CONNECTION};

            while (pServerdata) {
               for (i=0;i<sizeof(itype)/sizeof(int);i++) {
                  switch (itype[i]){
                     case OT_MON_SESSION:
                        pRefreshParams=&(pServerdata->ServerSessionsRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpServerSessionData);
                        bwithsystem    =  pServerdata->HasSystemServerSessions;
                        break;
                     case OT_MON_ICE_CONNECTED_USER:
                        pRefreshParams=&(pServerdata->IceConnUsersRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceConnUsersData);
                        bwithsystem    =  pServerdata->HasSystemIceConnUsers;
                        break;
                     case OT_MON_ICE_ACTIVE_USER:
                        pRefreshParams=&(pServerdata->IceActiveUsersRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceActiveUsersData);
                        bwithsystem    =  pServerdata->HasSystemIceActiveUsers;
                        break;
                     case OT_MON_ICE_TRANSACTION:
                        pRefreshParams=&(pServerdata->IceTransactionsRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceTransactionsData);
                        bwithsystem    =  pServerdata->HasSystemIceTransactions;
                        break;
                     case OT_MON_ICE_CURSOR:
                        pRefreshParams=&(pServerdata->IceCursorsRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceCursorsData);
                        bwithsystem    =  pServerdata->HasSystemIceCursors;
                        break;
                     case OT_MON_ICE_FILEINFO:
                        pRefreshParams=&(pServerdata->IceCacheRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceCacheInfoData);
                        bwithsystem    =  pServerdata->HasSystemIceCacheInfo;
                        break;
                     case OT_MON_ICE_DB_CONNECTION:
                        pRefreshParams=&(pServerdata->IceDbConnectRefreshParms);
                        pptemp        = (void **)&(pServerdata->lpIceDbConnectData);
                        bwithsystem    =  pServerdata->HasSystemIceDbConnectInfo;
                        break;
                     default:
                        return RES_ERR;
                  }
                  bLocalParentRefreshed=FALSE;
                  if (*pptemp) {
                     if (DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
						if (bShouldTestOnly) {
							*pbAnimRefreshRequired = TRUE;
							return RES_SUCCESS;
						}
                     }
                  }
                  DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                                  0,(LPUCHAR *)&(pServerdata->ServerDta), pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
								  bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
               }
               pServerdata=pServerdata->pnext;
            }
         }
         break;
      case OT_MON_LOCKLIST :
         {
            struct LockListData * pLockListdata = (struct LockListData * )pstartoflist;
            int itype[]={OT_MON_LOCK};

            while (pLockListdata) {
               for (i=0;i<sizeof(itype)/sizeof(int);i++) {
                  switch (itype[i]){
                     case OT_MON_LOCK:
                        pRefreshParams=&(pLockListdata->LocksRefreshParms);
                        pptemp        = (void **)&(pLockListdata->lpLockData);
                        bwithsystem    =  pLockListdata->HasSystemLocks;
                        break;
                     default:
                        return RES_ERR;
                  }
                  bLocalParentRefreshed=FALSE;
                  if (*pptemp) {
                     if (DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
						if (bShouldTestOnly) {
							*pbAnimRefreshRequired = TRUE;
							return RES_SUCCESS;
						}
                     }
                  }
                  DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                                  0,(LPUCHAR *)&(pLockListdata->LockListDta), pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
								  bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
               }
               pLockListdata=pLockListdata->pnext;
            }
         }
         break;

      case OT_VIEW      :
         {
            struct ViewData * pViewData = (struct ViewData * )pstartoflist;
            int itype[]={OT_VIEWTABLE,
                         OT_VIEWCOLUMN };

            while (pViewData) {
               fstrncpy(Parents[1],
                        StringWithOwner(pViewData->ViewName,
                                        pViewData->ViewOwner,
                                        bufObjectWithOwner),
                        MAXOBJECTNAME);
               for (i=0;i<sizeof(itype)/sizeof(int);i++) {
                  switch (itype[i]){
                     case OT_VIEWTABLE:
                        pRefreshParams=&(pViewData->ViewTablesRefreshParms);
                        pptemp = (void **) &(pViewData->lpViewTableData);
                        bwithsystem    = pViewData->HasSystemViewTables;
                        break;
                     case OT_VIEWCOLUMN:
                        pRefreshParams=&(pViewData->ColumnsRefreshParms);
                        pptemp = (void **) &(pViewData->lpColumnData);
                        bwithsystem   =  pViewData->HasSystemColumns;
                        break;
                     default:
                        return RES_ERR;
                  }
                  bLocalParentRefreshed=FALSE;
                  if (*pptemp) {
                     if (DOMIsTimeElapsed(refreshtime,pRefreshParams, bParentRefreshed)) {
						if (bShouldTestOnly) {
							*pbAnimRefreshRequired = TRUE;
							return RES_SUCCESS;
						}
                     }
                  }
                  DOMNodeRefresh (refreshtime, hnodestruct, itype[i], *pptemp,
                                  1,Parents4Call, pdispwind, bLocalParentRefreshed, pbRefreshAll, pbRefreshMon,
								  bShouldTestOnly,pbAnimRefreshRequired,bFromAnimation, hwndAnimation);
               }
               pViewData=pViewData->pnext;
            }
         }
         break;
      case OT_COLUMN           :
          return RES_SUCCESS;
          break;
      default:
         {
            return myerror(ERR_OBJECTNOEXISTS);
         }
         break;
   }
   return ires;
}
Esempio n. 18
0
/** 
 * Compute the Cross-Correlation Function
 * 
 * @param data1 
 *    Array containing the first data sequence
 * @param data2 
 *    Array containing the second data sequence
 * @param nsamps 
 *    Number of samples in data sequence
 * @param nwin 
 *    Requested Number of windows
 * @param wlen 
 *    Requested number of samples in each window.  The 
 *    subroutine will calculate the window overlap. 
 *    Maximum value is 2048
 * @param type 
 *    Type of data analysis window to use.  Valid values
 *    are:
 *     -   <HAM>MING
 *     -   <HAN>NING
 *     -   <C>OSINE
 *     -   <R>ECTAN
 *     -   <T>RIANG
 * @param c 
 *    Output Array containing resulting 2*\p wlen -1 length 
 *    correlation coefficients.  The correlation sequence is 
 *    circularly rotated in the array so that the zeroth lag 
 *    is at the beginning.  Array dimensions 0:4095
 * @param nfft 
 *    Number of samples in the correlation sequence.  
 *    May be padded with zeros.
 * @param err 
 *    Error Message
 * @param err_s 
 *    Length of string \p err
 *
 * @return Nothing
 *
 * \author   Dave Harris
 *           L-205
 *           Lawrence Livermore National Laboratory
 *           Livermore, Ca  94550
 *
 * \date 800130  Created
 * \date 840621  Last Modified
 *
 *
 */
void 
crscor(float     *data1, 
       float     *data2, 
       int        nsamps, 
       int        nwin, 
       int        wlen, 
       char      *type, 
       float     *c, 
       int       *nfft, 
       char      *err, 
       int        err_s)
{
	char temp[131];
	int half, i, j, k, lsamp, nlags, nverlp, point;
	float scale, scale1, scale2, xi, xr, yi, yr;

	float *const Data1 = &data1[0] - 1;
	float *const Data2 = &data2[0] - 1;

	/*  Initializations
	 * */
	fstrncpy( err, err_s-1,  " ", 1 );


	/*  Check for legal window length and compute overlap
	 * */
	nlags = 2*wlen - 1;
	if( nwin < 1 ){

		fstrncpy( err, err_s-1, " CRSCOR - too few windows ", 26 );
		return;

		}
	else if( wlen < 1 || wlen > nsamps ){

		fstrncpy( err, err_s-1," CRSCOR - illegal window length " , 32 );
		return;

		}
	else{

		/*                                               Everything OK */

		if( nwin*wlen <= nsamps ){
			nverlp = 0;
			}
		else{
			nverlp = (nwin*wlen - nsamps)/(nwin - 1);
			if( nwin*wlen - nverlp*(nwin - 1) > nsamps ){
				nverlp = nverlp + 1;
				}
			}
		lsamp = wlen - 1;

		}


	/*  Find first power of two >= #LAGS
	 * */
	*nfft = 8;
L_2:
	;
	if( *nfft >= nlags )
		goto L_3;
	*nfft = *nfft*2;
	goto L_2;
L_3:
	;
	half = *nfft/2;


        if ((big.w = (float *)malloc(wlen*sizeof(float))) == NULL) {
          printf("memory allocation failed in crscor\n");
          goto L_8892;
	}

        if ((big.caux = (float *)malloc(*nfft*sizeof(float))) == NULL) {
          printf("memory allocation failed in crscor\n");
          goto L_8891;
	}

        if ((big.workr = (float *)malloc(*nfft*sizeof(float))) == NULL) {
          printf("memory allocation failed in crscor\n");
          goto L_8890;
	}

        if ((big.worki = (float *)malloc(*nfft*sizeof(float))) == NULL) {
          printf("memory allocation failed in crscor\n");
          goto L_8889;
	}

	/*  Generate window
	 * */
	for( i = 0; i <= lsamp; i++ ){
		big.w[i] = 1.;
		/*             I */
		}
	window( &big.w[0], wlen, type, 1, wlen, &big.w[0], err,err_s );

	/*  Check validity of window calculation
	 * */
	if( memcmp(err,"        ",8) != 0 ){
                fstrncpy(temp, 130, err, strlen(err));
                fstrncpy(temp+strlen(err),130-strlen(err), " (from CROSS)", 13);
                fstrncpy(err,err_s-1,temp,strlen(temp));
                goto L_8888;
		}

	/*  Compute cross-correlation function
	 *
	 *
	 *    Initialize window pointer
	 * */
	point = 1;

	/*    Initialize correlation arrays
	 * */
	zero( &c[0], *nfft );
	zero( &big.caux[0],*nfft );

	/*    Compute cross-spectrum for each window,  then average
	 * */
	for( i = 1; i <= nwin; i++ ){

		/*    Zero work arrays
		 * */
		zero( &big.workr[0], *nfft );
		zero( &big.worki[0], *nfft );

		/*    Load data into arrays
		 * */
        /* copy( (int*)&Data1[point], (int*)&big.workr[0], wlen ); */
        /* copy( (int*)&Data2[point], (int*)&big.worki[0], wlen ); */

		copy_float( &(Data1[point]), big.workr, wlen );
		copy_float( &(Data2[point]), big.worki, wlen );

		/*    Compute scale factors
		 * */
		scale1 = rms( &big.workr[0], wlen );
		scale2 = rms( &big.worki[0], wlen );
		scale = scale1*scale2;

		/*    Window and scale data
		 * */
		for( j = 0; j <= lsamp; j++ ){
			big.workr[j] = big.workr[j]*big.w[j]/scale1;
			big.worki[j] = big.worki[j]*big.w[j]/scale2;
			/*               J */
			}

		/*    Compute and average cross spectra
		 * */
		fft( &big.workr[0], &big.worki[0], *nfft, -1 );

		/*      Special case for point at 0
		 * */
		c[0] = c[0] + big.workr[0]*big.worki[0]*scale;

		/*      All other points
		 * */
		for( j = 1; j <= half; j++ ){

			k = *nfft - j;

			xr = (big.workr[j] + big.workr[k])*.5;
			xi = (big.worki[j] - big.worki[k])*.5;
			yr = (big.worki[j] + big.worki[k])*.5;
			yi = (big.workr[k] - big.workr[j])*.5;

			c[j] = c[j] + (xr*yr + xi*yi)*scale;
			big.caux[j] = big.caux[j] + (xr*yi - xi*yr)*scale;
			c[k] = c[j];
			big.caux[k] = -big.caux[j];

			}

		/*    Update window pointer
		 * */
		point = point + wlen - nverlp;

		}

	/*    Inverse fft for correlation computation
	 * */
	fft( &c[0], &big.caux[0], *nfft, 1 );

	/*  Bye
	 * */

L_8888:
        free(big.worki);

L_8889:
        free(big.workr);

L_8890:
        free(big.caux);

L_8891:
        free(big.w);

L_8892:
	return;
} 
Esempio n. 19
0
void fprintmsg(FILE *stream, struct fix_message *msg)
{
	char buf[FIX_MAX_LINE_LENGTH];
	struct fix_field *field;
	int size = sizeof buf;
	char delim = '|';
	int len = 0;
	int i;

	if (!msg)
		return;

	if (msg->begin_string && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=", delim, BeginString);
		len += fstrncpy(buf + len, msg->begin_string, size - len);
	}

	if (msg->body_length && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=%lu", delim, BodyLength, msg->body_length);
	}

	if (msg->msg_type && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=", delim, MsgType);
		len += fstrncpy(buf + len, msg->msg_type, size - len);
	}

	if (msg->sender_comp_id && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=", delim, SenderCompID);
		len += fstrncpy(buf + len, msg->sender_comp_id, size - len);
	}

	if (msg->target_comp_id && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=", delim, TargetCompID);
		len += fstrncpy(buf + len, msg->target_comp_id, size - len);
	}

	if (msg->msg_seq_num && len < size) {
		len += snprintf(buf + len, size - len, "%c%d=%lu", delim, MsgSeqNum, msg->msg_seq_num);
	}

	for (i = 0; i < msg->nr_fields && len < size; i++) {
		field = msg->fields + i;

		switch (field->type) {
			case FIX_TYPE_STRING:
				len += snprintf(buf + len, size - len, "%c%d=", delim, field->tag);
				len += fstrncpy(buf + len, field->string_value, size - len);
				break;
			case FIX_TYPE_FLOAT:
				len += snprintf(buf + len, size - len, "%c%d=%f", delim, field->tag, field->float_value);
				break;
			case FIX_TYPE_CHAR:
				len += snprintf(buf + len, size - len, "%c%d=%c", delim, field->tag, field->char_value);
				break;
			case FIX_TYPE_CHECKSUM:
			case FIX_TYPE_INT:
				len += snprintf(buf + len, size - len, "%c%d=%" PRId64, delim, field->tag, field->int_value);
				break;
			default:
				break;
		}
	}

	if (len < size)
		buf[len++] = '\0';

	fprintf(stream, "%s%c\n", buf, delim);
}
Esempio n. 20
0
VOID DosTrimPath(BYTE * lpszPathNamep)
{
    BYTE *lpszLast,
         *lpszNext,
         *lpszRoot = NULL;
    COUNT nChars,
          flDotDot;

    /* First, convert all '/' to '\'.  Look for root as we scan     */
    if (*lpszPathNamep == '\\')
        lpszRoot = lpszPathNamep;
    for (lpszNext = lpszPathNamep; *lpszNext; ++lpszNext)
    {
        if (*lpszNext == '/')
            *lpszNext = '\\';
        if (!lpszRoot &&
                *lpszNext == ':' && *(lpszNext + 1) == '\\')
            lpszRoot = lpszNext + 1;
    }

    /* NAMEMAX + 2, must include C: TE*/
    for (lpszLast = lpszNext = lpszPathNamep, nChars = 0;
            *lpszNext != '\0' && nChars < NAMEMAX+2;)
    {
        /* Initialize flag for loop.                            */
        flDotDot = FALSE;

        /* If we are at a path seperator, check for extra path  */
        /* seperator, '.' and '..' to reduce.                   */
        if (*lpszNext == '\\')
        {
            /* If it's '\', just move everything down one.  */
            if (*(lpszNext + 1) == '\\')
                fstrncpy(lpszNext, lpszNext + 1, NAMEMAX);
            /* also check for '.' and '..' and move down    */
            /* as appropriate.                              */
            else if (*(lpszNext + 1) == '.')
            {
                if (*(lpszNext + 2) == '.'
                        && !(*(lpszNext + 3)))
                {
                    /* At the end, just truncate    */
                    /* and exit.                    */
                    if (lpszLast == lpszRoot)
                        *(lpszLast + 1) = '\0';
                    else
                        *lpszLast = '\0';
                    return;
                }

                if (*(lpszNext + 2) == '.'
                        && *(lpszNext + 3) == '\\')
                {
                    fstrncpy(lpszLast, lpszNext + 3, NAMEMAX);
                    /* bump back to the last        */
                    /* seperator.                   */
                    lpszNext = lpszLast;
                    /* set lpszLast to the last one */
                    if (lpszLast <= lpszPathNamep)
                        continue;
                    do
                    {
                        --lpszLast;
                    }
                    while (lpszLast != lpszPathNamep
                            && *lpszLast != '\\');
                    flDotDot = TRUE;
                }
                /* Note: we skip strange stuff that     */
                /* starts with '.'                      */
                else if (*(lpszNext + 2) == '\\')
                {
                    fstrncpy(lpszNext, lpszNext + 2, NAMEMAX);
                    flDotDot = TRUE;
                }
                /* If we're at the end of a string,     */
                /* just exit.                           */
                else if (*(lpszNext + 2) == NULL)
                {
                    return;
                }
                /*
                   Added this "else" because otherwise we might not pass
                   any of the foregoing tests, as in the case where the
                   incoming string refers to a suffix only, like ".bat"

                   -SRM
                 */
                else
                {
                    lpszLast = lpszNext++;
                }
            }
            else
            {
                /* No '.' or '\' so mark it and bump    */
                /* past                                 */
                lpszLast = lpszNext++;
                continue;
            }

            /* Done.  Now set last to next to mark this     */
            /* instance of path seperator.                  */
            if (!flDotDot)
                lpszLast = lpszNext;
        }
        else
            /* For all other cases, bump lpszNext for the   */
            /* next check                                   */
            ++lpszNext;
    }
}
Esempio n. 21
0
void /*FUNCTION*/ inispe()
{
	/*=====================================================================
	 * PURPOSE: Variable initialization of common blocks CMSPE and KMSPE.
	 *=====================================================================
	 * MODULE/LEVEL:  SPE/4
	 *=====================================================================
	 * PARAMETERS:
	 *    MLNPE:   Length of prediction error function. [i]
	 *    MWINTP:  Number of window types. [i]
	 *    MPSPTP:  Number of spectral estimate plot types. [i]
	 *    MPREWH:  Maximum number of prewhitening filter coefficients. [i]
	 *=====================================================================
	 * VARIABLE DEFINITIONS:
	 *    LFILE:   .TRUE. if one evenly spaced data file is in memory. [l]
	 *    NDXDAT:  Index (first word address in SACMEM array) of data. [i]
	 *    NLNDAT:  Length (number of points) of data. [i]
	 *    SAMFRQ:  Sampling freqency of data. [f]
	 *    NDXCOR:  Index of correlation function. [i]
	 *    NDXPE:   Index of prediction error function. [i]
	 *    NDXSPE:  Index of spectral estimate. [i]
	 *    NDXAUX:  Index of auxiliary (scratch) space. [i]
	 *    LCOR:    .TRUE. if correlation function has been calculated. [l]
	 *    IWNCOR:  Type of window used used in correlation. [i]
	 *             (Index into KWINTP array.)
	 *    NUMWIN:  Number of windows used in correlation. [i]
	 *    WINLEN:  Window length in seconds. [f]
	 *    NWINLN:  Window length in samples. [i]
	 *    LSNUMW:  .TRUE. if the number of windows is specified. [l]
	 *             .FALSE. if the number of windows is calculated from
	 *             the data length and window length.
	 *    LPREWH:  .TRUE. if prewhitening of data is on. [l]
	 *    NPRERQ:  Requested number of prewhitening filter coefficients. [i]
	 *    NPREWH:  Number of prewhitening coefficients used. [i]
	 *    CPREWH:  Array used to save prewhitening filter coefficients. [f]
	 *    KSCALE:  Type of scaling used in autocorrelation. [c10]
	 *             ='STOCHASTIC' if data is noise.
	 *             ='TRANSIENT' if data contains a waveform.
	 *    NLNCOR:  Length of autocorrelation function. [i]
	 *    NLNFFT:  Length of FFT used to compute autocorrelation. [i]
	 *    NLNSPE:  Length of spectral estimate. [i]
	 *    LSPE:    .TRUE. if spectral estimate has been calculated. [l]
	 *    KWINTP:  List of allowed window types. [k]
	 *             Used in autocorrelation and PDS calculations.
	 *    LPCSEC:  .TRUE. if partial correlation plot is requested. [l]
	 *    PCSEC:   Width in seconds of partial correlation plot. [f]
	 *    IWNPDS:  Type of window used in PDS calculation. [i]
	 *             (Index into KWINTP array.)
	 *    SECPDS:  Window length in seconds for PDS. [f]
	 *    NLGPDS:  Window length in lags for PDS. [i]
	 *    NLGMEM:  Order of estimate in lags for MEM. [i]
	 *    NLGMLM:  Order of estimate in lags for MLM. [i]
	 *    LRESL:   .TRUE. if a resolution has been calculated. [l]
	 *    RESL:    Resolution in Hz. [f]
	 *    LCL      .TRUE. if a confidence limit has been calculated. [l]
	 *    CLU:     Upper confidence limit. [f]
	 *    CLL:     Lower confidence limit. [f]
	 *    LRQCL:  .TRUE. if confidence limits are to be plotted.. [l]
	 *    LSPEID:  .TRUE. if spectral estimate id is to be plotted. [l]
	 *    KPSPTP:  List of allowed spectral estimate plot types. [k]
	 *    NPSPTP:  Length of KPSPTP.
	 *    IPSPTP:  Type of spectral estimate plot format. [i]
	 *    KPSPLB:  Label to put on spectral estimate plot. [k]
	 *    KNMCOR:  Correlation function file name. [c]
	 *    KNMSPE:   Spectral estimate file name. [c]
	 *    KERMSG:  Error message returned from Harris's subroutines. [c130]
	 *===================================================================== */
	/* PROCEDURE: */
	cmspe.lfile = FALSE;
	cmspe.lcor = FALSE;
	cmspe.winlen = 10.0;
	cmspe.lsnumw = FALSE;
	cmspe.numwin = 10;
	cmspe.lprewh = FALSE;
	cmspe.nprerq = 6;
	strcpy( kmspe.kscale, "STOCHASTIC" );
	cmspe.nlnspe = 1024;
	strcpy( kmspe.kwintp[0], "HAMMING " );
	strcpy( kmspe.kwintp[1], "HANNING " );
	strcpy( kmspe.kwintp[2], "COSINE  " );
	strcpy( kmspe.kwintp[3], "RECTANGL" );
	strcpy( kmspe.kwintp[4], "TRIANGLE" );
	cmspe.iwncor = 1;
	cmspe.iwnpds = 1;
	cmspe.nlgmem = 25;
	cmspe.nlgmlm = 25;
	cmspe.lrqcl = FALSE;
	cmspe.lspeid = TRUE;
	strcpy( kmspe.kpsptp[0], "POWER   " );
	strcpy( kmspe.kpsptp[1], "LOG     " );
	strcpy( kmspe.kpsptp[2], "AMPLITUD" );
	cmspe.npsptp = 3;
	cmspe.ipsptp = 1;
	fstrncpy( kmspe.knmspe, MCPFN, "spe", 3 );
	fstrncpy( kmspe.knmcor, MCPFN, "cor", 3 );

	cmspe.firstPowerOf2 = MINPOW ;

       
	return;

	/*=====================================================================
	 * MODIFICATION HISTORY:
	 *    841227:  Changes due to major rewrite of SPE subprocess.
	 *    810414:  Original version.
	 *=====================================================================
	 * DOCUMENTED/REVIEWED:  850109
	 *===================================================================== */

} /* end of function */
Esempio n. 22
0
/** 
 * Parse and evaluate a "logical" expression
 * 
 * @param string 
 *    Character string containing logical expression. [c]
 *    Must be of the form: "number logical number" where
 *    number is an integer or floating point number and
 *    logical is one of: 'LT', 'LE', 'GT', 'GE', 'EQ', 'NE'.
 *    Integers are converted to floating before being evaluated.
 *    Leading, trailing, and extra white space is ignored.
 * @param string_s 
 *    Length of \p string
 * @param result 
 *    - "TRUE" if expression is true
 *    - "FALSE" if expression is false
 *    - "ERROR" if and error occurred during parsing
 * @param result_s 
 *    Length of \p result
 *
 * @bug This should return an int (-1,0,1)
 *
 * @date   970129:  Add parameter (0) to cnvatf.  0 means that if a string
 *             of digits is too long, let it slide by.  maf 
 * @date   900606:  Modified tests for reals to handle case where
 *             both numbers are zero.
 * @date   871117:  Changed tests of (in)equality of reals to include
 *             the possible effects of roundoff.
 *             These are now tests for equivalence not equality.
 * @date   871103:  Added ability to check for (in)equality of strings.
 * @date   870811:  Original version.
 *
 */
void 
evallogical(char *string, 
            int   string_s, 
            char *result, 
            int   result_s) {

  UNUSED(string);
  UNUSED(string_s);

	int lresult;
	float x, y;

  Token *t1, *t2, *top;

  if(!(t1 = arg()))  { goto ERROR; }
  arg_next();
  if(!(top = arg())) { goto ERROR; }
  arg_next();
  if(!(t2 = arg()))  { goto ERROR; }
  arg_next();

	/* - If first and third tokens are not floating point numbers (i.e. strings)
	 *   then the only tests that are allowed are "EQ" and "NE". */

	if( (token_is_string(t1) || token_is_quoted_string(t1) || token_is_escape_string(t1)) &&
      (token_is_string(t2) || token_is_quoted_string(t2) || token_is_escape_string(t2))) {
    lresult = strcmp(t1->str, t2->str);
    if(is_undefined(t1->str) && strcmp(t2->str, "-12345  ") == 0) {
      lresult = 0;
    }
    if(is_undefined(t2->str) && strcmp(t1->str, "-12345  ") == 0) {
      lresult = 0;
    }
    if( token_is_eq(top) ) {
      lresult = lresult == 0;
      goto L_8000;
    }	else if( token_is_ne(top) ) {
      lresult = lresult != 0;
			goto L_8000;
    }	else {
			goto ERROR;
    }
  }
  if(!token_is_number(t1) || !token_is_number(t2)) {
    if( (token_is_string(t1) || token_is_quoted_string(t1) || token_is_escape_string(t1)) &&
        is_undefined(t1->str) &&
        token_is_number(t2) ) {
        t1->value = -12345;
    } else if( (token_is_string(t2) || token_is_quoted_string(t2) || token_is_escape_string(t2)) &&
               is_undefined(t2->str) &&
               token_is_number(t1) ) {
      t2->value = -12345;
    } else {
      goto ERROR;
    }
  }

	/* - Evaluate logical expressions involving floating point numbers. */

  if(token_is_lt(top)) {
    lresult = t1->value < t2->value;
  } else if(token_is_le(top)) {
    lresult = t1->value <= t2->value;
  } else if(token_is_gt(top)) {
    lresult = t1->value > t2->value;
  } else if(token_is_ge(top)) {
    lresult = t1->value >= t2->value;
  } else if(token_is_eq(top)) {
    /* y = t1 - t2;
       x = MAX((t1 + t2)/2, 1e-30)
       (t1-t2)/(t1+t2)/2 <= RNDOFF
    */
    y = fabs( t1->value - t2->value );
    x = fmax( 0.5*(t1->value + t2->value), VSMALL );
    lresult = (y/x) <= RNDOFF;
  } else if(token_is_ne(top)) {
    y = fabs( t1->value - t2->value );
    x = fmax( 0.5*(t1->value + t2->value), VSMALL );
    lresult = (y/x) > RNDOFF;
  } else {
    goto ERROR;
  }

L_8000:
	if( lresult ){
		fstrncpy( result, result_s - 1, "TRUE", 4 );
		}
	else{
		fstrncpy( result, result_s - 1, "FALSE", 5 );
		}
	return;

 ERROR:
  fstrncpy( result, result_s-1, "ERROR", 5 );
  return;
} /* end of function */