Пример #1
0
int32 OldFitIDLSeek(int argc,char *argv[]) {

  struct OldFitIDLFp *idlfitfp;
  struct OldFitFp fitfp;

  IDL_FILE_STAT stat;
  FILE *ffp=NULL,*ifp=NULL;
  int s;

  int32 yr,mo,dy,hr,mt;
  double sc;
  double *atme;

  idlfitfp=(struct OldFitIDLFp *) argv[0];
  
  IDL_FileStat(idlfitfp->fitunit,&stat);
 
  /* Find the file pointer */

  ffp=stat.fptr; 
  
  if (ffp==NULL) return -1;

  fflush(ffp);

  if (idlfitfp->inxunit !=-1) {
    IDL_FileStat(idlfitfp->inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  fitfp.fitfp=fileno(ffp);
  if (ifp !=NULL) fitfp.inxfp=fileno(ifp);
  else fitfp.inxfp=-1;
 
  yr=*( (int32 *) argv[1]);
  mo=*( (int32 *) argv[2]);
  dy=*( (int32 *) argv[3]);
  hr=*( (int32 *) argv[4]);
  mt=*( (int32 *) argv[5]);
  sc=*( (double *) argv[6]);
  atme=(double *) argv[7];
 
  OldFitIDLToFitFp(idlfitfp,&fitfp);

  s=OldFitSeek(&fitfp,yr,mo,dy,hr,mt,sc,atme);

  OldFitFitFpToIDL(&fitfp,idlfitfp);

  return s;
}
Пример #2
0
int32 OldFitIDLOpen(int argc,char *argv[]) {
  struct OldFitIDLFp *idlfitfp;
  struct OldFitFp *fitfp;
  IDL_FILE_STAT stat;
  FILE *ffp=NULL,*ifp=NULL;
  int fitunit,inxunit; 
  int s;
  
  fitunit = *( (int32 *) argv[0]);
  inxunit = *( (int32 *) argv[1]);


  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,fitunit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(fitunit,&stat);
 
  /* Find the file pointer */

  ffp=stat.fptr; 
  
  if (ffp==NULL) return -1;

  fflush(ffp);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,inxunit,IDL_EFS_STDIO);
  if (s==TRUE) {
    IDL_FileStat(inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  if (ifp !=NULL) fitfp=OldFitOpenFd(fileno(ffp),fileno(ifp));
  else fitfp=OldFitOpenFd(fileno(ffp),-1);
 
  idlfitfp=(struct OldFitIDLFp *) argv[2];
  idlfitfp->fitunit=fitunit;
  idlfitfp->inxunit=inxunit;
  OldFitFitFpToIDL(fitfp,idlfitfp);
  free(fitfp);
  return s;
}
Пример #3
0
int32 OldFitIDLPoint(int argc,char *argv[]) {
  int fildes;
  struct OldFitIDLFp *idlfitfp;
  IDL_FILE_STAT stat;
  FILE *fp;
  int32 offset;
  int s;

  idlfitfp=(struct OldFitIDLFp *) argv[0];  
  IDL_FileStat(idlfitfp->fitunit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  offset=*( (int32 *) argv[1]);

  fildes=fileno(fp);
  s=lseek(fildes,offset,SEEK_SET);

  return s;

}
Пример #4
0
int32 OldCnvMapIDLPoint(int argc,char *argv[]) {
  int fildes;
  int unit;
  IDL_FILE_STAT stat;
  FILE *fp;
  int32 offset;
  int s;

  unit = *( (int32 *) argv[0]);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  offset=*( (int32 *) argv[1]);

  fildes=fileno(fp);
  s=lseek(fildes,offset,SEEK_SET);

  return s;

}
Пример #5
0
static IDL_VPTR IDLOldRawWriteHeader(int argc,IDL_VPTR *argv) {
  int s=0;
  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct RadarIDLParm *iprm=NULL;
  struct RawIDLData *iraw=NULL;
  FILE *fp;

  char vstring[256];

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_STRUCTURE(argv[2]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);

  /* Find the file pointer */

  fp=stat.fptr;

  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct RadarIDLParm *) argv[1]->value.s.arr->data;
  iraw=(struct RawIDLData *) argv[2]->value.s.arr->data;

  sprintf(vstring,"%d.%.3d",(int) iraw->revision.major,
	                    (int) iraw->revision.minor);
  s=OldRawHeaderFwrite(fp,"rawwrite",vstring,iraw->thr,"IDL output");

  return (IDL_GettmpLong(s));
}
Пример #6
0
int32 OldRawIDLSeek(int argc,char *argv[]) {

  struct OldRawIDLFp *idlrawfp;
  struct OldRawFp rawfp;

  IDL_FILE_STAT stat;
  FILE *fp;
  int s;

  int32 yr,mo,dy,hr,mt;
  double sc;
  double *atme;

  idlrawfp=(struct OldRawIDLFp *) argv[0];
  
  IDL_FileStat(idlrawfp->rawunit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  rawfp.rawfp=fileno(fp);
  rawfp.inxfp=0;

  yr=*( (int32 *) argv[1]);
  mo=*( (int32 *) argv[2]);
  dy=*( (int32 *) argv[3]);
  hr=*( (int32 *) argv[4]);
  mt=*( (int32 *) argv[5]);
  sc=*( (double *) argv[6]);
  atme=(double *) argv[7];
 
  OldRawIDLToRawFp(idlrawfp,&rawfp);

  s=OldRawSeek(&rawfp,yr,mo,dy,hr,mt,sc,atme);

  OldRawRawFpToIDL(&rawfp,idlrawfp);

  return s;
}
Пример #7
0
int32 OldFitIDLWriteHeader(int argc,char *argv[]) {

  struct RadarIDLParm *idlprm;
  struct FitIDLData *idlfit;

  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  char vstring[256];

 
  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  idlprm=(struct RadarIDLParm *) argv[1];
  idlfit=(struct FitIDLData *) argv[2];

  sprintf(vstring,"%d.%.3d",idlfit->revision.major,idlfit->revision.minor);
  s=OldFitHeaderFwrite(fp,"IDL output","fitwrite",vstring);

  return s;
}
Пример #8
0
int32 OldRawIDLOpen(int argc,char *argv[]) {
  struct OldRawIDLFp *idlrawfp;
  struct OldRawFp *rawfp;
  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;
  
  unit = *( (int32 *) argv[0]);


  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
    
  if (fp==NULL) return -1;

  fflush(fp);

  rawfp=OldRawOpenFd(fileno(fp),0);
  idlrawfp=(struct OldRawIDLFp *) argv[1];
  idlrawfp->rawunit=unit;
  idlrawfp->inxunit=0;
  OldRawRawFpToIDL(rawfp,idlrawfp);
  free(rawfp);
  return s;
}
Пример #9
0
int32 OldCnvMapIDLSeek(int argc,char *argv[]) {

  struct RfileIndex inx;
  IDL_FILE_STAT stat;
  FILE *fp;
  int unit,s; 
  int32 yr,mo,dy,hr,mt;
  double sc;
  double *atme;

  inx.num=0;
  inx.time.start=NULL;
  inx.time.end=NULL;
  inx.offset=NULL;
  
  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  yr=*( (int32 *) argv[1]);
  mo=*( (int32 *) argv[2]);
  dy=*( (int32 *) argv[3]);
  hr=*( (int32 *) argv[4]);
  mt=*( (int32 *) argv[5]);
  sc=*( (double *) argv[6]);
  atme=(double *) argv[7];

  if (argc>8) {
    inx.num=*( (int32 *) argv[8]);
    if (inx.num !=0) inx.time.start=malloc(sizeof(double)*inx.num);
    if (inx.time.start !=NULL) inx.time.end=malloc(sizeof(double)*inx.num);
    if ((inx.time.start !=NULL) && (inx.time.end !=NULL)) 
        inx.offset=malloc(sizeof(int32)*inx.num);
    if (inx.offset==NULL) {
      if (inx.time.start !=NULL) free(inx.time.start);
      if (inx.time.end !=NULL) free(inx.time.end);
      inx.time.start=NULL;
      inx.time.end=NULL;
      inx.num=0; 
    } 
    if ((inx.time.start !=NULL) && (inx.time.end !=NULL) &&
        (inx.offset !=NULL)) {
      memcpy(inx.time.start,argv[9],sizeof(double)*inx.num);
      memcpy(inx.time.end,argv[10],sizeof(double)*inx.num);
      memcpy(inx.offset,argv[11],sizeof(int32)*inx.num);
      inx.st_time=inx.time.start[0];
      inx.ed_time=inx.time.end[inx.num-1];
    }
  }


  if (inx.num !=0) s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,(int) sc,&inx,atme);
  else s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,(int) sc,NULL,atme);

  if (inx.num !=0) {
    free(inx.offset);
    free(inx.time.start);
    free(inx.time.end);
  }

  return s;
}
Пример #10
0
static IDL_VPTR IDLOldCnvMapSeek(int argc,IDL_VPTR *argv,char *argk) {

  struct OldCnvMapIDLInx *ifptr;

  int s=0,n;
  struct RfileIndex *finx=NULL;
  static IDL_VPTR vatme;
  double atme=0;

  int outargc=0;
  IDL_VPTR outargv[8];
  static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN,
			       {"ATME",IDL_TYP_UNDEF,1,
                                IDL_KW_OUT | IDL_KW_ZERO,0,
                                IDL_CHARA(vatme)},
				 {NULL}};


  IDL_LONG unit=0,yr=0,mo=0,dy=0,hr=0,mt=0,sc=0;
  IDL_FILE_STAT stat;

  FILE *fp=NULL;

  IDL_KWCleanup(IDL_KW_MARK);
  outargc=IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1);


  IDL_ENSURE_SCALAR(outargv[0]);
  IDL_ENSURE_SCALAR(outargv[1]);
  IDL_ENSURE_SCALAR(outargv[2]);
  IDL_ENSURE_SCALAR(outargv[3]);
  IDL_ENSURE_SCALAR(outargv[4]);
  IDL_ENSURE_SCALAR(outargv[5]);
  IDL_ENSURE_SCALAR(outargv[6]);

  if (outargc>7) IDL_ENSURE_ARRAY(outargv[7]);

  unit=IDL_LongScalar(outargv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  yr=IDL_LongScalar(outargv[1]);
  mo=IDL_LongScalar(outargv[2]);
  dy=IDL_LongScalar(outargv[3]);
  hr=IDL_LongScalar(outargv[4]);
  mt=IDL_LongScalar(outargv[5]);
  sc=IDL_LongScalar(outargv[6]);

  /* test for existence of index */

  if (outargc>7) {
    /* decode index here */
    finx=malloc(sizeof(struct RfileIndex));
    if (finx==NULL) {
      s=-1;
      return (IDL_GettmpLong(s));
    }
    finx->num=outargv[7]->value.s.arr->n_elts;
    finx->time.start=malloc(sizeof(double)*finx->num);
    if (finx->time.start==NULL) {
      s=-1;
      free(finx);
      return (IDL_GettmpLong(s));
    } 
    finx->time.end=malloc(sizeof(double)*finx->num);
    if (finx->time.end==NULL) {
      s=-1;
      free(finx->time.start);
      free(finx);
      return (IDL_GettmpLong(s));
    } 

    finx->offset=malloc(sizeof(int)*finx->num);
    if (finx->offset==NULL) {
      s=-1;
      free(finx->time.start);
      free(finx->time.end);
      free(finx);
      return (IDL_GettmpLong(s));
    } 
    for (n=0;n<finx->num;n++) {
      ifptr=(struct OldCnvMapIDLInx *) (outargv[7]->value.s.arr->data+
                                    n*outargv[7]->value.s.arr->elt_len);
      finx->time.start[n]=ifptr->st_time;
      finx->time.end[n]=ifptr->ed_time;
      finx->offset[n]=ifptr->offset;
    }
    finx->st_time=finx->time.start[0];
    finx->ed_time=finx->time.end[finx->num-1];

  }


  s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,sc,finx,&atme);

  if (vatme) IDL_StoreScalar(vatme,IDL_TYP_DOUBLE,(IDL_ALLTYPES *) &atme);
 
  if (finx !=NULL) {
    free(finx->time.start);
    free(finx->time.end);
    free(finx->offset);
    free(finx);
  }
   
  IDL_KWCleanup(IDL_KW_CLEAN);
  return (IDL_GettmpLong(s));


}
Пример #11
0
static IDL_VPTR IDLOldCnvMapRead(int argc,IDL_VPTR *argv) {

  int s=0;


  IDL_VPTR vprm=NULL,vstvec=NULL,vgvec=NULL,vmvec=NULL,vcoef=NULL,vbnd=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;


  struct CnvMapData *map=NULL;
  struct GridData *grd=NULL;

  struct CnvMapIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
  struct GridIDLGVec *imvec=NULL;
  struct CnvMapIDLBnd *ibnd=NULL;
  double *icoef=NULL; 

  IDL_MEMINT cdim[2];

  FILE *fp=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[4]);
  IDL_EXCLUDE_EXPR(argv[5]);
  IDL_EXCLUDE_EXPR(argv[6]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 

  map=CnvMapMake(); 
  grd=GridMake();

  s=OldCnvMapFread(fp,map,grd);

  if (s==-1) {
    CnvMapFree(map);
    GridFree(grd);
    return (IDL_GettmpLong(s));
  }

  iprm=IDLMakeCnvMapPrm(&vprm);
  if (grd->stnum !=0) istvec=IDLMakeGridStVec(grd->stnum,&vstvec);
  if (grd->vcnum !=0) igvec=IDLMakeGridGVec(grd->vcnum,&vgvec);
  if (map->num_model !=0) imvec=IDLMakeGridGVec(map->num_model,&vmvec);
  if (map->num_bnd !=0) ibnd=IDLMakeCnvMapBnd(map->num_bnd,&vbnd);
  if (map->num_coef !=0) {
    int n=0;
    cdim[1]=4;
    cdim[0]=map->num_coef;
    icoef=(double *) 
      IDL_MakeTempArray(IDL_TYP_DOUBLE,2,cdim,IDL_ARR_INI_ZERO,&vcoef);
   
      for (n=0;n<map->num_coef;n++) {
       icoef[n]=map->coef[4*n];
       icoef[map->num_coef+n]=map->coef[4*n+1];
       icoef[2*map->num_coef+n]=map->coef[4*n+2];
       icoef[3*map->num_coef+n]=map->coef[4*n+3];
      }

  }

  /* copy the data here */
   
  IDLCopyCnvMapPrmToIDL(map,grd,iprm);
  if (istvec !=NULL) IDLCopyGridStVecToIDL(grd,grd->stnum,
                                    vstvec->value.s.arr->elt_len,istvec);
  if (igvec !=NULL) IDLCopyGridGVecToIDL(grd,grd->vcnum,
                                    vgvec->value.s.arr->elt_len,igvec);
  if (imvec !=NULL) IDLCopyCnvMapGVecToIDL(map,map->num_model,
                                           vmvec->value.s.arr->elt_len,imvec);
  if (ibnd !=NULL) IDLCopyCnvMapBndToIDL(map,map->num_bnd,
                                         vbnd->value.s.arr->elt_len,ibnd);

  CnvMapFree(map);
  GridFree(grd);

  IDL_VarCopy(vprm,argv[1]);  
  if (vstvec !=NULL) IDL_VarCopy(vstvec,argv[2]);
  if (vgvec !=NULL) IDL_VarCopy(vgvec,argv[3]);
  if (vmvec !=NULL) IDL_VarCopy(vmvec,argv[4]);
  if (vcoef !=NULL) IDL_VarCopy(vcoef,argv[5]);
  if (vbnd !=NULL) IDL_VarCopy(vbnd,argv[6]);


  return (IDL_GettmpLong(s));

}
Пример #12
0
int32 OldRawIDLRead(int argc,char *argv[]) {

  int n;
  int x;

  struct OldRawIDLFp *idlrawfp;
  struct OldRawFp rawfp;
  char combftmp[COMBF_SIZE+1];
  struct RadarIDLParm *idlprm;
  struct RawIDLData *idlraw;
  struct RadarParm prm;
  struct RawData raw;

  IDL_FILE_STAT stat;
  FILE *fp;
  int s;

  /* zero out the data structures */

  memset(&prm,0,sizeof(struct RadarParm));
  memset(&raw,0,sizeof(struct RawData));
  memset(&combftmp,0,COMBF_SIZE+1);
  
  idlrawfp=(struct OldRawIDLFp *) argv[0];
  
  IDL_FileStat(idlrawfp->rawunit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);
   
  rawfp.rawfp=fileno(fp);
  rawfp.inxfp=0;
 
  OldRawIDLToRawFp(idlrawfp,&rawfp);

  s=OldRawRead(&rawfp,&prm,&raw);

  OldRawRawFpToIDL(&rawfp,idlrawfp);

  if (s==-1) return -1;
   
  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  idlraw=(struct RawIDLData *) argv[2];

  /* load up the structures.
   *
   * Note: We do not do a direct memcpy as the possibility
   * exists that the IDL data structure is different from 
   * the C data structure.
   *
   */

  idlprm->revision.major=prm.revision.major;
  idlprm->revision.minor=prm.revision.minor;
  idlprm->origin.code=prm.origin.code;
  IDL_StrDelete(&idlprm->origin.time,1);
  IDL_StrDelete(&idlprm->origin.command,1);
  idlprm->cp=prm.cp;
  idlprm->stid=prm.stid;
  idlprm->time.yr=prm.time.yr;
  idlprm->time.mo=prm.time.mo;
  idlprm->time.dy=prm.time.dy;
  idlprm->time.hr=prm.time.hr;
  idlprm->time.mt=prm.time.mt;
  idlprm->time.sc=prm.time.sc;
  idlprm->time.us=prm.time.us;
  idlprm->txpow=prm.txpow;
  idlprm->nave=prm.nave;
  idlprm->atten=prm.atten;
  idlprm->lagfr=prm.lagfr;
  idlprm->smsep=prm.smsep;
  idlprm->ercod=prm.ercod;
  idlprm->stat.agc=prm.stat.agc;
  idlprm->stat.lopwr=prm.stat.lopwr;
  idlprm->noise.search=prm.noise.search;
  idlprm->noise.mean=prm.noise.mean;
  idlprm->channel=prm.channel;
  idlprm->bmnum=prm.bmnum;
  idlprm->bmazm=prm.bmazm;
  idlprm->scan=prm.scan;
  idlprm->rxrise=prm.rxrise;
  idlprm->intt.sc=prm.intt.sc;
  idlprm->intt.us=prm.intt.us;
  idlprm->txpl=prm.txpl;
  idlprm->mpinc=prm.mpinc;
  idlprm->mppul=prm.mppul;
  idlprm->mplgs=prm.mplgs;
  idlprm->nrang=prm.nrang;
  idlprm->frang=prm.frang;
  idlprm->rsep=prm.rsep;
  idlprm->xcf=prm.xcf;
  idlprm->tfreq=prm.tfreq;
  idlprm->offset=prm.offset;
  idlprm->mxpwr=prm.mxpwr;
  idlprm->lvmax=prm.lvmax;

  for (n=0;n<prm.mppul;n++) idlprm->pulse[n]=prm.pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    idlprm->lag[n]=prm.lag[n][0];
    idlprm->lag[LAG_SIZE+n]=prm.lag[n][1];
  }

  strncpy(combftmp,prm.combf,COMBF_SIZE);

  IDL_StrDelete(&idlprm->combf,1);
  IDL_StrStore(&idlprm->combf,combftmp);
  
  idlraw->revision.major=raw.revision.major;
  idlraw->revision.minor=raw.revision.minor;
  idlraw->thr=raw.thr;

  for (n=0;n<prm.nrang;n++) {
    idlraw->pwr0[n]=raw.pwr0[n];
    for (x=0;x<prm.mplgs;x++) {
      idlraw->acfd[x*MAX_RANGE+n]=raw.acfd[n][x][0];
      idlraw->acfd[LAG_SIZE*MAX_RANGE+MAX_RANGE*x+n]=raw.acfd[n][x][1];
      if (prm.xcf !=0) {
        idlraw->xcfd[x*MAX_RANGE+n]=raw.xcfd[n][x][0];
        idlraw->xcfd[LAG_SIZE*MAX_RANGE+MAX_RANGE*x+n]=raw.xcfd[n][x][1];
      }
    }
  } 
  return s;
}
Пример #13
0
static IDL_VPTR IDLOldGridWrite(int argc,IDL_VPTR *argv) {

  int s=0;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct GridData *grd=NULL;
  struct GridIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
 
  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_ARRAY(argv[2]);
  IDL_ENSURE_ARRAY(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct GridIDLPrm *) argv[1]->value.s.arr->data;
  if (argv[2]->type==IDL_TYP_STRUCT) 
     istvec=(struct GridIDLStVec *) argv[2]->value.s.arr->data;
  if (argv[3]->type==IDL_TYP_STRUCT) 
     igvec=(struct GridIDLGVec *) argv[3]->value.s.arr->data;


  grd=GridMake(); 

  IDLCopyGridPrmFromIDL(iprm,grd);
  if (istvec !=NULL)  IDLCopyGridStVecFromIDL(istvec,iprm->stnum,
                        argv[2]->value.s.arr->elt_len,grd);
  else grd->stnum=0;

  if (igvec !=NULL) IDLCopyGridGVecFromIDL(igvec,iprm->vcnum,
       argv[3]->value.s.arr->elt_len,grd);
  else grd->vcnum=0;

  s=OldGridFwrite(fp,grd);

  GridFree(grd);

  return (IDL_GettmpLong(s));


}
Пример #14
0
static IDL_VPTR IDLOldGridRead(int argc,IDL_VPTR *argv) {

  int s=0;


  IDL_VPTR vprm=NULL,vstvec=NULL,vgvec=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;


  struct GridData *grd=NULL;
  struct GridIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL; 

  FILE *fp=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);


  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);
   
  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 

  grd=GridMake(); 

  s=OldGridFread(fp,grd);

  if (s==-1) {
    GridFree(grd);
    return (IDL_GettmpLong(s));
  }

  iprm=IDLMakeGridPrm(&vprm);
  if (grd->stnum !=0) istvec=IDLMakeGridStVec(grd->stnum,&vstvec);
  if (grd->vcnum !=0) igvec=IDLMakeGridGVec(grd->vcnum,&vgvec);

  /* copy the data here */
   
  IDLCopyGridPrmToIDL(grd,iprm);
  if (istvec !=NULL) IDLCopyGridStVecToIDL(grd,grd->stnum,
                                    vstvec->value.s.arr->elt_len,istvec);
  if (igvec !=NULL) IDLCopyGridGVecToIDL(grd,grd->vcnum,
                                    vgvec->value.s.arr->elt_len,igvec);


  
  GridFree(grd);

  IDL_VarCopy(vprm,argv[1]);  
  if (vstvec !=NULL) IDL_VarCopy(vstvec,argv[2]);
  if (vgvec !=NULL) IDL_VarCopy(vgvec,argv[3]);

  return (IDL_GettmpLong(s));

}
Пример #15
0
int32 OldCnvMapIDLRead(int argc,char *argv[]) {

  int32 *idlstnum;
  int32 *idlvcnum;
  int32 *idlmodnum;
  int32 *idlcoefnum;
  int32 *idlbndnum;


  IDL_STRING *idlptr=NULL;
  struct CnvMapData map;
  struct GridData grd;

  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);
 
  /* Read in the record */

  memset(&grd,0,sizeof(struct GridData));
  memset(&map,0,sizeof(struct CnvMapData));

  s=OldCnvMapFread(fp,&map,&grd);
  if (s==-1) return -1;

  /* get the output pointers */

  idlstnum=(int32 *) argv[1];
  idlvcnum=(int32 *) argv[2];
  idlmodnum=(int32 *) argv[3];
  idlcoefnum=(int32 *) argv[4];
  idlbndnum=(int32 *) argv[5];

  idlptr=(IDL_STRING *) argv[6];
  
  IDL_StrEnsureLength(idlptr,sizeof(struct GridData)+
                      grd.stnum*sizeof(struct GridSVec)+
                      grd.vcnum*sizeof(struct GridGVec)+
                      sizeof(struct CnvMapData)+
                      map.num_model*sizeof(struct GridGVec)+
                      map.num_coef*4*sizeof(double)+ 
                      map.num_bnd*2*sizeof(double));
  memcpy(idlptr->s,&grd,sizeof(struct GridData)); 
  memcpy(idlptr->s+sizeof(struct GridData),grd.sdata,
         grd.stnum*sizeof(struct GridSVec));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec),
         grd.data,grd.vcnum*sizeof(struct GridGVec));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec)+
          grd.vcnum*sizeof(struct GridGVec),
          &map,sizeof(struct CnvMapData));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec)+
         grd.vcnum*sizeof(struct GridGVec)+sizeof(struct CnvMapData),
         map.model,map.num_model*sizeof(struct GridGVec));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec)+
         grd.vcnum*sizeof(struct GridGVec)+sizeof(struct CnvMapData)+
         map.num_model*sizeof(struct GridGVec),map.coef,
         map.num_coef*4*sizeof(double));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec)+
         grd.vcnum*sizeof(struct GridGVec)+sizeof(struct CnvMapData)+
         map.num_model*sizeof(struct GridGVec)+map.num_coef*4*sizeof(double),
         map.bnd_lat,map.num_bnd*sizeof(double));
  memcpy(idlptr->s+sizeof(struct GridData)+grd.stnum*sizeof(struct GridSVec)+
         grd.vcnum*sizeof(struct GridGVec)+sizeof(struct CnvMapData)+
         map.num_model*sizeof(struct GridGVec)+map.num_coef*4*sizeof(double)+
         map.num_bnd*sizeof(double),map.bnd_lon,map.num_bnd*sizeof(double));

  *idlstnum=grd.stnum;
  *idlvcnum=grd.vcnum;
  *idlmodnum=map.num_model;
  *idlcoefnum=map.num_coef;
  *idlbndnum=map.num_bnd;

  return s;
}
Пример #16
0
int32 OldFitIDLRead(int argc,char *argv[]) {

  int n;

  struct OldFitIDLFp *idlfitfp;
  struct OldFitFp fitfp;
  char combftmp[COMBF_SIZE+1];
  struct RadarIDLParm *idlprm;
  struct FitIDLData *idlfit;
  struct RadarParm prm;
  struct FitData fit;

  IDL_FILE_STAT stat;
  FILE *ffp=NULL,*ifp=NULL;
  int s;

  /* zero out the data structures */

  memset(&prm,0,sizeof(struct RadarParm));
  memset(&fit,0,sizeof(struct FitData));
  memset(&combftmp,0,COMBF_SIZE+1);
  
  idlfitfp=(struct OldFitIDLFp *) argv[0];
  
  IDL_FileStat(idlfitfp->fitunit,&stat);
 
  /* Find the file pointer */

  ffp=stat.fptr; 

  fflush(ffp);
  
  if (ffp==NULL) return -1;

  if (idlfitfp->inxunit !=-1) {
    IDL_FileStat(idlfitfp->inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  fitfp.fitfp=fileno(ffp);
  if (ifp !=NULL) fitfp.inxfp=fileno(ifp);
  else fitfp.inxfp=-1;
 
  

  OldFitIDLToFitFp(idlfitfp,&fitfp);

  s=OldFitRead(&fitfp,&prm,&fit);

  OldFitFitFpToIDL(&fitfp,idlfitfp);

  if (s==-1) return -1;
   
  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  idlfit=(struct FitIDLData *) argv[2];

  /* load up the structures.
   *
   * Note: We do not do a direct memcpy as the possibility
   * exists that the IDL data structure is different from 
   * the C data structure.
   *
   */

  idlprm->revision.major=prm.revision.major;
  idlprm->revision.minor=prm.revision.minor;
  idlprm->origin.code=prm.origin.code;
  IDL_StrDelete(&idlprm->origin.time,1);
  IDL_StrDelete(&idlprm->origin.command,1);
  idlprm->cp=prm.cp;
  idlprm->stid=prm.stid;
  idlprm->time.yr=prm.time.yr;
  idlprm->time.mo=prm.time.mo;
  idlprm->time.dy=prm.time.dy;
  idlprm->time.hr=prm.time.hr;
  idlprm->time.mt=prm.time.mt;
  idlprm->time.sc=prm.time.sc;
  idlprm->time.us=prm.time.us;
  idlprm->txpow=prm.txpow;
  idlprm->nave=prm.nave;
  idlprm->atten=prm.atten;
  idlprm->lagfr=prm.lagfr;
  idlprm->smsep=prm.smsep;
  idlprm->ercod=prm.ercod;
  idlprm->stat.agc=prm.stat.agc;
  idlprm->stat.lopwr=prm.stat.lopwr;
  idlprm->noise.search=prm.noise.search;
  idlprm->noise.mean=prm.noise.mean;
  idlprm->channel=prm.channel;
  idlprm->bmnum=prm.bmnum;
  idlprm->bmazm=prm.bmazm;
  idlprm->scan=prm.scan;
  idlprm->rxrise=prm.rxrise;
  idlprm->intt.sc=prm.intt.sc;
  idlprm->intt.us=prm.intt.us;
  idlprm->txpl=prm.txpl;
  idlprm->mpinc=prm.mpinc;
  idlprm->mppul=prm.mppul;
  idlprm->mplgs=prm.mplgs;
  idlprm->nrang=prm.nrang;
  idlprm->frang=prm.frang;
  idlprm->rsep=prm.rsep;
  idlprm->xcf=prm.xcf;
  idlprm->tfreq=prm.tfreq;
  idlprm->offset=prm.offset;
  idlprm->mxpwr=prm.mxpwr;
  idlprm->lvmax=prm.lvmax;

  for (n=0;n<prm.mppul;n++) idlprm->pulse[n]=prm.pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    idlprm->lag[n]=prm.lag[n][0];
    idlprm->lag[LAG_SIZE+n]=prm.lag[n][1];
  }

  strncpy(combftmp,prm.combf,COMBF_SIZE);

  IDL_StrDelete(&idlprm->combf,1);
  IDL_StrStore(&idlprm->combf,combftmp);
  
  idlfit->revision.major=fit.revision.major;
  idlfit->revision.minor=fit.revision.minor;
  idlfit->noise.sky=fit.noise.skynoise;
  idlfit->noise.lag0=fit.noise.lag0;
  idlfit->noise.vel=fit.noise.vel;
  for (n=0;n<prm.nrang;n++) {
    idlfit->pwr0[n]=fit.rng[n].p_0;
    idlfit->nlag[n]=fit.rng[n].nump;
    idlfit->qflg[n]=fit.rng[n].qflg;
    idlfit->gflg[n]=fit.rng[n].gsct;
    idlfit->p_l[n]=fit.rng[n].p_l;
    idlfit->p_l_e[n]=fit.rng[n].p_l_err;
    idlfit->p_s[n]=fit.rng[n].p_s;
    idlfit->p_s_e[n]=fit.rng[n].p_s_err;
    idlfit->v[n]=fit.rng[n].v;
    idlfit->v_e[n]=fit.rng[n].v_err;
    idlfit->w_l[n]=fit.rng[n].w_l;
    idlfit->w_l_e[n]=fit.rng[n].w_l_err;
    idlfit->w_s[n]=fit.rng[n].w_s;
    idlfit->w_s_e[n]=fit.rng[n].w_s_err;
    idlfit->sd_l[n]=fit.rng[n].sdev_l;
    idlfit->sd_s[n]=fit.rng[n].sdev_s;
    idlfit->sd_phi[n]=fit.rng[n].sdev_phi;
    if (prm.xcf !=0) {
      idlfit->elv_low[n]=fit.elv[n].low;
      idlfit->elv[n]=fit.elv[n].normal;
      idlfit->elv_high[n]=fit.elv[n].high;
      idlfit->x_qflg[n]=fit.xrng[n].qflg;
      idlfit->x_gflg[n]=fit.xrng[n].gsct;
      idlfit->x_p_l[n]=fit.xrng[n].p_l;
      idlfit->x_p_l_e[n]=fit.xrng[n].p_l_err;
      idlfit->x_p_s[n]=fit.xrng[n].p_s;
      idlfit->x_p_s_e[n]=fit.xrng[n].p_s_err;
      idlfit->x_v[n]=fit.xrng[n].v;
      idlfit->x_v_e[n]=fit.xrng[n].v_err;
      idlfit->x_w_l[n]=fit.xrng[n].w_l;
      idlfit->x_w_l_e[n]=fit.xrng[n].w_l_err;
      idlfit->x_w_s[n]=fit.xrng[n].w_s;
      idlfit->x_w_s_e[n]=fit.xrng[n].w_s_err;
      idlfit->x_sd_l[n]=fit.xrng[n].sdev_l;
      idlfit->x_sd_s[n]=fit.xrng[n].sdev_s;
      idlfit->x_sd_phi[n]=fit.xrng[n].sdev_phi;
      idlfit->phi0[n]=fit.xrng[n].phi0;
      idlfit->phi0_e[n]=fit.xrng[n].phi0_err;
    }
  }
  return s;

}
Пример #17
0
static IDL_VPTR IDLOldRawWrite(int argc,IDL_VPTR *argv) {
  int s=0;
  IDL_LONG unit=0,recnum;
  IDL_FILE_STAT stat;

  struct RadarIDLParm *iprm=NULL;
  struct RawIDLData *iraw=NULL;

  struct RadarParm *prm=NULL;
  struct RawData *raw=NULL;

  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_STRUCTURE(argv[2]);
  IDL_ENSURE_SCALAR(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);

  unit=IDL_LongScalar(argv[0]);
  recnum=IDL_LongScalar(argv[3]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }


  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);

  /* Find the file pointer */

  fp=stat.fptr;

  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct RadarIDLParm *) argv[1]->value.s.arr->data;
  iraw=(struct RawIDLData *) argv[2]->value.s.arr->data;

  prm=RadarParmMake();
  raw=RawMake();

  IDLCopyRadarParmFromIDL(iprm,prm);
  IDLCopyRawDataFromIDL(prm->nrang,prm->mplgs,prm->xcf,iraw,raw);

  s=OldRawFwrite(fp,"rawwrite",prm,raw,recnum,NULL);

  RadarParmFree(prm);
  RawFree(raw);



  return (IDL_GettmpLong(s));
}
Пример #18
0
int32 OldFitIDLWrite(int argc,char *argv[]) {

  int n;
  struct RadarIDLParm *idlprm;
  struct FitIDLData *idlfit;
  struct RadarParm prm;
  struct FitData fit;

  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  if (unit !=-1) { /* a real file */
    /* Make sure that the "STDIO" keyword was used to
     * open the file in IDL.
     */

    s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
    if (s==FALSE) return -1;

    /* Get information about the file */

    IDL_FileStat(unit,&stat);
 
    /* Find the file pointer */

    fp=stat.fptr; 
  
    if (fp==NULL) return -1;

    fflush(fp);

  } else fp=NULL; /* dummy routine */

  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  idlfit=(struct FitIDLData *) argv[2];
  
  memset(&prm,0,sizeof(struct RadarParm));
  memset(&fit,0,sizeof(struct FitData));

  /* load up the data structures */

  prm.revision.major=idlprm->revision.major;
  prm.revision.minor=idlprm->revision.minor;
  prm.cp=idlprm->cp;
  prm.stid=idlprm->stid;
  prm.time.yr=idlprm->time.yr;
  prm.time.mo=idlprm->time.mo;
  prm.time.dy=idlprm->time.dy;
  prm.time.hr=idlprm->time.hr;
  prm.time.mt=idlprm->time.mt;
  prm.time.sc=idlprm->time.sc;
  prm.time.us=idlprm->time.us;
  prm.txpow=idlprm->txpow;
  prm.nave=idlprm->nave;
  prm.atten=idlprm->atten;
  prm.lagfr=idlprm->lagfr;
  prm.smsep=idlprm->smsep;
  prm.ercod=idlprm->ercod;
  prm.stat.agc=idlprm->stat.agc;
  prm.stat.lopwr=idlprm->stat.lopwr;
  prm.noise.search=idlprm->noise.search;
  prm.noise.mean=idlprm->noise.mean;
  prm.channel=idlprm->channel;
  prm.bmnum=idlprm->bmnum;
  prm.scan=idlprm->scan;
  prm.rxrise=idlprm->rxrise;
  prm.intt.sc=idlprm->intt.sc;
  prm.intt.us=idlprm->intt.us;
  prm.txpl=idlprm->txpl;
  prm.mpinc=idlprm->mpinc;
  prm.mppul=idlprm->mppul;
  prm.mplgs=idlprm->mplgs;
  prm.nrang=idlprm->nrang;
  prm.frang=idlprm->frang;
  prm.rsep=idlprm->rsep;
  prm.xcf=idlprm->xcf;
  prm.tfreq=idlprm->tfreq;
  prm.offset=idlprm->offset;
  prm.mxpwr=idlprm->mxpwr;
  prm.lvmax=idlprm->lvmax;

  for (n=0;n<prm.mppul;n++) prm.pulse[n]=idlprm->pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    prm.lag[n][0]=idlprm->lag[n];
    prm.lag[n][1]=idlprm->lag[LAG_SIZE+n];
  }

  if (strlen(IDL_STRING_STR(&idlprm->combf)) !=0) 
    strncpy(prm.combf,IDL_STRING_STR(&idlprm->combf),COMBF_SIZE);


  fit.revision.major=idlfit->revision.major;
  fit.revision.minor=idlfit->revision.minor;
  fit.noise.skynoise=idlfit->noise.sky;
  fit.noise.lag0=idlfit->noise.lag0;
  fit.noise.vel=idlfit->noise.vel;

  for (n=0;n<prm.nrang;n++) {
    fit.rng[n].p_0=idlfit->pwr0[n];
    fit.rng[n].nump=idlfit->nlag[n];
    fit.rng[n].qflg=idlfit->qflg[n];
    fit.rng[n].gsct=idlfit->gflg[n];
    fit.rng[n].p_l=idlfit->p_l[n];
    fit.rng[n].p_l_err=idlfit->p_l_e[n];
    fit.rng[n].p_s=idlfit->p_s[n];
    fit.rng[n].p_s_err=idlfit->p_s_e[n];
    fit.rng[n].v=idlfit->v[n];
    fit.rng[n].v_err=idlfit->v_e[n];
    fit.rng[n].w_l=idlfit->w_l[n];
    fit.rng[n].w_l_err=idlfit->w_l_e[n];
    fit.rng[n].w_s=idlfit->w_s[n];
    fit.rng[n].w_s_err=idlfit->w_s_e[n];
    fit.rng[n].sdev_l=idlfit->sd_l[n];
    fit.rng[n].sdev_s=idlfit->sd_s[n];
    fit.rng[n].sdev_phi=idlfit->sd_phi[n];
    if (prm.xcf !=0) {
      fit.elv[n].low=idlfit->elv_low[n];
      fit.elv[n].normal=idlfit->elv[n];
      fit.elv[n].high=idlfit->elv_high[n];
      fit.xrng[n].qflg=idlfit->x_qflg[n];
      fit.xrng[n].gsct=idlfit->x_gflg[n];
      fit.xrng[n].p_l=idlfit->x_p_l[n];
      fit.xrng[n].p_l_err=idlfit->x_p_l_e[n];
      fit.xrng[n].p_s=idlfit->x_p_s[n];
      fit.xrng[n].p_s_err=idlfit->x_p_s_e[n];
      fit.xrng[n].v=idlfit->x_v[n];
      fit.xrng[n].v_err=idlfit->x_v_e[n];
      fit.xrng[n].w_l=idlfit->x_w_l[n];
      fit.xrng[n].w_l_err=idlfit->x_w_l_e[n];
      fit.xrng[n].w_s=idlfit->x_w_s[n];
      fit.xrng[n].w_s_err=idlfit->x_w_s_e[n];
      fit.xrng[n].sdev_l=idlfit->x_sd_l[n];
      fit.xrng[n].sdev_s=idlfit->x_sd_s[n];
      fit.xrng[n].sdev_phi=idlfit->x_sd_phi[n];
      fit.xrng[n].phi0=idlfit->phi0[n];
      fit.xrng[n].phi0_err=idlfit->phi0_e[n];
    }
  }
  
  s=OldFitFwrite(fp,&prm,&fit,NULL);
  
  return s;

}
Пример #19
0
static IDL_VPTR IDLOldRawRead(int argc,IDL_VPTR *argv) {

  int s=0;

  IDL_VPTR vprm=NULL,vraw=NULL;;

  IDL_FILE_STAT stat;

  struct OldRawIDLFp *irawfp;
  struct OldRawFp rawfp;

  struct RadarIDLParm *iprm=NULL;
  struct RawIDLData *iraw=NULL;

  struct RadarParm *prm=NULL;
  struct RawData *raw=NULL;

  FILE *ffp=NULL,*ifp=NULL;

  IDL_ENSURE_STRUCTURE(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);

  
  irawfp=(struct OldRawIDLFp *) argv[0]->value.s.arr->data;
  
  s=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  IDL_FileFlushUnit(irawfp->rawunit);
  IDL_FileStat(irawfp->rawunit,&stat);
 

  ffp=stat.fptr;
  
  if (ffp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 
  if (irawfp->inxunit !=-1) {
    IDL_FileFlushUnit(irawfp->inxunit);
    IDL_FileStat(irawfp->inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  rawfp.rawfp=fileno(ffp);
  if (ifp !=NULL) rawfp.inxfp=fileno(ifp);
  else rawfp.inxfp=-1;

  OldRawIDLToRawFp(irawfp,&rawfp);

  prm=RadarParmMake();
  raw=RawMake(); 

  s=OldRawRead(&rawfp,prm,raw);

  OldRawRawFpToIDL(&rawfp,irawfp);
 
  if (s==-1) {
    RadarParmFree(prm);
    RawFree(raw);
    return (IDL_GettmpLong(s));
  }

  iprm=IDLMakeRadarParm(&vprm);
  iraw=IDLMakeRawData(&vraw);

  /* copy data here */



  IDLCopyRadarParmToIDL(prm,iprm);
  IDLCopyRawDataToIDL(prm->nrang,prm->mplgs,prm->xcf,raw,iraw);

  RadarParmFree(prm);
  RawFree(raw);

  IDL_VarCopy(vprm,argv[1]);  
  IDL_VarCopy(vraw,argv[2]);
    
  return (IDL_GettmpLong(s));

}
Пример #20
0
int32 OldFitIDLInxClose(int argc,char *argv[]) {

  int n;
  struct RadarIDLParm *idlprm;
  struct RadarParm prm;
  int32 irec;
  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  /* get the structure pointers */

  idlprm=(struct RadarIDLParm *) argv[1];
  irec=*((int32 *) argv[2]);

  memset(&prm,0,sizeof(struct RadarParm));

  /* load up the data structures */

  prm.revision.major=idlprm->revision.major;
  prm.revision.minor=idlprm->revision.minor;
  prm.cp=idlprm->cp;
  prm.stid=idlprm->stid;
  prm.time.yr=idlprm->time.yr;
  prm.time.mo=idlprm->time.mo;
  prm.time.dy=idlprm->time.dy;
  prm.time.hr=idlprm->time.hr;
  prm.time.mt=idlprm->time.mt;
  prm.time.sc=idlprm->time.sc;
  prm.time.us=idlprm->time.us;
  prm.txpow=idlprm->txpow;
  prm.nave=idlprm->nave;
  prm.atten=idlprm->atten;
  prm.lagfr=idlprm->lagfr;
  prm.smsep=idlprm->smsep;
  prm.ercod=idlprm->ercod;
  prm.stat.agc=idlprm->stat.agc;
  prm.stat.lopwr=idlprm->stat.lopwr;
  prm.noise.search=idlprm->noise.search;
  prm.noise.mean=idlprm->noise.mean;
  prm.channel=idlprm->channel;
  prm.bmnum=idlprm->bmnum;
  prm.scan=idlprm->scan;
  prm.rxrise=idlprm->rxrise;
  prm.intt.sc=idlprm->intt.sc;
  prm.intt.us=idlprm->intt.us;
  prm.txpl=idlprm->txpl;
  prm.mpinc=idlprm->mpinc;
  prm.mppul=idlprm->mppul;
  prm.mplgs=idlprm->mplgs;
  prm.nrang=idlprm->nrang;
  prm.frang=idlprm->frang;
  prm.rsep=idlprm->rsep;
  prm.xcf=idlprm->xcf;
  prm.tfreq=idlprm->tfreq;
  prm.offset=idlprm->offset;
  prm.mxpwr=idlprm->mxpwr;
  prm.lvmax=idlprm->lvmax;

  for (n=0;n<prm.mppul;n++) prm.pulse[n]=idlprm->pulse[n];
  for (n=0;n<prm.mplgs;n++) {
    prm.lag[n][0]=idlprm->lag[n];
    prm.lag[n][1]=idlprm->lag[LAG_SIZE+n];
  }

  if (strlen(IDL_STRING_STR(&idlprm->combf)) !=0) 
    strncpy(prm.combf,IDL_STRING_STR(&idlprm->combf),COMBF_SIZE);

 
  s=OldFitInxFclose(fp,&prm,irec);
  
  return s;

}
Пример #21
0
static IDL_VPTR IDLOldRawSeek(int argc,IDL_VPTR *argv,char *argk) {

  IDL_FILE_STAT stat;
  struct OldRawIDLFp *irawfp;
  struct OldRawFp rawfp;
  int s=0;
  static IDL_VPTR vatme;
  double atme=0;

  IDL_VPTR outargv[8];
  static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN,
			       {"ATME",IDL_TYP_UNDEF,1,
                                IDL_KW_OUT | IDL_KW_ZERO,0,
                                IDL_CHARA(vatme)},
				 {NULL}};


  IDL_LONG yr=0,mo=0,dy=0,hr=0,mt=0,sc=0;
  FILE *ffp=NULL,*ifp=NULL;

  IDL_KWCleanup(IDL_KW_MARK);
  IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1);

  IDL_ENSURE_STRUCTURE(outargv[0]);
  IDL_ENSURE_SCALAR(outargv[1]);
  IDL_ENSURE_SCALAR(outargv[2]);
  IDL_ENSURE_SCALAR(outargv[3]);
  IDL_ENSURE_SCALAR(outargv[4]);
  IDL_ENSURE_SCALAR(outargv[5]);
  IDL_ENSURE_SCALAR(outargv[6]);

  yr=IDL_LongScalar(outargv[1]);
  mo=IDL_LongScalar(outargv[2]);
  dy=IDL_LongScalar(outargv[3]);
  hr=IDL_LongScalar(outargv[4]);
  mt=IDL_LongScalar(outargv[5]);
  sc=IDL_LongScalar(outargv[6]);

  irawfp=(struct OldRawIDLFp *) outargv[0]->value.s.arr->data;
  
  s=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  IDL_FileFlushUnit(irawfp->rawunit);
  IDL_FileStat(irawfp->rawunit,&stat);
 

  ffp=stat.fptr;
  
  if (ffp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 
  if (irawfp->inxunit !=-1) {
    IDL_FileFlushUnit(irawfp->inxunit);
    IDL_FileStat(irawfp->inxunit,&stat);
    ifp=stat.fptr;
  }

  if (ifp !=NULL) fflush(ifp);

  rawfp.rawfp=fileno(ffp);
  if (ifp !=NULL) rawfp.inxfp=fileno(ifp);
  else rawfp.inxfp=-1;

  OldRawIDLToRawFp(irawfp,&rawfp);

  s=OldRawSeek(&rawfp,yr,mo,dy,hr,mt,sc,&atme);

  OldRawRawFpToIDL(&rawfp,irawfp);


  if (vatme) IDL_StoreScalar(vatme,IDL_TYP_DOUBLE,(IDL_ALLTYPES *) &atme);
 
  IDL_KWCleanup(IDL_KW_CLEAN);
  return (IDL_GettmpLong(s));
}
Пример #22
0
static IDL_VPTR IDLOldCnvMapLoadInx(int argc,IDL_VPTR *argv) {

  int s=0,n;

  IDL_VPTR vinx=NULL;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  FILE *fp=NULL;

  struct OldCnvMapIDLInx *ifptr=NULL;
  struct RfileIndex *finx=NULL;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_EXCLUDE_EXPR(argv[1]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }
 
  finx=RfileLoadIndex(fp);

  if (finx==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  ifptr=IDLMakeOldCnvMapInx(finx->num,&vinx);
  
  for (n=0;n<finx->num;n++) {
    ifptr[n].st_time=finx->time.start[n];
    ifptr[n].ed_time=finx->time.end[n];
    ifptr[n].offset=finx->offset[n];
  }
  
  free(finx->time.start);
  free(finx->time.end);
  free(finx->offset);
  free(finx);

  IDL_VarCopy(vinx,argv[1]); 
   
  return (IDL_GettmpLong(s));
}
Пример #23
0
static IDL_VPTR IDLOldRawOpen(int argc,IDL_VPTR *argv) {

  IDL_VPTR vrawfp;  
  struct OldRawIDLFp *irawfp;
  struct OldRawFp *rawfp;
  void *s;
  int st;

  static IDL_MEMINT hdim[]={1,80};
  static IDL_MEMINT ddim[]={1,32};
  static IDL_MEMINT edim[]={1,256};

  static IDL_STRUCT_TAG_DEF trawfp[]={
    {"RAWUNIT",0,(void *) IDL_TYP_LONG},
    {"INXUNIT",0,(void *) IDL_TYP_LONG},
    {"RAW_RECL",0,(void *) IDL_TYP_LONG},
    {"INX_RECL",0,(void *) IDL_TYP_LONG},
    {"BLEN",0,(void *) IDL_TYP_LONG},
    {"INX_SREC",0,(void *) IDL_TYP_LONG},
    {"INX_EREC",0,(void *) IDL_TYP_LONG},
    {"CTIME",0,(void *) IDL_TYP_DOUBLE},
    {"STIME",0,(void *) IDL_TYP_DOUBLE},
    {"ETIME",0,(void *) IDL_TYP_DOUBLE},
    {"TIME",0,(void *) IDL_TYP_LONG},
    {"HEADER",hdim,(void *) IDL_TYP_BYTE},
    {"DATE",ddim,(void *) IDL_TYP_BYTE},
    {"EXTRA",edim,(void *) IDL_TYP_BYTE},
    {"MAJOR_REV",0,(void *) IDL_TYP_BYTE},
    {"MINOR_REV",0,(void *) IDL_TYP_BYTE},
    {"RAWREAD",0,(void *) IDL_TYP_LONG},
    {"BNUM",0,(void *) IDL_TYP_LONG},
    0};

  static IDL_MEMINT ilDims[IDL_MAX_ARRAY_DIM];

  IDL_VARIABLE unit;
  IDL_VPTR fargv[2];
  IDL_FILE_STAT stat;


  int ffd=-1,ifd=-1;

  IDL_ENSURE_STRING(argv[0]);
  if (argc>1) IDL_ENSURE_STRING(argv[1]);
  
  s=IDL_MakeStruct("RAWFP",trawfp);
  ilDims[0]=1;
  irawfp=(struct OldRawIDLFp *) IDL_MakeTempStruct(s,1,ilDims,&vrawfp,TRUE);

  unit.type=IDL_TYP_LONG;
  unit.flags=0;

  fargv[0]=&unit;
  fargv[1]=argv[0];

  IDL_FileGetUnit(1,fargv);
  IDL_FileOpen(2,fargv,NULL,IDL_OPEN_R,IDL_F_STDIO,1,0);
  irawfp->rawunit=IDL_LongScalar(&unit);
  irawfp->inxunit=-1;

  st=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);

  if (st==FALSE) {
    st=0;
    IDL_Deltmp(vrawfp);
    return (IDL_GettmpLong(st));
  }
  
  if (argc>1) {
    fargv[1]=argv[1];
    IDL_FileGetUnit(1,fargv);
    IDL_FileOpen(2,fargv,NULL,IDL_OPEN_R,IDL_F_STDIO,1,0);
    irawfp->inxunit=IDL_LongScalar(&unit); 
    st=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER);
    if (st==FALSE) { /* free unit for index but continue */
      IDL_FileFreeUnit(1,argv);
      irawfp->inxunit=-1;
    }
  }
 

  IDL_FileStat(irawfp->rawunit,&stat);
  ffd=fileno(stat.fptr);

  if (irawfp->inxunit !=-1) {
    IDL_FileStat(irawfp->inxunit,&stat);
    ifd=fileno(stat.fptr);
  }

  rawfp=OldRawOpenFd(ffd,ifd);
  OldRawRawFpToIDL(rawfp,irawfp);

  free(rawfp);
  
  return vrawfp;
}
Пример #24
0
static IDL_VPTR IDLOldCnvMapWrite(int argc,IDL_VPTR *argv) {

  int s=0;

  IDL_LONG unit=0;
  IDL_FILE_STAT stat;

  struct CnvMapData *map=NULL;
  struct GridData *grd=NULL;

  struct CnvMapIDLPrm *iprm=NULL;
  struct GridIDLStVec *istvec=NULL;
  struct GridIDLGVec *igvec=NULL;
  struct GridIDLGVec *imvec=NULL;
  struct CnvMapIDLBnd *ibnd=NULL;
  double *icoef=NULL; 

  FILE *fp;

  IDL_ENSURE_SCALAR(argv[0]);
  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_ENSURE_ARRAY(argv[2]);
  IDL_ENSURE_ARRAY(argv[3]);
  IDL_EXCLUDE_EXPR(argv[1]);
  IDL_EXCLUDE_EXPR(argv[2]);
  IDL_EXCLUDE_EXPR(argv[3]);

  unit=IDL_LongScalar(argv[0]);

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER);

  if (s==FALSE) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  /* Get information about the file */

  IDL_FileFlushUnit(unit);
  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr;
  
  if (fp==NULL) {
    s=-1;
    return (IDL_GettmpLong(s));
  }

  iprm=(struct CnvMapIDLPrm *) argv[1]->value.s.arr->data;
  if (argv[2]->type==IDL_TYP_STRUCT) 
     istvec=(struct GridIDLStVec *) argv[2]->value.s.arr->data;
  if (argv[3]->type==IDL_TYP_STRUCT) 
     igvec=(struct GridIDLGVec *) argv[3]->value.s.arr->data;
  if (argv[4]->type==IDL_TYP_STRUCT)
     imvec=(struct GridIDLGVec *) argv[4]->value.s.arr->data;
  if (argv[5]->type==IDL_TYP_DOUBLE) 
     icoef=(double *) argv[5]->value.s.arr->data;
  if (argv[6]->type==IDL_TYP_STRUCT) 
     ibnd=(struct CnvMapIDLBnd *) argv[6]->value.s.arr->data;

  map=CnvMapMake(); 
  grd=GridMake();

  IDLCopyCnvMapPrmFromIDL(iprm,map,grd);
  if (istvec !=NULL)  IDLCopyGridStVecFromIDL(istvec,iprm->stnum,
                        argv[2]->value.s.arr->elt_len,grd);
  else grd->stnum=0;

  if (igvec !=NULL) IDLCopyGridGVecFromIDL(igvec,iprm->vcnum,
       argv[3]->value.s.arr->elt_len,grd);
  else grd->vcnum=0;

  if (imvec !=NULL) IDLCopyCnvMapGVecFromIDL(imvec,
                        iprm->modnum,argv[4]->value.s.arr->elt_len,map);
  else map->num_model=0;

  if (ibnd !=NULL) IDLCopyCnvMapBndFromIDL(ibnd,
                        iprm->bndnum,argv[6]->value.s.arr->elt_len,map);
  else map->num_bnd=0;

  if (icoef !=NULL) {
    int n=0;
    map->coef=malloc(sizeof(double)*map->num_coef*4);
    for (n=0;n<map->num_coef;n++) {
      map->coef[4*n]=icoef[n];
      map->coef[4*n+1]= icoef[map->num_coef+n];
      map->coef[4*n+2]=icoef[2*map->num_coef+n];
      map->coef[4*n+3]=icoef[3*map->num_coef+n];
    }
  } else map->num_coef=0;


  s=OldCnvMapFwrite(fp,map,grd);

  CnvMapFree(map);
  GridFree(grd);

  return (IDL_GettmpLong(s));


}
Пример #25
0
int32 OldCnvMapIDLWrite(int argc,char *argv[]) {

  int n;
  struct CnvMapIDLPrm *prm;
  struct GridIDLStVec *stvec;
  struct GridIDLGVec *gvec;
  struct GridIDLGVec *mvec;
  double *coef;
  struct CnvMapIDLBnd *bnd;
  struct GridData grd;
  struct CnvMapData map;

  IDL_FILE_STAT stat;
  FILE *fp;
  int unit; 
  int s;

  unit = *( (int32 *) argv[0]);

  /* Make sure that the "STDIO" keyword was used to
   * open the file in IDL.
   */

  s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO);
  if (s==FALSE) return -1;

  /* Get information about the file */

  IDL_FileStat(unit,&stat);
 
  /* Find the file pointer */

  fp=stat.fptr; 
  
  if (fp==NULL) return -1;

  fflush(fp);

  /* get the structure pointers */

  prm=(struct CnvMapIDLPrm *) argv[1];
  stvec=(struct GridIDLStVec *) argv[2];
  gvec=(struct GridIDLGVec *) argv[3];
  mvec=(struct GridIDLGVec *) argv[4];
  coef=(double *) argv[5];
  bnd=(struct CnvMapIDLBnd *) argv[6];


  memset(&grd,0,sizeof(struct GridData));
  memset(&map,0,sizeof(struct CnvMapData));

  /* load up the data structures */

  grd.st_time=TimeYMDHMSToEpoch(prm->start.yr,prm->start.mo,prm->start.dy,
                                prm->start.hr,prm->start.mt,prm->start.sc);
  grd.ed_time=TimeYMDHMSToEpoch(prm->end.yr,prm->end.mo,prm->end.dy,
                                prm->end.hr,prm->end.mt,prm->end.sc);

  grd.stnum=prm->stnum;
  grd.vcnum=prm->vcnum;
  grd.xtd=prm->xtd;

  map.num_model=prm->modnum;
  map.num_coef=prm->coefnum;
  map.num_bnd=prm->bndnum;

  grd.sdata=malloc(sizeof(struct GridSVec)*grd.stnum);
  if (grd.sdata==NULL) return -1;
  if (grd.vcnum !=0) {
    grd.data=malloc(sizeof(struct GridGVec)*grd.vcnum);
    if (grd.data==NULL) {
      free(grd.sdata);
      return -1;
    }
  } 

  if (map.num_model !=0) {
    map.model=malloc(sizeof(struct GridGVec)*map.num_model);
    if (map.model==NULL) {
      if (grd.data !=NULL) free(grd.data);
      free(grd.sdata);
      return -1;
    }
  } 

  if (map.num_coef !=0) {
    map.coef=malloc(sizeof(double)*4*map.num_coef);
    if (map.coef==NULL) {
      if (map.model !=NULL) free(map.model);
      if (grd.data !=NULL) free(grd.data);
      free(grd.sdata);
      return -1;
    }
  } 

  if (map.num_bnd !=0) {
    map.bnd_lat=malloc(sizeof(double)*map.num_bnd);
    if (map.bnd_lat==NULL) {
      if (map.coef !=NULL) free(map.coef);
      if (map.model !=NULL) free(map.model);
      if (grd.data !=NULL) free(grd.data);
      free(grd.sdata);
      return -1;
    }
  } 

  if (map.num_bnd !=0) {
    map.bnd_lon=malloc(sizeof(double)*map.num_bnd);
    if (map.bnd_lon==NULL) {
      if (map.bnd_lat !=NULL) free(map.bnd_lat);
      if (map.coef !=NULL) free(map.coef);
      if (map.model !=NULL) free(map.model);
      if (grd.data !=NULL) free(grd.data);
      free(grd.sdata);
      return -1;
    }
  } 

  map.st_time=grd.st_time;
  map.ed_time=grd.ed_time;
  map.major_rev=prm->major_rev;
  map.minor_rev=prm->minor_rev;

  if (prm->source.slen !=0) {
    n=prm->source.slen;
    if (n>256) n=256;
    strncpy(map.source,prm->source.s,n);
  }

  map.num_model=prm->modnum;
  map.doping_level=prm->doping_level;
  map.model_wt=prm->model_wt;
  map.error_wt=prm->error_wt;
  map.imf_flag=prm->imf_flag;
  map.imf_delay=prm->imf_delay;
  map.Bx=prm->Bx;
  map.By=prm->By;
  map.Bz=prm->Bz;
  
  if (prm->model[0].slen !=0) {
    n=prm->model[0].slen;
    if (n>64) n=64;
    strncpy(map.imf_model[0],prm->model[0].s,n);
  }

  if (prm->model[1].slen !=0) {
    n=prm->model[1].slen;
    if (n>64) n=64;
    strncpy(map.imf_model[1],prm->model[1].s,n);
  }

  map.hemisphere=prm->hemisphere;
  map.fit_order=prm->fit_order;
  map.latmin=prm->latmin;
  map.num_coef=prm->coefnum;
  map.chi_sqr=prm->chi_sqr;
  map.chi_sqr_dat=prm->chi_sqr_dat;
  map.rms_err=prm->rms_err;
  map.lon_shft=prm->lon_shft;
  map.lat_shft=prm->lat_shft;
  map.mlt.start=prm->mlt.st;
  map.mlt.end=prm->mlt.ed;
  map.mlt.av=prm->mlt.av;
  map.pot_drop=prm->pot_drop;
  map.pot_drop_err=prm->pot_drop_err;
  map.pot_max=prm->pot_max;
  map.pot_max_err=prm->pot_max_err;
  map.pot_min=prm->pot_min;
  map.pot_min_err=prm->pot_min_err;
  map.num_bnd=prm->bndnum;

  for (n=0;n<grd.stnum;n++) {
    grd.sdata[n].st_id=stvec[n].stid;
    grd.sdata[n].chn=stvec[n].chn;
    grd.sdata[n].npnt=stvec[n].npnt;
    grd.sdata[n].freq0=stvec[n].freq;
    grd.sdata[n].major_revision=stvec[n].major_revision;
    grd.sdata[n].minor_revision=stvec[n].minor_revision;
    grd.sdata[n].prog_id=stvec[n].prog_id;
    grd.sdata[n].gsct=stvec[n].gsct;
    grd.sdata[n].noise.mean=stvec[n].noise.mean;
    grd.sdata[n].noise.sd=stvec[n].noise.sd;
    grd.sdata[n].vel.min=stvec[n].vel.min;
    grd.sdata[n].vel.max=stvec[n].vel.max;
    grd.sdata[n].pwr.min=stvec[n].pwr.min;
    grd.sdata[n].pwr.max=stvec[n].pwr.max;
    grd.sdata[n].wdt.min=stvec[n].wdt.min;
    grd.sdata[n].wdt.max=stvec[n].wdt.max;
    grd.sdata[n].verr.min=stvec[n].verr.min;
    grd.sdata[n].verr.max=stvec[n].verr.max;
  }

  for (n=0;n<grd.vcnum;n++) {
     grd.data[n].st_id=gvec[n].stid;
     grd.data[n].chn=gvec[n].chn;
     grd.data[n].index=gvec[n].index;
     grd.data[n].mlat=gvec[n].mlat;
     grd.data[n].mlon=gvec[n].mlon;
     grd.data[n].azm=gvec[n].azm;
     grd.data[n].vel.median=gvec[n].vel.median;
     grd.data[n].vel.sd=gvec[n].vel.sd;
     if (grd.xtd !=0) {
       grd.data[n].pwr.median=gvec[n].pwr.median;
       grd.data[n].pwr.sd=gvec[n].pwr.sd;
       grd.data[n].wdt.median=gvec[n].wdt.median;
       grd.data[n].wdt.sd=gvec[n].wdt.sd;
     }
  }

  for (n=0;n<map.num_model;n++) {
    map.model[n].mlat=mvec[n].mlat;
    map.model[n].mlon=mvec[n].mlon;
    map.model[n].azm=mvec[n].azm;
    map.model[n].vel.median=mvec[n].vel.median;
  } 

  for (n=0;n<map.num_coef;n++) {
     map.coef[4*n]=coef[n];
     map.coef[4*n+1]=coef[map.num_coef+n];
     map.coef[4*n+2]=coef[2*map.num_coef+n];
     map.coef[4*n+3]=coef[3*map.num_coef+n];
  }
 

  for (n=0;n<map.num_bnd;n++) {
    map.bnd_lat[n]=bnd[n].lat;
    map.bnd_lon[n]=bnd[n].lon;
  } 


  s=OldCnvMapFwrite(fp,&map,&grd);
  

  free(grd.sdata);
  if (grd.data !=NULL) free(grd.data);
  if (map.model !=NULL) free(map.model);
  if (map.coef !=NULL) free(map.coef);
  if (map.bnd_lat !=NULL) free(map.bnd_lat);
  if (map.bnd_lon !=NULL) free(map.bnd_lon);



  return s;

}