Class: NumRu::GPhys::Grib::GribPDS

Inherits:
Object
  • Object
show all
Includes:
NumRu::GPhys::GribUtils
Defined in:
lib/numru/gphys/grib.rb

Overview

end definition of class GribIS

Instance Method Summary collapse

Instance Method Details

#aveObject



659
660
661
# File 'lib/numru/gphys/grib.rb', line 659

def ave
  return @pds.to_uint2(18)
end

#bms?Boolean

Returns:

  • (Boolean)


501
502
503
504
# File 'lib/numru/gphys/grib.rb', line 501

def bms?
  flag = @pds.to_uint1(4)
  return (flag>>6)&1==1
end

#centerObject



459
460
461
# File 'lib/numru/gphys/grib.rb', line 459

def center
  return CENTERS[cid]
end

#dateObject



613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/numru/gphys/grib.rb', line 613

def date
  dt = DateTime.new((@pds.to_uint1(21)-1)*100 + @pds.to_uint1(9),
                     @pds.to_uint1(10), @pds.to_uint1(11),
                     @pds.to_uint1(12), @pds.to_uint1(13) )
  dt += Units[time_unit].convert(p1,"day")  
    # REMARK (horinouchi):
    # Just to add p1 should be OK in the crudest sense,
    # though one can further consider time_range
    # (ref: http://rda.ucar.edu/docs/formats/grib/gribdoc/timer.html)
  d = dt.to_date
  h = [dt.hour, dt.min]
  return [d,h]
end

#dfactObject



683
684
685
# File 'lib/numru/gphys/grib.rb', line 683

def dfact
  return str2int2( @pds[23,2] )
end

#gds?Boolean

Returns:

  • (Boolean)


482
483
484
485
# File 'lib/numru/gphys/grib.rb', line 482

def gds?
  flag = @pds.to_uint1(4)
  return (flag>>7)&1==1
end

#getObject



691
692
693
# File 'lib/numru/gphys/grib.rb', line 691

def get
  uint2str(length,3)<<@pds
end

#gidObject



474
475
476
# File 'lib/numru/gphys/grib.rb', line 474

def gid
  return @pds.to_uint1(3)
end

#initialObject



598
599
600
# File 'lib/numru/gphys/grib.rb', line 598

def initial
  return [@pds.to_uint1(21), @pds.to_uint1(9), @pds.to_uint1(10), @pds.to_uint1(11),  @pds.to_uint1(12), @pds.to_uint1(13)]
end

#lengthObject



448
449
450
# File 'lib/numru/gphys/grib.rb', line 448

def length
  @pds.length+3
end

#missObject



667
668
669
# File 'lib/numru/gphys/grib.rb', line 667

def miss
  return @pds.to_uint1(20)
end

#nameObject



519
520
521
# File 'lib/numru/gphys/grib.rb', line 519

def name
  return param[0]
end

#p1Object



635
636
637
# File 'lib/numru/gphys/grib.rb', line 635

def p1
  return @pds.to_uint1(15)
end

#p2Object



643
644
645
# File 'lib/numru/gphys/grib.rb', line 643

def p2
  return @pds.to_uint1(16)
end

#pidObject



466
467
468
# File 'lib/numru/gphys/grib.rb', line 466

def pid
  return @pds.to_uint1(2)
end

#set_ave(val) ⇒ Object Also known as: ave=



662
663
664
665
# File 'lib/numru/gphys/grib.rb', line 662

def set_ave(val)
  @pds[18,2] = uint2str(val,2)
  return val
end

#set_bms(bms) ⇒ Object Also known as: bms=



505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/numru/gphys/grib.rb', line 505

def set_bms(bms)
  flag = gds? ? 128 : 0
  if bms
    flag += 64
    @pds[4..4] = uint2str(flag,1)
    @sgm.bms.exist
    return true
  else
    @pds[4..4] = uint2str(flag,1)
    @sgm.bms.not_exist
    return false
  end
end

#set_center_id(id) ⇒ Object Also known as: center_id=



462
463
464
# File 'lib/numru/gphys/grib.rb', line 462

def set_center_id(id)
  @pds[1..1] = uint2str(id,1)
end

#set_dfact(val) ⇒ Object Also known as: dfact=



686
687
688
689
# File 'lib/numru/gphys/grib.rb', line 686

def set_dfact(val)
  @pds[23..24] = int2str(val,2)
  return val
end

#set_gds(gds) ⇒ Object Also known as: gds=



486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/numru/gphys/grib.rb', line 486

def set_gds(gds)
  flag = bms? ? 64 : 0
  if gds
    flag += 128
    @pds[4..4] = uint2str(flag,1)
    @sgm.gds.exist
    set_gid(255)
    return true
  else
    @pds[4..4] = uint2str(flag,1)
    @sgm.gds.not_exist
    return false
  end
end

#set_gid(id) ⇒ Object Also known as: gid=



477
478
479
480
# File 'lib/numru/gphys/grib.rb', line 477

def set_gid(id)
  @pds[3..3] = uint2str(id,1)
  return id
end

#set_initial(year, month, day, hour, min) ⇒ Object Also known as: initial=



601
602
603
604
605
606
607
608
609
610
611
# File 'lib/numru/gphys/grib.rb', line 601

def set_initial(year,month,day,hour,min)
  cent = year/100+1
  year = year%100
  @pds[21,1] = uint2str(cent,1)
  @pds[9,1] = uint2str(year,1)
  @pds[10,1] = uint2str(month,1)
  @pds[11,1] = uint2str(day,1)
  @pds[12,1] = uint2str(hour,1)
  @pds[13,1] = uint2str(min,1)
  return initial
