Ejemplo n.º 1
0
EXPORT	void	read_print_SESAME_params(
	SESAME_EOS    *seos,
	const IO_TYPE *io_type)
{
	char	s[10];
	FILE	*file = io_type->file;
	(void) fgetstring(file,"sesame library = ");
	(void) fscanf(file,"%s",seos->seslib);
	(void) fgetstring(file,"Sesame material index = ");
	(void) fscanf(file,"%d",&seos->ids2);

	seos->eps = fread_float("Discreteness = ",io_type);

	Rho_min(seos) = fread_float("minimum density = ",io_type);
	Rho_max(seos) = fread_float("maximum density = ",io_type);
	Rho_ref(seos) = fread_float("reference density = ",io_type);
	Temp_min(seos) = fread_float("minimum temperature = ",io_type);
	Temp_max(seos) = fread_float("maximum temperature = ",io_type);
	Temp_ref(seos) = fread_float("reference temperature = ",io_type);
	Reference_sound_speed(seos) =
		fread_float("reference sound speed = ",io_type);
	(void) fgetstring(file,"density mesh = ");
	(void) fscanf(file,"%d",&Nrho_hyp(seos));
	(void) fgetstring(file,"temperature mesh = ");
	(void) fscanf(file,"%d",&Ntemp_hyp(seos));
	seos->abser0 = fread_float("Absolute error = ",io_type);
	seos->reler0 = fread_float("relative error = ",io_type);

	Pressure_min(seos) = fread_float("minimum pressure = ",io_type);
	Pressure_max(seos) = fread_float("maximum pressure = ",io_type);
	Pressure_ref(seos) = fread_float("reference pressure = ",io_type);

	Energy_min(seos) = fread_float("minimum energy = ",io_type);
	Energy_max(seos) = fread_float("maximum energy = ",io_type);
	Energy_ref(seos) = fread_float("reference energy = ",io_type);

	Entropy_min(seos) = fread_float("minimum entropy = ",io_type);
	Entropy_max(seos) = fread_float("maximum entropy = ",io_type);
	RS_entropy_scale(seos) =
	    fread_float("density-entropy entropy scale = ",io_type);
	RS_entropy_shift(seos) =
	    fread_float("density-entropy entropy shift = ",io_type);
	PS_entropy_scale(seos) =
	    fread_float("pressure-entropy entropy scale = ",io_type);
	PS_entropy_shift(seos) =
	    fread_float("pressure-entropy entropy shift = ",io_type);

	(void) fgetstring(file,"Multiphase eos = ");
	(void) fscanf(file,"%s",s);
	multiphase_eos(seos) = (s[0] == 'Y') ? YES : NO;
}		/*end read_print_SESAME_params*/
Ejemplo n.º 2
0
Archivo: file.c Proyecto: nrhtr/genesis
/* slower, but we get clean output */
cStr *read_file(filec_t * file)
{
    register char *p, *s;
    register int len;
    cStr *str;

    if (feof(file->fp))
        THROWN((eof_id, "End of file.")) str = fgetstring(file->fp);

    if (!str)
        THROWN((eof_id, "End of file."))
            /* ok, munch meta-characters */
            p = s = string_chars(str);
    len = string_length(str);

    while (len-- && *s) {
        if (ISPRINT(*s)) {
            *p = *s;
            p++;
        } else if (*s == '\t') {
            *p = ' ';
            p++;
        }
        s++;
    }
    *p = '\0';

    str->len = p - string_chars(str);

    return str;
}
Ejemplo n.º 3
0
EXPORT	void	stripcomm(
	char	   *scfname,	/*Strip commented file name*/
	const char *fname)	/*Raw input file name*/
{
	FILE	*file = fopen(fname,"r");
	FILE	*scfile;
	char	*c, line[2048];
	static const char *separator = ": ";
	boolean	status;
	size_t	sep_len = strlen(separator);
	long	io_pid;

	if (file == NULL)
	{
	    screen("ERROR in stripcomm(), can't open %s\n",fname);
	    clean_up(ERROR);
	}
	if (fgetstring(file,separator) == FUNCTION_FAILED)
	{
	    /*File is already stripcommented*/
	    (void) strcpy(scfname,fname);
	    (void) fclose(file);
	    return;
	}

	io_pid = (is_io_node(pp_mynode())) ? (long) getpid() : 0;
	pp_global_lmax(&io_pid,1L);

	(void) sprintf(scfname,"%s-%ld.sc",fname,io_pid);

	if (is_io_node(pp_mynode()))
	{
	    rewind(file);
	    if ((scfile = fopen(scfname,"w")) == NULL)
	    	status = NO;
	    else
	    {
	    	status = YES;
	    	while (fgets(line,2046,file) != NULL)
	    	    if ((c = strstr(line,separator)) != NULL)
		    	(void) fprintf(scfile,"%s",c+sep_len);
	        (void) fclose(scfile);
	    }
	}
	else
	    status = YES;

	(void) fclose(file);

	if (pp_min_status(status) == NO)
	{
	    screen("ERROR in stripcomm(), can't open %s\n",scfname);
	    clean_up(ERROR);
	}

	return;
}		/*end stripcomm*/
Ejemplo n.º 4
0
EXPORT	double	read_print_float(
	const char    *search_string,
	double	      dflt_value,
	const IO_TYPE *io_type)
{
	FILE	*file = io_type->file;
	double	value = dflt_value;

	if ((search_string != NULL) && (!fgetstring(file,search_string)))
	    return value; 
	value = fread_float(NULL,io_type);
	return value;
}		/*end read_print_float*/
Ejemplo n.º 5
0
void AGSPlatformDriver::ReadPluginsFromDisk(FILE *iii) {
  if (getw(iii) != 1)
    quit("ERROR: unable to load game, invalid version of plugin data");

  int numPlug = getw(iii), a, datasize;
  char buffer[80];

  for (a = 0; a < numPlug; a++) {
    // read the plugin name
    fgetstring (buffer, iii);
    datasize = getw(iii);
    fseek (iii, datasize, SEEK_CUR);
  }

}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {
    int error = 0;
    char command[20];
    char args[10][10];
    int pid = 0;
    int psw = 0;
    int page_table = 0;
    int reg1 = 0;
    int reg2 = 0;
    int reg3 = 0;
    int group = 0;
    int regs[3];
    FILE *file;
	int priority = 0;
    if (argc == 1){
        file = stdin;
    }
    else if (argc == 2){
        file = fopen(argv[1], "r");
    }
    else{
        printf("Usage:\n./processmanager_test.o (to read from stdin)\n");
        printf("./processmanager_test.o <filename> (to read from filename)\n");
        exit(-1);
    }

    init(GROUP);


    while(1) {
        /*printf("***reading the file***\n");*/
        if (file == stdin) {
            printf("> ");
        }
        error = fscanf(file," %s", command);
        if (error == 1){
            /* printf("%s\n", line); */
            /* printf("%s\n", command); */

            if (!strcmp(command, "INIT")) {
                error = fscanf(file, " %s", args[0]);
                if (error == 1){
                    if (!strcmp(args[0], "GROUP")){
                        printf("\n***INIT command issued (%s)***\n", args[0]);
                        init(GROUP);
                    }
                    else if(!strcmp(args[0], "PRIORITY")){
                        printf("\n***INIT command issued (%s)***\n", args[0]);
                        init(PRIORITY);
                    }
                    else{
                        printf("Usage: INIT <GROUP | PRIORITY>\n");
                    }
                }
                else{
                    printf("Usage: INIT <GROUP | PRIORITY>\n");
                }

            }
            else if (!strcmp(command, "LIST")) {
                error = fscanf(file, " %s", args[0]);
                if (error == 1){
                    printf("\n***LISTING command issued (%s)***\n", args[0]);
                    if (!strcmp(args[0], "NEW")){
                        list_Q(NEW);
                    }
                    else if (!strcmp(args[0], "WAITING")){
                        list_Q(WAITING);
                    }
                    else if (!strcmp(args[0], "READY")){
                        list_ready();
                    }
                    else if (!strcmp(args[0], "TERMINATED")){
                        list_Q(TERMINATED);
                    }
                    else if (!strcmp(args[0], "RUNNING")){
                        list_Q(RUNNING);
                    }
                    else if (!strcmp(args[0], "ALL")){
                        list_all();
                    }
                    else if (!strcmp(args[0], "SCHED")){
                        list_sched();
                    }
                    else{
                        printf("Usage: LIST <NEW | WAITING | READY | TERMINATED | RUNNING | ALL | SCHED>\n");
                    }
                }
                else{
                    printf("Usage: LIST <NEW | WAITING | READY | TERMINATED | RUNNING | ALL | SCHED>\n");
                }
            }
            else if (!strcmp(command, "GO")){
                printf("\n***GO command issued***\n");
                error = go();
                if (error == ERROR_NO_READY_PROCESS){
                    printf("Could not GO: %s\n", error_to_string(error));
                }
                else if (error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_SWITCH_DEFAULT ||
						error == ERROR_PROCESS_NOT_EXIST){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "UNWAIT")) {
                error = fscanf(file, " %d", &pid);
                if (error == 1){
                    printf("\n***UNWAIT command issued (PID: %d)***\n", pid);
                    error = unwait(pid);
                    if (error == ERROR_QUEUE_EMPTY){
                        printf("Could not UNWAIT: No waiting processes\n");
                    }
                    else if (error == ERROR_PROCESS_NOT_EXIST){
                        printf("Could not UNWAIT: PID does not exist in waiting queue\n");
                    }
                    else if (error == ERROR_QUEUE_FULL){
                        printf("FATAL ERROR: %s\n", error_to_string(error));
                        exit(-1);
                    }
                }
                else{
                    printf("Usage: UNWAIT <pid>\n");
                }
            }
			else if (!strcmp(command, "SET_PRIORITY")) {

				error = fscanf(file, " %d %d", &pid, &priority);
				if (error == 2){
					printf("\n***SET_PRIORITY command issued (PID: %d)***\n", pid);
					error = set_priority(pid, priority);
					if (error == ERROR_WRONG_SCHEDULER){
						printf("Could not SET_PRIORITY: Command only avaliable in Priority Scheduler\n");
					}
					else if (error == ERROR_PROCESS_NOT_EXIST){
						printf("Could not SET_PRIORITY: PID does not exist in ready queue\n");
					}
					else if (error == ERROR_INVALID_PARAMETER){
						printf("Could not SET_PRIORITY: Priority must be between 1 and %d\n", MAX_PRIORITY);
					}
				}
				else{
					printf("Usage: SET_PRIORITY <pid> <priority>\n");
				}

            }
            else if (!strcmp(command, "EOLIFE")) {
                printf("\n***EOLIFE command issued***\n");
                error = eolife();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not EOLIFE: No running processes\n");
                }
                else if (error == ERROR_QUEUE_FULL){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "WAIT")) {
                printf("\n***WAIT command issued***\n");
                error = wait_();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not WAIT: No running processes\n");
                }
                else if (error == ERROR_QUEUE_FULL){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "CREATE")) {
                /*Group Scheduler*/
                if (scheduler == GROUP){
                    error = fscanf(file, " %d %d %d %d %d %d", &psw, &page_table, &reg1, &reg2, &reg3, &group);
                    if (error == 6){
                        /* printf("pid: %d, psw: %d, page_table: %d, reg1: %d, reg2: %d, reg3: %d\n", pid, psw, page_table, reg1, reg2, reg3); */
                        regs[0] = reg1;
                        regs[1] = reg2;
                        regs[2] = reg3;

						error = create(psw, page_table, regs, group);
						if (error == ERROR_MAX_PROCESSES){
							printf("Could not CREATE: Maximum allowed processes reached\n");
						}
						else if (error == ERROR_GROUP_NOT_EXIST){
							printf("Could not CREATE: Invalid group number\n");
						}
						else if (error == ERROR_PROCESS_NOT_UNIQUE ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL) {
							printf("FATAL ERROR: %s\n", error_to_string(error));
							exit(-1);
						}
						else if (error == ERROR_SUCCESS){
							printf("\n***CREATE command issued (PID: %d)***\n", (pid_counter - 1));
						}
					}
					else{
						printf("Usage: CREATE <psw> <page_table> <reg1> <reg2> <reg3> <group>\n");
					}
				}
				/*Priority Scheduler*/
				else{
					error = fscanf(file, " %d %d %d %d %d", &psw, &page_table, &reg1, &reg2, &reg3);
					if (error == 5){
						/* printf("pid: %d, psw: %d, page_table: %d, reg1: %d, reg2: %d, reg3: %d\n", pid, psw, page_table, reg1, reg2, reg3); */
						regs[0] = reg1;
						regs[1] = reg2;
						regs[2] = reg3;

						printf("\n***CREATE command issued (PID: %d)***\n", pid_counter);
						/*Priority scheduler defaults to group 0*/
						error = create(psw, page_table, regs, 0);
						if (error == ERROR_MAX_PROCESSES){
							printf("Could not CREATE: Maximum allowed processes reached\n");
						}
						else if (error == ERROR_PROCESS_NOT_UNIQUE ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_GROUP_NOT_EXIST) {
							printf("FATAL ERROR: %s\n", error_to_string(error));
							exit(-1);
						}
						else if (error == ERROR_SUCCESS){
							printf("\n***CREATE command issued (PID: %d)***\n", (pid_counter - 1));
						}
					}
					else{
						printf("Usage: CREATE <psw> <page_table> <reg1> <reg2> <reg3>\n");
					}
				}
            }
            else if (!strcmp(command, "EMPTY_TERM")){
                printf("\n***EMPTY_TERM command issued***\n");
                error = empty_term();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not EMPTY_TERM: No process in terminated queue\n");
                }
            }
            else if (!strcmp(command, "#")) {
                printf("\n################################################################################\n");
                printf("#");
                textcolor(BRIGHT, WHITE, BLACK);
                printf("%s\n", fgetstring(file));
                textcolor(RESET, -1, -1);
                printf("################################################################################\n");
            }
            else {
                printf("Unrecognized command: %s\n", command);
            }
        }
        else
            if (error == EOF) {
                printf("\n");
                break;
            }
    }

    fclose(file);

    return(0);
}
Ejemplo n.º 7
0
EXPORT	double	fread_float(
	const char    *label,
	const IO_TYPE *io_type)
{
	FILE	*file = io_type->file;
	double	x;
	char	s[81];
	int	c;
	char *string;
	size_t size;

	if (label != NULL)
	    (void) fgetstring(file,label);
	if ((c = getc(file)) != '\f') /*NOBINARY*/
	{
	    long current;
	    (void) ungetc(c,file);
	    current = ftell(file);
	    string = fgets(s,5,file);
	    if (strncasecmp("inf",s,3) == 0)
	    	x = HUGE_VAL;
	    else if (strncasecmp("-inf",s,4) == 0)
	    	x = -HUGE_VAL;
	    else
	    {
		(void) fseek(file,current,SEEK_SET);
	        if (fscanf(file,scan_float_fmt,&x) != 1)
		{
	    	    screen("ERROR in fread_float(), "
	    	           "can't read floating point variable\n");
	    	    clean_up(ERROR);
		}
	    }
	}
	else
	{
	    (void) getc(file);
	    if (io_type->read_float_size == io_type->cpu_float_size)
	    {
	        size = fread((void *)&x,sizeof(double),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(x);
	    }
	    else if (io_type->read_float_size > io_type->cpu_float_size)
	    {
		double tmp;
	        size = fread((void *)&tmp,sizeof(double),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(tmp);
		x = tmp;
	    }
	    else
	    {
	        TRUEfloat tmp;
	        size = fread((void *)&tmp,sizeof(TRUEfloat),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(tmp);
		x = tmp;
	    }
	}
	return x;
}		/* end fread_float*/
Ejemplo n.º 8
0
static bool pass2( FILE *fin, int fout, char **helpstr )
{
    char            buffer[ BUFFER_SIZE ];
    a_helpnode      *h;
    unsigned long   indexlen;

    printf( "Pass Two:\n" );
    if( GenIndex ) {
        indexlen = CalcIndexSize( helpstr, GenStrings );
        lseek( fout, indexlen, SEEK_SET );
    }
    for( h = HelpNodes; h != NULL; h = h->next ) {
        if( Verbose ) {
            printf( "   %s %d %d", h->name, h->maxrow, h->maxcol );
            if( h->row != -1 ) {
                printf( "%d %d", h->row, h->col );
            }
            if( h->lines != -1 ) {
                printf( "%d", h->lines );
            }
            printf( "\n" );
        }
        fseek( fin, h->fpos, SEEK_SET );
        fgetstring( buffer, BUFFER_SIZE, fin );
        h->maxcol += 1;
        h->maxcol = (h->maxcol / 2) * 2;
        if( h->maxcol > MaxCol ) {
            PrintError( "%s %d %d image too wide\n",
                     h->name, h->maxrow, h->maxcol );
            h->maxcol = MaxCol;
        }
        if( h->maxcol > MaxCol-10 ) {
            h->maxcol = MaxCol;
        }
        if( h->maxrow > MaxRow ) {
            if( h->maxrow > MaxRow ) {
                h->maxrow = MaxRow;
            }
        }
        if( Height ) {
            h->maxrow = Height;
        }
        if( Width ) {
            h->maxcol = Width;
        }
        sprintf( buffer, "::::\"%s\" %d %d %d %d %d\r\n",
                 h->name, h->maxrow, h->maxcol, h->row, h->col, h->lines );
        if( GenIndex ) {
            h->fpos = tell( fout );
        }
        write( fout, buffer, strlen( buffer ) );

        while( !feof( fin ) ) {
            fgetstring( buffer, BUFFER_SIZE, fin );
            if( memcmp( buffer, "::::", 4 ) == 0 )
                break;
            check_buffer( h, buffer );
            write( fout, buffer, strlen( buffer ) );
        }
    }
    return( TRUE );
}
Ejemplo n.º 9
0
static bool pass1( FILE *fin, char **helpstr )
{
    char            buffer[ BUFFER_SIZE ];
    int             buflen;
    long            fpos;
    a_helpnode      *h;
    a_helpnode      **hn;
    char            *ptr;
    int             cmp;
    char            *namebuff;
    unsigned        namebuff_len;
    int             count;
    int             len;
    unsigned        topic_len;
    unsigned        desc_len;

    namebuff = NULL;
    namebuff_len = 0;
    topic_len = strlen( DEFTOPIC );
    desc_len = strlen( DESCRIPTION );

    printf( "Pass One:\n" );
    fpos = 0;
    while( !feof( fin ) ) {
        fpos = ftell( fin );
        fgetstring( buffer, BUFFER_SIZE, fin );
        if( memcmp( buffer, DEFTOPIC, topic_len ) == 0 ) {
            if( helpstr[0] != NULL ) {
                PrintError( "more than one DEFTOPIC found\n" );
            } else {
                if( !GenStrings || !GenIndex ) {
                    PrintError( "DEFTOPIC string ignored with this format.\n" );
                }
                if( GenStrings ) {
                    ptr = find_str( &buffer[topic_len] );
                    helpstr[0] = HelpMemAlloc( strlen( ptr ) + 1 );
                    strcpy( helpstr[0], ptr);
                }
            }
        } else if( memcmp( buffer, DESCRIPTION, desc_len ) == 0 ) {
            if( helpstr[1] != NULL ) {
                PrintError( "more than one DESCRIPTION found\n" );
            } else {
                if( !GenStrings || !GenIndex ) {
                    PrintError( "DESCRIPTION string ignored with this format.\n" );
                }
                if( GenStrings ) {
                    ptr = find_str( &buffer[desc_len] );
                    helpstr[1] = HelpMemAlloc( strlen( ptr ) + 1 );
                    strcpy( helpstr[1], ptr );
                }
            }
        } else if( memcmp( buffer, "::::", 4 ) == 0 )
            break;
    }
    while( !feof( fin ) ) {
        h = (a_helpnode *)HelpMemAlloc( sizeof( a_helpnode ) );
        h->fpos = fpos;
        buflen = strlen( buffer );
        if( buffer[ buflen-1 ] == '\n' ) {
            buffer[ buflen-1 ] = '\0';
        }
        h->maxrow = 0;
        h->maxcol = 0;
        h->row = -1;
        h->col = -1;
        h->lines = -1;
        ptr = &buffer[4];
        if( *ptr == '"' ) {
            ptr ++;
            while( *ptr != '\0' && *ptr != '"' ) {
                if( *ptr == HELP_ESCAPE )
                    ptr++;
                ptr++;
            }
            len = ptr - &buffer[5];
            if( namebuff_len <= len ) {
                HelpMemFree( namebuff );
                namebuff = HelpMemAlloc( len + 1 );
                namebuff_len = len + 1;
            }
            memcpy( namebuff, &buffer[5], len );
            namebuff[len] = '\0';
            if( *ptr == '"' )
                ++ptr;
        } else {
            for( ; *ptr != '\0'  &&  !isspace(*ptr); ++ptr )
                ;
            while( *ptr != '\0'  &&  !isspace(*ptr) ) {
                if( *ptr == HELP_ESCAPE )
                    ptr++;
                ptr++;
            }
            len = ptr - &buffer[4];
            if( namebuff_len <= len ) {
                HelpMemFree( namebuff );
                namebuff = HelpMemAlloc( len + 1 );
                namebuff_len = len + 1;
            }
            memcpy( namebuff, &buffer[4], len );
            namebuff[len] = '\0';
        }
        while( isspace( *ptr ) )
            ++ptr;
        if( *ptr != '\0' ) {
            count = sscanf( ptr, "%d %d %d %d %d",
                    &h->maxrow, &h->maxcol, &h->row, &h->col,
                    &h->lines );
            if( count != 2  && count != 4  &&  count != 5 ) {
                PrintError( "invalid help topic line '%s'\n", buffer );
            }
        }
        h->name = strdup( namebuff );
        if( Verbose ) {
            printf( "   %s\n", h->name );
        }
        for( hn=&HelpNodes; *hn != NULL; hn=&(*hn)->next ) {
            cmp = stricmp( h->name, (*hn)->name );
            if( cmp == 0 ) {
                PrintError( "Duplicate Help Topic '%s'\n", h->name );
            }
            if( cmp <= 0 ) {
                h->next = *hn;
                *hn = h;
                break;
            }
        }
        if( *hn == NULL ) {
            h->next = NULL;
            *hn = h;
        }
        if( h->row == -1 ) {
            h->row = 0;
            h->col = 0;
        }
        h->maxcol = 0;
        h->maxrow = 0;
        h->lines = 0;
        while( !feof( fin ) ) {
            fpos = ftell( fin );
            fgetstring( buffer, BUFFER_SIZE, fin );
            if( memcmp( buffer, "::::", 4 ) == 0 )
                break;
            if( strnicmp( buffer, ":eh", 3 ) == 0
                || strnicmp( buffer, ":et", 3 ) == 0 ) {
                h->lines = 0;
            } else if( strnicmp( buffer, ":h", 2 ) == 0
                    || strnicmp( buffer, ":t", 2 ) == 0  ) {
            } else {
                buflen = line_len( buffer );
                if( buflen - 1 > h->maxcol ){
                    h->maxcol = buflen - 1;
                }
                h->lines += 1;
                h->maxrow += 1;
            }
        }
    }
    HelpMemFree( namebuff );
    return( TRUE );
}
Ejemplo n.º 10
0
EXPORT void read_rectangular_grid(
	const IO_TYPE *io_type,
	RECT_GRID     *gr,
	boolean	      bufzones,
	REMAP         *remap)
{
	FILE *file = io_type->file;
	char Line[2048];
	char ss[120];
	long offset;
	int  i, c;
	int  dim;
	int  maxd = MAXD, size_float = FLOAT;
	boolean b_iput;
	int status;
	char *string;

	if (gr == NULL)
	{
	    (void) printf("WARNING in read_rectangular_grid(), grid is null\n");
	    return;
	}
	zero_scalar(gr,sizeof(RECT_GRID));
	gr->Remap = *remap;

	if (fgetstring(file,"Grid Dimension = ") == FUNCTION_FAILED)
	{
	    gr->dim = 2;
	}
	else
	{
	    status = fscanf(file,"%d",&dim);
	    while ((c = getc(file)) != '\n');
	    if ((c = getc(file)) == '\f') /* Binary input */
	    {
	        c = getc(file);
	        if (c == 1) /*oldstyle printout*/
	        {
		    size_t nbytes;
		    (void) printf("WARNING in read_rectangular_grid(), "
		                  "old style binary IO only valid for\n"
				  "reading from runs with same floating "
				  "point precision and endian as output\n");
	            nbytes = fread((void *)gr,sizeof(RECT_GRID),1,file);
		    return;
		}
		if (c != 0)
		{
		    screen("ERROR in read_rectangular_grid(), "
		           "Improper output format\n");
		    clean_up(ERROR);
		    return;
		}
		b_iput = YES;
		status = fscanf(file,"%*s%*s%d%*s%*s%d",&maxd,&size_float);
		(void) getc(file); /* newline */
	    }
	    else
	    {
	        b_iput = NO;
		(void) ungetc(c,file);
	    }
	}
	gr->dim = dim;
	(void) sprintf(ss,"%10s = ",remap->Dnm[0]);
	if (fgetstring(file,ss) == FUNCTION_FAILED)
	{
	    (void) printf("WARNING in read_rectangular_grid(), "
			  "grid not found\n");
	    return;
	}
	string = fgets(Line,2046,file);		/* clear end of X,Y line */

#define read_grid_float(x)						\
	if (b_iput)							\
	{								\
	    (void) getc(file); /* get blank */				\
	    (void) read_binary_real_array(x,1,io_type);			\
	}								\
	else								\
	    (void) fscan_float(file,(x))

	/* Read grid endpoints */
	for (i = 0; i < dim; ++i)
	{
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->L+i);
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->U+i);
	}
	/* Read grid spacings */
	for (i = 0; i < dim; ++i)
	{
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->h+i);
	    status = fscanf(file,"%*s%*s%d",gr->gmax+i);
	}

	offset = ftell(file);
	(void) sprintf(ss,"  G%sL = ",remap->Dnm[0]);
	if (fgetstring(file,ss) == FUNCTION_FAILED)
	{
	    for (i = 0; i < dim; ++i)
	    {
	    	if (bufzones == YES)
	    	{
	    	    gr->lbuf[i] = gr->ubuf[i] = 1;
	            gr->GL[i] = gr->L[i];
		    gr->GU[i] = gr->U[i];
		    gr->VL[i] = gr->L[i] - cell_width(0,i,gr);
		    gr->VU[i] = gr->U[i] + cell_width(gr->gmax[i]-1,i,gr);
		}
		else
		{
		    gr->lbuf[i] = gr->ubuf[i] = 0;
		    gr->GL[i] = gr->L[i];
		    gr->GU[i] = gr->U[i];
		    gr->VL[i] = gr->L[i];
		    gr->VU[i] = gr->U[i];
		}
	    }
	    return;
	}
	(void) fseek(file,offset,SEEK_SET);
	/* Read global grid endpoints */
	for (i = 0; i < dim; ++i)
	{
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->GL+i);
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->GU+i);
	}
	/* Read virtual domain endpoints */
	for (i = 0; i < dim; ++i)
	{
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->VL+i);
	    status = fscanf(file,"%*s%*s");
	    read_grid_float(gr->VU+i);
	}
	/* Read buffer zone widths */
	for (i = 0; i < dim; ++i)
	    status = fscanf(file,"%*s%*s%d%*s%*s%d",gr->lbuf+i,gr->ubuf+i);

	set_rect_grid(gr->L,gr->U,gr->GL,gr->GU,gr->lbuf,gr->ubuf,gr->gmax,
		      dim,&gr->Remap,gr);

#undef read_grid_float
	return;
}		/*end read_rectangular_grid*/