Class: NumRu::NetCDFAtt
- Inherits:
-
Object
- Object
- NumRu::NetCDFAtt
- Defined in:
- lib/numru/netcdf.rb,
ext/numru/netcdfraw.c
Instance Method Summary collapse
- #==(Attb) ⇒ Object
- #atttype ⇒ Object
-
#clone ⇒ Object
The methods of the NetCDFAtt class.
- #copy(Var_or_File) ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
- #inspect ⇒ Object
- #name ⇒ Object
- #name=(new_att_name) ⇒ Object
- #put(val, atttype = nil) ⇒ Object
-
#putraw ⇒ Object
atttype: nil or a String (“string”,“int”,etc).
- #typecode ⇒ Object
Instance Method Details
#==(Attb) ⇒ Object
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 |
# File 'ext/numru/netcdfraw.c', line 2048 VALUE NetCDF_att_eql(VALUE Atta,VALUE Attb) { struct NetCDFAtt *Netcdf_atta; struct NetCDFAtt *Netcdf_attb; if( rb_obj_is_kind_of(Attb, cNetCDFAtt) ){ Data_Get_Struct(Atta,struct NetCDFAtt,Netcdf_atta); Data_Get_Struct(Attb,struct NetCDFAtt,Netcdf_attb); if(Netcdf_atta->ncid == Netcdf_atta->ncid && Netcdf_atta->varid == Netcdf_attb->varid && strcmp(Netcdf_atta->name,Netcdf_attb->name)==0){ return Qtrue; } else { return Qfalse; } } else { return Qfalse; } } |
#atttype ⇒ Object
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
# File 'ext/numru/netcdfraw.c', line 1616 VALUE NetCDF_att_atttype(VALUE Att) { int ncid; int varid; int status; char *att_name; const char *Attname; struct NetCDFAtt *Netcdf_att; nc_type xtypep; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; att_name = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,att_name,&xtypep); if(status != NC_NOERR) NC_RAISE(status); Attname = nctype2natype(xtypep); return(rb_str_new2(Attname)); } |
#clone ⇒ Object
The methods of the NetCDFAtt class
537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'ext/numru/netcdfraw.c', line 537 VALUE NetCDF_att_clone(VALUE att) { VALUE clone; struct NetCDFAtt *na1, *na2; Data_Get_Struct(att, struct NetCDFAtt, na1); na2 = NetCDF_att_init(na1->ncid, na1->varid, na1->name); clone = Data_Wrap_Struct(cNetCDFAtt, 0, Netcdf_att_free, na2); CLONESETUP(clone, att); return clone; } |
#copy(Var_or_File) ⇒ Object
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 |
# File 'ext/numru/netcdfraw.c', line 1580 VALUE NetCDF_att_copy(VALUE Att,VALUE Var_or_File) { int ncid_in,ncid_out; int status; int varid_in,varid_out; char *att_name; struct NetCDFAtt *Netcdf_att; struct NetCDFVar *Netcdf_var; struct Netcdf *ncfile; struct NetCDFAtt *Netcdf_att_out; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid_in=Netcdf_att->ncid; varid_in=Netcdf_att->varid; att_name=Netcdf_att->name; if( rb_obj_is_kind_of(Var_or_File, cNetCDFVar) ){ Data_Get_Struct(Var_or_File,struct NetCDFVar, Netcdf_var); ncid_out=Netcdf_var->ncid; varid_out=Netcdf_var->varid; } else if ( rb_obj_is_kind_of(Var_or_File, cNetCDF) ){ Data_Get_Struct(Var_or_File,struct Netcdf, ncfile); ncid_out=ncfile->ncid; varid_out=NC_GLOBAL; } else { rb_raise(rb_eNetcdfError,"The argument must be a NetCDFVar or a NetCDF"); } status = nc_copy_att(ncid_in,varid_in,att_name,ncid_out,varid_out); if(status != NC_NOERR) NC_RAISE(status); Netcdf_att_out = NetCDF_att_init(ncid_out,varid_out,att_name); return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att_out)); } |
#delete ⇒ Object
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 |
# File 'ext/numru/netcdfraw.c', line 1660 VALUE NetCDF_att_delete(VALUE Att) { int ncid; int status; int varid; char *c_att_name; struct NetCDFAtt *Netcdf_att; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid=Netcdf_att->ncid; varid=Netcdf_att->varid; c_att_name=Netcdf_att->name; status = nc_del_att(ncid,varid,c_att_name); if(status != NC_NOERR) NC_RAISE(status); return Qnil; } |
#get ⇒ Object
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 |
# File 'ext/numru/netcdfraw.c', line 1697 VALUE NetCDF_att_get(VALUE Att) { int ncid; int varid; char *c_attname; int status; struct NetCDFAtt *Netcdf_att; nc_type xtypep; size_t lenp; na_shape_t attlen[1]; /* NArray uses int instead of size_t */ char *tp; unsigned char *up; short *sp; int *ip; float *fp; double *dp; VALUE NArray; VALUE str; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; c_attname = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,c_attname,&xtypep); if(status != NC_NOERR) NC_RAISE(status); switch(xtypep){ case NC_CHAR: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); tp = ALLOCA_N(char,lenp+1); tp[lenp]= '\0'; status = nc_get_att_text(ncid,varid,c_attname,tp); if(status != NC_NOERR) NC_RAISE(status); str = rb_str_new2(tp); OBJ_TAINT(str); return(str); break; case NC_BYTE: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cbyte_to_NArray(NArray,1,attlen,up); status = nc_get_att_uchar(ncid,varid,c_attname,up); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_SHORT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Csint_to_NArray(NArray,1,attlen,sp); status = nc_get_att_short(ncid,varid,c_attname,sp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_INT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Clint_to_NArray(NArray,1,attlen,ip); status = nc_get_att_int(ncid,varid,c_attname,ip); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_FLOAT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cfloat_to_NArray(NArray,1,attlen,fp); status = nc_get_att_float(ncid,varid,c_attname,fp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_DOUBLE: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cdouble_to_NArray(NArray,1,attlen,dp); status = nc_get_att_double(ncid,varid,c_attname,dp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; default: rb_raise(rb_eNetcdfError,"atttype isn't supported in netCDF"); } return Qnil; } |
#inspect ⇒ Object
791 792 793 |
# File 'lib/numru/netcdf.rb', line 791 def inspect 'NetCDFAtt:'+name end |
#name ⇒ Object
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 |
# File 'ext/numru/netcdfraw.c', line 1287 VALUE NetCDF_att_inq_name(VALUE Att) { char *c_att_name; struct NetCDFAtt *Netcdf_att; VALUE str; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); c_att_name=Netcdf_att->name; str = rb_str_new2(c_att_name); OBJ_TAINT(str); return(str); } |
#name=(new_att_name) ⇒ Object
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
# File 'ext/numru/netcdfraw.c', line 1302 VALUE NetCDF_att_rename(VALUE Att,VALUE new_att_name) { int ncid; int status; int varid; char *c_att_name; char *c_new_att_name; struct NetCDFAtt *Netcdf_att; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid=Netcdf_att->ncid; varid=Netcdf_att->varid; c_att_name=Netcdf_att->name; Check_Type(new_att_name,T_STRING); SafeStringValue(new_att_name); c_new_att_name=StringValueCStr(new_att_name); status = nc_rename_att(ncid,varid,c_att_name,c_new_att_name); if(status != NC_NOERR) NC_RAISE(status); strcpy(Netcdf_att->name,c_new_att_name); return Qnil; } |
#put(val, atttype = nil) ⇒ Object
787 788 789 |
# File 'lib/numru/netcdf.rb', line 787 def put(val,atttype=nil) putraw(val,atttype) end |
#putraw ⇒ Object
atttype: nil or a String (“string”,“int”,etc). If nil,
the type of attribute is determined from the type of value
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 |
# File 'ext/numru/netcdfraw.c', line 1682 VALUE NetCDF_att_put(VALUE Att,VALUE value,VALUE atttype) /* * atttype: nil or a String ("string","int",etc). If nil, * the type of attribute is determined from the type of value */ { struct NetCDFAtt *ncatt; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,ncatt); return( NetCDF_put_att__(ncatt->ncid, ncatt->name, value, atttype, ncatt->varid) ); } |
#typecode ⇒ Object
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 |
# File 'ext/numru/netcdfraw.c', line 1639 VALUE NetCDF_att_typecode(VALUE Att) { int ncid; int varid; int status; char *att_name; struct NetCDFAtt *Netcdf_att; nc_type xtypep; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; att_name = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,att_name,&xtypep); if(status != NC_NOERR) NC_RAISE(status); return(INT2NUM(nctype2natypecode(xtypep))); } |