Class NumRu::HE5SwField
In: lib/hdfeos5.rb
Parent: Object
HE5Za HE5Gd HE5 HE5ZaField HE5GdField HE5Pt HE5SwField HE5Sw HE5PtField lib/hdfeos5.rb NumRu dot/m_0_0.png

HE5SwField クラスに関して

Methods

[]   []=   __rubber_expansion   att_names   attr   create   dim   dim_names   dim_val   each_att   get   get_att   get_with_miss   inspect   name=   natts   ndims   ntype   open   put   put_att   put_with_miss   rank   shape   shape_current   shape_ul0   simple_get   simple_put   typecode  

Constants

MissValAtts = ["MissingValue","_FillValue"]

Public Class methods

[Source]

     # File lib/hdfeos5.rb, line 343
343:        def create(file, sname,fldname)
344:          if(file.is_a?(String))
345:            swid = HE5Sw.create(file,sname)
346:          elsif(!file.is_a?(HE5))
347:            raise TypeError,
348:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
349:          end
350:          file.var(fldname)
351:        end

[Source]

     # File lib/hdfeos5.rb, line 353
353:        def open(file, sname, fldname)
354:          if(file.is_a?(String))
355:            swid = HE5Sw.open(file, sname)
356:          elsif(!file.is_a?(HE5))
357:            raise TypeError,
358:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
359:          end
360:          swid.var(fldname)
361:        end

Public Instance methods

[Source]

     # File lib/hdfeos5.rb, line 665
665:     def [](*a)
666:       if a.length == 0
667:         return self.get
668:       end
669:       a = __rubber_expansion(a)
670:       first = Array.new
671:       last = Array.new
672:       stride = Array.new
673:       set_stride = false
674:       a.each{|i|
675:       if(i.is_a?(Fixnum))
676:         first.push(i)
677:         last.push(i)
678:         stride.push(1)
679:       elsif(i.is_a?(Range))
680:         first.push(i.first)
681:         last.push(i.exclude_end? ? i.last-1 : i.last)
682:         stride.push(1)
683:       elsif(i.is_a?(Hash))
684:         r = (i.to_a[0])[0]
685:         s = (i.to_a[0])[1]
686:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
687:             raise TypeError, "Hash argument must be {a_Range, step}"
688:         end
689:         first.push(r.first) 
690:         last.push(r.exclude_end? ? r.last-1 : r.last)
691:         stride.push(s)
692:         set_stride = true
693:       elsif(i.is_a?(TrueClass))
694:         first.push(0)
695:         last.push(-1)
696:         stride.push(1)
697:       elsif( i.is_a?(Array) || i.is_a?(NArray))
698:         a_new = a.dup
699:         at = a.index(i)
700:         i = NArray.to_na(i) if i.is_a?(Array)
701:         for n in 0..i.length-1
702:           a_new[at] = i[n]..i[n]
703:           na_tmp = self[*a_new]
704:           if n==0 then
705:             k = at
706:             if at > 0
707:               a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
708:             end
709:             shape_tmp = na_tmp.shape
710:             shape_tmp[k] = i.length
711:             na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
712:             index_tmp = Array.new(shape_tmp.length,true)
713:           end
714:           index_tmp[k] = n..n
715:           na[*index_tmp] = na_tmp
716:         end
717:         return na
718:       else
719:          raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
720:       end
721:       }
722: 
723:       if(set_stride)
724:         na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
725:       else
726:         na = self.get({"start"=>first, "end"=>last})
727:       end
728:       shape = na.shape
729:       (a.length-1).downto(0){ |i|
730:          shape.delete_at(i) if a[i].is_a?(Fixnum)
731:       }
732:       na.reshape!( *shape )
733:       na
734:     end

[Source]

     # File lib/hdfeos5.rb, line 736
