View Single Post
  #8  
Old March 13th 04, 01:21 AM
Jan Panteltje
external usenet poster
 
Posts: n/a
Default How To Decode The MER Image Filenames

On a sunny day (Fri, 12 Mar 2004 21:11:39 GMT) it happened "Joe Knapp"
wrote in
m:


"Jan Panteltje" wrote
Here's a small application to dump the image info:

[snip]
That compiles fine on Linux,

rawid ./
works OPK,
but
rawid 1M131649564EFF0544P2933M2M1.JPG
does nothing.


Thanks Jan. I fixed the bug & updated the files:

http://www.copperas.com/astro/rawid.exe (Windows command-line executable)
http://www.copperas.com/astro/rawid (Linux command-line i386 executable)
http://www.copperas.com/astro/rawid.c (source code)

Joe

I still got the same C file, here is what I did (tossed MS windows):

// Program by Joe Knapp March 11, 2004
#define MAXFN 1200
#define FNLEN 27
#define OPPORTUNITY '1'
#define SPIRIT '2'
#define SCID 0
#define CAMERAID 1
#define SCCLK_START 2
#define SCCLK_END 10
#define SCCLK_LEN (SCCLK_END - SCCLK_START + 1)
#define PRODTYPE 11
#define SITENO 14
#define DRIVENO 16
#define CMDSEQNO 18
#define CAMEYE 23
#define CAMFILT 24
#define PRODUCER 25
#define VERSION 26
#define UNIX 1
#define MER2UTIME 946727273
#define SECSPERSOL 88775.244
#define OPP_SOL1 128228618
#define SPR_SOL1 126408373
#define CWD "."
#include stdio.h
#include string.h
#include sys/types.h
#include sys/stat.h
#include stdlib.h
#include time.h

#if UNIX
#include dirent.h
#include libgen.h
#include unistd.h
#else
#include windows.h
#include io.h
#endif
char * d2hms(double) ;
int isdr(char *) ;
int dumpinfo(char *) ;
char * bname(char *) ;
char * dname(char *) ;
int main(int, char**) ;
int main(int argc, char *argv[])
{
char fname[MAXFN] ;
int i ;
DIR * cwd ;
struct dirent *dent ;

char datadir[MAXFN] ;
static struct
{
char type[80] ;
} lfilts[8] =
{
"EMPTY (clear)",
"753 nm (20 nm bp) infrared",
"673 nm (16 nm bp) red",
"601 nm (17 nm bp) orange",
"535 nm (20 nm bp) green",
"482 nm (25 nm bp) cyan",
"432 nm (32 nm shortpass) blue",
"440 nm solar ND"
} ;

static struct
{
char type[80] ;
} rfilts[8] = {
"436 nm (37 nm sp) blue",
"754 nm (20 nm bp) infrared",
"803 nm (20 nm bp) infrared",
"864 nm (17 nm bp) infrared",
"904 nm (26 nm bp) infrared",
"934 nm (25 nm bp) infrared",
"1009 nm (38 nm lp) infrared",
"880 nm solar ND"
} ;

if (argc != 2)
{
fprintf(stderr,"usage: %s MER raw image path\n",argv[0]) ;
fprintf(stderr," or %s partial MER raw image path\n",argv[0]) ;
fprintf(stderr," e.g., %s 1F132089069EDN05A6P1141R0M1.jpg\n",argv[0]) ;
fprintf(stderr," %s R0\n",argv[0]) ;
fprintf(stderr," %s images/dir/1F132089069EDN05A6P1141R0M1.jpg\n",argv[0]) ;
fprintf(stderr," %s images/dir/R0\n",argv[0]) ;
exit(1) ;
}

strncpy(fname, bname(argv[1]), MAXFN) ;
strncpy(datadir, dname(argv[1]), MAXFN) ;

fname[MAXFN] = '\0' ;
datadir[MAXFN] = '\0' ;

if (!isdr(fname))
{
long patlen, gotit, gotone ;
char pat[MAXFN] ;

strncpy(pat,fname,MAXFN) ;

patlen = strlen(pat) ;
gotone = 0 ;
gotit = 0 ;

cwd = opendir(datadir) ;
while(dent = readdir(cwd))
{
if (isdr(dent-d_name))
{
gotit = 0 ;
printf("%s %d %s\n",pat,patlen,dent-d_name) ;

for (i = 0 ; i FNLEN ; i++)
if (!strncmp(dent-d_name+i,pat,patlen))
{
gotit = 1 ;
gotone = 1 ;
}

if (gotit)
{
strncpy(fname,dent-d_name,FNLEN) ;
fname[FNLEN] = '\0' ;
printf("-----------------------------------------------------------------------\n") ;
dumpinfo(fname) ;
}
}
}

if (!gotone)
{
fprintf(stderr,"ERROR: could not find MER data file matching %s in directory %s\n",fname,datadir) ;
exit(1) ;
}
else printf("-----------------------------------------------------------------------\n") ;
}
else
{
dumpinfo(fname);
}

return(0) ;
}


