# $Id: CDFginfo,v 1.20 1994/08/29 22:06:34 mintha Exp mintha $ # # Given a cdf file structure get all the global attributes # and all the variable names, dims, and attributes # # $Log: CDFginfo,v $ # Revision 1.20 1994/08/29 22:06:34 mintha # Added patch for CDF type SHORT # # Revision 1.19 1994/07/21 23:01:01 mintha # Refixed /tmp thing # # Revision 1.18 1994/05/12 23:06:12 mintha # Fix by phil # # Revision 1.17 1994/04/21 10:37:39 mintha # Couple more cleanups # # Revision 1.16 1994/04/21 10:34:15 mintha # Now using a proper temp file to transfer information from C->Splus # as well as cleanups. # # Revision 1.15 1994/04/19 10:39:00 mintha # Pass attribute data by directly writing an Splus file to get around # bug in Splus. Various heuristics to get a unique name, pass it and # use it w/'C' # # Revision 1.14 1994/04/18 16:08:03 phil # this is Jim's new version, with rcsid moved into function body # # Revision 1.11 1994/04/18 15:11:51 mintha # save Jim's changes # # Revision 1.10 1993/12/03 17:21:07 mintha # Refixed integer attributes, allow variable length attributes # (i.e. 2 int values for one attribute) # # Revision 1.9 1993/12/03 16:41:10 mintha # Typo # # Revision 1.8 1993/12/03 16:40:01 mintha # Fixes to pointers for integer values. # # Revision 1.7 1993/12/03 16:37:48 mintha # Added integer type to attribute get # # Revision 1.6 1993/08/26 19:20:50 mintha # Changed dimnames component to dnames to be consistent # # Revision 1.5 1993/08/20 08:22:02 mintha # Make unlimited dimension a dim_id (i.e. don't subtract 1) # # Revision 1.4 1993/08/20 07:38:00 mintha # Syntax error # # Revision 1.3 1993/08/20 07:33:12 mintha # Return unlimited dimension in global structure # # Revision 1.2 1993/08/20 07:28:37 mintha # Changes to cdf_attr_info to speed up getting dim labels. Done in # C now, returning the proper dim id if attribute ends in .lab # # Revision 1.1 1993/08/10 23:29:12 mintha # Initial revision # "CDFginfo"<- function(cdfp) { version_"$Id: CDFginfo,v 1.20 1994/08/29 22:06:34 mintha Exp mintha $" ginfo <- vector("list",5) names(ginfo) <- c("ncid", "numvars", "dims", "dnames", "dimlabs") ginfo$ncid <- cdfp$ncid ginfo$numvars <- cdfp$nvars ginfo$dims <- numeric(cdfp$ndims) ginfo$dnames <- character(cdfp$ndims) ginfo$dimlabs <- character(cdfp$ndims) ginfo$unlimdim <- cdfp$unlimd # # Get dim stuff # for(ctr in seq(to = cdfp$ndims)){ dim <- .C("cdf_dim_info", as.integer(cdfp$ncid), as.integer(ctr-1), name = character(0), size = integer(1), pointers = c(F,F,T,F)) ginfo$dnames[ctr] <- dim$name ginfo$dims[ctr] <- dim$size } # # Get global attributes # if(cdfp$ngatts != 0){ tmpfile <- unix("echo cdftmp.$$") for(ctr in seq(to = cdfp$ngatts)){ attr <- .C("cdf_attr_info2", as.integer(cdfp$ncid), as.integer(-1), as.integer(ctr-1), dimid = integer(1), as.character(tmpfile), name = character(0), pointers = c(F,F,F,F,F,T)) synchronize() temp <- get(name=tmpfile,where="/tmp") # phil's fix # attach("/tmp", pos = 2) # temp <- get(name = tmpfile, where = 2) # remove(list = tmpfile, where = 2) # detach(what = 2) if(attr$dimid != -1){ ginfo$dimlabs[attr$dimid+1] <- temp } else{ temp2 <- integer(1) names(temp2) <- attr$name ginfo <- append(ginfo, temp2) ginfo[[attr$name]] <- temp } } remove(list=tmpfile,where="/tmp") } ginfo }