コード例 #1
0
ファイル: part.c プロジェクト: CARV-ICS-FORTH/scoop
int
sm_block_partition(sm_matrix *A, sm_matrix **L, sm_matrix **R)
{
int cols_visited, rows_visited;
register sm_row *prow;
register sm_col *pcol;
if (A->nrows == 0) {
return 0;
}
for(prow = A->first_row; prow != 0; prow = prow->next_row) {
prow->flag = 0;
}
for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col) {
pcol->flag = 0;
}
cols_visited = rows_visited = 0;
if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) {
return 0;
} else {
*L = sm_alloc();
*R = sm_alloc();
for(prow = A->first_row; prow != 0; prow = prow->next_row) {
if (prow->flag) {
copy_row(*L, prow);
} else {
copy_row(*R, prow);
}
}
return 1;
}
}
コード例 #2
0
ファイル: MONO.C プロジェクト: NonCreature0714/descent2
void scroll( short n )
{
	register row, col;

	if (!OPEN) return;

	col = 0;
	for ( row = 0; row < (HEIGHT-1); row++ )
		copy_row( WIDTH, (short *)&XCHAR(row+1,col), (short *)&CHAR(row,col), (short *)&XCHAR(row,col) );

//		for ( col = 0; col < WIDTH; col++ )
//		{
//			CHAR( row, col ) = XCHAR( row+1, col );
//			ATTR( row, col ) = XATTR( row+1, col );
//			XCHAR( row, col ) = XCHAR( row+1, col );
//			XATTR( row, col ) = XATTR( row+1, col );
//		}

	for ( col = 0; col < WIDTH; col++ )
	{
		CHAR( HEIGHT-1, col ) = ' ';
		ATTR( HEIGHT-1, col ) = XATTR( HEIGHT-1, col );
		XCHAR( HEIGHT-1, col ) = ' ';
	}

}
コード例 #3
0
//------------------------------------------------------------------------------------------------
void ImplFragmentorRepetitive::performFragmentation(
		const HAlignment & sample,
		const HAlignandum & row,
		const HAlignandum & col )
{

  /* since src1 and src2 are const, I have to create two work-copies,
     so that the boundaries can be changed. */

  HAlignandum copy_row(row->getClone());
  HAlignandum copy_col(col->getClone());

  while ( 1 ) {

    HAlignment result = sample->getNew();
    mAlignator->align( result, copy_row, copy_col );

    if (result->getScore() >= mMinScore)
    {
      mFragments->push_back( result );
      copy_row->mask( result->getRowFrom(), result->getRowTo() );
      copy_col->mask( result->getColFrom(), result->getColTo() );

    } else
    {
      break;
    }
  }
}
コード例 #4
0
static
rc_t copy_table ( const vtblcp_parms *pb, VCursor *dcurs, const VCursor *scurs,
    const vtblcp_column_map *cm, uint32_t count, uint32_t rdfilt_idx )
{
    /* open source */
    rc_t rc = VCursorOpen ( scurs );
    if ( rc != 0 )
        LOGERR ( klogErr, rc, "failed to open source cursor" );
    else
    {
        /* get row range */
        int64_t row, last;
        uint64_t range_count;
        
        rc = VCursorIdRange ( scurs, 0, & row, & range_count );
        last = row + range_count;
        if ( rc != 0 )
            LOGERR ( klogInt, rc, "failed to determine row range for source cursor" );
        else
        {
            /* open desination cursor */
            rc = VCursorOpen ( dcurs );
            if ( rc != 0 )
                LOGERR ( klogErr, rc, "failed to open destination cursor" );
            else
            {
                /* focus destination on initial source row */
                rc = VCursorSetRowId ( dcurs, row );
                if ( rc != 0 )
                    PLOGERR ( klogErr,  (klogErr, rc, "failed to set destination cursor row to id '$(row)'", "row=%" LD64, row ));
                else
                {
                    /* copy each row */
                    for ( ; row <= last; ++ row )
                    {
                        rc = copy_row ( pb, dcurs, scurs, cm, count, rdfilt_idx, row );
                        if ( rc != 0 )
                            break;
                    }

                    /* commit changes */
                    if ( rc == 0 )
                        rc = VCursorCommit ( dcurs );
                }
            }
        }
    }

    return rc;
}
コード例 #5
0
int create_decoding_matrix(int *gen_matrix, int *dec_matrix, int *missing_idxs, int k, int m)
{
  int i, j;
  int n = k+m;

  for (i = 0, j = 0; i < n && j < k; i++) {
    if (!is_missing(missing_idxs, i)) {
      copy_row(gen_matrix, dec_matrix, i, j, k);
      j++; 
    } 
  }

  return j == k;
}
コード例 #6
0
ファイル: part.c プロジェクト: jimmysitu/espresso2verilog
int
sm_block_partition(sm_matrix *A, sm_matrix **L, sm_matrix **R)
{
    int cols_visited, rows_visited;
    register sm_row *prow;
    register sm_col *pcol;

    /* Avoid the trivial case */
    if (A->nrows == 0) {
	return 0;
    }

    /* Reset the visited flags for each row and column */
    for(prow = A->first_row; prow != 0; prow = prow->next_row) {
	prow->flag = 0;
    }
    for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col) {
	pcol->flag = 0;
    }

    cols_visited = rows_visited = 0;
    if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) {
	/* we found all of the rows */
	return 0;
    } else {
	*L = sm_alloc();
	*R = sm_alloc();
	for(prow = A->first_row; prow != 0; prow = prow->next_row) {
	    if (prow->flag) {
		copy_row(*L, prow);
	    } else {
		copy_row(*R, prow);
	    }
	}
	return 1;
    }
}
コード例 #7
0
ファイル: 10_6_ii.c プロジェクト: PytLab/C-Primer-Plus
void copy_arr(const double (* source)[N], double (* target)[N], int row_num)
{
    //复制整个二维数组
    int row;
    void copy_row(const double *, double *, int);

    for(row = 0; row < row_num; row++)
    {
        double * source_ptr;
        double * target_ptr;

        source_ptr = (double *)(source + row);
        target_ptr = (double *)(target + row);
        copy_row(source_ptr, target_ptr, N);
    }
}
コード例 #8
0
ファイル: spread.c プロジェクト: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
void
add_row (struct spread_row *spread_row_ptr)
/* ---------------------------------------------------------------------- */
{
  g_spread_sheet.rows =
    (struct spread_row **) PHRQ_realloc (g_spread_sheet.rows,
					 sizeof (struct spread_row *) *
					 (g_spread_sheet.count_rows + 1));
  if (g_spread_sheet.rows == NULL)
  {
    malloc_error ();
  }
  else
  {
    g_spread_sheet.rows[g_spread_sheet.count_rows++] =
      copy_row (spread_row_ptr);
  }
}
コード例 #9
0
ファイル: ops.c プロジェクト: vr3d/heman
heman_image* heman_ops_stitch_horizontal(heman_image** images, int count)
{
    assert(count > 0);
    int width = images[0]->width;
    int height = images[0]->height;
    int nbands = images[0]->nbands;
    for (int i = 1; i < count; i++) {
        assert(images[i]->width == width);
        assert(images[i]->height == height);
        assert(images[i]->nbands == nbands);
    }
    heman_image* result = heman_image_create(width * count, height, nbands);

#pragma omp parallel for
    for (int y = 0; y < height; y++) {
        for (int tile = 0; tile < count; tile++) {
            copy_row(images[tile], result, tile * width, y);
        }
    }

    return result;
}
コード例 #10
0
double *gauss_cyclic(double **a, double *b)
{
    double *x, l[n*n], *buf;
    int i, k, j, r, tag = 42;
    MPI_Status status;
    struct { double val; int node; } z, y;
    x = (double *) malloc(n * sizeof(double));
    buf = (double *) malloc((n+1) * sizeof(double));

    for (k=0; k<n-1; k++) { /* Forward elimination */
        r = max_col_loc(a, k);
        z.node = me;
        if (r != -1) {
            z.val = fabs(a[r][k]);
        } else {
            z.val = 0.0;
        }
        // z = local max
        // y = global max
        MPI_Allreduce(&z, &y, 1, MPI_DOUBLE_INT, MPI_MAXLOC, MPI_COMM_WORLD);
        //printf("p%d says global max is own by p%d = %f\n", me, y.node, y.val);
        if (k % p == y.node) { /* Pivot row and row k are on the same processor */
            if (k % p == me) {
                if (a[k][k] != y.val) exchange_row(a, b, r, k);
                copy_row(a, b, k, buf);
            }
        } else { /* Pivot row and row k are owned by different processor */
            if (k % p == me) {
                copy_row(a, b, k, buf);
                MPI_Send(buf+k, n-k+1, MPI_DOUBLE, y.node, tag, MPI_COMM_WORLD);
            } else if (y.node == me) {
                MPI_Recv(buf+k, n-k+1, MPI_DOUBLE, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
                copy_exchange_row(a, b, r, buf, k);
            }
        }
        MPI_Bcast(buf+k, n-k+1, MPI_DOUBLE, y.node, MPI_COMM_WORLD);
        if ((k % p != y.node) && (k % p == me)) {
            copy_back_row(a, b, buf, k);
        }
        i = k+1; while (i % p != me) i++;
        for (; i<n; i+=p) {
            l[i] = a[i][k] / buf[k];
            for (j=k+1; j<n;j++) {
                a[i][j] = a[i][j] - l[i] * buf[j];
            }
            b[i] = b[i] - l[i] * buf[n];
        }
    }

    double sum;
    for (k=n-1; k>=0; k--) { /* Backward substition */
        if (k % p == me) {
            sum = 0.0;
            for (j=k+1; j<n; j++) {
                sum = sum + a[k][j] * x[j];
            }
            x[k] = 1/a[k][k] * (b[k] - sum);
        }
        MPI_Bcast(&x[k], 1, MPI_DOUBLE, k%p, MPI_COMM_WORLD);
    }
    free(buf);
    return x;
}
コード例 #11
0
ファイル: ReaderWriterTIFF.cpp プロジェクト: joevandyk/osg
unsigned char *
simage_tiff_load(std::istream& fin,
                 int& width_ret,
                 int& height_ret,
                 int& numComponents_ret,
                 uint16& bitspersample)
{
    TIFF *in;
    uint16 dataType;
    uint16 samplesperpixel;
    uint16 photometric;
    uint32 w, h;
    uint16 config;
    uint16* red;
    uint16* green;
    uint16* blue;
    unsigned char *inbuf = NULL;
    tsize_t rowsize;
    uint32 row;
    int format;
    unsigned char *buffer;
    int width;
    int height;
    unsigned char *currPtr;

    TIFFSetErrorHandler(tiff_error);
    TIFFSetWarningHandler(tiff_warn);

    in = TIFFClientOpen("inputstream", "r", (thandle_t)&fin,
            libtiffStreamReadProc, //Custom read function
            libtiffStreamWriteProc, //Custom write function
            libtiffStreamSeekProc, //Custom seek function
            libtiffStreamCloseProc, //Custom close function
            libtiffStreamSizeProc, //Custom size function
            libtiffStreamMapProc, //Custom map function
            libtiffStreamUnmapProc); //Custom unmap function

    if (in == NULL)
    {
        tifferror = ERR_OPEN;
        return NULL;
    }
    if (TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric) == 1)
    {
        if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE &&
            photometric != PHOTOMETRIC_MINISWHITE &&
            photometric != PHOTOMETRIC_MINISBLACK)
        {
            osg::notify(osg::DEBUG_INFO) << "Bad photometric; can only handle Grayscale, RGB and Palette images" << std::endl;
            TIFFClose(in);
            tifferror = ERR_UNSUPPORTED;
            return NULL;
        }
    }
    else
    {
        tifferror = ERR_READ;
        TIFFClose(in);
        return NULL;
    }

    if (TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel) == 1)
    {
        if (samplesperpixel != 1 &&
            samplesperpixel != 2 &&
            samplesperpixel != 3 &&
            samplesperpixel != 4)
        {
            osg::notify(osg::DEBUG_INFO) << "Bad samples/pixel" << std::endl;
            tifferror = ERR_UNSUPPORTED;
            TIFFClose(in);
            return NULL;
        }
    }
    else
    {
        tifferror = ERR_READ;
        TIFFClose(in);
        return NULL;
    }

    if (TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample) == 1)
    {
         if (bitspersample != 8 && bitspersample != 16)
        {
            osg::notify(osg::DEBUG_INFO) << "can only handle 8 and 16 bit samples" << std::endl;
            TIFFClose(in);
            tifferror = ERR_UNSUPPORTED;
            return NULL;
        }
    }
    else
    {
        tifferror = ERR_READ;
        TIFFClose(in);
        return NULL;
    }
    
    if (TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w) != 1 ||
        TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h) != 1 ||
        TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config) != 1)
    {
        TIFFClose(in);
        tifferror = ERR_READ;
        return NULL;
    }

        
    TIFFGetField(in, TIFFTAG_DATATYPE, &dataType);
    osg::notify(osg::INFO)<<"TIFFTAG_DATATYPE="<<dataType<<std::endl;


    /*
    if (photometric == PHOTOMETRIC_MINISWHITE ||
        photometric == PHOTOMETRIC_MINISBLACK)
        format = 1;
    else
        format = 3;
    */
    // if it has a palette, data returned is 3 byte rgb
    // so set format to 3.
    if (photometric == PHOTOMETRIC_PALETTE)
        format = 3; 
    else
        format = samplesperpixel * bitspersample / 8;
    
    
    int bytespersample = bitspersample / 8;
    int bytesperpixel = bytespersample * samplesperpixel;
    
    osg::notify(osg::INFO)<<"format="<<format<<std::endl;
    osg::notify(osg::INFO)<<"bytespersample="<<bytespersample<<std::endl;
    osg::notify(osg::INFO)<<"bytesperpixel="<<bytesperpixel<<std::endl;
    
    buffer = new unsigned char [w*h*format];

    if (!buffer)
    {
        tifferror = ERR_MEM;
        TIFFClose(in);
        return NULL;
    }

    // initialize memory
    for(unsigned char* ptr=buffer;ptr<buffer+w*h*format;++ptr) *ptr = 0;

    width = w;
    height = h;

    currPtr = buffer + (h-1)*w*format;

    tifferror = ERR_NO_ERROR;

    switch (pack(photometric, config))
    {
        case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_CONTIG):
        case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_CONTIG):
        case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_SEPARATE):
        case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_SEPARATE):
            inbuf = new unsigned char [TIFFScanlineSize(in)];
            for (row = 0; row < h; row++)
            {
                if (TIFFReadScanline(in, inbuf, row, 0) < 0)
                {
                    tifferror = ERR_READ;
                    break;
                }
                invert_row(currPtr, inbuf, w, photometric == PHOTOMETRIC_MINISWHITE, bitspersample);
                currPtr -= format*w;
            }
            break;

        case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG):
        case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE):
            if (TIFFGetField(in, TIFFTAG_COLORMAP, &red, &green, &blue) != 1)
                tifferror = ERR_READ;
            /* */
            /* Convert 16-bit colormap to 8-bit (unless it looks */
            /* like an old-style 8-bit colormap). */
            /* */
            if (!tifferror && checkcmap(1<<bitspersample, red, green, blue) == 16)
            {
                int i;
                for (i = (1<<bitspersample)-1; i >= 0; i--)
                {
                    red[i] = CVT(red[i]);
                    green[i] = CVT(green[i]);
                    blue[i] = CVT(blue[i]);
                }
            }

            inbuf = new unsigned char [TIFFScanlineSize(in)];
            for (row = 0; row < h; row++)
            {
                if (TIFFReadScanline(in, inbuf, row, 0) < 0)
                {
                    tifferror = ERR_READ;
                    break;
                }
                remap_row(currPtr, inbuf, w, red, green, blue);
                currPtr -= format*w;
            }
            break;

        case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG):
            inbuf = new unsigned char [TIFFScanlineSize(in)];
            for (row = 0; row < h; row++)
            {
                if (TIFFReadScanline(in, inbuf, row, 0) < 0)
                {
                    tifferror = ERR_READ;
                    break;
                }
                copy_row(currPtr, inbuf, w,samplesperpixel);
                currPtr -= format*w;
            }
            break;

        case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE):
            rowsize = TIFFScanlineSize(in);
            inbuf = new unsigned char [format*rowsize];
            for (row = 0; !tifferror && row < h; row++)
            {
                int s;
                for (s = 0; s < format; s++)
                {
                    if (TIFFReadScanline(in, (tdata_t)(inbuf+s*rowsize), (uint32)row, (tsample_t)s) < 0)
                    {
                        tifferror = ERR_READ; break;
                    }
                }
                if (!tifferror)
                {
                    if (format==3) interleave_row(currPtr, inbuf, inbuf+rowsize, inbuf+2*rowsize, w, format);
                    else if (format==4) interleave_row(currPtr, inbuf, inbuf+rowsize, inbuf+2*rowsize, inbuf+3*rowsize, w, format);
                    currPtr -= format*w;
                }
            }
            break;
        default:
            tifferror = ERR_UNSUPPORTED;
            break;
    }

    if (inbuf) delete [] inbuf;
    TIFFClose(in);

    if (tifferror)
    {
        if (buffer) delete [] buffer;
        return NULL;
    }
    width_ret = width;
    height_ret = height;
    if (photometric == PHOTOMETRIC_PALETTE)
        numComponents_ret = format;
    else
        numComponents_ret = samplesperpixel;

    return buffer;
}
コード例 #12
0
ファイル: tests.c プロジェクト: jejatu/SudokuSolver
void run_tests(void) {
    int unsolved[HEIGHT][WIDTH] = { { 5, 3, 0, 0, 7, 0, 0, 0, 0 },
                                    { 6, 0, 0, 1, 9, 5, 0, 0, 0 },
                                    { 0, 9, 8, 0, 0, 0, 0, 6, 0 },
                                    { 8, 0, 0, 0, 6, 0, 0, 0, 3 },
                                    { 4, 0, 0, 8, 0, 3, 0, 0, 1 },
                                    { 7, 0, 0, 0, 2, 0, 0, 0, 6 },
                                    { 0, 6, 0, 0, 0, 0, 2, 8, 0 },
                                    { 0, 0, 0, 4, 1, 9, 0, 0, 5 },
                                    { 0, 0, 0, 0, 8, 0, 0, 7, 9 } };

    int illegal[HEIGHT][WIDTH] = { { 5, 3, 5, 2, 7, 6, 7, 8, 9 },
                                   { 6, 1, 0, 1, 9, 5, 0, 0, 0 },
                                   { 0, 9, 8, 0, 0, 0, 0, 6, 0 },
                                   { 8, 2, 2, 0, 6, 0, 0, 0, 3 },
                                   { 4, 4, 0, 8, 0, 3, 6, 0, 1 },
                                   { 7, 0, 5, 0, 2, 0, 0, 0, 6 },
                                   { 0, 6, 0, 0, 0, 0, 2, 8, 0 },
                                   { 0, 0, 0, 4, 1, 9, 0, 0, 5 },
                                   { 4, 0, 0, 0, 8, 0, 0, 7, 9 } };

    int solved[HEIGHT][WIDTH] = { { 5, 3, 4, 6, 7, 8, 9, 1, 2 },
                                  { 6, 7, 2, 1, 9, 5, 3, 4, 8 },
                                  { 1, 9, 8, 3, 4, 2, 5, 6, 7 },
                                  { 8, 5, 9, 7, 6, 1, 4, 2, 3 },
                                  { 4, 2, 6, 8, 5, 3, 7, 9, 1 },
                                  { 7, 1, 3, 9, 2, 4, 8, 5, 6 },
                                  { 9, 6, 1, 5, 3, 7, 2, 8, 4 },
                                  { 2, 8, 7, 4, 1, 9, 6, 3, 5 },
                                  { 3, 4, 5, 2, 8, 6, 1, 7, 9 } };

    int row[WIDTH];
    int column[HEIGHT];
    int sub[SUB_HEIGHT][SUB_WIDTH];

    puts("Unsolved tests");
    test_rows(unsolved, 0);
    test_columns(unsolved, 0);
    test_subs(unsolved, 0);
    test_whole(unsolved, 0);

    copy_row(unsolved, 0, row);
    test_row_legality(row, 1);

    copy_column(unsolved, 0, column);
    test_column_legality(column, 1);

    copy_sub(unsolved, 0, 0, sub);
    test_sub_legality(sub, 1);

    test_legality(unsolved, 1);

    int illegal_move[3] = {0, 2, 5};
    test_legality_after_move(unsolved, illegal_move, 0);

    int legal_move[3] = {0, 2, 4};
    test_legality_after_move(unsolved, legal_move, 1);

    puts("Illegal tests");
    test_rows(illegal, 0);
    test_columns(illegal, 0);
    test_subs(illegal, 0);
    test_whole(illegal, 0);

    copy_row(illegal, 0, row);
    test_row_legality(row, 0);

    copy_column(illegal, 0, column);
    test_column_legality(column, 0);

    copy_sub(illegal, 0, 0, sub);
    test_sub_legality(sub, 0);

    test_legality(illegal, 0);

    puts("Presolved tests");
    test_rows(solved, 1);
    test_columns(solved, 1);
    test_subs(solved, 1);
    test_whole(solved, 1);

    solve(unsolved);

    puts("Solved tests");
    test_rows(unsolved, 1);
    test_columns(unsolved, 1);
    test_subs(unsolved, 1);
    test_whole(unsolved, 1);

    print_test_results();
}
コード例 #13
0
ファイル: spread.c プロジェクト: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
int
read_solution_spread (void)
/* ---------------------------------------------------------------------- */
{
/*
 *      Reads solution data
 *
 *      Arguments:
 *         none
 *
 *      Returns:
 *         KEYWORD if keyword encountered, input_error may be incremented if
 *                    a keyword is encountered in an unexpected position
 *         EOF     if eof encountered while reading mass balance concentrations
 *         ERROR   if error occurred reading data
 *
 */
  struct spread_row *heading, *row_ptr, *units;
  int i, j, l, j1, num, count;
  int strings, numbers;
  int spread_lines;
  char token[MAX_LENGTH], token1[MAX_LENGTH];
  char *ptr;
  struct defaults defaults = {
    25,
    1,
    "mmol/kgw",
    "pe",
    7,
    4,
    1,
    1,
    iso_defaults,
  };
  int return_value, opt;
  char *next_char;
  const char *opt_list[] = {
    "temp",			/* 0 */
    "temperature",		/* 1 */
    "dens",			/* 2 */
    "density",			/* 3 */
    "units",			/* 4 */
    "redox",			/* 5 */
    "ph",			/* 6 */
    "pe",			/* 7 */
    "unit",			/* 8 */
    "isotope",			/* 9 */
    "water",			/* 10 */
    "isotope_uncertainty",	/* 11 */
    "uncertainty",		/* 12 */
    "uncertainties"		/* 13 */
  };
  int count_opt_list = 14;
  if (svnid == NULL)
    fprintf (stderr, " ");

  heading = NULL;
  units = NULL;
  defaults.count_iso = count_iso_defaults;
  defaults.iso =
    (struct iso *) PHRQ_malloc ((size_t) defaults.count_iso *
				sizeof (struct iso));
  if (defaults.iso == NULL)
    malloc_error ();
  memcpy (defaults.iso, iso_defaults,
	  (size_t) defaults.count_iso * sizeof (struct iso));
  return_value = UNKNOWN;
  spread_lines = 0;
/*
 *   Loop on solutions
 */
  for (;;)
  {
    opt = get_option (opt_list, count_opt_list, &next_char);
    if (spread_lines == 0 && opt != OPTION_DEFAULT)
    {
      row_ptr = string_to_spread_row (line);
      count = 0;
      ptr = line;
      numbers = 0;
      strings = 0;
      while (((j = copy_token (token, &ptr, &l)) != EMPTY))
      {
	count++;
	if (j == UPPER || j == LOWER)
	  strings++;
	if (j == DIGIT)
	  numbers++;
      }
#ifdef SKIP
      for (i = 0; i < row_ptr->count; i++)
      {
	if (row_ptr->type_vector[i] == STRING)
	{
	  strings++;
	}
	else if (row_ptr->type_vector[i] == NUMBER)
	{
	  numbers++;
	}
      }
#endif
      /*
       * Is 2nd token all number
       */
      ptr = line;
      copy_token (token, &ptr, &l);
      j = copy_token (token, &ptr, &l);
      num = FALSE;
      if (j == DIGIT)
      {
	strtod (token, &ptr);
	j1 = copy_token (token1, &ptr, &l);
	if (j1 != EMPTY)
	{
	  num = FALSE;
	}
	else
	{
	  num = TRUE;
	}
      }

      /*
       *   Starts with hyphen
       */
      ptr = line;
      copy_token (token, &ptr, &l);
      if (token[0] == '-')
      {
	opt = opt;
      }
      else
      {
	switch (opt)
	{
	case 0:		/* temp */
	case 1:		/* temperature */
	case 2:		/* dens */
	case 3:		/* density */
	case 10:		/* water */
	  if (count == 2 && num == TRUE)
	  {
	    opt = opt;
	  }
	  else
	  {
	    opt = OPTION_DEFAULT;
	  }
	  break;
	case 6:		/* ph */
	case 7:		/* pe */
	  if ((count == 2 || count == 3 || count == 4) && num == TRUE)
	  {
	    opt = opt;
	  }
	  else
	  {
	    opt = OPTION_DEFAULT;
	  }
	  break;
	case 5:		/* redox */
	case 4:		/* units */
	case 8:		/* unit */
	  if (count == 2)
	  {
	    opt = opt;
	  }
	  else
	  {
	    opt = OPTION_DEFAULT;
	  }
	  break;
	case 9:		/* isotope */
	  if (row_ptr->count > 4)
	  {
	    opt = OPTION_DEFAULT;
	  }
	  else
	  {
	    opt = opt;
	  }
	  break;
	case 11:		/* isotope_uncertainty */
	case 12:		/* uncertainty */
	case 13:		/* uncertainties */
	  if (row_ptr->count > 3)
	  {
	    opt = OPTION_DEFAULT;
	  }
	  else
	  {
	    opt = opt;
	  }
	  break;
	}
      }
      spread_row_free (row_ptr);
    }
    if (opt == OPTION_DEFAULT)
    {
      if (spread_lines == 0)
      {
	opt = 100;
      }
      spread_lines++;
    }
    switch (opt)
    {
    case OPTION_EOF:		/* end of file */
      return_value = EOF;
      break;
    case OPTION_KEYWORD:	/* keyword */
      return_value = KEYWORD;
      break;
    case OPTION_ERROR:
      input_error++;
      error_msg ("Unknown input in SOLUTION keyword.", CONTINUE);
      error_msg (line_save, CONTINUE);
      break;
    case OPTION_DEFAULT:	/* solution definition */
      row_ptr = string_to_spread_row (line);
      if (spread_lines == 2)
      {
	numbers = 0;
	strings = 0;
	for (i = 0; i < heading->count; i++)
	{
	  if (row_ptr->type_vector[i] == STRING)
	  {
	    strings++;
	  }
	  else if (row_ptr->type_vector[i] == NUMBER)
	  {
	    numbers++;
	  }
#ifdef SKIP
	  if (row_ptr->type_vector[i] == STRING &&
	      (strcmp_nocase (heading->char_vector[i], "units") != 0) &&
	      (strcmp_nocase (heading->char_vector[i], "unit") != 0) &&
	      (strcmp_nocase (heading->char_vector[i], "description") != 0) &&
	      (strcmp_nocase (heading->char_vector[i], "desc") != 0) &&
	      (strcmp_nocase (heading->char_vector[i], "descriptor") != 0) &&
	      (strcmp_nocase (heading->char_vector[i], "redox") != 0))
	  {
	    break;
	  }
#endif
	}
#ifdef SKIP
	if (i < heading->count)
	{
	  units = row_ptr;
	  break;
	}
#endif
	if (numbers == 0)
	{
	  units = row_ptr;
	  break;
	}
      }
      spread_row_to_solution (heading, units, row_ptr, defaults);
#ifdef PHREEQCI_GUI
      add_row (row_ptr);
#endif
      spread_row_free (row_ptr);
      break;
    case 0:			/* temperature */
    case 1:
      sscanf (next_char, SCANFORMAT, &(defaults.temp));
      break;
    case 2:			/* density */
    case 3:
      sscanf (next_char, SCANFORMAT, &(defaults.density));
      break;
    case 4:			/* units */
    case 8:			/* unit */
      if (copy_token (token, &next_char, &l) == EMPTY)
	break;
      if (check_units (token, FALSE, FALSE, NULL, TRUE) == OK)
      {
	defaults.units = string_hsave (token);
      }
      else
      {
	input_error++;
      }
      break;
    case 5:			/* redox */
      if (copy_token (token, &next_char, &l) == EMPTY)
	break;
      if (parse_couple (token) == OK)
      {
	defaults.redox = string_hsave (token);
      }
      else
      {
	input_error++;
      }
      break;
    case 6:			/* ph */
      copy_token (token, &next_char, &l);
      sscanf (token, SCANFORMAT, &(defaults.ph));
      if (copy_token (token, &next_char, &l) != EMPTY)
      {
	warning_msg
	  ("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD.");
      }
      break;
    case 7:			/* pe */
      copy_token (token, &next_char, &l);
      sscanf (token, SCANFORMAT, &(defaults.pe));
      if (copy_token (token, &next_char, &l) != EMPTY)
      {
	warning_msg
	  ("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD.");
      }
      break;
    case 11:			/* isotope_uncertainty */
    case 12:			/* uncertainty */
    case 13:			/* uncertainties */
      if (copy_token (token, &next_char, &l) != DIGIT)
      {
	input_error++;
	sprintf (error_string, "Expected isotope name to"
		 " begin with an isotopic number.");
	error_msg (error_string, CONTINUE);
	continue;
      }
      for (i = 0; i < defaults.count_iso; i++)
      {
	if (strcmp (token, defaults.iso[i].name) == 0)
	{
	  break;
	}
      }
      if (i == defaults.count_iso)
      {
	defaults.iso =
	  (struct iso *) PHRQ_realloc (defaults.iso,
				       (size_t) (i +
						 1) * sizeof (struct iso));
	if (defaults.iso == NULL)
	  malloc_error ();
	defaults.iso[i].name = string_duplicate (token);
	defaults.iso[i].value = NAN;
	defaults.iso[i].uncertainty = NAN;
	defaults.count_iso++;
      }

      /* read and store isotope ratio uncertainty */
      if ((j = copy_token (token, &next_char, &l)) != EMPTY)
      {
	if (j != DIGIT)
	{
	  input_error++;
	  sprintf (error_string,
		   "Expected numeric value for uncertainty in isotope ratio.");
	  error_msg (error_string, CONTINUE);
	  continue;
	}
	else
	{
	  sscanf (token, SCANFORMAT, &(defaults.iso[i].uncertainty));
	}
      }
      else
      {
	defaults.iso[i].uncertainty = NAN;
      }
      break;
    case 10:			/* water */
      j = copy_token (token, &next_char, &l);
      if (j != DIGIT)
      {
	input_error++;
	sprintf (error_string,
		 "Expected numeric value for mass of water in solution.");
	error_msg (error_string, CONTINUE);
      }
      else
      {
	sscanf (token, SCANFORMAT, &(defaults.water));
      }
      break;
    case 9:			/* isotope */
      if (copy_token (token, &next_char, &l) != DIGIT)
      {
	input_error++;
	sprintf (error_string, "Expected isotope name to"
		 " begin with an isotopic number.");
	error_msg (error_string, CONTINUE);
	continue;
      }
      for (i = 0; i < defaults.count_iso; i++)
      {
	if (strcmp (token, defaults.iso[i].name) == 0)
	{
	  break;
	}
      }
      if (i == defaults.count_iso)
      {
	defaults.iso =
	  (struct iso *) PHRQ_realloc (defaults.iso,
				       (size_t) (i +
						 1) * sizeof (struct iso));
	if (defaults.iso == NULL)
	  malloc_error ();
	defaults.iso[i].name = string_duplicate (token);
	defaults.iso[i].value = NAN;
	defaults.iso[i].uncertainty = NAN;
	defaults.count_iso++;
      }
      /* read and store isotope ratio */
      if (copy_token (token, &next_char, &l) != DIGIT)
      {
	input_error++;
	sprintf (error_string,
		 "Expected numeric value for default isotope ratio.");
	error_msg (error_string, CONTINUE);
	break;
      }
      sscanf (token, SCANFORMAT, &(defaults.iso[i].value));
      /* read and store isotope ratio uncertainty */
      if ((j = copy_token (token, &next_char, &l)) != EMPTY)
      {
	if (j != DIGIT)
	{
	  input_error++;
	  sprintf (error_string,
		   "Expected numeric value for uncertainty in isotope ratio.");
	  error_msg (error_string, CONTINUE);
	  continue;
	}
	else
	{
	  sscanf (token, SCANFORMAT, &(defaults.iso[i].uncertainty));
	}
      }
      break;
    case 100:			/* read headings */
      heading = string_to_spread_row (line);
      for (i = 0; i < heading->count; i++)
      {
	while (replace (" ", "", heading->char_vector[i]) == TRUE);
	while (replace (",", "_", heading->char_vector[i]) == TRUE);
      }

      break;
    }
    if (return_value == EOF || return_value == KEYWORD)
      break;
  }
#ifdef PHREEQCI_GUI
  if (heading)
    g_spread_sheet.heading = copy_row (heading);
  if (units)
    g_spread_sheet.units = copy_row (units);
  copy_defaults (&g_spread_sheet.defaults, &defaults);
#endif
  spread_row_free (heading);
  spread_row_free (units);
  /* free non-default iso names */
  for (i = count_iso_defaults; i < defaults.count_iso; i++)
  {
    defaults.iso[i].name = (char *) free_check_null (defaults.iso[i].name);
  }
  defaults.iso = (struct iso *) free_check_null (defaults.iso);
  return (return_value);
}