"Fossies" - the Fresh Open Source Software Archive

Member "PerlCDF38_0/testString.pl" (19 Nov 2019, 4236 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.

    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 # Display title.
   54 #############################################################################
   55 
   56 print "\nTesting Perl-CDF Internal/C interface for strings\n\n";
   57 
   58 #############################################################################
   59 # Open CDF.
   60 #############################################################################
   61 my $id;
   62 my $status;
   63 
   64 $status = CDF::CDFlib (&OPEN_, &CDF_, $ARGV[0], \$id,
   65                &NULL_);
   66 QuitCDF ("4.0", $status) if ($status < &CDF_OK) ;
   67 
   68 #############################################################################
   69 # PUT to attributes.
   70 #############################################################################
   71 my @strings;
   72 my $string;
   73 my $numStrings;
   74 my $i;
   75 
   76 $status = CDF::CDFlib (&SELECT_, &ATTR_, 0,
   77                 &zVAR_, 0,
   78                 &zENTRY_, 0,
   79                &GET_, &zENTRY_STRINGSDATA_, \@strings,
   80 #              &GET_, &zENTRY_DATA_, \$string,
   81                &NULL_);
   82 
   83 if ($status == &CDF_OK) {
   84   $numStrings = scalar(@strings);
   85   for ($i = 0; $i < $numStrings; ++$i) {
   86     print "$i:\"$strings[$i]\" \n";
   87   }
   88 #  print "\"$string\"\n";
   89 }
   90 
   91 $status = CDF::CDFlib (&SELECT_, &ATTR_, 1,
   92                 &zVAR_, 0,
   93                 &zENTRY_, 0,
   94                &GET_, &zENTRY_STRINGSDATA_, \@strings,
   95 #              &GET_, &zENTRY_DATA_, \$string,
   96                &NULL_);
   97 
   98 if ($status == &CDF_OK) {
   99   $numStrings = scalar(@strings);
  100   for ($i = 0; $i < $numStrings; ++$i) {
  101     print "$i:\"$strings[$i]\" \n";
  102   }
  103 #  print "\"$string\" \n";
  104 }
  105 
  106 $status = CDF::CDFlib (&SELECT_, &ATTR_, 2,
  107                 &zVAR_, 0,
  108                 &zENTRY_, 0,
  109                &GET_, &zENTRY_STRINGSDATA_, \@strings,
  110 #              &GET_, &zENTRY_DATA_, \$string,
  111                &NULL_);
  112 if ($status == &CDF_OK) {
  113   $numStrings = scalar(@strings);
  114 for ($i = 0; $i < $numStrings; ++$i) {
  115     print "$i:\"$strings[$i]\" \n";
  116   }
  117 #  print "\"$string\" \n";
  118 }
  119 $status = CDF::CDFlib (&CLOSE_, &CDF_,
  120                &NULL_);
  121 QuitCDF ("28.2", $status) if ($status < &CDF_OK) ;
  122 
  123 #############################################################################
  124 # Successful completion.
  125 #############################################################################
  126 print "All tests completed successfully\n";
  127 exit;
  128 
  129 #############################################################################
  130 # QuitCDF.
  131 #############################################################################
  132 sub QuitCDF {
  133     my ($where, $status)=@_;
  134 
  135   print "Aborting at $where ...\n";
  136   if ($status < &CDF_OK) {
  137     my $text;
  138     CDF::CDFlib (&SELECT_, &CDF_STATUS_, $status,
  139            &GET_, &STATUS_TEXT_, \$text,
  140            &NULL_);
  141     print $text;
  142   }
  143   CDF::CDFlib (&CLOSE_, &CDF_,
  144       &NULL_);
  145   print "...test aborted.\n";
  146   exit;
  147     
  148 }#endsub QuitCDF
  149