#ifndef lint static char *sccsid = "@(#)arcdrlst.c MgnAlt 2.4 (MIT/CSR) 9/11/92"; #endif /* Function: List contents of an ARCDR data file System: Magellan Altimetry Data Reduction Phase: LIB Module: arcdrlst.c Revision: 2.4 Date: 9/11/92 Author: pgf@space.mit.edu Created: Mon Jan 6 15:04:35 EST 1992 Control: SCCS This software has been tested on a variety of platforms: Sun/680x0 SunOS 4.0.3, 4.1.1 Sun/SPARC SunOS 4.0.3, 4.1, 4.1.1 Decstation: Ultrix 4.1 Microvax: Ultrix 3.3 and 2.2; BSD 4.3; VMS 5.4 NeXT: Mach 2.0 IBM-PC: MS-DOS 3.1 PC-AT: MS-DOS 3.3 Macintosh: MacOS 5.2, 6.0.5, 7.0 */ #define VERSION " Version 2.4 (9/11/92)" #include #include #include /* ** Conditional compilation for various platforms ** The default is UNIX, non-LSB, IEEE-754 floats (e.g. Sun) */ /* #define MSDOS uncomment for MS-DOS */ /* #define C86 uncomment for MS-DOS C-86 Compiler only */ /* #define THINK_C uncomment for Apple Macintosh Think-C Compiler */ /* #define LSB uncomment for DecStation (MIPS) and MS-DOS */ /* #define vax uncomment for VAX/UNIX (Ultrix or BSD) */ /* #define VMS uncomment for VAX/VMS */ /* #define POLANG uncomment for RDF polarization test files */ #ifdef THINK_C #include #include #define ISDELIM(c) ((c) == ':') #define DIRDLM ':' #define perror xperror #endif #ifdef C86 #define MSDOS #define FL #else #include #define FL (float *) #endif #ifdef mips #define LSB #endif #ifdef VMS #define ISDELIM(c) ((c) == ':' || (c) == ']') #define DIRDLM '\0' #endif #ifdef MSDOS #define LSB #define ISDELIM(c) ((c) == '\\' || (c) == ':') #define DIRDLM '\\' #endif #ifndef ISDELIM #define ISDELIM(c) ((c) == '/') #define DIRDLM '/' #endif /* ** Determine local integer and float types */ #ifdef vax #define FLTTYPE 'V' #define INTTYPE 'V' #else #define FLTTYPE 'I' #ifdef LSB #define INTTYPE 'V' #else #define INTTYPE 'I' #endif #endif #include "arcdr.h" #define NT 100 /* max number of data types */ #define OPENMODE "rb" /* open for "binary" access */ #define MGM_ERR 1 /* Mgm error with message text */ #define MGM_PERR 2 /* UNIX library error */ #define MGMERROR(a,b,c) mgmErr(MGM_ERR,(a),(b),(c)) #define MGMPERROR(a,b) mgmErr(MGM_PERR,(a),(b),(char *)0) /* ** Input data records */ ar_rec ar; /* altimetry input record */ rr_rec rr; /* radiometry input record */ oh_rec oh; /* orbit header input record */ /* ** Data field decriptor structure */ typedef struct { float *ptr; /* pointer to input field */ ulong flag; /* bad flag bits for this field */ ulong reqd; /* flag required for this field */ char *tit; /* output header title */ char *fmt; /* output printf() format */ char *desc; /* description */ } ar_tab; /* ** ar_tab flag values */ #define AR_INT 0x80000000 #define AR_DBL 0x40000000 #define AR_SCT 0x20000000 #define AR_FLG 0x10000000 #define AR_SQI 0x08000000 #define AR_FLT 0x00000000 /* ** flag conbinations used in alts[] and rads[] */ #define AOK AR_BAD #define IOK (AR_BAD | AR_INT) #define RBAD (AR_BAD | AR_RBAD) #define R2BAD (AR_BAD | AR_RBAD | AR_RAD2BAD) #define CBAD (AR_BAD | AR_CBAD | AR_SLOPEBAD) #define FBAD (AR_BAD | AR_CBAD | AR_RHOBAD) #define ABAD (AR_BAD | AR_RBAD | AR_CBAD | AR_SLOPEBAD) #define BBAD (AR_BAD | AR_RBAD | AR_CBAD | AR_RHOBAD) #define DBAD (AR_BAD | AR_CBAD | AR_SLOPEBAD | AR_RHOBAD) #define NOS1 RR_NOS1 #define NOS2 RR_NOS2 #define ROK RR_BAD #define ROK2 (RR_BAD|RR_CAL) /* ** Special code values */ #define CODE_PROF -3 /* display non-range-sharpened profile */ #define CODE_RSPROF -2 /* display range-sharpened profile */ #define CODE_ECHO -1 /* display all echo values */ /* ** Data field descriptor tables */ ar_tab alts[] = { FL &ar.ar_nfoot, AR_INT, 0, " foot ", "%5ld ", "Altimeter Footprint Number", FL &ar.ar_flag, AR_INT, 0, " flags ","0x%08lx ","ADF Record Flag Field (hex)", FL &ar.ar_flag, AR_INT|AR_FLG, 0, " flags ","0x%08lx ","ADF Record Flag Field (ASCII)", FL &ar.ar_scet, AR_SCT, 0, " echo-time ", "%s ", "Echo Time (hh:mm:ss, TDB)", FL &ar.ar_scet, AR_DBL, 0, " echo-time ", "%14.3f ", "Echo Time (sec, TDB)", FL &ar.ar_pos[0], AR_DBL, 0, " xpos ","%10.3f ", "S/C X-Coordinate (km, J2000)", FL &ar.ar_pos[1], AR_DBL, 0, " ypos ","%10.3f ", "S/C Y-Coordinate (km, J2000)", FL &ar.ar_pos[2], AR_DBL, 0, " zpos ","%10.3f ", "S/C Z-Coordinate (km, J2000)", FL &ar.ar_vel[0], AR_DBL, 0, " xvel ", "%6.3f ", "S/C X-Velocity (km/sec, J2000)", FL &ar.ar_vel[1], AR_DBL, 0, " yvel ", "%6.3f ", "S/C Y-Velocity (km/sec, J2000)", FL &ar.ar_vel[2], AR_DBL, 0, " zvel ", "%6.3f ", "S/C Z-Velocity (km/sec, J2000)", &ar.ar_lon, AOK, 0, " lon ", "%7.3f ", "Footprint Longitude (deg, VBF85)", &ar.ar_lat, AOK, 0, " lat ", "%7.3f ", "Footprint Latitude (deg, VBF85)", &ar.ar_xfoot, AOK, 0, " xfoot ", "%7.3f ", "Along-track Footprint Size (km)", &ar.ar_yfoot, AOK, 0, " yfoot ", "%7.3f ", "Cross-track Footprint Size (km)", &ar.ar_rcal, AOK, 0, " rcal ", "%8.3f ", "Rcvr Noise Calibration (km-sq)", &ar.ar_range, RBAD, 0, " range ", "%8.3f ", "Uncorrected Range to Nadir (km)", &ar.ar_atmos, AOK, 0, " atm ", "%5.3f ", "Atmospheric Corrn to Range (km)", &ar.ar_radius, RBAD, 0, " radius ", "%8.3f ", "Derived Planetary Radius (km)", &ar.ar_slope, CBAD, 0, " slope ", "%6.3f ", "Derived RMS Surface Slope (deg)", &ar.ar_rho, FBAD, 0, " rho ", "%6.4f ", "Derived Fresnel Reflectivity", &ar.ar_rhocor, AOK, AR_RHOC, " rhoc ", "%6.4f ", "Rho Diffuse Scatter Corrn Factor", ar.ar_error, RBAD, 0, " erad ", "%5.3f ", "Formal Error in Radius (km)", ar.ar_error+1, CBAD, 0, " eslo ", "%6.3f ", "Formal Error in Slope (deg)", ar.ar_error+2, FBAD, 0, " erho ", "%5.4f ", "Formal Error in Rho", ar.ar_correl, ABAD, 0, " ra-sl ", "%6.4f ", "Sensitivity: Radius vs. Slope", ar.ar_correl+1, DBAD, 0, " sl-rh ", "%6.4f ", "Sensitivity: Slope vs. Rho", ar.ar_correl+2, BBAD, 0, " rh-ra ", "%6.4f ", "Sensitivity: Rho vs. Radius", ar.ar_correl+3, ABAD, 0, " sl-ra ", "%6.4f ", "Sensitivity: Slope vs. Radius", ar.ar_correl+4, DBAD, 0, " rh-sl ", "%6.4f ", "Sensitivity: Rho vs. Slope", ar.ar_correl+5, BBAD, 0, " ra-rh ", "%6.4f ", "Sensitivity: Radius vs. Rho", &ar.ar_drad, RBAD, AR_EPHC, " drad ", "%6.3f ", "Ephem Radius Corrn (km)", &ar.ar_dlon, RBAD, AR_EPHC, " dlon ", "%6.3f ", "Ephem Longitude Corrn (deg, VBF85)", &ar.ar_dlat, RBAD, AR_EPHC, " dlat ", "%6.3f ", "Ephem Latitude Corrn (deg, VBF85)", &ar.ar_fit, AOK, 0, " fit ", "%5.3f ", "Non-range-sharp Goodness-of-Fit", &ar.ar_rsfit, AOK, 0, "rsfit ", "%5.3f ", "Range-sharp Goodness-of-Fit", &ar.ar_rhofact, FBAD, AR_RAD2, " frho ", "%6.4f ", "Multi-peak Corrn applied to ar_rho", &ar.ar_radius2, R2BAD, AR_RAD2, " rad2 ", "%8.3f ", "Radius from Thresh Detector (km)", &ar.ar_sqi, AR_SQI|RBAD, AR_RAD2, " sqi ", "%6.2f ", "Signal Quality Indicator (dB)", &ar.ar_scale, AOK, 0, " scale ", "%8.3f ", "Profile Scaling Factor (km-sq)", &ar.ar_rsscale, AOK, 0, " rsscale ", "%8.3f ", "Range-sharp Scaling Factor (km-sq)", FL &ar.ar_looks, IOK, 0, " nl ", "%3ld ", "Number of non-range-sharp Looks", FL &ar.ar_rslooks, IOK, 0, "nrs ", "%3ld ", "Number of range-sharp Looks", FL &ar.ar_thresh, IOK, AR_RAD2, "thr ", "%3ld ", "Threshold Detector Index", }; ar_tab rads[] = { FL &rr.rr_burst, AR_INT, 0, "burst ", "%5ld ", "Radiometer Burst Number", FL &rr.rr_flag, AR_INT, 0, " flags ","0x%08lx ","RDF Record Flag Field (hex)", FL &rr.rr_flag, AR_INT|AR_FLG, 0, " flags ","0x%08lx ","RDF Record Flag Field (ASCII)", FL &rr.rr_scet, AR_SCT, 0, " burst-time ", "%s ", "Burst Time (hh:mm:ss, TDB)", FL &rr.rr_scet, AR_DBL, 0, " burst-time ", "%14.3f ", "Burst Time (sec, TDB)", FL &rr.rr_pos[0], AR_DBL, 0, " xpos ","%10.3f ", "S/C X-Coordinate (km, J2000)", FL &rr.rr_pos[1], AR_DBL, 0, " ypos ","%10.3f ", "S/C Y-Coordinate (km, J2000)", FL &rr.rr_pos[2], AR_DBL, 0, " zpos ","%10.3f ", "S/C Z-Coordinate (km, J2000)", FL &rr.rr_vel[0], AR_DBL, 0, " xvel ", "%6.3f ", "S/C X-Velocity (km/sec, J2000)", FL &rr.rr_vel[1], AR_DBL, 0, " yvel ", "%6.3f ", "S/C Y-Velocity (km/sec, J2000)", FL &rr.rr_vel[2], AR_DBL, 0, " zvel ", "%6.3f ", "S/C Z-Velocity (km/sec, J2000)", &rr.rr_lon, ROK, 0, " lon ", "%7.3f ", "Footprint Longitude (deg, VBF85)", &rr.rr_lat, ROK, 0, " lat ", "%7.3f ", "Footprint Latitude (deg, VBF85)", &rr.rr_xfoot, ROK2, 0, " xfoot ", "%7.3f ", "Along Track Footprint Size (km)", &rr.rr_yfoot, ROK2, 0, " yfoot ", "%7.3f ", "Cross Track Footprint Size (km)", rr.rr_sfoot, NOS1, 0, " sft0 ", "%7.3f ", "SAR #1 Footprint Diameter (km)", rr.rr_sfoot+1, NOS2, 0, " sft1 ", "%7.3f ", "SAR #2 Footprint Diameter (km)", rr.rr_sar, NOS1, 0, " sar0 ", "%7.3f ", "SAR #1 Average Backscatter (dB)", rr.rr_sar+1, NOS2, 0, " sar1 ", "%7.3f ", "SAR #2 Average Backscatter (dB)", &rr.rr_angle, ROK2, 0, " ang ", "%6.2f ", "Incidence Angle (deg)", &rr.rr_bright, ROK, 0, " brt ", "%7.2f ", "Brightness Temperature (K)", &rr.rr_radius, ROK2, 0, " radius ", "%8.3f ", "Average Planetary Radius (km)", &rr.rr_anttemp, ROK, 0, " ant ", "%7.2f ", "Antenna System Temperature (K)", &rr.rr_skytemp, ROK2, 0, " sky ", "%7.2f ", "Warm Sky Temperature (K)", &rr.rr_rcvrtemp, ROK, 0, " rcvr ", "%7.2f ", "Receiver System Temperature (K)", &rr.rr_surftemp, ROK2, 0, " surf ", "%7.2f ", "Surface Brightness Temperature (K)", &rr.rr_emiss, ROK2, 0, "emiss ", "%5.3f ", "Surface Emissivity", &rr.rr_dedrad, ROK2, RR_RAD2, " dedrad ", "%8.3f ", "Partial of Emissivity wrt Radius", &rr.rr_phystemp, ROK2, RR_RAD2, " phys ", "%7.2f ", "Physical Surface Temperature (K)", &rr.rr_antval, ROK, RR_RAD2, " antval ", "%8.3f ", "Raw Antenna Signal", &rr.rr_loadval, ROK, RR_RAD2, " loadval ", "%8.3f ", "Raw Load Signal", FL &rr.rr_acr, ROK|AR_INT, RR_RAD2, "acr ", "%3ld ", "Altimeter Coarse Range", #ifdef POLANG FL rr.rr_spare, ROK, 0x4000, "polang ", "%6.2f ", "Polarization Angle (deg)", #endif }; #define NALTS (sizeof(alts)/sizeof(alts[0])) #define NRADS (sizeof(rads)/sizeof(rads[0])) /* ** Input file characteristics */ FILE *fIn; /* input file descriptor */ char inDir[1024]; /* input ARCDR directory name */ char inFile[1024]; /* input ARCDR file name */ char *pType; /* expected file label keyword */ char cType; /* first char of DATA_FORMAT_TYPE */ ar_tab *pAR; /* pointer to element table */ int nOrbit; /* orbit number */ /* ** Output characteristics */ FILE *fOut; /* output file descriptor */ char outFile[1024]; /* output file name */ int hFlag = 1; /* output header switch */ /* ** Latitude selection */ float maxLat = 90; /* maximum latitude */ float minLat = -90; /* minimum latitude */ /* ** Data code selection */ int nTypes; /* number of elements to look up */ int dTypes[NT]; /* array of element codes */ /* ** Terminal characteristics */ int LI; /* number of screen lines */ int CO; /* number of screen columns */ char *SO; /* ANSI inverse video */ char *SE; /* end ANSI inverse video */ char *US; /* ANSI underscore */ char *UE; /* end ANSI underscore */ char *MD; /* ANSI highlighted */ char *ME; /* end ANSI highlighted */ char term_quit[32]; /* stdin EOF */ char term_tit[128]; /* bottom of screen message */ int term_blk; /* blanks before term_tit */ /* ** Miscellaneous */ char buf[2048]; /* scratch buffer */ int pFlag = 1; /* main prompt switch */ int kFlag = 0; /* = 1 to list header keywords */ jmp_buf env; /* long jump environment */ /* ** Start here - prompt for input and execute requests */ main() { /* determine terminal characteristics */ setTermCap(); /* set return exit */ setjmp(env); for (;;) { /* arcdr> prompt */ if (arcdrCmd()) continue; /* determine file type */ if (testFileType()) continue; /* print keyword labels */ if (kFlag) { putc('\n', fOut); if (readFileLabels()) perror(inFile); else fclose(fIn); putc('\n', fOut); continue; } /* print OHF or EPF */ if (*pType == 'O') { readOHFile(); continue; } else if (*pType == 'E') { readEPFile(); continue; } /* determine latitude,longitude limits */ limitsCmd(); /* determine data field codes */ if (codesCmd()) continue; /* open the data file, read its labels */ if (readFileLabels()) { perror(inFile); continue; } /* finally, write selected data */ writeDataList(); } } /* ** Convert SCET to character string (valid for 1958-1999) */ char * scetStr(sec) DOUBLE sec; /* time past J2000 (sec) */ { static int months[] = { /* month table */ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static char cbuf[32]; /* returned value */ int year, month, day, hour, min, i; long loff; if (sec == 0) { strcpy(cbuf, "N/A"); return cbuf; } loff = 2436204L - 2451545L; sec -= (loff * 86400.0) - 43200.0; day = sec / 86400.0; sec -= day * 86400.0; for (year = 1958; ; year++) { i = 365 + ((year % 4) == 0); if (day <= i) break; day -= i; } months[1] = (year % 4) ? 28 : 29; for (month = 0; month < 12 && day > months[month]; month++) day -= months[month]; hour = sec / 3600.0; sec -= hour * 3600.0; min = sec / 60.0; sec -= min * 60.0; sprintf(cbuf, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month+1, day, hour, min, sec); return cbuf; } /* ** Main arcdr> prompt loop */ arcdrCmd() { char *c; int i; if (fOut == NULL) fOut = stdout; else if (fOut != stdout) fflush(fOut); /* prompt for name of input file */ inputPrompt(pFlag); if (fgets(c = buf, sizeof(buf), stdin) == NULL) exit(1); /* parse response for special syntax */ while (isspace(*c)) c++; i = strlen(c)-1; if (c[i] == '\n') c[i] = 0; pFlag = kFlag = 0; switch (*c) { #ifndef THINK_C case '!': /* issue system command (except in MacOS) */ i = system(c+1); #ifndef VMS if (i) /* VMS system() returns unhelpful code */ printf("\7%s: loader error %d.\n", c+1, i); else #endif putchar('\n'); return 1; #endif case '?': /* repeat prompt with full message */ pFlag = 1; return 1; case '\0': /* same input file as last time */ if (! inFile[0]) return 1; break; case '<': /* specify input directory name */ while (isspace(*++c)) ; for (i = 0; inDir[i] = *c++; i++) ; for (c = inDir+i; --c >= inDir && isspace(*c); ) *c = '\0'; if (c >= inDir && *c != DIRDLM) *++c = DIRDLM; inFile[0] = *++c = '\0'; return 1; case '>': /* specify output file name */ while (isspace(*++c)) ; for (i = 0; outFile[i] = *c++; i++) ; for (c = outFile+i; --c >= outFile && isspace(*c); ) *c = '\0'; if (fOut != stdout) fclose(fOut); if (c < outFile) fOut = stdout; else if ((fOut = fopen(outFile, "w")) == NULL) perror(outFile); hFlag = 1; return 1; case '+': /* list file keywords */ kFlag = 1; while (isspace(*++c)) ; if (! *c) break; default: /* copy input file name */ strcpy(inFile, inDir); for (i = strlen(inFile); inFile[i] = *c++; i++) ; for (c = inFile+i; --c >= inFile && isspace(*c); ) *c = '\0'; break; } return 0; } /* ** Determine input file type */ testFileType() { char *c; #ifdef C86 /* test if file exists, else C-86 library can bomb */ c = filedir(inFile, 0); if (! *c) { free(c); errno = ENOENT; perror(inFile); return 1; } #endif /* determine file type according to first letter of name */ for (c = inFile+strlen(inFile)-1; c >= inFile; --c) if (ISDELIM(*c)) break; switch(*++c) { case 'a': case 'A': pAR = alts; pType = "ALTIMETRY_FILE\r\n"; break; case 'o': case 'O': pType = "ORBIT_HEADER_RECORD\r\n"; break; case 'e': case 'E': pType = "EPHEMERIS\r\n"; break; case 'r': case 'R': pAR = rads; pType = "RADIOMETRY_FILE\r\n"; break; default: printf("\7Unknown file type: %s.\n", inFile); return 1; } return 0; } /* ** Prompt for latitude limits */ limitsCmd() { char *c; int sw; float f; /* prompt for latitude limits */ for (sw = 0; ; sw++) { limitsPrompt(sw); if (fgets(c = buf, sizeof(buf)-1, stdin) == NULL) exit(1); while (isspace(*c)) c++; if (*c == '?') continue; if (! *c) { printf("latitude range: %g to %g\n", maxLat, minLat); break; } else if (sscanf(buf, "%f%f", &maxLat, &minLat)==2) break; printf("\7Illegal range: %s.\n", buf); } /* maxLat must be >= minLat */ if (maxLat < minLat) { f = maxLat; maxLat = minLat; minLat = f; } } /* ** Prompt for data codes */ codesCmd() { static int ntLast; /* previous element count */ static ar_tab *pARlast; /* pointer to previous element table */ int sw, m, i, n, *ip; /* scratch */ char *c; /* scratch */ /* prompt for data type indices */ for (sw = 0; ; sw++) { codesPrompt(sw); if (fgets(c = buf, sizeof(buf), stdin) == NULL) exit(1); while (*c && isspace(*c)) c++; /* '?' generates list of data types */ if (*c == '?') { m = (*pType == 'A') ? NALTS : NRADS; putchar('\n'); for (i = (CO-25)/2; --i >= 0; putchar(' ')) ; sprintf(buf, "\1Codes for %cDF Data Fields\2\n", *pType); PR(buf); for (i = 0; i < m; ) { n = (i/2) + ((m+1)/2)*(i & 1); sprintf(buf, " \1%2d\2 %-34.34s", n+1, pAR[n].desc); PR(buf); if ((i++ & 1) || i == m) putchar('\n'); } sw = -1; continue; } if (*pType == 'A' && strncmp(c, "echo", 4) == 0) { nTypes = 1; dTypes[0] = CODE_ECHO; break; } if (*pType == 'A' && strncmp(c, "prof", 4) == 0) { nTypes = 1; dTypes[0] = CODE_PROF; break; } if (*pType == 'A' && strncmp(c, "rsprof", 6) == 0) { nTypes = 1; dTypes[0] = CODE_RSPROF; break; } /* read and test data types */ for (nTypes = n = 0; *c; nTypes++) { if (sscanf(c, " %d", ip = &dTypes[nTypes]) != 1) printf("\7Bad value: %s.\n", c); else if (*pType == 'A' && (*ip < 1 || *ip > NALTS)) printf("\7Bad ALT value: %d.\n", *ip); else if (*pType == 'R' && (*ip < 1 || *ip > NRADS)) printf("\7Bad RAD value: %d.\n", *ip); else if (nTypes >= NT) printf("\7Too many elements.\n"); else if (n) printf( "\7ASCII flag field (%d) must be last in list.\n", n); else { /* skip to start of next field */ if (pAR[*ip-1].flag & AR_FLG) n = *ip; while (*++c && !isspace(*c)) ; while (isspace(*c)) c++; continue; } break; } if (! *c) break; } /* determine whether to use previous code list */ if (nTypes || pAR != pARlast) { pARlast = pAR; ntLast = nTypes; hFlag = 1; } else if ((nTypes = ntLast) && dTypes[0] > 0) { PR("Using codes:"); for (i = 0; i < nTypes; i++) printf(" %d", dTypes[i]); putchar('\n'); } if (nTypes == 0) { PR("No codes selected. Nothing to list.\n"); return 1; } return 0; } /* ** Write ADF or RDF data */ writeDataList() { float fLat; /* footprint latitude */ long lFlg; /* ar_rec or rr_rec flags */ int nDel = 0; /* delay index (used only for echoes) */ int i, m, n; /* scratch */ /* write a header line */ printf("%cDF File: %s\n", *pType, inFile); if (hFlag || fOut == stdout) { switch (dTypes[0]) { case CODE_PROF: strcpy(buf, "Range-unsharpened profile "); break; case CODE_RSPROF: strcpy(buf, "Range-sharpened profile "); break; case CODE_ECHO: strcpy(buf, "norb foot del prof tmpl rsprof rstmpl "); break; default: strcpy(buf, "norb "); for (i = 0; i < nTypes; i++) strcat(buf, pAR[dTypes[i]-1].tit); break; } m = strlen(buf)-1; buf[m] = '\n'; fputs(buf, fOut); if (fOut == stdout) m = (m+CO-1)/CO+1; else hFlag = 0; } /* read data records */ while (! ferror(fOut)) { if (*pType == 'A' && nDel == 0) { if (readADFile()) break; cvtFloat(&ar.ar_lat, 1, &fLat); cvtLong(&ar.ar_flag, 1, &lFlg); } else if (*pType == 'R') { if (readRDFile()) break; cvtFloat(&rr.rr_lat, 1, &fLat); cvtLong(&rr.rr_flag, 1, &lFlg); } /* check latitude */ if (fLat > maxLat || fLat < minLat) continue; /* write output line to 'buf' */ switch (dTypes[0]) { case CODE_PROF: case CODE_RSPROF: writeProf(fLat); m = LI; break; case CODE_ECHO: nDel = writeEcho(nDel); break; default: writeVars(lFlg); break; } /* at end of screen, prompt to continue */ n = (strlen(buf)+CO-2)/CO; if (fOut == stdout && (m += n) >= LI) { for (i = term_blk; --i >= 0; putchar(' ')) ; PR(term_tit); for (m = 0; (i = getchar()) != '\n'; m++) if (i == EOF) exit(1); if (m) break; m = n; } /* replace trailing blank with newline */ buf[strlen(buf)-1] = '\n'; fputs(buf, fOut); } /* cleanup */ fclose(fIn); fIn = NULL; if (ferror(fOut)) perror(outFile); } /* ** Format the variable list into 'buf' */ writeVars(lFlg) long lFlg; /* ar_rec or rr_rec flags */ { ar_tab *a; /* pointer to item in element table */ char *c; /* pointer to end of 'buf' */ int i; /* data index */ long l; /* converted long integer */ float f; /* converted float */ DOUBLE d; /* converted double */ sprintf(c = buf, "%4d ", nOrbit); for (i = 0; i < nTypes; i++) { a = &pAR[dTypes[i]-1]; c += strlen(c); if (a->reqd && ! (lFlg & a->reqd)) l = 1; else l = lFlg & a->flag; if (a->flag & AR_FLG) cvtFlgs(pAR, lFlg, c); else if (a->flag & AR_INT) { if (l) l = 0; else cvtLong(a->ptr, 1, &l); sprintf(c, a->fmt, l); } else if (a->flag & (AR_DBL|AR_SCT)) { if (l) d = 0; else cvtDouble(a->ptr, 1, &d); if (a->flag & AR_DBL) sprintf(c, a->fmt, d); else sprintf(c, a->fmt, scetStr(d)); } else { if (l) f = 0; else if ((a->flag & AR_SQI) && cType == 'V') cvtSqi(a->ptr, &f); else cvtFloat(a->ptr, 1, &f); sprintf(c, a->fmt, f); } } } /* ** Change ar_sqi field to VAX format */ cvtSqi(c, d) uchar *c, *d; { d[1] = c[0]+1; d[0] = c[1]; d[3] = c[2]; d[2] = c[3]; cvtFloat(d, 1, d); } /* ** Format an echo line in 'buf' */ writeEcho(nDelay) int nDelay; /* delay index */ { long l; /* converted long integer */ float g, h; /* profile scaling factors */ int i, n; /* template indices */ cvtLong(&ar.ar_nprof0, 1, &l); i = (nDelay - l + 302) % 302; cvtFloat(&ar.ar_scale, 1, &g); g /= 255; cvtLong(&ar.ar_rsnprof0, 1, &l); n = (nDelay - l + 302) % 302; cvtFloat(&ar.ar_rsscale, 1, &h); h /= 255; cvtLong(&ar.ar_nfoot, 1, &l); sprintf(buf, "%4d %5ld %3d %10.2f %10.2f %10.2f %10.2f ", nOrbit, l, nDelay, ar.ar_prof[nDelay] * g, (i < 0 || i > 49) ? 0 : ar.ar_tmpl[i] * g, ar.ar_rsprof[nDelay] * h, (n < 0 || n > 49) ? 0 : ar.ar_rstmpl[n] * h); return (nDelay+1) % 302; } /* ** Write echo profile and template */ writeProf(fLat) float fLat; /* footprint latitude */ { float f; /* scratch */ float fScale; /* scaling factor */ int x, y, z; /* graph indices */ long tOff; /* template offset */ long nFoot; /* footprint number */ uchar *p, *t; /* pointer to profile and template */ if (dTypes[0] == CODE_PROF) { p = ar.ar_prof; t = ar.ar_tmpl; cvtLong(&ar.ar_nprof0, 1, &tOff); cvtFloat(&ar.ar_scale, 1, &fScale); } else { p = ar.ar_rsprof; t = ar.ar_rstmpl; cvtLong(&ar.ar_rsnprof0, 1, &tOff); cvtFloat(&ar.ar_rsscale, 1, &fScale); } z = (LI > 30) ? 27 : (LI - 3); for (y = z; y > 0; y--) { switch (y) { case 16: fputs("Orbit Number", fOut); break; case 15: fprintf(fOut, "%12d", nOrbit); break; case 14: fputs("Footprint ", fOut); break; case 13: cvtLong(&ar.ar_nfoot, 1, &nFoot); fprintf(fOut, "%12ld", nFoot); break; case 12: fputs("Latitude ", fOut); break; case 11: fprintf(fOut, "%12.3f", fLat); break; case 10: fputs("Longitude ", fOut); break; case 9: cvtFloat(&ar.ar_lon, 1, &f); fprintf(fOut, "%12.3f", f); break; case 8: fputs("Radius ", fOut); break; case 7: cvtFloat(&ar.ar_radius, 1, &f); fprintf(fOut, "%12.3f", f); break; case 6: fputs("R.M.S. Slope", fOut); break; case 5: cvtFloat(&ar.ar_slope, 1, &f); fprintf(fOut, "%12.3f", f); break; case 4: fputs("Reflectivity", fOut); break; case 3: cvtFloat(&ar.ar_rho, 1, &f); fprintf(fOut, "%12.4f", f); break; case 2: fputs(dTypes[0] == CODE_PROF ? "NRS Scale " : "RS Scale ", fOut); break; case 1: fprintf(fOut, "%12g", fScale); break; default: fputs(" ", fOut); } fputs((y % 5) ? " |" : " +", fOut); for (x = 0; x < 50; x++) { if (p[(x+tOff) % 302] * z >= y * 255) putc((t[x] * z >= y * 255) ? 'o' : '+', fOut); else putc((t[x] * z >= y * 255) ? '-' : ' ', fOut); } putc('\n', fOut); } fputs(" ", fOut); fputs("|----+----|----+----|----+----|----+----|----+----|\n", fOut); fputs("Echo Delay: ", fOut); fputs("0 10 20 30 40 50\n", fOut); sprintf(buf, "Range-%ssharpened profile ", dTypes[0] == CODE_PROF ? "un" : ""); } /* ** Read OHF record */ readOHFile() { int rc; /* scratch */ if (readFileLabels()) { perror(inFile); return; } rc = fread((char *)&oh, sizeof(oh), 1, fIn); fclose(fIn); fIn = NULL; if (rc != 1) MGMPERROR("readOHFile", inFile); if (strncmp((char *)&oh, OHF_SFDU_LABEL, 12)) MGMERROR("%s: bad label: %-12.12s", inFile, (char *)&oh); cvtLong(&oh.oh_norbit, 3, &oh.oh_norbit); cvtDouble(&oh.oh_alt_start, 10, &oh.oh_alt_start); printf("OHF File: %s\n", inFile); fprintf(fOut, "\nOrbit Number = %ld\n", oh.oh_norbit); fprintf(fOut, "Altimetry Footprint Count = %ld\n", oh.oh_nalt); fprintf(fOut, "Radiometry Burst Count = %ld\n", oh.oh_nrad); fprintf(fOut, "Altimetry Start Time (ET) = %14.3f (%s)\n", oh.oh_alt_start, scetStr(oh.oh_alt_start)); fprintf(fOut, "Altimetry End Time (ET) = %14.3f (%s)\n", oh.oh_alt_end, scetStr(oh.oh_alt_end)); fprintf(fOut, "Radiometry Start Time (ET) = %14.3f (%s)\n", oh.oh_rad_start, scetStr(oh.oh_rad_start)); fprintf(fOut, "Radiometry End Time (ET) = %14.3f (%s)\n", oh.oh_rad_end, scetStr(oh.oh_rad_end)); fprintf(fOut, "Periapsis Time (ET) = %14.3f (%s)\n", oh.oh_avg.oe_scet, scetStr(oh.oh_avg.oe_scet)); fprintf(fOut, "Semi-Major Axis (km) = %.6f\n", oh.oh_avg.oe_sma); fprintf(fOut, "Eccentricity of Orbit = %.10f\n", oh.oh_avg.oe_ecc); fprintf(fOut, "Orbit Inclination (deg) = %.9f\n", oh.oh_avg.oe_incl); fprintf(fOut, "Long. of Asc. Node (deg) = %.8f\n", oh.oh_avg.oe_long); fprintf(fOut, "Arg. of Periapsis (deg) = %.8f\n\n", oh.oh_avg.oe_arg); } /* ** Read contents of EPF file */ readEPFile() { int i, m, n; /* scratch */ char *c; /* scratch */ if (readFileLabels()) { perror(inFile); return; } printf("EPF file: %s\n", inFile); for (m = 0; fgets(buf, sizeof(buf)-1, fIn) && ! ferror(fOut); ) { /* test for trailer label */ if (strncmp(buf, "CCSD1R000003", 12) == 0) break; /* strip trailing whitespace */ for (c = buf+strlen(buf); --c >= buf && isspace(*c); *c = '\0') ; /* at end of screen, prompt to continue */ n = ((c-buf)+CO)/CO; if (fOut == stdout && (m += n) >= LI) { for (i = term_blk; --i >= 0; putchar(' ')) ; PR(term_tit); for (m = 0; (i = getchar()) != '\n'; m++); if (i == EOF) exit(1); if (m) break; m = n; } fputs(buf, fOut); putc('\n', fOut); } fclose(fIn); } /* ** Read a single ADF record */ readADFile() { fread((char *)&ar, sizeof(ar), 1, fIn); if (strncmp((char *)&ar, "CCSD1R000003", 12) == 0) return 1; if (feof(fIn)) MGMERROR("readADFile: %s: unexpected EOF", inFile, ""); if (ferror(fIn)) MGMPERROR("readADFile", inFile); if (strncmp((char *)&ar, "NJPL1I000000", 12) != 0) if (strncmp((char *)&ar, ADF_SFDU_LABEL, 12)) MGMERROR("%s: bad sfdu label: %12.12s", inFile, (char *)&ar); return 0; } /* ** Read a single RDF record */ readRDFile() { fread((char *)&rr, sizeof(rr), 1, fIn); if (strncmp((char *)&rr, "CCSD1R000003", 12) == 0) return 1; if (feof(fIn)) MGMERROR("readRDFile: %s: unexpected EOF", inFile, ""); if (ferror(fIn)) MGMPERROR("readRDFile", inFile); if (strncmp((char *)&rr, "NJPL1I000000", 12)) if (strncmp((char *)&rr, RDF_SFDU_LABEL, 12)) MGMERROR("%s: bad sfdu label: %12.12s", inFile, (char *)&rr); return 0; } /* ** Read the SFDU header labels */ readFileLabels() { char *pStr; /* keyword search string */ int i; /* scratch */ /* read up to keyword section */ if ((fIn = fopen(inFile, OPENMODE)) == NULL) return 1; readSFDU("CCSD1Z000001"); i = readSFDU("NJPL1K00KL00"); cType = '\0'; nOrbit = -1; /* Read keywords and values */ while (i > 0) { if (fgets(buf, sizeof(buf)-1, fIn) == NULL) if (feof(fIn)) MGMERROR("readFileLabels: %s: unexpected EOF", inFile, ""); else MGMPERROR("readFileLabels", inFile); pStr = "PRODUCT_TYPE="; if (!strncmp(pStr, buf, strlen(pStr))) if (strcmp(pType, pStr = buf+strlen(pStr))) MGMERROR("%s: bad PRODUCT_TYPE: '%s'", inFile, pStr); pStr = "DATA_OBJECT_TYPE="; if (!strncmp(pStr, buf, strlen(pStr))) if (strcmp(pType, pStr = buf+strlen(pStr))) MGMERROR("%s: bad DATA_OBJECT_TYPE: '%s'", inFile, pStr); pStr = "DATA_FORMAT="; if (!strncmp(pStr, buf, strlen(pStr))) cType = buf[strlen(pStr)]; pStr = "DATA_FORMAT_TYPE="; if (!strncmp(pStr, buf, strlen(pStr))) cType = buf[strlen(pStr)]; pStr = "ORBIT_NUMBER="; if (!strncmp(pStr, buf, strlen(pStr)) && sscanf(pStr = buf+strlen(pStr), "%d", &nOrbit) != 1) MGMERROR("%s: bad ORBIT_NUMBER: %s", inFile, pStr); i -= strlen(buf); if (kFlag) { pStr = buf + strlen(buf); while (--pStr >= buf && isspace(*pStr)) *pStr = '\0'; fprintf(fOut, " %s\n", buf); } } if (nOrbit <= 0) MGMERROR("%s: missing ORBIT_NUMBER", inFile, ""); if (*pType == 'E') { /* skip ephemeris file comments */ i = readSFDU("NJPL1S00KL00"); while (--i >= 0) getc(fIn); i = readSFDU("CCSD1S000002"); while (--i >= 0) getc(fIn); } else { /* Validate DATA_FORMAT_TYPE keyword */ if (cType != 'I' && cType != 'V') MGMERROR("%s: unknown CPU type: %.1s", inFile, &cType); /* Return if no SMARKER label */ if (*pType == 'O') return 0; } /* Read past SMARKER label */ i = readSFDU("CCSD1R000003"); while (--i >= 0) getc(fIn); return 0; } /* ** Read SFDU header and return length of value */ readSFDU(s) char *s; /* expected SFDU header */ { sfdu sf; /* SFDU header buffer */ int i, n; /* scratch */ if (fread((char *)&sf, sizeof(sfdu), 1, fIn) != 1) if (feof(fIn)) MGMERROR("readSFDU: %s: unexpected EOF", inFile, ""); else MGMPERROR("readSFDU", inFile); if (strncmp((char *)&sf, s, 12)) MGMERROR("%s: bad sfdu: %12.12s", inFile, (char *)&sf); for (i = n = 0; i < 8; i++) n = 10 * n + sf.sf_length.sf_clen[i] - '0'; return n; } /* ** Convert flag fields to characters */ cvtFlgs(a, flg, c) ar_tab *a; /* alts or rads */ ulong flg; /* flag field */ char *c; /* output buffer */ { if (a == alts) { if (flg & AR_FIT) strcat(c, "FIT "); if (flg & AR_EPHC) strcat(c, "EPHC "); if (flg & AR_RHOC) strcat(c, "RHOC "); if (flg & AR_RS2) strcat(c, "RS2 "); if (flg & AR_NRS2) strcat(c, "NRS2 "); if (flg & AR_BAD) strcat(c, "BAD "); if (flg & AR_RBAD) strcat(c, "RBAD "); if (flg & AR_CBAD) strcat(c, "CBAD "); if (flg & AR_TMARK) strcat(c, "TMARK "); if (flg & AR_CMARK) strcat(c, "CMARK "); if (flg & AR_FMARK) strcat(c, "FMARK "); if (flg & AR_HAGFORS) strcat(c, "HAGFORS "); if (flg & AR_BADALTA) strcat(c, "BADALTA "); if (flg & AR_SLOPEBAD) strcat(c, "SLOPEBAD "); if (flg & AR_RHOBAD) strcat(c, "RHOBAD "); if (flg & AR_RAD2) strcat(c, "RAD2 "); if (flg & AR_RAD2BAD) strcat(c, "RAD2BAD "); if (flg & AR_AMBIG) strcat(c, "AMBIG "); if (flg & AR_AMBIG2) strcat(c, "AMBIG2 "); } else { if (flg & RR_GEOC) strcat(c, "GEOC "); if (flg & RR_RADC) strcat(c, "RADC "); if (flg & RR_NOS1) strcat(c, "NOS1 "); if (flg & RR_NOS2) strcat(c, "NOS2 "); if (flg & RR_BAD) strcat(c, "BAD "); if (flg & RR_CAL) strcat(c, "CAL "); if (flg & RR_NRAD) strcat(c, "NRAD "); if (flg & RR_RAD2) strcat(c, "RAD2 "); #ifdef POLANG if (flg & 0x4000) strcat(c, "POL "); #endif } } /* ** Convert long integer */ cvtLong(in, n, out) register ulong *in, *out; register int n; { register ulong i; while (--n >= 0) { i = *in++; if (cType != INTTYPE) *out++ = ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | ((i >> 24) & 0xff); else *out++ = i; } } /* ** Convert float */ cvtFloat(in, n, out) register ulong *in, *out; register int n; { register ulong i; while (--n >= 0) { i = *in++; if (cType == FLTTYPE) if (cType == INTTYPE) /* vax->vax | sun->sun */ ; else /* sun->dec */ i = ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | ((i >> 24) & 0xff); else if (cType == INTTYPE) { /* vax->dec */ if (i & 0x7f00) i -= 0x100; i = (i << 16) | (i >> 16); } else if (cType == 'V') { /* vax->sun */ if (i & 0x7f0000) i -= 0x10000; i = ((i & 0xff00ff) << 8) | ((i >> 8) & 0xff00ff); } else { /* sun->vax */ if (i & 0x7f) i++; i = ((i & 0xff00ff) << 8) | ((i >> 8) & 0xff00ff); } *out++ = i; } } /* ** Convert double */ cvtDouble(in, n, out) ulong *in, *out; int n; { register ulong i, j, k; while (--n >= 0) { i = *in++; k = *in++; if (cType == FLTTYPE) if (cType == INTTYPE) /* vax->vax | sun->sun */ j = k; else { /* sun->dec */ j = ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | ((i >> 24) & 0xff); i = ((k & 0xff) << 24) | ((k & 0xff00) << 8) | ((k >> 8) & 0xff00) | ((k >> 24) & 0xff); } else if (cType == INTTYPE) { /* vax->dec */ j = (i << 16) | (i >> 16); i = (k << 16) | (k >> 16); if (k = j & 0x7f800000) { i = (j << 29) | (i >> 3); j = (j & 0x80000000) | ((j & 0x7fffff) >> 3) | ((k >> 3) + 0x37e00000); } else i = j = 0; } else if (cType == 'V') { /* vax->sun */ i = ((i & 0xff00ff) << 8) | ((i >> 8) & 0xff00ff); j = ((k & 0xff00ff) << 8) | ((k >> 8) & 0xff00ff); if (k = i & 0x7f800000) { j = (i << 29) | (j >> 3); i = (i & 0x80000000) | ((i & 0x7fffff) >> 3) | ((k >> 3) + 0x37e00000); } else i = j = 0; } else { /* sun->vax */ i = ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | ((i >> 24) & 0xff); j = ((k & 0xff) << 24) | ((k & 0xff00) << 8) | ((k >> 8) & 0xff00) | ((k >> 24) & 0xff); if (k = i & 0x7ff00000) { i = (i & 0x80000000) | ((k - 0x37e00000) << 3) | ((i & 0xfffff) << 3) | (j >> 29); j <<= 3; i = (i << 16) | (i >> 16); j = (j << 16) | (j >> 16); } else i = j = 0; } *out++ = i; *out++ = j; } } /* ** General error reporting routine, then take long jump. */ mgmErr(sw, msg, insert1, insert2) int sw; /* Type of Message */ char *msg; /* Body of Error Message */ char *insert1; /* First Text Insert */ char *insert2; /* Second Text Insert */ { switch (sw) { case MGM_PERR: printf("%s: ", msg); fflush(stdout); perror(insert1); break; case MGM_ERR: default: putchar('\7'); printf(msg, insert1, insert2); fputs(".\n", stdout); break; } if (fIn) fclose(fIn); fIn = NULL; longjmp(env, 1); } #ifdef C86 /* ** Write I/O error message to console */ perror(name) char *name; { char *str, buf2[32]; switch (errno) { case EFNUM: str = "invalid function number"; break; case ENOENT: str = "File not found"; break; case EPNFOUND: str = "Path not found"; break; case EMFILES: str = "Too many open files (out of handles)"; break; case ENACCESS: str = "Access denied"; break; case EHANDLE: str = "Invalid Handle"; break; case ECNTLBLK: str = "Memory Control Block Destroyed"; break; case ENOMEM: str = "Insufficient memory"; break; case EMBA: str = "Invalid memory block address"; break; case EENV: str = "Invalid Environment"; break; case EFORMAT: str = "Invalid Format"; break; case ECODE: str = "Invalid access code"; break; case EDATA: str = "Invalid Data"; break; case EDRIVE: str = "Invalid drive was specified"; break; case ECDIR: str = "Attempt to remove current directory"; break; case EDEVICE: str = "Not same device"; break; case EFILES: str = "No more files"; break; case EDOM: str = "arg not in domain of function"; break; case ERANGE: str = "result too large"; break; case EFULDSK: str = "Full disk"; break; case ESKCDEV: str = "Seek on Character Device"; break; default: sprintf(str = buf, "error code %d", errno); break; } printf("\7%s: %s.\n", name, str); } #endif #ifdef THINK_C /* ** Write I/O error message to console */ perror(name) char *name; { char *str, buf2[32]; switch (errno) { case ESRCH: str = "No such process"; break; case EINTR: str = "Interrupted system call"; break; case EBADF: str = "Bad file number"; break; case ENODEV: str = "No such device"; break; case EINVAL: str = "Invalid argument"; break; case EMFILE: str = "Too many open files"; break; case EDOM: str = "Bad math argument"; break; case ERANGE: str = "Math result too large"; break; case -33: str = "File directory full"; break; case -34: str = "Volume allocation blocks full"; break; case -35: str = "Volume does not exist"; break; case -36: str = "Disk I/O error"; break; case -37: str = "Bad file of volume name"; break; case -38: str = "File not open"; break; case -39: str = "Logical end-of-file read"; break; case -40: str = "Attempt to seek past start of file"; break; case -41: str = "System heap full"; break; case -42: str = "Too many open files"; break; case -43: str = "File not found"; break; case -44: str = "Volume is hardware locked"; break; case -45: str = "File is locked"; break; case -46: str = "Volume is software locked"; break; case -47: str = "One or more files open"; break; case -48: str = "File already exists"; break; case -49: str = "Multiple write access paths"; break; case -50: str = "No default volume"; break; case -51: str = "Bad file reference number"; break; case -53: str = "Volume not on-line"; break; case -54: str = "No write permission"; break; case -55: str = "Volume already mounted and on-line"; break; case -56: str = "No such drive number"; break; case -57: str = "Volume lacks Mac-format directory"; break; case -58: str = "External file system error"; break; case -59: str = "Problem during rename"; break; case -60: str = "Bad master directory block"; break; case -61: str = "No write permission"; break; case -108: str = "Not enough room in heap zone"; break; case -120: str = "Directory not found"; break; case -121: str = "Too many working directories open"; break; case -122: str = "Attempted move into offspring"; break; case -123: str = "Attemted HFS op on non-HFS volume"; break; case -127: str = "Internal file system error"; break; default: sprintf(str = buf, "error code %d", errno); break; } printf("\7%s: %s.\n", name, str); } #endif inputPrompt(sw) { static int init; int i; if (! init++ || sw) { putchar('\n'); for (i = (CO-20-strlen(VERSION))/2; --i >= 0; putchar(' ')) ; sprintf(buf, "\1ARCDR List Utility %s\2\n\n", VERSION); PR(buf); PR("The purpose of this command is to prepare "); PR("ASCII listings of selected binary\n"); PR("data fields in the Magellan Altimetry and "); PR("Radiometry Composite Data Records\n\n"); PR(" \1ADF\2\3nnnnn\4.\3v\4: altimetry data file "); PR("for orbit \3nnnnn\4, version \3v\4,\n"); PR(" \1EPF\2\3nnnnn\4.\3vv\4: ephemeris file "); PR("for orbit \3nnnnn\4, version \3vv\4,\n"); PR(" \1OHF\2\3nnnnn\4.\3v\4: orbit header file "); PR("for orbit \3nnnnn\4, version \3v\4,\n"); PR(" \1RDF\2\3nnnnn\4.\3v\4: radiometry data file "); PR("for orbit \3nnnnn\4, version \3v\4,\n\n"); #ifdef THINK_C PR("Specify Macintosh filenames as "); PR("device:folder:folder:...:filename\n"); #endif PR("Command syntax is as follows (terminate all entries "); PR("with the \1RETURN\2 key)\n\n"); PR(" \3filename\4 "); PR("list selected fields from an ARCDR data file\n"); PR(" \1RETURN\2 "); PR("continue to list fields from the same input file\n"); #ifdef THINK_C PR(" \1<\2\3folder\4 "); PR("specify a default input folder name\n"); #else PR(" \1<\2\3directory\4 "); PR("specify a default input directory name\n"); #endif PR(" \1>\2\3filename\4 "); PR("direct subsequent listings to an output file\n"); PR(" \1>\2 "); PR("direct subsequent listings to the console\n"); PR(" \1+\2\3filename\4 "); PR("list the keyword labels in an ARCDR data file\n"); #ifndef THINK_C PR(" \1!\2\3command\4 "); PR("execute a system command without leaving ARCDRLST\n"); #endif PR(" \1"); PR(term_quit); PR("\2"); PR(" "+strlen(term_quit)-6); PR("close the output file and terminate the program\n"); PR(" \1?\2 "); PR("repeat this introductory message\n\n"); } printf("arcdr> %s", inDir); } limitsPrompt(sw) { static int init; if (! init++ || sw) { PR("\nEnter the maximum and minimum latitudes desired. "); PR("The two values must be\n"); PR("separated by one or more spaces. Type \1RETURN\2"); PR(" to retain the previous range.\n"); PR("The initial limits are set to \00190\2 and \1-90\2.\n\n"); } PR("latitude limits> "); } codesPrompt(sw) { static int init; if (! init++ || sw) { PR("\nEnter the code numbers of the ARCDR "); PR("data fields you wish to list.\n"); PR("Separate the numbers by tabs or spaces. "); PR("Type \1?\2 for a list of available\n"); if (*pType == 'A') { PR("code numbers, or type \1echo\2 to list "); PR("each echo profile, or type \1prof\2 to\n"); PR("draw a plot of the echo profile and "); PR("best-fit template, or type \1rsprof\2\n"); PR("to draw a plot of the range-sharpened "); PR("profile and template. Enter an\n"); } else { PR("code numbers, or enter an "); } PR("empty line to retain the previous choice.\n\n"); } PR("data codes> "); } #ifdef THINK_C #define BOLD mask = 0x80 #define EBOLD mask = 0x00 #define USCORE mask = 0x00 #define EUSCORE mask = 0x00 #define INVERT mask = 0x80 #define EINVERT mask = 0x00 setTermCap() { cinverse(1, stdout); strcpy(term_tit, "\5-More-\6"); strcpy(term_quit, "COMMAND-."); term_blk = 0; LI = 25; CO = 80; } #else #define BOLD fputs(MD, stdout); #define EBOLD fputs(ME, stdout); #define USCORE fputs(US, stdout); #define EUSCORE fputs(UE, stdout); #define INVERT fputs(SO, stdout); #define EINVERT fputs(SE, stdout); #ifdef VMS setTermCap() { strcpy(term_tit, "\5Press RETURN to continue\6"); strcpy(term_quit, "CTRL-Z"); term_blk = 28; LI = 24; CO = 80; SO = "\033[7m"; SE = "\033[m"; US = "\033[4m"; UE = "\033[m"; MD = "\033[1m"; ME = "\033[m"; } #else #ifdef MSDOS setTermCap() { strcpy(term_tit, "\5Press RETURN to continue\6"); strcpy(term_quit, "CTRL-Z"); term_blk = 28; LI = 24; CO = 80; SO = "\033[7m"; SE = "\033[m"; US = "\033[4m"; UE = "\033[m"; MD = "\033[1m"; ME = "\033[m"; } #else static char ba[1024]; /* termcap variable buffer */ extern char *getenv(); /* C library */ extern char *tgetstr(); /* -ltermcap */ char * getTCval(str, dft, ptr) char *str; /* termcap identifier */ char *dft; /* default value */ char **ptr; /* pointer to value buffer */ { char *val; /* returned value */ if ((val = tgetstr(str, ptr)) == NULL) return dft; while (isprint(*val)) val++; return val; } setTermCap() { char *c; /* scratch */ strcpy(term_tit, "\5-More-\6"); strcpy(term_quit, "CTRL-D"); term_blk = 0; if (! (c = getenv("TERM")) || tgetent(buf, c) != 1) { LI = 24; CO = 80; SO = MD = US = SE = ME = UE = ""; return; } if (tgetnum("li") > 1) LI = tgetnum("li"); if (tgetnum("co") > 1) CO = tgetnum("co"); c = ba+1; SO = getTCval("so", ba, &c); MD = getTCval("md", SO, &c); US = getTCval("us", SO, &c); SE = getTCval("se", ba, &c); ME = getTCval("me", SE, &c); UE = getTCval("ue", SE, &c); } #endif #endif #endif /* ** Write string with special characters */ PR(str) char *str; { static int mask; for (; *str; str++) switch(*str) { case 1: BOLD; break; case 2: EBOLD; break; case 3: USCORE; break; case 4: EUSCORE; break; case 5: INVERT; break; case 6: EINVERT; break; default: putchar(*str | mask); break; } }