fits_sci.cpp
来自「本源码是一个用于卫星数据处理的程序」· C++ 代码 · 共 729 行 · 第 1/3 页
CPP
729 行
return status;
if ( fits_update_key(fp, TSTRING , "OBSERVER", "", "", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "TELESCOP", "HXMT", "telescope", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "INSTRUME", "HXT", "instrument", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "OBS_MODE", "POINTING", "Observation mode", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "DATAMODE", "", "", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "READMODE", "", "", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "OBS_ID", "", "Observation id", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "SEQ_NUM", "", "Sequence number", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "FILENAME", (void *)fits_name.c_str(), "Name of the current data file", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "FILESIZE", "2", "Size of the current data file", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "REVISION", "1", "Edition of the data package", &status) )
return status;
status = 0;
int tfields = 8; /* table will have 2 columns */
long nrows = 0;
char extname[] = "SCID_Binary"; /* extension name */
char *ttype[] = { "time", "time_d", "trans_lon", "trans_lon_angle", "trans_lat", "trans_lat_angle", "energy", "detector" };
char *tform[] = { "7B", "1D", "1D", "1D", "1D", "1D", "1B", "1B" };
char *tunit[] = { "\0", "s", "\0", "\0", "\0", "\0", "\0", "\0" };
if ( fits_create_tbl( fp, BINARY_TBL, nrows, tfields, ttype, tform, tunit, extname, &status) ){
return status;
}
if ( fits_update_key(fp, TSTRING , "CHECKSUM", "0", "HUD checksum updated", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "DATASUM", "0", "data unit checksum", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "FILEDATE", buf, "Date and time of file creaton", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "DATE-OBS", buf, "Date and time of observation start", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "DATE-END", buf, "Date and time of observation stop", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "TSTART", "adas", "Observation start time", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "TSTOP", "asdas", "Observation end time", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "MISSSION", "HXMT", "Mission", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "PI_ID", "", "", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "OBSERVER", "", "", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "TELESCOP", "HXMT", "telescope", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "INSTRUME", "HXT", "instrument", &status) )
return status;
if ( fits_update_key(fp, TSTRING , "SEQ_NUM", "", "Sequence number", &status) )
return status;
}
}
*fptr = fp;
return 0;
}
/*****************************************************
** 函数名: write_fits_sx_sci
** 输入:*fptr,data,time,n,ptime
** fptr --- fits文件结构(structure used to store basic HDU information)
** data --- 数组,存放能量和通道号
** time --- 时间结构
** n
** ptime
**
** 输出:
** 返回0函数执行成功
** 调用说明:
** FindZT() .......得到对应的姿态数据
** 功能描述: 按照需求把需要的字段写入fits文件中
****************************************************************************************/
/**********************函数的注释参照上面的高能X射线********************************/
int write_fits_sx_sci( fitsfile *fptr, const char *data, sx_t &time, int n, const timespec_t *ptime )
{
if( fptr == NULL || ptime == NULL || data == NULL )
return -1;
int status = 0;
unsigned int nrows = 0;
int hdutype;
if ( fits_movabs_hdu(fptr, 2, &hdutype, &status) )
return status;
if( fits_read_key(fptr, TINT, "NAXIS2", &nrows, NULL, &status) )
return status;
// for( int i = 0; i < n; i++, nrows++ )
{
if (fits_insert_rows(fptr, nrows, 1, &status))
return status;
int firstrow = nrows + 1;
int firstelem = 1;
const ZT_t * Minzt;
Minzt = FindZT(get_sci_data(), ptime);
double time_b = ptime->time;
unsigned char var[10];
memset( var, 0, sizeof(var) );
u_long t = htonl(time.time);
memcpy( var, &t, 4 );
t = htonl(time.usec);
memcpy( var+4, &t, 4 );
if(*(data+1) == 0)
return 0;
fits_write_col(fptr, TBYTE, 1, firstrow, firstelem, 7, (void *)var, &status);
fits_write_col(fptr, TDOUBLE, 2, firstrow, firstelem, 1, (void *)&time_b, &status);
fits_write_col(fptr, TDOUBLE, 3, firstrow, firstelem, 1, (void *)&Minzt->trans_lon, &status);
fits_write_col(fptr, TDOUBLE, 4, firstrow, firstelem, 1, (void *)&Minzt->trans_lon_angle, &status);
fits_write_col(fptr, TDOUBLE, 5, firstrow, firstelem, 1, (void *)&Minzt->trans_lat, &status);
fits_write_col(fptr, TDOUBLE, 6, firstrow, firstelem, 1, (void *)&Minzt->trans_lat_angle, &status);
fits_write_col(fptr, TBYTE, 7, firstrow, firstelem, 1, (void *)data, &status);
fits_write_col(fptr, TBYTE, 8, firstrow, firstelem, 1, (void *)(data+1), &status);
}
return 0;
}
/*****************************************************
** 函数名: update_fits_keys
** 输入:*fptr,start,end,mode
** fptr --- fits文件结构(structure used to store basic HDU information)
** start ---
** end ---
** mode ---
** 输出:
** 返回0函数执行成功
** 调用说明:
** time2strUTC_fitshead() .......把秒时间转换成对应的年月日时分秒格式
** get_eph_orbit_number() .......在星历文件中取得对应时间的圈次
** 功能描述: 更新fits头中的关键字
****************************************************************************************/
int update_fits_keys( fitsfile *fptr, const timespec_t *start, const timespec_t *end, int mode )
{
int status = 0;
char buf[40];
int hdutype;
float f_start;
float f_end;
float f_length;
if ( fits_movabs_hdu(fptr, 1, &hdutype, &status))//转到fits头1
{
return status;
}
long filesize = fptr->Fptr->logfilesize;//得到文件大小
memset( buf, 0, sizeof(buf) );
time2strUTC_fitshead(buf, sizeof(buf), start );//第一个事例的时间
if ( fits_update_key(fptr, TSTRING , "DATE-OBS", buf, "Date and time of observation start", &status) )
return status;
memset( buf, 0, sizeof(buf) );
time2strUTC_fitshead(buf, sizeof(buf), end ); //最后一个事例的时间
if ( fits_update_key(fptr, TSTRING , "DATE-END", buf, "Date and time of observation stop", &status) )
return status;
f_start = start->time;//第一个事例时间,用秒表示
if ( fits_update_key(fptr, TFLOAT , "TSTART", &f_start, "Observation start time", &status) )
return status;
f_end = end->time;//最后一个事例时间,用秒表示
if ( fits_update_key(fptr, TFLOAT , "TSTOP", &f_end, "Observation end time", &status) )
return status;
f_length = f_end - f_start;
if ( fits_update_key(fptr, TFLOAT , "DURATION", &f_length, "Observation length", &status) )
return status;
if ( fits_update_key(fptr, TINT , "FILESIZE", &filesize, "Size of the current data file", &status) )
return status;
if( mode > 0 ){
int t = get_eph_orbit_number(start);
if ( fits_update_key(fptr, TINT , "OBTSTART", (void *)&t, "Start orbit number", &status) )
return status;
t = get_eph_orbit_number(end);
if ( fits_update_key(fptr, TINT , "OBT-END", (void *)&t, "End orbit number", &status) )
return status;
}
if ( fits_movabs_hdu(fptr, 2, &hdutype, &status))//转到fits头2
{
return status;
}
memset( buf, 0, sizeof(buf) );
time2strUTC_fitshead(buf, sizeof(buf), start );
if ( fits_update_key(fptr, TSTRING , "DATE-OBS", buf, "Date and time of observation start", &status) )
return status;
memset( buf, 0, sizeof(buf) );
time2strUTC_fitshead(buf, sizeof(buf), end );
if ( fits_update_key(fptr, TSTRING , "DATE-END", buf, "Date and time of observation stop", &status) )
return status;
f_start = start->time;
if ( fits_update_key(fptr, TFLOAT , "TSTART", &f_start, "Observation start time", &status) )
return status;
f_end = end->time;
if ( fits_update_key(fptr, TFLOAT , "TSTOP", &f_end, "Observation end time", &status) )
return status;
if( mode > 0 ){
int t = get_eph_orbit_number(start);//得到第一个事例对应的圈次
if ( fits_update_key(fptr, TINT , "OBTSTART", (void *)&t, "Start orbit number", &status) )
return status;
t = get_eph_orbit_number(end);//得到最后一个事例对应的圈次
if ( fits_update_key(fptr, TINT , "OBT-END", (void *)&t, "End orbit number", &status) )
return status;
}
return 0;
}
int close_fits_sci( fitsfile *fptr )//此函数功能为关闭fits文件
{
int status = 0;
if( fits_close_file( fptr, &status) )
return status;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?