コード例 #1
0
ファイル: interfile.c プロジェクト: jbpoline/compile_ecat2ana
/** Verify that given file is a valid Interfile header file.
\return Returns 0 if not, and 1 if it is a valid header file. If image data
    filename is requested and found in header, then 2 is returned.
 */
int interfileIsHeader(
    /** Interfile header filename, with correct extension */
    const char *hdrfile,
    /** Pointer to allocated string where Interfile image data filename is
     *  written if found in header; enter NULL if not needed. */
    char *imgfile
) {
    char /*key[256], value[256],*/ temp[FILENAME_MAX];
    IFT ift;
    int li, ret;

    //printf("\ninterfileIsHeader(%s, *imgfile)\n", hdrfile);
    if(hdrfile==NULL || strlen(hdrfile)<1) return 0;
    if(imgfile!=NULL) strcpy(imgfile, "");
    iftInit(&ift);
    strcpy(temp, hdrfile);
    ret=iftRead(&ift, temp, 0);
    if(ret!=0 || ift.keyNr<2) {
        iftEmpty(&ift);
        return(0);
    }
    /* Check that file starts with !INTERFILE */
    //iftWriteItem(&ift, 0, stdout);
    if(ift.item[0].type!='!') {
        iftEmpty(&ift);
        return(0);
    }
    if(strcasecmp(ift.item[0].value, "INTERFILE")!=0) {
        iftEmpty(&ift);
        return(0);
    }
    /* If imgfile was not requested, then we are done */
    if(imgfile==NULL) {
        iftEmpty(&ift);
        return(1);
    }
    /* Find filename for image data */
    //iftWriteItem(&ift, 1, stdout);
    li=iftGetFrom(&ift, 1, "name of data file");
    if(li<0 || strlen(ift.item[li].value)<1) {
        iftEmpty(&ift);
        return(1);
    }
    strcpy(imgfile, ift.item[li].value);
    iftEmpty(&ift);
    return(2);
}
コード例 #2
0
ファイル: vol.c プロジェクト: phoboz/volkit
/** Read Volume Range Definition File.
\return Returns 0 if successful.
 */
int vrdRead(
  /** Volume Range Definition File filename, which contains image volume corners
   *  (x y z) in IFT format: corner1 = x y z corner2 = x y z */
  char *vrdfile,
  /** Image volume range */
  VOL_RANGE *vol_range,
  /** Pointer to a string (allocated for at least 64 chars) where error message
      or other execution status will be written; enter NULL, if not needed */     
  char *status
) {
  int ret, ii, x, y, z;
  IFT ift;
  char key[256];

  /* Check that input is ok */
  if(vrdfile==NULL || strlen(vrdfile)<1 || vol_range==NULL) {
    if(status!=NULL) strcpy(status, "program error");
    return 1;
  }
  /* Read VDF as IFT file */
  iftInit(&ift); ret=iftRead(&ift, vrdfile, 1); if(ret) {
    if(status!=NULL) strcpy(status, ift.status);
    iftEmpty(&ift); return 2;
  }
  /* Try to find keys 'corner1' and 'corner2' */
  strcpy(key, "corner1"); ii=iftGet(&ift, key);
  if(ii>=0) {
    ret=string_to_xyz(ift.item[ii].value, &x, &y, &z);
    if(ret==0) {
      vol_range->x1=x; vol_range->y1=y; vol_range->z1=z;
      strcpy(key, "corner2"); ii=iftGet(&ift, key);
      if(ii>=0) {
        ret=string_to_xyz(ift.item[ii].value, &x, &y, &z);
        vol_range->x2=x; vol_range->y2=y; vol_range->z2=z;
        if(ret==0) {
          vrdReorder(vol_range);
          if(status!=NULL) strcpy(status, "ok");
          iftEmpty(&ift); return 0;
        }
      }
    }
  }
  /* We are here only if keys were not found */
  /* Lets not care about keys at all */
  for(ii=0, ret=0; ii<ift.keyNr; ii++) {
    if(ret==0 && string_to_xyz(ift.item[ii].value, &x, &y, &z)==0)
    {
      vol_range->x1=x; vol_range->y1=y; vol_range->z1=z;
      ret++; continue;
    }
    if(ret==1 && string_to_xyz(ift.item[ii].value, &x, &y, &z)==0)
    {
      vol_range->x2=x; vol_range->y2=y; vol_range->z2=z;
      ret++; break;
    }
  }
  if(ret<2) {
    if(status!=NULL) strcpy(status, "volume definitions not found");
    iftEmpty(&ift); return 2;
  }

  vrdReorder(vol_range);
  if(status!=NULL) strcpy(status, "ok");
  iftEmpty(&ift);
  return 0;
}