コード例 #1
0
ファイル: tsvbksb.cpp プロジェクト: benoit-leveau/morph3D
void main()  {
  
  printf("\n Input data file name: "); scanf("%s", filename);
  fp = fopen(filename, "r");

  //read size of linear system
  fscanf(fp,"%d", &m);
  fscanf(fp,"%d", &n);

//allocate memory
  vmblock = vminit();
  A  = (REAL **) vmalloc(vmblock, MATRIX, m+1, n+1);
  U  = (REAL **) vmalloc(vmblock, MATRIX, m+1, n+1);
  V  = (REAL **) vmalloc(vmblock, MATRIX, n+1, n+1);
  B  = (REAL *)  vmalloc(vmblock, VEKTOR, m+1, 0);
  W  = (REAL *)  vmalloc(vmblock, VEKTOR, n+1, 0);
  X  = (REAL *)  vmalloc(vmblock, VEKTOR, n+1, 0);

// read matrix A
  for (i=1; i<=m; i++)
    for (j=1; j<=n; j++)
      fscanf(fp,"%lf", &A[i][j]);
// read vector B
  for (i=1; i<=m; i++)
    fscanf(fp,"%lf", &B[i]);
  fclose(fp);
  
  fp = fopen("tsvbksb.lst", "w");
  fprintf(fp,"\n  M = %d\n", m);
  fprintf(fp,"  N = %d\n", n);
  WriteMat("  Matrix A:",A,m,n);
  WriteVec("  Vector B:",B,m);
// Save A in U
  for (i=1; i<=m; i++)
    for (j=1; j<=n; j++)
      U[i][j]=A[i][j];
//call singular value decomposition subroutine
  SVDCMP(U,m,n,W,V);
  WriteMat("  Matrix U:",U,m,n);
  WriteVec("  Vector W:",W,n);
  WriteMat("  Matrix V:",V,m,n);
//seek highest value of W's and set near-zero
//values to exactly zero (for near-singular cases)
  WMAX=0.0;
  for (j=1; j<=n; j++)
    if (W[j] > WMAX)  WMAX=W[j];
  WMIN=WMAX*1e-6;
  for (j=1; j<=n; j++)
    if (W[j] < WMIN)  W[j]=0.0;
//call solver for SVD matrix
  SVBKSB(U,W,V,m,n,B,X);
//print solution
  WriteVec("  Solution:",X,n);
// free memory  
  vmfree(vmblock);
  fclose(fp);
  printf("\n Results in file tsvbksb.lst.\n\n");

}
コード例 #2
0
ファイル: mlexmac.c プロジェクト: ABratovic/open-watcom-v2
STATIC TOKEN_T lexSubString( STRM_T s )
/**************************************/
{
    char        text[MAX_TOK_SIZE];     /* temporary storage                */
    unsigned    pos;                    /* position in text                 */
    TOKEN_T     state;                  /* what are we collecting           */
    BOOLEAN     done;                   /* are we done collecting ?         */
    VECSTR      vec;                    /* build string here                */

    assert( isascii( s ) );

    vec = StartVec();

    if( ismacc( s ) ) {
        state = MAC_NAME;
    } else if( isws( s ) ) {
        state = MAC_WS;
    } else {
        state = MAC_PUNC;
    }

    pos = 0;
    done = FALSE;
    while( !done ) {
        text[pos++] = s;
        if( pos == MAX_TOK_SIZE - 1 ) {
            text[pos] = NULLCHAR;
            WriteVec( vec, text );
            pos = 0;
        }

        s = PreGetCH();
        switch( s ) {
        case EOL:               /* always stop on these characters */
        case STRM_END:
        case STRM_MAGIC:
        case ')':
        case DOLLAR:
            done = TRUE;
            break;
        default:
            switch( state ) {
            case MAC_NAME:  done = !ismacc( s );                break;
            case MAC_WS:    done = !isws( s );                  break;
            case MAC_PUNC:  done = ismacc( s ) || isws( s );    break;
            }
        }
    }
    UnGetCH( s );
    text[pos] = NULLCHAR;
    WriteVec( vec, text );

    CurAttr.u.ptr = FinishVec( vec );
    return( state );
}
コード例 #3
0
char *GetCurDeps( BOOLEAN younger, BOOLEAN isMacInf )
/**********************************************************/
{
    TLIST           *walk;
    VECSTR          vec;
    BOOLEAN         written;
    TARGET          *targ;
    struct exStack  cur;
    const char      *formattedString;
    char            *ret;

    cur = exGetCurVars();

    // This is for Glob.microsoft and Glob.posix
    // $< and $** are different
    if( isMacInf ) {
        cur.dep = cur.impDep;
    } else {
        if( cur.dep == NULL ) {
            cur.dep = cur.impDep;
        }
    }

    if( (younger && cur.targ == NULL) ||
        cur.dep == NULL || cur.dep->targs == NULL ) {
        return( StrDupSafe( "" ) );
    }

    vec = StartVec();
    written = FALSE;

    walk = cur.dep->targs;
    while( walk != NULL ) {
        targ = walk->target;
        if( !younger || dateCmp( cur.targ->date, targ->date ) < 0 ) {
            if( written ) {
                WriteVec( vec, " " );
            }
            formattedString = procPath( targ->node.name );
            WriteVec( vec, formattedString );
            written = TRUE;
        }
        walk = walk->next;
    }
    ret = FinishVec( vec );

    return( ret );
}
コード例 #4
0
STATIC char *doStringSubstitute( const char *name, const char *oldString, const char *newString )
/************************************************************************************************
 *   $(macroname:oldstr=newstr)
 *   substitute any occurence of oldstr with new str
 */
{
    VECSTR      output;
    char const  *current;
    char const  *start;
    size_t      old_len;

    output = StartVec();
    WriteVec( output, "" );

    assert( name != NULL && oldString != NULL && newString != NULL );

    old_len = strlen( oldString );
    for( start = current = name; *current != NULLCHAR; current++ ) {
        if( strncmp( current, oldString, old_len ) == 0 ) {
            CatNStrToVec( output, start, current - start );
            CatStrToVec( output, newString );
            start   = current + old_len;
            current = start - 1;
        }
    }
    CatStrToVec( output, start );

    return( FinishVec( output ) );
}
コード例 #5
0
ファイル: mupdate.c プロジェクト: Azarien/open-watcom-v2
char *GetCurDeps( bool younger, bool isMacInf )
/*********************************************/
{
    TLIST           *tlist;
    VECSTR          vec;
    bool            written;
    TARGET          *targ;
    struct exStack  cur;
    const char      *formattedString;
    char            *ret;

    cur = exGetCurVars();

    // This is for Glob.compat_nmake and Glob.compat_posix
    // $< and $** are different
    if( isMacInf ) {
        cur.dep = cur.impDep;
    } else {
        if( cur.dep == NULL ) {
            cur.dep = cur.impDep;
        }
    }

    if( (younger && cur.targ == NULL) ||
        cur.dep == NULL || cur.dep->targs == NULL ) {
        return( StrDupSafe( "" ) );
    }

    vec = StartVec();
    written = false;

    for( tlist = cur.dep->targs; tlist != NULL; tlist = tlist->next ) {
        targ = tlist->target;
        if( !younger || dateCmp( cur.targ->date, targ->date ) < 0 ) {
            if( written ) {
                WriteVec( vec, " " );
            }
            formattedString = procPath( targ->node.name );
            WriteVec( vec, formattedString );
            written = true;
        }
    }
    ret = FinishVec( vec );

    return( ret );
}
コード例 #6
0
ファイル: mlexmac.c プロジェクト: ABratovic/open-watcom-v2
STATIC char *CatModifier( char *inString, BOOLEAN destroy )
/**********************************************************
 *  Get the modifier
 *  if it is modify the value inInString to the specs of the modifier
 *  it then returns the modified string with the right format
 */
{
    STRM_T  s;
    VECSTR  output;
    char    buffer[2];
    char    *ret;

    assert( inString != NULL );

    s = PreGetCH();

    if( ismsmodifier( s ) ) {
        buffer[0] = s;
        buffer[1] = NULLCHAR;
        output = StartVec();
        WriteVec( output, "" );
        CatStrToVec( output, inString );
        CatStrToVec( output, buffer );
        if( destroy ) {
            FreeSafe( inString );
        }
        return( FinishVec( output ) );
    } else {
        UnGetCH( s );
        ret = StrDupSafe( inString );
        if( destroy ) {
            FreeSafe( inString );
        }
        return( ret );
    }
}
コード例 #7
0
TOKEN_T LexPath( STRM_T s )
/*********************************
 * returns: ({filec}*";")+          TOK_PATH
 *          EOL                     EOL
 *          STRM_END                STRM_END
 */
{
    char        path[_MAX_PATH];
    char        string_open;
    unsigned    pos;
    VECSTR      vec;                /* we'll store file/path here */

    for( ;; ) {                     /* get first valid character */
        if( s == EOL || s == STRM_END ) {
            /* now we pass this to LexParser() so that it can reset */
            return( LexParser( s ) );
        }

        if( s == STRM_MAGIC ) {
            InsString( DeMacro( TOK_EOL ), TRUE );
        } else if( !isfilec( s ) && s != PATH_SPLIT && s != ';' && s != '\"' && !isws( s ) ) {
            PrtMsg( ERR | LOC | EXPECTING_M, M_PATH );
        } else if( !isws( s ) ) {
            break;
        }

        s = PreGetCH(); /* keep fetching characters */
    }
    /* just so you know what we've got now */
    assert( isfilec( s ) || s == PATH_SPLIT || s == ';' || s == '\"' );

    vec = StartVec();

    pos = 0;
    for( ;; ) {
        /*
         * Extract path from stream. If double quote is found, start string mode
         * and ignore all filename character specifiers and just copy all
         * characters. String mode ends with another double quote. Backslash can
         * be used to escape only double quotes, otherwise they are recognized
         * as path seperators.  If we are not in string mode character validity
         * is checked against isfilec().
         */

        string_open = 0;

        while( pos < _MAX_PATH && s != EOL && s != STRM_END ) {
            if( s == BACKSLASH ) {
                s = PreGetCH();

                if( s == DOUBLEQUOTE ) {
                    path[pos++] = DOUBLEQUOTE;
                } else if( s == EOL || s == STRM_END ) {
                    // Handle special case when backslash is placed at end of
                    // line or file
                    path[pos++] = BACKSLASH;
                } else {
                    path[pos++] = BACKSLASH;

                    // make sure we don't cross boundaries
                    if( pos < _MAX_PATH ) {
                        path[pos++] = s;
                    }
                }
            } else {
                if( s == DOUBLEQUOTE ) {
                    string_open = !string_open;
                } else {
                    if( string_open ) {
                        path[pos++] = s;
                    } else if( isfilec( s ) ) {
                        path[pos++] = s;
                    } else {
                        break; // not valid path character, break out.
                    }
                }
            }

            s = PreGetCH();
        }

        if( string_open ) {
            FreeSafe( FinishVec( vec ) );
            PrtMsgExit(( FTL | LOC | ERROR_STRING_OPEN ));
        }

        if( pos == _MAX_PATH ) {
            FreeSafe( FinishVec( vec ) );
            PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, _MAX_PATH - 1 )); // NOTREACHED
        }

        path[pos] = NULLCHAR;
        WriteVec( vec, path );

        if( s != PATH_SPLIT && s != ';' ) {
            break;
        }

        pos = 0;
        path[pos++] = PATH_SPLIT;
        s = PreGetCH();        /* use Pre here to allow path;&(nl)path */
    }
    UnGetCH( s );

    CurAttr.u.ptr = FinishVec( vec );

    return( TOK_PATH );
}