# $Id: CDFginfo,v 1.10 1993/12/03 17:21:07 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.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.good"<- function(cdfp) { 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 # for(ctr in seq(to = cdfp$ngatts)){ cat("Getting attr\n") attr <- .C("cdf_attr_info", as.integer(cdfp$ncid), as.integer(-1), as.integer(ctr-1), type = integer(1), dimid = integer(1), name = character(0), cval = character(0), lval = integer(0), fval = single(0), dval = double(0), pointers = c(F,F,F,F,F,T,T,T,T,T)) new_type <- attr$type new_name <- attr$name new_dimid <- attr$dimid cat("Attribute Type: ", new_type, "\n") if(new_type == 2) temp <- attr$cval if(new_type == 4) temp <- attr$lval if(new_type == 5) temp <- attr$fval if(new_type == 6) temp <- attr$dval attr <- 1 # This is code to check to dim labels (.lab) this is extremely slow # in splus so the C routine does it now, and if attribute ends in .lab # then it returns the dimid it refers to. # clen <- nchar(new_name) # if(substring(new_name, clen-3, clen) == ".lab"){ # num <- 1 # num <- match(substring(new_name, 1, nchar(new_name)-4), # ginfo$dnames, nomatch=-1) # if(num != -1) ginfo$dimlabs[num] <- temp # else cat("Mismatches dim label\n") # } if(new_dimid != -1){ ginfo$dimlabs[new_dimid+1] <- temp } else{ temp2 <- integer(1) names(temp2) <- new_name ginfo <- append(ginfo, temp2) ginfo[[new_name]] <- temp } } ginfo }