Changeset 3658 in Sophya for trunk/AddOn/TAcq/minifits.cc


Ignore:
Timestamp:
Oct 18, 2009, 11:10:33 AM (16 years ago)
Author:
ansari
Message:

1/ Gestion multi-fibre ds RAcqMemZoneMgr et les DMAReader/DiskWriter (brproc.cc)
2/ Possibilite d'ajout de mot cle ds l'entete FITS par la classe MiniFITSFile

Reza , 18/10/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/AddOn/TAcq/minifits.cc

    r3639 r3658  
    55// #include <iostream>
    66
     7//////////////////////////////////////////////////////////////////////
     8///     Classe  MiniFITSException
     9//////////////////////////////////////////////////////////////////////
     10
     11
     12/* --Methode-- */
     13MiniFITSException::MiniFITSException(const char * m)   throw()
     14{
     15  if (m!=NULL) {
     16    strncpy(msg_, m, MFEX_MAXMSGLEN-1);
     17    msg_[MFEX_MAXMSGLEN-1] = '\0';
     18  }
     19  else msg_[0] = '\0';
     20}
     21
     22/* --Methode-- */
     23MiniFITSException::MiniFITSException(const string& m)   throw()
     24{
     25  strncpy(msg_, m.c_str(), MFEX_MAXMSGLEN-1);
     26  msg_[MFEX_MAXMSGLEN-1] = '\0';
     27}
     28
     29/* --Methode-- */
     30MiniFITSException::~MiniFITSException()  throw()
     31{
     32}
     33
     34/* --Methode-- */
     35const char* MiniFITSException::what() const throw()
     36{
     37  return msg_;
     38}
     39
     40/* --Methode-- */
     41string const MiniFITSException::Msg() const
     42{
     43  return (string(msg_));
     44}
     45
     46//////////////////////////////////////////////////////////////////////
     47///     Classe  MiniFITSFile
     48//////////////////////////////////////////////////////////////////////
     49
    750#define MFITSHLEN 2880
    851
     52/* --Methode-- */
    953MiniFITSFile::MiniFITSFile()
    1054{
     
    1256}
    1357
     58/* --Methode-- */
    1459MiniFITSFile::MiniFITSFile(string const & nom, MiniFITS_Mode rwm)
    1560{
     
    1863}
    1964
     65/* --Methode-- */
    2066MiniFITSFile::MiniFITSFile(const char* nom, MiniFITS_Mode rwm)
    2167{
     
    2571
    2672
     73/* --Methode-- */
    2774MiniFITSFile::~MiniFITSFile()
    2875{
     
    3178}
    3279
     80/* --Methode-- */
    3381void MiniFITSFile::Init()
    3482{
     
    4088  totwsz = 0;
    4189  header = new char[MFITSHLEN];
    42 
    43 }
    44 
     90  for(int i=0; i<MFITSHLEN; i++)  header[i]=' ';
     91  nkeya_ = 0;
     92}
     93
     94/* --Methode-- */
    4595void MiniFITSFile::Open(const char* nom, MiniFITS_Mode rwm)
    4696{
     
    65115}
    66116
     117/* --Methode-- */
    67118void MiniFITSFile::Close()
    68119{
     
    71122          // on remplit avec des zeros pour avoir une longueur multiple de 2880
    72123          size_t padsz = MFITSHLEN-(totwsz%MFITSHLEN);
    73           for(size_t k=0; k<padsz; k++) header[k]=0;
    74           fwrite(header, 1, padsz, fip);
     124          char zeros[160];
     125          for(size_t k=0; k<160; k++) zeros[k]=0;
     126          while(padsz>160) {
     127            fwrite(zeros, 1, 160, fip);
     128            padsz-=160;
     129          }
     130          if (padsz>0)  fwrite(zeros, 1, padsz, fip);
    75131          // On reecrit l'entete
    76132          FillHeader();
     
    84140}
    85141
     142/* --Methode-- */
    86143void MiniFITSFile::setDTypeNaxis(MiniFITS_DT dt, size_t na1, size_t na2)
    87144{
     
    95152}
    96153
     154/* --Methode-- */
    97155string MiniFITSFile::DataTypeToString()
    98156{
     
    103161}
    104162
     163/* --Methode-- */
    105164int MiniFITSFile::Write(void* data, size_t sz)
    106165{
     
    110169}
    111170
     171/* --Methode-- */
    112172int MiniFITSFile::Read(void* data, size_t sz, size_t offset)
    113173{
     
    117177}
    118178
     179/* --Methode-- */
    119180void MiniFITSFile::FillHeader()
    120181{
    121   for(int i=0; i<MFITSHLEN; i++)  header[i]=' ';
    122182  strcpy(header, "SIMPLE  =                    T / file does conform to FITS standard");
    123183  header[strlen(header)] = ' ';
     
    138198  sprintf(buff, "NAXIS2  = %20ld /   number of bits per data pixel", (long)nax2);
    139199  buff[strlen(buff)] = ' ';
    140   buff = header+400;
     200  buff = header+400+nkeya_*80;
    141201  strcpy(buff,"COMMENT  BAO-Radio / MiniFITSFile ");
    142202  buff[strlen(buff)] = ' ';
    143   buff = header+480;
     203  buff = header+480+nkeya_*80;
    144204  strcpy(buff,"END");
    145205  buff[strlen(buff)] = ' ';
     
    148208}
    149209
    150 
     210/* --Methode-- */
     211int MiniFITSFile::AddKeyI(const char* key, long val, const char* comm)
     212{
     213  if (nkeya_ >= 29) return 0;
     214  char cle[10];
     215  strncpy(cle,key,8);
     216  cle[8]='=';
     217  for(int i=0;i<8;i++)
     218    if (cle[i]=='\0') cle[i]=' ';
     219  cle[9]='\0';
     220  char* buff=header+400+nkeya_*80;
     221  if (comm!=NULL) {
     222    char tcom[50];
     223    strncpy(tcom,comm,48); 
     224    tcom[48]='\0';
     225    sprintf(buff,"%s %20ld / %s", cle, val, tcom);
     226  }
     227  else  sprintf(buff,"%s %20ld / ", cle, val);
     228  buff[strlen(buff)]=' ';
     229  nkeya_++;
     230  return nkeya_;
     231}
     232
     233/* --Methode-- */
     234int MiniFITSFile::AddKeyD(const char* key, double val, const char* comm)
     235{
     236  if (nkeya_ >= 29) return 0;
     237  char cle[10];
     238  strncpy(cle,key,8);
     239  cle[8]='=';
     240  for(int i=0;i<8;i++)
     241    if (cle[i]=='\0') cle[i]=' ';
     242  cle[9]='\0';
     243  char* buff=header+400+nkeya_*80;
     244  if (comm!=NULL) {
     245    char tcom[50];
     246    strncpy(tcom,comm,48); 
     247    tcom[48]='\0';
     248    sprintf(buff,"%s %20lg / %s", cle, val, tcom);
     249  }
     250  else  sprintf(buff,"%s %20ld / ", cle, val);
     251  buff[strlen(buff)] = ' ';
     252  nkeya_++;
     253  return nkeya_;
     254}
     255
     256/* --Methode-- */
     257int MiniFITSFile::AddKeyS(const char* key, const char* val, const char* comm)
     258{
     259  if (nkeya_ >= 29) return 0;
     260  char cle[10];
     261  strncpy(cle,key,8);
     262  cle[8]='=';
     263  for(int i=0;i<8;i++)
     264    if (cle[i]=='\0') cle[i]=' ';
     265  cle[9]='\0';
     266  char tcom[72];
     267  tcom[0]='\'';
     268  strncpy(tcom+1,val,65);
     269  int l=strlen(tcom);
     270  strcpy(tcom+l,"' / ");
     271  l+=4;
     272  if ((l<70)&&(comm!=NULL)) strncpy(tcom+l,comm,70-l);
     273  tcom[70]='\0';
     274  char* buff=header+400+nkeya_*80;
     275  sprintf(buff,"%s %s", cle, tcom);
     276  buff[strlen(buff)] = ' ';
     277  nkeya_++;
     278  return nkeya_;
     279}
     280
     281/* --Methode-- */
    151282void MiniFITSFile::DecodeHeader()
    152283{
Note: See TracChangeset for help on using the changeset viewer.