diff --git a/php/classes/FilesMgr.php b/php/classes/FilesMgr.php index 624b5a6..1f1d756 100644 --- a/php/classes/FilesMgr.php +++ b/php/classes/FilesMgr.php @@ -217,7 +217,7 @@ class FilesMgr extends AmdaObjectMgr { exec('ncvarinfo '.$this->fileName.' '.$this->param2dd($varId), $results); $tempArr = explode(' ', $results[0]); - // data type + // data type switch ($tempArr[0]) { case "5": $data_type = 'FLOAT'; break; @@ -241,7 +241,15 @@ class FilesMgr extends AmdaObjectMgr $size = 1; } - return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs); + $units = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' UNITS'); + if (substr($units, 0,5) == 'error') $units = ''; + + $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' _Fillvalue'); // _Fillvalue + if (substr($fillval, 0,5) == 'error') $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' Fillvalue'); + if (substr($fillval, 0,5) == 'error') $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' Fillval'); + if (substr($fillval, 0,5) == 'error') $fillval = ''; + + return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs, 'units' => $units, 'fillvalue' => $fillval); } protected function param2dd($paramID) diff --git a/php/src/Makefile b/php/src/Makefile index 80a303e..9d1ac0b 100644 --- a/php/src/Makefile +++ b/php/src/Makefile @@ -4,7 +4,7 @@ CFLAGS = -ggdb -DLINUX -m64 -march=core2 -fPIC -Dlinux -D_REENTRANT -malign-doub CC = gcc EXE = nctimestring2double nctimeinfo getncvars ncvarinfo \ - ncinfo_remote \ + ncinfo_remote ncvar_attr \ cdfinfo cdfvarinfo cdfstartstopfromdata cdfsamplingfromdata cdfvar_attr \ AddVI @@ -14,8 +14,11 @@ AddVI: AddVI.c ${CC} ${CFLAGS} -o AddVI AddVI.c ${INC} ${LIB} -lDDClientLibC ncinfo_remote: ncinfo_remote.c - ${CC} ${CFLAGS} -o ncinfo_remote ncinfo_remote.c ${INC} ${LIB} -lnetcdf - + ${CC} ${CFLAGS} -o ncinfo_remote ncinfo_remote.c ${INC} ${LIB} -lnetcdf + +ncvar_attr: ncvar_attr.c + ${CC} ${CFLAGS} -o ncvar_attr ncvar_attr.c ${INC} ${LIB} -lnetcdf + nctimestring2double: nctimestring2double.c ${CC} ${CFLAGS} -o nctimestring2double nctimestring2double.c ${INC} ${LIB} -lDDClientLibC -lnetcdf diff --git a/php/src/ncvar_attr.c b/php/src/ncvar_attr.c new file mode 100644 index 0000000..e041a0e --- /dev/null +++ b/php/src/ncvar_attr.c @@ -0,0 +1,75 @@ +/* + * get parameter info from nc file + * args : ncfile varId infoId + * infoId : + * UNITS + * FILLVALUE + */ + +#include +#include +#include +#include + +void check(int stat) +{ + if (stat != NC_NOERR) + { + printf("error: %s\n", nc_strerror(stat)); + exit(1); + } +} + +main(int argc, char **argv) +{ + int ncID, varID; + size_t i, k; +// char varname[NC_MAX_NAME]; + int stat = 0; + nc_type xtype; + char name_in[NC_MAX_NAME]; + float number_attr; + int nattsp; + + if (argc <= 3) { + printf("Incorrect number of arguments\n"); + exit(1); + } + + check(nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID)); + + check(nc_inq_varid(ncID, argv[2], &varID)); + check(nc_inq_varnatts(ncID, varID, &nattsp)); + // fprintf(stdout, "%d\n", nattsp); + + for (i = 0; i < nattsp; i++) { + check(nc_inq_attname(ncID, varID, i, name_in)); + + if (strcasecmp(name_in, argv[3]) == 0) { + + check(nc_inq_atttype(ncID, varID, name_in, &xtype)); + + if (xtype == NC_CHAR) { + size_t attlen = 0; + check(nc_inq_attlen(ncID, varID, name_in, &attlen)); + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); + + check(nc_get_att(ncID, varID, name_in, string_attr)); + fprintf(stdout, "%s\n", string_attr); + free(string_attr); + } + else { + check(nc_get_att(ncID, varID, name_in, &number_attr)); + fprintf(stdout, "%e\n", number_attr); + } + + exit(0); + } + } + + stat = nc_close(ncID); + fprintf(stdout, "undefined\n"); + exit(0); +} + + -- libgit2 0.21.2