736:     def []=(*a)
737:       val = a.pop
738:       a = __rubber_expansion(a)
739:       first = Array.new
740:       last = Array.new
741:       stride = Array.new
742:       set_stride = false
743:       a.each{|i|
744:       if(i.is_a?(Fixnum))
745:         first.push(i)
746:         last.push(i)
747:         stride.push(1)
748:       elsif(i.is_a?(Range))
749:         first.push(i.first)
750:         last.push(i.exclude_end? ? i.last-1 : i.last)
751:         stride.push(1)
752:       elsif(i.is_a?(Hash))
753:         r = (i.to_a[0])[0]
754:         s = (i.to_a[0])[1]
755:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
756:             raise ArgumentError, "Hash argument must be {first..last, step}"
757:         end
758:         first.push(r.first) 
759:         last.push(r.exclude_end? ? r.last-1 : r.last)
760:         stride.push(s)
761:         set_stride = true
762:       elsif(i.is_a?(TrueClass))
763:         first.push(0)
764:         last.push(-1)
765:         stride.push(1)
766:       elsif(i.is_a?(Array) || i.is_a?(NArray))
767:         a_new = a.dup
768:         at = a.index(i)
769:         i = NArray.to_na(i) if i.is_a?(Array)
770:         val = NArray.to_na(val) if val.is_a?(Array)
771:         rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length
772:         if val.rank != rank_of_subset
773:            raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
774:                  "of the subset specified by #{a.inspect} (#{rank_of_subset})"
775:         end
776:         k = at
777:         a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
778:         if i.length != val.shape[k]
779:            raise "length of the #{k+1}-th dim of rhs is incorrect "+
780:                  "(#{i.length} for #{val.shape[k]})"
781:         end
782:         index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
783:         for n in 0..i.length-1
784:           a_new[at] = i[n]..i[n]
785:           if !val.is_a?(Numeric) then
786:             index_tmp[k] = n..n
787:             self[*a_new] = val[*index_tmp]
788:           else
789:             self[*a_new] = val
790:           end
791:         end
792:         first.push(val.first)
793:         last.push(val.last)
794:         return self
795:       else
796:         raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
797:       end
798:       }
799:       if(set_stride)
800:         self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
801:       else
802:         self.put(val, {"start"=>first, "end"=>last})
803:       end
804:     end

[Source]

     # File lib/hdfeos5.rb, line 425
425:     def att_names
426:       nattrs, attrnames, strbufsize = inqlocattrs()
427:       return attrnames.split(/,/)
428:     end

[Source]

     # File lib/hdfeos5.rb, line 449
449:     def attr
450:       @attr
451:     end

[Source]

     # File lib/hdfeos5.rb, line 393
393:     def dim(dimid)
394:       rank, dims, ntype, dimlist = fieldinfo()
395:       return dimlist.split(",")[dimid]
396:     end

[Source]

     # File lib/hdfeos5.rb, line 403
403:     def dim_names
404:       rank, dims, ntype, dimlist = fieldinfo()
405:       return dimlist.split(",").reverse
406:     end

[Source]

     # File lib/hdfeos5.rb, line 398
398:     def dim_val(dimid)
399:       rank, dims, ntype, dimlist = fieldinfo()
400:       return dimlist.split(",")[dimid]
401:     end

[Source]

     # File lib/hdfeos5.rb, line 430
430:     def each_att
431:       attlist=Array.new
432:       attnames=att_names()
433:       attnum = natts()
434:       attnames.each{|attname|
435:         list=Array.new
436:         attrval=att(attname)
437:         list.push(attname, attrval)
438:         attlist.push(list)
439:       }
440:       attlist
441:     end
get(*args)

Alias for get_with_miss

[Source]

     # File lib/hdfeos5.rb, line 417
417:     def get_att(attname)
418:       if att_names.include?(attname)
419:         get_att_(attname)
420:       else
421:         nil
422:       end
423:     end

[Source]

     # File lib/hdfeos5.rb, line 632
632:     def get_with_miss(*args)
633:       na = simple_get(*args)
634:       mv = nil
635:       MissValAtts.each do |nm|
636:         mv = get_att(nm)
637:         break if !mv.nil?
638:       end
639:       if mv.nil?
640:         na
641:       else
642:         NArrayMiss.to_nam_no_dup( na, (na.ne(mv[0])) )
643:       end
644:     end

[Source]

     # File lib/hdfeos5.rb, line 806
806:     def inspect
807:       'HE5SwField:'+swath.file.path+'?var='+name
808:     end

[Source]

     # File lib/hdfeos5.rb, line 408
408:     def name=
409:       raise "name= not supported"
410:     end

[Source]

     # File lib/hdfeos5.rb, line 412
412:     def natts
413:       nattrs, attrname, strbufsize = inqlocattrs()
414:       return nattrs
415:     end

[Source]

     # File lib/hdfeos5.rb, line 387
387:     def ndims
388:       rank, dims, ntype, dimlist = fieldinfo()
389:       return rank
390:     end

[Source]

     # File lib/hdfeos5.rb, line 364
364:     def ntype
365:       rank, dims, ntype, dimlist = fieldinfo()
366:       return ntype
367:     end
put(data, *args)

Alias for put_with_miss

[Source]

     # File lib/hdfeos5.rb, line 443
