예제 #1
0
static char *GetFileName(char *experiment,char **ctx)
{
  char *ans = 0;
  static char pathname[1024];
  static char *path;
  int fd = -1;
  char *semi = 0;
  char *part;
  if (*ctx == NULL)
  {
    if (path != NULL)
      TranslateLogicalFree(path);
    strcpy(pathname,experiment);
    strcat(pathname,"_path");
    path = (char *)TranslateLogical(pathname);
    part = path;
  }
  else if (*ctx == pathname)
    return NULL;
  else
    part = *ctx;
  if (part != NULL)
  {
    char *delim = TREE_PATH_DELIM;
    char *tmp;
    if ((semi = (char *)index(part, ';')) != 0)
      *semi = '\0';
    strncpy(pathname,part,500);
    if (semi == 0) 
      *ctx = pathname;
    else
      *ctx = part + strlen(part) + 1;
    tmp = MaskReplace(pathname,experiment,0);
    strcpy(pathname,tmp);
    free(tmp);
    if (pathname[strlen(pathname)-1] == '+')
    {
      int i;
      for (i=strlen(pathname)-1;(i >= 0) && (pathname[i] != delim[0]);i--);
      if (i >= 0)
        pathname[i+1] = 0;
    }
    else
    {
      if (pathname[strlen(pathname)-1] != delim[0])
        strcat(pathname,TREE_PATH_DELIM);
    }
    strcat(pathname,"shotid.sys");
    ans = pathname;
  }
  return ans;
}
예제 #2
0
int       TreeGetCurrentShotId(char *experiment)
{
  int shot = 0;
  int status = 0;
  char *path = 0;
  char *exp = strcpy(malloc(strlen(experiment)+6),experiment);
  int i;
  int slen;
  for (i=0;exp[i] != '\0';i++)
    exp[i] = _ToLower(exp[i]);
  strcat(exp,"_path");
  path = TranslateLogical(exp);
  exp[strlen(experiment)]='\0';
  if (path && ((slen = strlen(path)) > 2) && (path[slen-1] == ':') && (path[slen-2] == ':'))
  {
    path[slen-2] = 0;
    status = TreeGetCurrentShotIdRemote(exp, path, &shot);
  }
  else
  {
    int fd = OpenShotIdFile(exp,O_RDONLY);
    if (fd != -1)
    {
      status = MDS_IO_READ(fd,&shot,sizeof(shot)) == sizeof(shot);
      MDS_IO_CLOSE(fd);
#ifdef WORDS_BIGENDIAN
      if (status & 1)
      {
        int lshot = shot;
        int i;
        char *optr = (char *)&shot;
        char *iptr = (char *)&lshot;
        for (i=0;i<4;i++) optr[i] = iptr[3-i];
      }
#endif
    }
  }
  if (path)
    TranslateLogicalFree(path);
  free(exp);
  return (status & 1) ? shot : 0;
}
예제 #3
0
int  TreeCreateTreeFiles(char *tree, int shot, int source_shot)
{
  size_t len = strlen(tree);
  char tree_lower[13];
  char pathname[32];
  char *path;
  char *pathin;
  size_t pathlen;
  char name[32];
  size_t i;
  int status = 1;
  int itype;
  char *types[] = {".tree",".characteristics",".datafile"};
  for (i=0;i<len && i < 12;i++)
    tree_lower[i] = tolower(tree[i]);
  tree_lower[i]=0;
  strcpy(pathname,tree_lower);
  strcat(pathname,TREE_PATH_SUFFIX);
#if defined(__VMS)
  pathin = strcpy(malloc(strlen(pathname)+1,pathname);
#else
  pathin = TranslateLogical(pathname);
#endif
  if (pathin)
  {
    pathlen = strlen(pathin);
    for (itype=0;itype<3 && (status & 1);itype++)
    {
      char *srcfile = 0;
      char *dstfile = 0;
      char *type = types[itype];
      char *part;
      path = MaskReplace(pathin,tree_lower,source_shot);
      pathlen = strlen(path);
      if (source_shot > 999)
        sprintf(name,"%s_%d",tree_lower,source_shot);
      else if (source_shot > 0)
        sprintf(name,"%s_%03d",tree_lower,source_shot);
      else if (source_shot == -1)
        sprintf(name,"%s_model",tree_lower);
      else
        return TreeINVSHOT;
      for (i=0,part=path;i<pathlen+1;i++)
      {
        if (*part == ' ') 
          part++;
        else if ((path[i] == ';' || path[i] == 0) && strlen(part))
        {
	      path[i] = 0;
          srcfile = strcpy(malloc(strlen(part)+strlen(name)+strlen(type)+2),part);
          if (srcfile[strlen(srcfile)-1] == '+')
	  {
            srcfile[strlen(srcfile)-1] = '\0';
          }
          else
	  {
	    if (strcmp(srcfile+strlen(srcfile)-1,TREE_PATH_DELIM))
	        strcat(srcfile,TREE_PATH_DELIM);
	    strcat(srcfile,name);
          }
	  strcat(srcfile,type);
          if (MDS_IO_EXISTS(srcfile))
            break;
          else
		  {
            free(srcfile);
            srcfile = 0;
	        part = &path[i+1];
          }
        }
      }
      free(path);
      if (srcfile)
      {
        path = MaskReplace(pathin,tree_lower,shot);
        pathlen = strlen(path);
        if (shot > 999)
          sprintf(name,"%s_%d",tree_lower,shot);
        else if (shot > 0)
          sprintf(name,"%s_%03d",tree_lower,shot);
        else if (shot == -1)
          sprintf(name,"%s_model",tree_lower);
        else
          return TreeINVSHOT;

        for (i=0,part=path;i<pathlen+1;i++)
        {
          if (*part == ' ') 
			  part++;
          else if ((path[i] == ';' || path[i] == 0) && strlen(part))
          {
	    path[i] = 0;
	    dstfile = strcpy(malloc(strlen(part)+strlen(name)+strlen(type)+2),part);
            if (dstfile[strlen(dstfile)-1] == '+')
	    {
              char *delim = TREE_PATH_DELIM;
              int j = (int)(strlen(dstfile) - 1);
              dstfile[j] = '\0';
              for (j--;j >= 0 && dstfile[j] != delim[0]; j--);
              if (j >= 0)
	      {
                dstfile[j] = 0;
                if (MDS_IO_EXISTS(dstfile))
		{
                  dstfile[j] = delim[0];
                  strcat(dstfile,type);
                  break;
                }
              }
            }
            else
	    {
	      if (strcmp(dstfile+strlen(dstfile)-1,TREE_PATH_DELIM) == 0)
                *(dstfile+strlen(dstfile)-1) = 0;
              if (MDS_IO_EXISTS(dstfile))
              {
                strcat(dstfile,TREE_PATH_DELIM);
                strcat(dstfile,name);
                strcat(dstfile,type);
                break;
              }
            }
            free(dstfile);
            dstfile = 0;
            part = &path[i+1];
          }
        }
        free(path);
        if (dstfile)
        {
          status = _CopyFile(srcfile,dstfile,itype != 0);
          free(dstfile);
        }
        else
          status = TreeINVPATH;
        free(srcfile);
      }
      else
        status = TreeTREENF;
    }
    TranslateLogicalFree(pathin);
  }
  else
    status = TreeINVPATH;
  return status;
}