"Fossies" - the Fresh Open Source Software Archive

Member "PerlCDF38_0/testepoch.pl" (19 Nov 2019, 8324 Bytes) of package /linux/misc/PerlCDF38_0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "testepoch.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl -w
    2 
    3 #
    4 # testPerlCDFii
    5 #
    6 #   This program tests the PerlCDF internal interface.  PerlCDF must be installed.
    7 #   See README.
    8 #
    9 #  Usage:
   10 #     perl testPerlCDFii.pl
   11 #
   12 # Written By:
   13 #
   14 #    Emily A. Greene
   15 #    NSSDC / Hughes STX
   16 #
   17 #    17 October, 1995
   18 #
   19 #    Version 1.0
   20 #    Modified by: Michael Liu  - 20 March, 1998
   21 #    Version 2.0
   22 #    Modified by: Michael Liu  - 07 January, 2005
   23 #
   24 #############################################################################
   25 #
   26 #  Translated from qst2ic.c v. 1.10 by J. Love
   27 #
   28 #  Differences include:
   29 #     z Variable is 5 strings each 8 characters long not a 40 character buffer
   30 #          tests changed accordingly
   31 #     maxiumum records written is a variable
   32 #     Arrays are all 1 Dimensional.  2 dimensionality handled within CDF.
   33 #     Added section confirming rVARs recCount, etc.
   34 #     Added a few informational messages
   35 #     Tests Epoch routines
   36 # Note: As Perl uses double, a variable of data type CDF_REAL4/FLOAT will 
   37 #   cause some minor value deviation due to different floating-point type 
   38 #   representations. If the value is returned from the CDF's C routine 
   39 #   and compared with Perl value, an epsilon is used for checkng their
   40 #   equality. 10**(-9) is used for double and 10**(-5) for 
   41 #   float/real. No problem for CDF_REAL8 data type.
   42 #     
   43 #############################################################################
   44 
   45 use strict;
   46 use Math::BigInt;
   47 
   48 BEGIN { unshift @INC,'/home/liu/PerlCDF38_0/blib/arch',
   49                      '/home/liu/PerlCDF38_0/blib/lib'; }
   50 use CDF;
   51 
   52 #############################################################################
   53 # Test Epoch Routines
   54 #############################################################################
   55 print "Test Epoch...\n";
   56 my $year = 1994;
   57 my $month = 10;
   58 my $day = 13;
   59 my $hour = 1;
   60 my $minute = 2;
   61 my $second = 3;
   62 my $msec = 987;
   63 
   64 my $epoch = CDF::computeEPOCH ($year, $month, $day, $hour, $minute,  
   65                                $second, $msec);
   66 
   67 my $epStringTrue = '13-Oct-1994 01:02:03.987';
   68 my $epString1True = '19941013.0431017';
   69 my $epString2True = '19941013010203';
   70 my $epString3True = '1994-10-13T01:02:03.987Z';
   71 my $epString4True = '1994-10-13T01:02:03.987';
   72 
   73 my ($epString, $epString1, $epString2, $epString3, $epString4);
   74 
   75 CDF::toEncodeEPOCH ($epoch, 0, $epString);
   76 QuitEPOCH ("30.0") if ($epString ne $epStringTrue);
   77 my (@epochd, @epochs);
   78 $epochd[0] = $epoch;
   79 $epochd[1] = $epoch;
   80 CDF::toEncodeEPOCH (\@epochd, 4, \@epochs);
   81 QuitEPOCH ("30.1") if ($epochs[0] ne $epString4True);
   82 QuitEPOCH ("30.2") if ($epochs[1] ne $epString4True);
   83 
   84 my $epochOut;
   85 $epochOut = CDF::toParseEPOCH ($epString);
   86 QuitEPOCH ("31.0") if ($epochOut != $epoch);
   87 $epochs[0] = $epString;
   88 $epochs[1] = $epString;
   89 @epochd = CDF::toParseEPOCH (\@epochs);
   90 QuitEPOCH ("31.1") if ($epochd[0] != $epoch);
   91 QuitEPOCH ("31.2") if ($epochd[1] != $epoch);
   92 
   93 #############################################################################
   94 # Test Epoch16 Routines
   95 #############################################################################
   96 print "Test Epoch16...\n";
   97 
   98 my $usec = 876;
   99 my $nsec = 765;
  100 my $psec = 654;
  101 my @epoch16;
  102 my $retco = CDF::computeEPOCH16 ($year, $month, $day, $hour, $minute, $second, 
  103                                  $msec, $usec, $nsec, $psec, \@epoch16);
  104 
  105 my $ep16StringTrue = '13-Oct-1994 01:02:03.987.876.765.654';
  106 my $ep16StringTruea = '13-Oct-1994 01:02:03.987.876.765.655';
  107 my $ep16StringTruex = '13-Oct-1994 01:02:03.987';
  108 my $ep16StringTruey = '13-Oct-1994 01:02:03.987Z';
  109 my $ep16StringTruez = '13-Oct-1994 01:02:03.987.876.765.654Z';
  110 my $ep16String1True = '19941013.043101711536640';
  111 my $ep16String2True = '19941013010203';
  112 my $ep16String3True = '1994-10-13T01:02:03.987.876.765.654Z';
  113 my $ep16String4True = '1994-10-13T01:02:03.987876765654';
  114 
  115 my ($ep16String, $ep16String1, $ep16String2, $ep16String3, $ep16String4);
  116 
  117 my @epoch16o;
  118 CDF::toEncodeEPOCH16 (\@epoch16, 0, $ep16String);
  119 QuitEPOCH ("40.0") if ($ep16String ne $ep16StringTrue);
  120 
  121 $epoch=CDF::toParseEPOCH16 ($ep16StringTrue, \@epoch16o);
  122 CDF::toEncodeEPOCH16 (\@epoch16o, 0, $ep16String);
  123 QuitEPOCH ("41.0") if ($epoch16[0] != $epoch16o[0]);
  124 QuitEPOCH ("41.1") if ($epoch16[1] != $epoch16o[1]);
  125 
  126 @epoch16o = ();
  127 $epoch=CDF::toParseEPOCH16 ($ep16StringTruea, \@epoch16o);
  128 CDF::toEncodeEPOCH16 (\@epoch16o, 0, $ep16String);
  129 print "a: $ep16StringTruea => $ep16String\n";
  130 
  131 @epoch16o = ();
  132 $epoch=CDF::toParseEPOCH16 ($ep16StringTruex, \@epoch16o);
  133 CDF::toEncodeEPOCH16 (\@epoch16o, 0, $ep16String);
  134 print "x: $ep16StringTruex => $ep16String\n";
  135 
  136 @epoch16o = ();
  137 $epoch=CDF::toParseEPOCH16 ($ep16StringTruey, \@epoch16o);
  138 CDF::toEncodeEPOCH16 (\@epoch16o, 0, $ep16String);
  139 print "y: $ep16StringTruey => $ep16String\n";
  140 
  141 @epoch16o = ();
  142 $epoch=CDF::toParseEPOCH16 ($ep16StringTruez, \@epoch16o);
  143 CDF::toEncodeEPOCH16 (\@epoch16o, 0, $ep16String);
  144 print "z: $ep16StringTruez => $ep16String\n";
  145 
  146 @epoch16o = ();
  147 $epoch=CDF::toParseEPOCH16 ($ep16String3True, \@epoch16o);
  148 QuitEPOCH ("41.3") if ($epoch16[0] != $epoch16o[0]) ;
  149 QuitEPOCH ("41.4") if ($epoch16[1] != $epoch16o[1]) ;
  150 CDF::toEncodeEPOCH16 (\@epoch16, 3, $ep16String);
  151 QuitEPOCH ("41.5") if ($ep16String ne $ep16String3True);
  152 
  153 @epoch16o = ();
  154 $epoch=CDF::toParseEPOCH16 ($ep16String4True, \@epoch16o);
  155 QuitEPOCH ("42.1") if ($epoch16[0] != $epoch16o[0]) ;
  156 QuitEPOCH ("42.2") if ($epoch16[1] != $epoch16o[1]) ;
  157 CDF::toEncodeEPOCH16 (\@epoch16, 4, $ep16String);
  158 QuitEPOCH ("42.3") if ($ep16String ne $ep16String4True);
  159 print "\n\n";
  160 #############################################################################
  161 # Test TT2000 Routines
  162 #############################################################################
  163 print "Test TT2000...\n";
  164 $year = 2010;
  165 
  166 my $tt2000=CDF::computeTT2000 ($year, $month, $day, $hour, $minute,  
  167                                $second, $msec, $usec, $nsec);
  168 my $ttString0True = '13-Oct-2010 01:02:03.987876765';
  169 my $ttString0Truex = '13-Oct-2010 01:02:03.987';
  170 my $ttString0Truey= '13-Oct-2010 01:02:03.987Z';
  171 my $ttString3True = '2010-10-13T01:02:03.987876765';
  172 my $ttString3Truex = '2010-10-13T01:02:03.987Z';
  173 my $ttString3Truey = '2010-10-13T01:02:03.987';
  174 my $ttString4True = '2010-10-13T01:02:03.987876765Z';
  175 my ($ttString0, $ttString3, $ttString4);
  176 
  177 CDF::toEncodeTT2000 ($tt2000, 0, $ttString0);
  178 QuitEPOCH ("50.0") if ($ttString0 ne $ttString0True);
  179 my (@tt2000d, @tt2000s);
  180 $tt2000d[0] = $tt2000;
  181 $tt2000d[1] = $tt2000;
  182 CDF::toEncodeTT2000 (\@tt2000d, 3, \@tt2000s);
  183 QuitEPOCH ("50.1") if ($tt2000s[0] ne $ttString3True);
  184 QuitEPOCH ("50.2") if ($tt2000s[1] ne $ttString3True);
  185 
  186 my $tt2000Out;
  187 my $tt2000n;
  188 
  189 $tt2000Out=CDF::toParseTT2000 ($ttString3True);
  190 QuitEPOCH ("51.0") if ($tt2000Out != $tt2000);
  191 
  192 $tt2000s[0] = $ttString3True;
  193 $tt2000s[1] = $ttString3True;
  194 @tt2000d=CDF::toParseTT2000 (\@tt2000s);
  195 QuitEPOCH ("51.3") if ($tt2000d[0] != $tt2000) ;
  196 QuitEPOCH ("51.4") if ($tt2000d[1] != $tt2000) ;
  197 
  198 my $tststr;
  199 CDF::toEncodeTT2000 (CDF::toParseTT2000 ($ttString0Truex), 3, $tststr);
  200 print "$ttString0Truex => $tststr\n";
  201 
  202 $tt2000Out=CDF::toParseTT2000 ($ttString0Truex);
  203 CDF::toEncodeTT2000 ($tt2000Out, 0, $tt2000n);
  204 print "$ttString0Truex => $tt2000n\n";
  205 
  206 $tt2000Out=CDF::toParseTT2000 ($ttString0Truey);
  207 CDF::toEncodeTT2000 ($tt2000Out, 0, $tt2000n);
  208 print "$ttString0Truey => $tt2000n\n";
  209 
  210 $tt2000Out=CDF::toParseTT2000 ($ttString3Truex);
  211 CDF::toEncodeTT2000 ($tt2000Out, 3, $tt2000n);
  212 print "$ttString3Truex => $tt2000n\n";
  213 
  214 $tt2000Out=CDF::toParseTT2000 ($ttString3Truey);
  215 CDF::toEncodeTT2000 ($tt2000Out, 3, $tt2000n);
  216 print "$ttString3Truey => $tt2000n\n";
  217 
  218 #############################################################################
  219 # Successful completion.
  220 #############################################################################
  221 print "All tests completed successfully\n";
  222 exit;
  223 
  224 #############################################################################
  225 # QuitCDF.
  226 #############################################################################
  227 sub QuitCDF {
  228     my $where=@_;
  229 
  230   print "Aborting at $where ...\n";
  231   exit;
  232     
  233 }#endsub QuitCDF
  234 
  235 #############################################################################
  236 #  QuitEPOCH
  237 #############################################################################
  238 sub QuitEPOCH {
  239   my ($where) = @_;
  240   print "Aborting at $where...test aborted.\n";
  241   exit;
  242 
  243 }#endsub QuitEPOCH