443:     def put_att(name,value,atttype=nil)
444:        count = Array.new
445:        count[0] = value.size
446:        writelocattr(name,atttype,count,value)
447:     end

[Source]

     # File lib/hdfeos5.rb, line 538
538:     def put_with_miss(data, *args)
539:       if data.is_a?( NArrayMiss )
540:         simple_put(data.to_na, *args)
541:       else
542:         simple_put(data, *args)
543:       end
544:     end
rank()

Alias for ndims

[Source]

     # File lib/hdfeos5.rb, line 370
370:     def shape
371:       rank, dims, ntype, dimlist = fieldinfo()
372:       return dims[-1..0].to_a   # NArray --> reverced --> Array
373:     end
shape_current()

Alias for shape

[Source]

     # File lib/hdfeos5.rb, line 377
377:     def shape_ul0
378:       sh = shape_current
379:       dim_names.each_with_index do |dnm,i|
380:         if dnm == "Unlim"
381:           sh[i] = 0
382:         end
383:       end
384:       sh
385:     end

[Source]

     # File lib/hdfeos5.rb, line 547
547:     def simple_get(hash=nil)
548:       if hash == nil
549:         if self.ntype == "char" || self.ntype=="byte"
550:           get_vars_char([0,0,0,0,0,0,0,0], nil, nil)
551:         elsif self.ntype=="sint"
552:           get_vars_short([0,0,0,0,0,0,0,0], nil, nil)
553:         elsif self.ntype=="int"
554:           get_vars_int([0,0,0,0,0,0,0,0], nil, nil)
555:         elsif self.ntype=="sfloat"
556:           get_vars_float([0,0,0,0,0,0,0,0], nil, nil)
557:         elsif self.ntype=="float"
558:           get_vars_double([0,0,0,0,0,0,0,0], nil, nil)
559:         else
560:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
561:         end
562:       elsif hash.key?("index")==true ||  hash.key?("start")==true
563:         h_sta = hash["start"]
564:         endq = hash.key?("end")
565:         strq = hash.key?("stride")
566:         if endq == false && strq == false
567:           if self.ntype == "char" || self.ntype=="byte"
568:             get_vars_char(h_sta, nil, nil)
569:           elsif self.ntype=="sint"
570:             get_vars_short(h_sta, nil, nil)
571:           elsif self.ntype=="int"
572:             get_vars_int(h_sta, nil, nil)
573:           elsif self.ntype=="sfloat"
574:             get_vars_float(h_sta, nil, nil)
575:           elsif self.ntype=="float"
576:             get_vars_double(h_sta, nil, nil)
577:           else
578:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
579:           end
580:         elsif endq == true && strq == false
581:           h_end = hash["end"]
582:           if self.ntype == "char" || self.ntype=="byte"
583:             get_vars_char(h_sta, nil, h_end)
584:           elsif self.ntype=="sint"
585:             get_vars_short(h_sta, nil, h_end)
586:           elsif self.ntype=="int"
587:             get_vars_int(h_sta, nil, h_end)
588:           elsif self.ntype=="sfloat"
589:             get_vars_float(h_sta, nil, h_end)
590:           elsif self.ntype=="float"
591:             get_vars_double(h_sta, nil, h_end)
592:           else
593:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
594:           end
595:         elsif endq == false && strq == true
596:           h_str = hash["stride"]
597:           if self.ntype == "char" || self.ntype=="byte"
598:             get_vars_char(h_sta, h_str, nil)
599:           elsif self.ntype=="sint"
600:             get_vars_short(h_sta, h_str, nil)
601:           elsif self.ntype=="int"
602:             get_vars_int(h_sta, h_str, nil)
603:           elsif self.ntype=="sfloat"
604:             get_vars_float(h_sta, h_str, nil)
605:           elsif self.ntype=="float"
606:             get_vars_double(h_sta, h_str, nil)
607:           else
608:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
609:           end
610:         else endq == true && strq == true
611:           h_end = hash["end"]
612:           h_str = hash["stride"]
613:           if self.ntype == "char" || self.ntype=="byte"
614:             get_vars_char(h_sta, h_str, h_end)
615:           elsif self.ntype=="sint"
616:             get_vars_short(h_sta, h_str, h_end)
617:           elsif self.ntype=="int"
618:             get_vars_int(h_sta, h_str, h_end)
619:           elsif self.ntype=="sfloat"
620:             get_vars_float(h_sta, h_str, h_end)
621:           elsif self.ntype=="float"
622:             get_vars_double(h_sta, h_str, h_end)
623:           else
624:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
625:           end
626:         end
627:       else
628:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
629:       end
630:     end

