Exemplo n.º 1
0
static int OpenShotIdFile(char *experiment,int mode)
{
  int fd=-1;
  char *ctx = 0;
  char *filename;
  int found = 0;
  while ((filename = GetFileName(experiment,&ctx)) && !(found=(MDS_IO_EXISTS(filename))));
  if (found)
    fd = MDS_IO_OPEN(filename,mode,0);
  else if (mode == O_WRONLY)
    fd = CreateShotIdFile(experiment);
  return fd;
}
Exemplo n.º 2
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;
}