/**************/ /* darea.c */ /**********************************************************/ /* to compile: */ /* gcc darea.c -o darea -L/home/SHARE/lib -lgm -lm */ /**********************************************************/ /* Usage: darea ncc spec path */ /*--------------------------------------------------------*/ /* ncc : nc[:iorg:korg] */ /* nc : Coordinate number */ /* iorg : Origin Lat. (minutes) */ /* korg : Origin Long. (minutes) */ /* spec : ift:igr[:llu:p1:p2] */ /* ift : File type (1-4 or 0) */ /* igr : Geodetic 1:WGS or 2:Tokyo */ /* llu : LatLonUnit 1:min. or 2:deg. */ /* p1 : Data position for Lat. */ /* p2 : Data position for Long. */ /* path : Input data file path */ /**********************************************************/ #include #include #include main(int argc, char *argv[]) { int nc=0, iorg=0, korg=0, ift=0, igr=0, llu=0, p1=0, p2=0; int ncm, ixs, iys, ixt, iyt; double dlat, dlon, d1, d2, vlat, vlon, valt, xn, ye, xmin, xmax, ymin, ymax; char buf[151], *ce; char fmt[91] = "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s" "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s"; FILE *fin; if (argc < 4) { printf("darea: parameters missing\n"); exit(1); } sscanf(argv[1], "%d:%d:%d", &nc, &iorg, &korg); sscanf(argv[2], "%d:%d:%d:%d:%d", &ift, &igr, &llu, &p1, &p2); ncm = ((nc<800)? nc: (nc-800)); if ((ncm>=1) && (ncm<=60)) { iorg = 0; korg = (ncm-30)*360 - 180; } else if (ncm == 61) { iorg = +5400; korg = 0; } else if (ncm == 62) { iorg = -5400; korg = 0; } if ((igr<1) || (igr>2)) { printf("darea: Illegal geod. specifier\n"); exit(1); } if (((igr==1) && (nc>=800)) || ((igr==2) && (nc<800))) igr += 2; switch (ift) { case 1: llu = 2; p1 = 5; p2 = 6; break; case 2: llu = 1; p1 = 2; p2 = 3; break; case 3: llu = 1; p1 = 3; p2 = 4; break; case 4: llu = 1; p1 = 1; p2 = 2; break; case 0: if ((llu<1) || (llu>2)) { printf("darea: Illegal specifier (llu)\n"); exit(1); } if ((p1<1) || (p1>30)) { printf("darea: Illegal specifier (p1)\n"); exit(1); } if ((p2<1) || (p2>30) || (p1==p2)) { printf("darea: Illegal specifier (p2)\n"); exit(1); } break; default: printf("darea: Unknown file type\n"); exit(1); } fmt[p1*3-2] = 'l'; fmt[p1*3-1] = 'f'; fmt[p2*3-2] = 'l'; fmt[p2*3-1] = 'f'; if (p1 < p2) { fmt[p2*3] = '\0'; } else { fmt[p1*3] = '\0'; } cvinit(nc, (double)iorg, (double)korg, 0., 0.); if ((fin=fopen(argv[3],"r")) == NULL) { printf("darea: input-file open fail\n"); exit(1); } while (1) { if (fgets(buf,151,fin) == NULL) { fclose(fin); printf("darea: no data found\n"); exit(1); } if ((buf[0]!='#') && (buf[0]!='&') && (buf[0]!='%')) break; } if (ift == 4) { if ((ce=strchr(buf,'N')) != NULL) *ce = ' '; if ((ce=strchr(buf,'E')) != NULL) *ce = ' '; if ((ce=strchr(buf,'m')) != NULL) *ce = ' '; if ((ce=strchr(buf,'n')) != NULL) *ce = ' '; if ((ce=strchr(buf,'T')) != NULL) *ce = ' '; if (sscanf(buf,"%lf %lf %lf %lf",&dlat,&dlon,&d1,&d2) != 4) { fclose(fin); printf("darea: input StdLIN format error\n"); exit(1); } } else { if (sscanf(buf,fmt,&d1,&d2) != 2) { fclose(fin); printf("darea: input-file format error\n"); exit(1); } if (p1 < p2) { dlat = d1; dlon = d2; } else { dlat = d2; dlon = d1; } if (llu == 2) { dlat *= 60.; dlon *= 60.; } } if (igr == 3) { xw84t(dlat, dlon, 0., &vlat, &vlon, &valt); cviken(vlat, vlon, &ye, &xn); } else if (igr == 4) { xtw84(dlat, dlon, 0., &vlat, &vlon, &valt); cviken(vlat, vlon, &ye, &xn); } else { cviken(dlat, dlon, &ye, &xn); } xmin = xmax = xn; ymin = ymax = ye; while (fgets(buf,151,fin) != NULL) { if ((buf[0]=='#') || (buf[0]=='&') || (buf[0]=='%')) continue; if (ift == 4) { if ((ce=strchr(buf,'N')) != NULL) *ce = ' '; if ((ce=strchr(buf,'E')) != NULL) *ce = ' '; if ((ce=strchr(buf,'m')) != NULL) *ce = ' '; if ((ce=strchr(buf,'n')) != NULL) *ce = ' '; if ((ce=strchr(buf,'T')) != NULL) *ce = ' '; sscanf(buf, "%lf %lf %lf %lf", &dlat,&dlon,&d1,&d2); } else { sscanf(buf,fmt,&d1,&d2); if (p1 < p2) { dlat = d1; dlon = d2; } else { dlat = d2; dlon = d1; } if (llu == 2) { dlat *= 60.; dlon *= 60.; } } if (igr == 3) { xw84t(dlat, dlon, 0., &vlat, &vlon, &valt); cviken(vlat, vlon, &ye, &xn); } else if (igr == 4) { xtw84(dlat, dlon, 0., &vlat, &vlon, &valt); cviken(vlat, vlon, &ye, &xn); } else { cviken(dlat, dlon, &ye, &xn); } if (xn < xmin) xmin = xn; if (xn > xmax) xmax = xn; if (ye < ymin) ymin = ye; if (ye > ymax) ymax = ye; } fclose(fin); ixs = (int)(xmin*1000.); ixt = (int)(xmax*1000.); iys = (int)(ymin*1000.); iyt = (int)(ymax*1000.); printf("OK\n"); printf("%d %d %d %d\n", ixs, iys, (ixt-ixs), (iyt-iys)); }