DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T a

⟦42151d9b8⟧ TextFile

    Length: 1760 (0x6e0)
    Types: TextFile
    Names: »ascii2var.c++«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/image/vartools/ascii2var.c++« 

TextFile

/*
    This contains the work routine that converts an image to
    a ascii file
*/
#include <stream.h>
#include <stdio.h>
#include <string.h>
#include <double_image.h++>
#include "vartools.h++"


// input is a file pointer to the input file
// output is a file pointer open for output
void
ascii2var(FILE *input , FILE *output)
    {
    int number_rows = -1;
    int number_cols = -1;
    // read the length and the width
    fscanf(input,"%d%d",&number_rows,&number_cols);
    // initialize the image
    double_image output_image(CREATE,number_rows,number_cols,output);

    // iterate through the output image reading in numbers
    while(output_image++)
	{
	fscanf(input,"%lf",&(output_image()));
	}
    
    // scan through the image until an end of file or a new line
    char c;
    for(;;) 
	{
	c = getc(input);
	if ( c == EOF ) return ;
	if ( c == '\n') break;
	}

    // read in the comments
    int comments_size = 128;
    char * comments = new char[comments_size];
    for ( int i = 0 ; EOF != (c = getc(input)) ; i++ )
	{
	// if you ran out of room double the size of the comments
	if ( i == comments_size )
	    {
	    char *new_comments = new char[comments_size + comments_size];
	    for( int j = 0 ; j < comments_size ; j++ )
		{
		new_comments[j] = comments[j];
		}
	    comments_size += comments_size;
	    comments = new_comments;
	    }
	comments[i] = c;
	}
    comments[i] = 0;
    output_image.set_comments(comments,i);

    // write the output to disk
    output_image.write();
    }
/*
Copyright (C) 1986, David Sher in the University of Rochester
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit, provided
this copyright notice is retained.
*/