[Date Prev][Date Next][Thread Prev][Thread Next] - [Date Index][Thread Index][Author Index]
Re: D-block utility
Paul,
Thanks for the info!! I have updated the routine to extract the time
and date and added a function "amsatDate" to convert AMSAT DAY to a
normal date.
The file names will now appear as:
YYMMDD-HHMMSS.jpg
010718-030958.jpg
010718-031858.jpg
010718-032758.jpg
010718-033658.jpg
010718-034558.jpg
010718-035458.jpg
010718-040358.jpg
010718-041258.jpg
010718-042158.jpg
010718-043059.jpg
010718-043959.jpg
010718-044859.jpg
010718-045759.jpg
010718-050659.jpg
D00329_PH.index <-- decoded d-block
void getJFIF(char path[],char fname[],char source[])
{
// "source" is the complete path to the D-block file
// "path" is just that, the path to the file
// "fname" is he file name with out the ".TLM"
FILE *fp1,*fp2;
unsigned char
c,c1,c2,c3,header[10],temp[255],date[100][20],time[100][20];
unsigned short i=0,d;
unsigned long x,s=0,index[100],indexCount=0;
//JFIF header pattern
header[0]=0xFF;
header[1]=0xD8;
header[2]=0xFF;
header[3]=0xE0;
header[4]=0x00;
header[5]=0x10;
header[6]=0x4A;
header[7]=0x46;
header[8]=0x49;
header[9]=0x46;
sprintf(temp,"%s/%s",path,fname);
fp1=fopen(source,"rb");
//printf("getJFIF %s\n",source);
while ( fread(&c,1,sizeof(unsigned char) ,fp1) )
{
if( c == header[i]) // serach for match
{
++i;
// printf("indexCount=%ld i=%d c=%X
\n%s\n",indexCount,i,c,path);
}
else
{
i=0;
}
if(i>9) // record start of JFIF images
{
index[indexCount]=ftell(fp1) -10;
//printf("indexCount=%ld start=%ld\n",indexCount,
index[indexCount]);
++indexCount;
i=0;
}
}
index[indexCount]=ftell(fp1); //store end of file.
fclose(fp1);
// get date and time for each image
fp1=fopen(source,"rb");
for(x=1;x<indexCount+1;x++)
{
// get time
fseek(fp1,(index[x]-5),SEEK_SET);
fread(&c1,1,sizeof(unsigned char) ,fp1);
fread(&c2,1,sizeof(unsigned char) ,fp1);
fread(&c3,1,sizeof(unsigned char) ,fp1);
sprintf(&time[x-1][0],"%02d%02d%02d",c3,c2,c1);
//printf("%s time x=%ld\n",&time[x],x);
// get and convert date
fread(&c1,1,sizeof(unsigned char) ,fp1);
fread(&c2,1,sizeof(unsigned char) ,fp1);
d=( (c2 *256 ) & 0xff00 ) + (c1 & 0x00ff );
amsatDate(d,temp); //convert AMSAT DAY to standard date
sprintf(&date[x-1][0],"%s",temp);
// printf("%s %s time x=%ld\n",&date[x-1][0],&time[x-1][0],x);
}
x=0; // point to curent image
s=0; //current postion in source file
// split out images
fp1=fopen(source,"rb");
for(x=0;x<indexCount;x++)
{
sprintf(temp,"%s/%s-%s.jpg",path,&date[x][0],&time[x][0]);
fp2=fopen(temp,"wb");
fseek(fp1,index[x],SEEK_SET); // goto start of next image
while( s < index[x+ 1])
{
fread(&c,1,sizeof(unsigned char) ,fp1);
fputc(c,fp2);
s=ftell(fp1);
}
fclose(fp2);
}
fclose(fp1);
}
// convert AMSAT DAY to normal date
// Ref. "The Satellite Experimenter's Handbook 2nd Edition" page 6-18
void amsatDate(short d,char date[])
{
unsigned short i=0,yy=0,x=0;
unsigned long dd;
char temp[255];
struct amsatDay {
char month[15][20];
unsigned short norm[15];
unsigned short leap[15];
};
struct amsatDay Aday;
sprintf(Aday.month[0],"%s","Error_\0");
sprintf(Aday.month[1],"%s","Jan\0");
sprintf(Aday.month[2],"%s","Feb\0");
sprintf(Aday.month[3],"%s","Mar\0");
sprintf(Aday.month[4],"%s","Apr\0");
sprintf(Aday.month[5],"%s","May\0");
sprintf(Aday.month[6],"%s","Jun\0");
sprintf(Aday.month[7],"%s","Jul\0");
sprintf(Aday.month[8],"%s","Aug\0");
sprintf(Aday.month[9],"%s","Sep\0");
sprintf(Aday.month[10],"%s","Oct\0");
sprintf(Aday.month[11],"%s","Nov\0");
sprintf(Aday.month[12],"%s","Dec\0");
Aday.norm[1]= 0; Aday.leap[1]=0;
Aday.norm[2]= 31; Aday.leap[2]=31;
Aday.norm[3]= 59; Aday.leap[3]=60;
Aday.norm[4]= 90; Aday.leap[4]=91;
Aday.norm[5]= 120; Aday.leap[5]=121;
Aday.norm[6]= 151; Aday.leap[6]=152;
Aday.norm[7]= 181; Aday.leap[7]=182;
Aday.norm[8]= 212; Aday.leap[8]=213;
Aday.norm[9]= 243; Aday.leap[9]=244;
Aday.norm[10]= 273; Aday.leap[10]=274;
Aday.norm[11]= 304; Aday.leap[11]=305;
Aday.norm[12]= 334; Aday.leap[12]=335;
Aday.norm[13]= 365; Aday.leap[13]=366; /// overflow
//d=8401; //1jan2001
yy=(d/365);
i=(int)( (1978+yy) - 1977)/4; //how many days to add because of leap
years
yy=(d-i)/365; //subtract out leap days
dd= d-(((1978+yy)-1978)* 365)+1 - (int)( (1978+yy) - 1977)/4;
for(i=1;i<14;i++){
if(dd<Aday.norm[i])
{
x=i-1;
i=100;
}
}
//dd=Aday.leap[d];
if(x > 13){x=1;}
//sprintf(date,"%ld%s%d",dd-Aday.norm[x],Aday.month[x],(yy+1978)); //
DAy Month Year
sprintf(date,"%02d%02d%02d",(yy+1978)-2000,x,dd-Aday.norm[x]); // YYMMDD
}
----
Via the amsat-bb mailing list at AMSAT.ORG courtesy of AMSAT-NA.
To unsubscribe, send "unsubscribe amsat-bb" to Majordomo@amsat.org
AMSAT Home