#include <stdio.h>
#include <string.h>
#include <ctype.h>
/* #define DEBUG */
#define TOKEN 40


double atof();

main(argc,argv)
int argc;
char *argv[];
{
char cx;
int i,nparams;
float latmin,latmax,latdel,lat,lonmin,lonmax,londel,lon;
char namtst[TOKEN],*s;

nparams=0;
for(i=1;i<argc;i++) {
  cx=argv[i][0];
  if(isdigit(cx) || cx=='.' || cx=='-' || cx=='+')nparams++;
};

latmin= -90.0;latmax=90.0;
lonmin= -180.0;lonmax=180.0;
latdel=30.0;londel=30.0;
switch(nparams){
 case 0:break;
 case 2:londel=atof(argv[1]);latdel=atof(argv[2]);break;
 case 4:lonmin=atof(argv[1]);lonmax=atof(argv[3]);
        latmin=atof(argv[2]);latmax=atof(argv[4]);break;
 case 6:lonmin=atof(argv[1]);lonmax=atof(argv[3]);
        latmin=atof(argv[2]);latmax=atof(argv[4]);
        londel=atof(argv[5]);latdel=atof(argv[6]);break;

  };
printf("Content-type: text/plain\n\n");
printf("&v0\nlon\tlat\t\n&r\n&d0\n");

for(lat=latmin;lat<=latmax;lat += latdel){
  for(lon=lonmin;lon<=lonmax; lon += londel/8.0){
    sprintf(namtst,"%7.2f",lon);
    s=namtst+strspn(namtst," ");
    printf("%s\t",s);
    sprintf(namtst,"%6.2f",lat);
    s=namtst+strspn(namtst," ");
    printf("%s\t\n",s);
  };
  printf("nd\tnd\t\n");
};
for(lon=lonmin;lon<=lonmax;lon += londel){
  for(lat=latmin;lat<=latmax; lat += latdel/8.0){
    sprintf(namtst,"%7.2f",lon);
    s=namtst+strspn(namtst," ");
    printf("%s\t",s);
    sprintf(namtst,"%6.2f",lat);
    s=namtst+strspn(namtst," ");
    printf("%s\t\n",s);
  };
  printf("nd\tnd\t\n");
};
printf("&e");
}
