/* *******************************************************************
 *                                                                   *
 * Copyright (c) L-DGO/MIT/JGOFS                                     *
 *                                                                   *
 *                                                                   *
 * File             : coast.c                                        *
 *                                                                   *
 * Purpose          :                                                *         
 *                                                                   *
 * Version Number   : 1.1a                                           *
 *                                                                   *
 * Revision History :                                                *
 *                                                                   *
 * Date                              Developer                       *
 * ----                              ---------                       *
 *                                                                   *
 * Sat Oct 17  1992 10.00           Glenn Flierl                     *
 * Thu Nov 12  1998 12:00	Christine Hammond	v1.1a	     *
 *		'type' all functions as void if no returned value    *
 *                                                                   *   
 * Thu Nov 12  1998 17:00	Christine Hammond	v1.1b	     *
 *		err call in ioopen generated compiler error	     *
 *		changed from err("coastline..",s);		     *
 *		to err("coastline...",s[0]);			     *
 *                                                                   *
 ******************************************************************* */

#include <stdio.h>
#include <string.h>

FILE *fl;
short d[2];
char *names[]={"lon","lat"};

void err(s,t)
char *s,*t;
{
printf("&x error - %s %s\n",s,t);
exit(1);
}

int ioopen_(s,nparams,ntotal)
char *s[];
int *nparams,*ntotal;
{
if((fl=fopen(s[0],"rb")) == NULL)err("coastline file name ",s[0]);
s[0][0] = 0;
*ntotal=2;
return 0;
}

void ioname_(vn,s)
int *vn;
char *s;
{
strcpy(s,names[*vn]);
}

int iovarlevel_(vn)
int *vn;
{
return 0;
}

int ioattrout_(vn,str)
int *vn;
char *str;
{
return 0;
}

void iovalreal_(vn,f)
int *vn;
float *f;
{
if(d[0] == 30000) *f= -9999.0;
else
switch (*vn){
  case 0: *f=d[1]/100.0;break;
  case 1: *f=d[0]/100.0;break;
  };
}

void iovalstr_(vn,tmp)
int *vn;
char *tmp;
{
float f;
if(d[0]==30000)
  strcpy(tmp,"nd");
else{
  iovalreal_(vn,&f);
  sprintf(tmp,"%-.2f",f);
};
}

int ioreadrec_(level)
int *level;
{
if(feof(fl))return 0;
if((int)fread(d,2,2,fl)<2) return 0;
return 1;
}

void ioclose_(maxlevel)
int *maxlevel;
{
fclose(fl);
}

int iocommout_(str)
char *str;
{
return 0;
}

int iowidth_(vn)
int *vn;
{
return 0;
}