int dumpinfo(char *fname)
{
char scclk[SCCLK_LEN+1] ;
long mertime ;
char siteno[3] ;
char driveno[3] ;
char cmdseqno[6] ;
int icmdseqno ;
int filtno ;
time_t unixtime ;
time_t umertime ;
double sols, csols, edays ;
int isols, icsols, iedays ;
int i,len ;
char pl[2] ;
static struct {
char type[80] ;
} lfilts[8] = {
"EMPTY (clear)",
"753 nm (20 nm bp) infrared",
"673 nm (16 nm bp) red",
"601 nm (17 nm bp) orange",
"535 nm (20 nm bp) green",
"482 nm (25 nm bp) cyan",
"432 nm (32 nm shortpass) blue",
"440 nm solar ND"
} ;
static struct {
char type[80] ;
} rfilts[8] = {
"436 nm (37 nm sp) blue",
"754 nm (20 nm bp) infrared",
"803 nm (20 nm bp) infrared",
"864 nm (17 nm bp) infrared",
"904 nm (26 nm bp) infrared",
"934 nm (25 nm bp) infrared",
"1009 nm (38 nm lp) infrared",
"880 nm solar ND"
} ;
i = 0 ;
len = strlen(fname) ;
while (i len) {
if (fname[i] == '.')
fname[i] = '\0' ;
i++ ;
}
if (strlen(fname) != FNLEN) {
fprintf(stderr,"ERROR: %s is not a valid MER data file name\n",fname) ;
return(0) ;
}
printf("Image info for: %s\n",fname) ;
if (fname[SCID] == OPPORTUNITY)
printf("Spacecraft: OPPORTUNITY\n") ;
else if (fname[SCID] == SPIRIT)
printf("Spacecraft: SPIRIT\n") ;
else {
fprintf(stderr,"ERROR: spacecraft ID %c in position %d unknown\n",fname[SCID],SCID+1) ;
return(0) ;
}
switch(fname[CAMERAID]) {
case 'F':
printf("Camera: Forward HAZCAM") ;
break ;
case 'R':
printf("Camera: Rear HAZCAM") ;
break ;
case 'N':
printf("Camera: NAVCAM") ;
break ;
case 'P':
printf("Camera: PANCAM") ;
break ;
case 'M':
printf("Camera: Microscopic Imager") ;
break ;
case 'E':
printf("EDLCAM") ;
break ;
default:
fprintf(stderr,"\nERROR: Camera ID %c in position %d unknown\n",fname[CAMERAID],CAMERAID+1) ;
return(0) ;
}
if (fname[CAMEYE] == 'L')
printf(", left") ;
else if (fname[CAMEYE] == 'R')
printf(", right") ;
if (fname[CAMFILT] != '0') {
if (fname[CAMEYE] == 'L') {
printf(", filter %c",fname[CAMFILT]) ;
filtno = (int)fname[CAMFILT] - (int)'0' - 1;
printf(", %s\n",lfilts[filtno].type) ;
}
else if (fname[CAMEYE] == 'R') {
printf(", filter %c",fname[CAMFILT]) ;
filtno = (int)fname[CAMFILT] - (int)'0' - 1;
printf(", %s\n",rfilts[filtno].type) ;
}
else if (fname[CAMEYE] == 'M') {
if (fname[CAMFILT] == '1')
printf(", dust cover CLOSED\n") ;
else if (fname[CAMFILT] == '2')
printf(", dust cover OPEN\n") ;
else
printf("\n") ;
}
}
else
printf("\n") ;
strncpy(scclk,fname+SCCLK_START,SCCLK_LEN) ;
mertime = atol(scclk) ;
printf("Spacecraft clock: %d (seconds since January 1, 2000, 11:58:55.816 UTC)\n",mertime) ;
printf("Product type: ") ;
if (fname[PRODTYPE] == 'E') {
char pid[3] ;
printf("EDR") ;
strncpy(pid,fname+PRODTYPE+1,2) ;
pid[2] = '\0' ;
if (!strcmp(pid,"FF"))
printf(" full frame") ;
else if (!strcmp(pid,"SF"))
printf(" sub-frame") ;
else if (!strcmp(pid,"DN"))
printf(" downsampled") ;
else if (!strcmp(pid,"TH"))
printf(" thumbnail") ;
else if (!strcmp(pid,"RS"))
printf(" row-summed") ;
else if (!strcmp(pid,"CS"))
printf(" column-summed") ;
else if (!strcmp(pid,"RP"))
printf(" reference pixels") ;
else if (!strcmp(pid,"HG"))
printf(" histogram") ;
else {
fprintf(stderr,"\nERROR: Unknown EDR type %s\n",pid) ;
return(0) ;
}
}
else
printf("RDR") ;
printf("\n") ;
strncpy(siteno,fname+SITENO,2) ;
siteno[2] = '\0' ;
printf("Site number: %s\n",siteno) ;
strncpy(driveno,fname+DRIVENO,2) ;
driveno[2] = '\0' ;
printf("Drive number: %s\n",driveno) ;
strncpy(cmdseqno,fname+CMDSEQNO,5) ;
cmdseqno[5] = '\0' ;
printf("Command sequence number: %s ",cmdseqno) ;
switch(fname[CMDSEQNO]) {
case 'C':
printf("(cruise)") ;
break ;
case 'D':
printf("(IDD & RAT)") ;
break ;
case 'E':
printf("(engineering)") ;
break ;
case 'F':
printf("(flight software seq rejected)") ;
break ;
case 'G':
printf("(spare)") ;
break ;
case 'K':
printf("(spare)") ;
break ;
case 'M':
printf("(master)") ;
break ;
case 'N':
printf("(in-situ instrument)") ;
break ;
case 'P':
printf("(PMA or remote sensing instrument)") ;
break ;
case 'R':
printf("(rover driving)") ;
break ;
case 'S':
printf("(submaster)") ;
break ;
case 'T':
printf("(test)") ;
break ;
case 'W':
printf("(seq triggered by comm window)") ;
break ;
case 'X':
printf("(contingency)") ;
break ;
case 'Y':
printf("(spare)") ;
break ;
case 'Z':
printf("(SCM seqs)") ;
break ;
default:
break ;
}
icmdseqno = atoi(cmdseqno+1) ;
if ((icmdseqno 4096) || (icmdseqno 0)) {
fprintf(stderr,"ERROR: invalid command sequence number %d\n",icmdseqno) ;
return(0) ;
}
if (icmdseqno 500)
printf(" misc. imaging") ;
else if (icmdseqno 1000)
printf(" unallocated") ;
else if (icmdseqno 1500)
printf(" HAZCAM") ;
else if (icmdseqno 2000)
printf(" NAVCAM") ;
else if (icmdseqno 2900)
printf(" PANCAM") ;
else if (icmdseqno 3000)
printf(" MI") ;
else if (icmdseqno 4000)
printf(" Mini-TES") ;
else if (icmdseqno 4096)
printf(" misc. PMA") ;
printf("\n") ;
printf("Producer: ") ;
switch(fname[PRODUCER]) {
case 'A':
printf("Arizona State University") ;
break ;
case 'C':
printf("Cornell University") ;
break ;
case 'F':
printf("USGS") ;
break ;
case 'J':
printf("Johannes Gutenberg University") ;
break ;
case 'M':
printf("MIPL/JPL") ;
break ;
case 'N':
printf("NASA Ames Research") ;
break ;
case 'P':
printf("Max Plank Institute") ;
break ;
case 'S':
printf("SOAS/JPL") ;
break ;
case 'U':
printf("University of Arizona") ;
break ;
case 'V':
printf("SSV/JPL") ;
break ;
case 'X':
printf("OTHER") ;
break ;
default:
fprintf(stderr,"ERROR; unknown data producer %c\n",fname[PRODUCER]) ;
return(0) ;
}
printf("\n") ;
time(&unixtime) ;
//printf("Unix time: %ld\n",(long)unixtime) ;
umertime = mertime + MER2UTIME ;
printf("Acquisition time (Earth): %s",ctime(&umertime)) ;
printf("Time zone: %s\n",tzname[0]) ;
if (fname[SCID] == OPPORTUNITY)
sols = 1.0 + (double)(mertime - OPP_SOL1)/SECSPERSOL ;
else
sols = 1.0 + (double)(mertime - SPR_SOL1)/SECSPERSOL ;
isols = (int)sols ;
printf("Acquisition time (Mars): Sol %d %s\n",isols,d2hms((double)(sols - isols))) ;
printf("Current local time (Earth): %s",ctime(&unixtime)) ;
if (fname[SCID] == OPPORTUNITY)
csols = 1.0 + (double)(unixtime - (OPP_SOL1 + MER2UTIME))/SECSPERSOL ;
else
csols = 1.0 + (double)(unixtime - (SPR_SOL1 + MER2UTIME))/SECSPERSOL ;
icsols = (int)csols ;
printf("Current local time (Mars): Sol %d %s\n",icsols,d2hms((double)(csols - icsols))) ;

edays = (unixtime - umertime)/86400. ;
iedays = (int)edays ;
if (iedays == 1)
strcpy(pl,"") ;
else
strcpy(pl,"s") ;
printf("Elapsed time since acquisition: %d day%s, %s\n",iedays,pl,d2hms((double)(edays - iedays))) ;
return(1) ;
}