end

#set_miss(val) ⇒ Object Also known as: miss=



670
671
672
673
# File 'lib/numru/gphys/grib.rb', line 670

def set_miss(val)
  @pds[20,1] = uint2str(val,1)
  return val
end

#set_name_id(id) ⇒ Object Also known as: name_id=



525
526
527
528
# File 'lib/numru/gphys/grib.rb', line 525

def set_name_id(id)
  @pds[5..5] = uint2str(id,1)
  return id
end

#set_p1(i) ⇒ Object Also known as: p1=



638
639
640
641
# File 'lib/numru/gphys/grib.rb', line 638

def set_p1(i)
  @pds[15,1] = uint2str(i,1)
  return i
end

#set_p2(i) ⇒ Object Also known as: p2=



646
647
648
649
# File 'lib/numru/gphys/grib.rb', line 646

def set_p2(i)
  @pds[16,1] = uint2str(i,1)
  return i
end

#set_pid(id) ⇒ Object Also known as: pid=



469
470
471
472
# File 'lib/numru/gphys/grib.rb', line 469

def set_pid(id)
  @pds[2..2] = uint2str(id,1)
  return id
end

#set_sub_center_id(id) ⇒ Object Also known as: sub_center_id=



678
679
680
681
# File 'lib/numru/gphys/grib.rb', line 678

def set_sub_center_id(id)
  @pds[22,1] = uint2str(id,1)
  return id
end

#set_time_range_id(id) ⇒ Object Also known as: time_range_id=



654
655
656
657
# File 'lib/numru/gphys/grib.rb', line 654

def set_time_range_id(id)
  @pds[17,1] = uint2str(id,1)
  return id
end

#set_time_unit_id(id) ⇒ Object Also known as: time_unit_id=



630
631
632
633
# File 'lib/numru/gphys/grib.rb', line 630

def set_time_unit_id(id)
  @pds[14,1] = uint2str(id,1)
  return id
end

#set_version(ver) ⇒ Object Also known as: version=



454
455
456
457
# File 'lib/numru/gphys/grib.rb', line 454

def set_version(ver)
  @pds[0..0] = uint2str(ver,1)
  return ver
end

#set_z_id(id) ⇒ Object Also known as: z_id=



550
551
552
553
# File 'lib/numru/gphys/grib.rb', line 550

def set_z_id(id)
  @pds[6..6] = uint2str(id,1)
  return id
end

#set_z_value(val) ⇒ Object Also known as: z_value=



583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/numru/gphys/grib.rb', line 583

def set_z_value(val)
  type = @pds.to_uint1(6)
  ary = Z_LEVELS[type]
  val.length==ary.length || raise("length of val is not collect")
  if val.length==1
    @pds[7,2] = uint2str(val[0],2)
  elsif val.length==2
    @pds[7,1] = uint2str(val[0],1)
    @pds[8,1] = uint2str(val[1],1)
  else
    raise "length of val is too large"
  end
  return val
end

#snameObject



530
531
532
533
534
535
536
# File 'lib/numru/gphys/grib.rb', line 530

def sname
  zid = @pds.to_uint1(6)
  sn = param[1]
  zt = Z_TYPES[zid]
  zn = zt ? zt[1] : zid.to_s
  return zn=="level" ? sn : sn+"_"+zn
end

#standard_nameObject



522
523
524
# File 'lib/numru/gphys/grib.rb', line 522

def standard_name
  return param[3]
end

#sub_centerObject



675
676
677
# File 'lib/numru/gphys/grib.rb', line 675

def sub_center
  return @pds.to_uint1(22)
end

#time_rangeObject



651
652
653
# File 'lib/numru/gphys/grib.rb', line 651

def time_range
  return @pds.to_uint1(17)
end

#time_unitObject



627
628
629
# File 'lib/numru/gphys/grib.rb', line 627

def time_unit
  return TIME_UNITS[ @pds.to_uint1(14) ]
end

#unitObject



537
538
539
# File 'lib/numru/gphys/grib.rb', line 537

def unit
  return param[2]
end

#versionObject



451
452
453
# File 'lib/numru/gphys/grib.rb', line 451

def version
  return @pds.to_uint1
end

#z_snameObject



555
556
557
558
559
560
561
562
563
# File 'lib/numru/gphys/grib.rb', line 555

def z_sname
  zid = @pds.to_uint1(6)
  if zn = Z_TYPES[zid]
    return zn[1]
  else
    warn "z type (#{zid}) is not defined yet"
    return "unknown_#{zid}"
  end
end

#z_typeObject



540
541
542
543
544
545
546
547
548
549
# File 'lib/numru/gphys/grib.rb', line 540

def z_type
  zid = @pds.to_uint1(6)
  zt = Z_TYPES[zid]
  if zt
    return zt[0]
  else
    warn "z type (#{zid}) is not defined yet"
    return zid.to_s
  end
end

#z_valueObject



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/numru/gphys/grib.rb', line 564

def z_value
  return @z_value if @z_value
  type = @pds.to_uint1(6)
  str = @pds[7,2]
  ary = Z_LEVELS[type]
  if ary.nil?
    ary = []
  else
    ary = ary.dup
  end
  if ary.length==1
    ary[0] = ary[0].dup.update( {"value"=> str.to_uint2} )
  elsif ary.length==2
    ary[0] = ary[0].dup.update( {"value"=> str.to_uint1} )
    ary[1] = ary[1].dup.update( {"value"=> str.to_uint1(1)} )
  end
  @z_value = ary
  return ary
end