[Source]

     # File lib/hdfeos5.rb, line 453
453:     def simple_put(var,hash=nil)
454:       if hash == nil
455:         if self.ntype == "char" || self.ntype=="byte"
456:           put_vars_char([0,0,0,0,0,0,0,0], nil, nil, var)
457:         elsif self.ntype=="sint"
458:           put_vars_short([0,0,0,0,0,0,0,0], nil, nil, var)
459:         elsif self.ntype=="int"
460:           put_vars_int([0,0,0,0,0,0,0,0], nil, nil, var)
461:         elsif self.ntype=="sfloat"
462:           put_vars_float([0,0,0,0,0,0,0,0], nil, nil, var)
463:         elsif self.ntype=="float"
464:           put_vars_double([0,0,0,0,0,0,0,0], nil, nil, var)
465:         else
466:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
467:         end
468:       elsif hash.key?("index")==true ||  hash.key?("start")==true
469:         h_sta = hash["start"]
470:         endq = hash.key?("end")
471:         strq = hash.key?("stride")
472:         if endq == false && strq == false
473:           if self.ntype == "char" || self.ntype=="byte"
474:             put_vars_char(h_sta, nil, nil, var)
475:           elsif self.ntype=="sint"
476:             put_vars_short(h_sta, nil, nil, var)
477:           elsif self.ntype=="int"
478:             put_vars_int(h_sta, nil, nil, var)
479:           elsif self.ntype=="sfloat"
480:             put_vars_float(h_sta, nil, nil, var)
481:           elsif self.ntype=="float"
482:             put_vars_double(h_sta, nil, nil, var)
483:           else
484:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
485:           end
486:         elsif endq == true && strq == false
487:           h_end = hash["end"]
488:           if self.ntype == "char" || self.ntype=="byte"
489:             put_vars_char(h_sta, nil, h_end, var)
490:           elsif self.ntype=="sint"
491:             put_vars_short(h_sta, nil, h_end, var)
492:           elsif self.ntype=="int"
493:             put_vars_int(h_sta, nil, h_end, var)
494:           elsif self.ntype=="sfloat"
495:             put_vars_float(h_sta, nil, h_end, var)
496:           elsif self.ntype=="float"
497:             put_vars_double(h_sta, nil, h_end, var)
498:           else
499:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
500:           end
501:         elsif endq == false && strq == true
502:           h_str = hash["stride"]
503:           if self.ntype == "char" || self.ntype=="byte"
504:             put_vars_char(h_sta, h_str, nil, var)
505:           elsif self.ntype=="sint"
506:             put_vars_short(h_sta, h_str, nil, var)
507:           elsif self.ntype=="int"
508:             put_vars_int(h_sta, h_str, nil, var)
509:           elsif self.ntype=="sfloat"
510:             put_vars_float(h_sta, h_str, nil, var)
511:           elsif self.ntype=="float"
512:             put_vars_double(h_sta, h_str, nil, var)
513:           else
514:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
515:           end
516:         else endq == true && strq == true
517:           h_end = hash["end"]
518:           h_str = hash["stride"]
519:           if self.ntype == "char" || self.ntype=="byte"
520:             put_vars_char(h_sta, h_str, h_end, var)
521:           elsif self.ntype=="sint"
522:             put_vars_short(h_sta, h_str, h_end, var)
523:           elsif self.ntype=="int"
524:             put_vars_int(h_sta, h_str, h_end, var)
525:           elsif self.ntype=="sfloat"
526:             put_vars_float(h_sta, h_str, h_end, var)
527:           elsif self.ntype=="float"
528:             put_vars_double(h_sta, h_str, h_end, var)
529:           else
530:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
531:           end
532:         end
533:       else
534:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
535:       end
536:     end
typecode()

Alias for ntype

Private Instance methods

[Source]

     # File lib/hdfeos5.rb, line 647
647:     def __rubber_expansion( args )
648:       if (id = args.index(false))  # substitution into id
649:         # false is incuded
650:         alen = args.length
651:         if args.rindex(false) != id
652:           raise ArguemntError,"only one rubber dimension is permitted"
653:         elsif alen > rank+1
654:           raise ArgumentError, "too many args"
655:         end
656:         ar = ( id!=0 ? args[0..id-1] : [] )
657:         args = ar + [true]*(rank-alen+1) + args[id+1..-1]
658:       elsif args.length == 0   # to support empty [], []=
659:         args = [true]*rank
660:       end
661:       args
662:     end

[Validate]