char * d2hms(double d)
{
int h, m, s ;
static char hms[80] ;

s = (int)(d*84600) ;
h = s/3600 ;
m = (s - h*3600)/60 ;
s %= 60 ;
sprintf(hms,"%02d:%02d:%02d",h,m,s) ;
return (hms) ;
}


// return true if fname is valid data record name
// modifies fname if it has an extension
int isdr(char *fname)
{
int i, len ;
i = 0 ;
len = strlen(fname) ;
while (i len) {
if (fname[i] == '.')
fname[i] = '\0' ;
i++ ;
}
if (strlen(fname) != FNLEN)
return(0) ;

if ((fname[SCID] != OPPORTUNITY) && (fname[SCID] != SPIRIT))
return(0) ;
return(1) ; // close enough for govt work
}


char *bname(char *path)
{
static char basename[MAXFN] ;

int i, len ;

len = strlen(path) ;

i = len - 1 ;
while (i 0) {
if ((path[i] == '/') || (path[i] == '\\'))
break ;
i-- ;
}
if (i == 0)
strncpy(basename,path,MAXFN) ;
else
strncpy(basename,path+i+1,MAXFN) ;

return(basename) ;
}


char *dname(char *path)
{
static char dirname[MAXFN] ;

int i, len ;

len = strlen(path) ;

i = len - 1 ;
while (i 0) {
if ((path[i] == '/') || (path[i] == '\\'))
break ;
i-- ;
}
if (i == 0)
strcpy(dirname,".") ;
else
strncpy(dirname,path,i) ;

return(dirname) ;
}