/* Program to copy FNOC Modal Height data from binary CD-ROM file */ /* to user's disc in ASCII or Binary for the specified range of */ /* records. NOTE: Integers assumed 4-byte length, short is 2-byte */ /* By: Peter W. Sloss */ /* NOAA/NGDC, Boulder, CO */ #include struct in_record { short longitude,latitude,modal_elev,max_elev,min_elev; char ridges_tot,ridges_dir,primary_sfc,secondary_sfc; short sfc_water,sfc_urban; }; float Latitude,Longitude; int i,j,k,nskip,ncopy,maxbands; long offset,nbytes,bytes_read,bytes_written; FILE *IN,*OUT; char infile[80],outfile[32],outbuf[42],isASCII,Ok,copy_ok; int swap2(); main() { struct in_record FNOC; printf("Enter FULL PATHNAME for FNOC.BIN;1 data file,\n"); /* next line gives Macintosh-style pathname */ /* for DOS PC, substitute CD drive letter, e.g., L:\ for */ /* "NGDC_RELIEF:", and backslashes (\) for rest of colons (:) */ printf("or @ for default (NGDC_RELIEF:TOPO:FNOC:FNOC.BIN;1)\n"); printf("Enter Path: "); scanf("%s",infile); if (infile[0] == '@') strcpy(infile,"NGDC_RELIEF:TOPO:FNOC:FNOC.BIN;1"); if (infile[0] == '@') strcpy(infile,"slossmac:FNOC.BIN"); if ((IN = fopen(infile,"rb"))==0) { printf("\nPlease check link to file %s\n",infile); printf("File not found. Sorry!\n"); exit(1); } printf("Enter file name for OUTPUT data: "); scanf("%s",outfile); if ((OUT = fopen(outfile,"wb"))==0) { printf("Error in opening output file\n"); exit(1); } printf("Enter choice of ASCII or Binary output [a/b]: "); scanf("%s",&isASCII); if (isASCII != 'b' && isASCII != 'B') isASCII = 'a'; if (isASCII=='a') printf("Standard FNOC ASCII output format chosen\n"); else printf("BINARY output chosen\n"); printf("Skip how many 5-degree bands? (<0 exits) "); scanf("%d",&nskip); maxbands = 36 - nskip; if (nskip < 0 || nskip > 35) exit(1); printf("Starting latitude = %d deg.\n",5*nskip-90); printf("Copy how many 5-degree bands? (up to %d) ",maxbands); scanf("%d",&ncopy); if (ncopy > maxbands) ncopy = maxbands; offset = 16200L*72*nskip; nbytes = 16200L*72*ncopy; if (isASCII = 'a') { printf("Display ASCII records being copied (y/n)? "); scanf("%s",&Ok); if (Ok=='Y') Ok = 'y'; } if (isASCII == 'a') nbytes = (nbytes/18)*40; printf("Copied data will occupy %ld bytes on disc. Continue? (y/n) ", nbytes); scanf("%s",©_ok); if (copy_ok != 'y' && copy_ok != 'Y') exit(1); bytes_read = 0; while (bytes_read < nbytes) { j = fseek(IN,offset,0); i = fread(&FNOC,18,1,IN); /* swap bytes in short integers for Macintosh, Sun, Amiga, and other */ /* computers which have high-byte first, comment out for DOS/VAX */ swap2(&(FNOC.latitude)); swap2(&(FNOC.longitude)); swap2(&(FNOC.modal_elev)); swap2(&(FNOC.max_elev)); swap2(&(FNOC.min_elev)); swap2(&(FNOC.sfc_water)); swap2(&(FNOC.sfc_urban)); Latitude = (float)(FNOC.latitude)/100.0; Longitude = (float)(FNOC.longitude)/100.0; offset += 18; bytes_read += 18; if (isASCII != 'a') { fwrite(&FNOC,18,1,OUT); bytes_written += 18; } else { sprintf(&outbuf[0], "%7.2f %6.2f %3d %3d %3d %2d%2d%2d%2d%3d%3d", Longitude,Latitude,FNOC.modal_elev,FNOC.max_elev,FNOC.min_elev, (int)(FNOC.ridges_tot),(int)(FNOC.ridges_dir), (int)(FNOC.primary_sfc),(int)(FNOC.secondary_sfc), FNOC.sfc_water,FNOC.sfc_urban); fwrite(outbuf,40,1,OUT); if (Ok == 'y') printf("%s\n",outbuf); bytes_written += 40; } fseek(OUT,bytes_written,0); } printf("%ld bytes written. Done.\n",bytes_written); } swap2(word) unsigned char word[2]; { unsigned char tmp; tmp = word[1]; word[1] = word[0]; word[0] = tmp; }