Attachment 'check_1001.py'

Download

   1 import codecs, os  
   2 
   3 fn = 'schrott.dat'
   4 
   5 print "In a first step the file is readed and afterwards some logical checks are done"
   6 print "if that file can't be readed you get immediatly a traceback and you have to check yourself what could be wrong"
   7 print "if you like to have some human assistance please ask ReimarBauer for help" 
   8 print "---------------------------------------------------------------------------"
   9 
  10 file = open(fn, 'r')
  11 lines = file.readlines()
  12 file.close()
  13 txt = lines[0].split()
  14 NO_HEADER = long(txt[0])
  15 FFI = long(txt[1])
  16 PI_NAME = lines[1].strip()
  17 PI_ORGANISATION = lines[2].strip()
  18 EXPERIMENT_NAME = lines[3].strip()
  19 CAMPAIGN = lines[4].strip()          
  20 txt = lines[5].split()         
  21 AVN = long(txt[0])
  22 TNV = long(txt[1])
  23 txt = lines[6].split() 
  24 DEPENDENT_TIME = "%s %s %s" %(txt[0],txt[1],txt[2]) 
  25 FILE_MODIFICATION_TIME = "%s %s %s" %(txt[3],txt[4],txt[5]) 
  26 TIME_INCREMENT = lines[7].strip() 
  27 TIME_BASE = lines[8].strip() 
  28 NUMBER_OF_VARS = long(lines[9])
  29 
  30 if NUMBER_OF_VARS == 1: 
  31     SCALE_FACTORS = [float(lines[10])]
  32     MISSING_VALUES = [float(lines[11])]
  33     SHORT_NAMES = [lines[12]]
  34 else:    
  35     txt =  lines[10].split()
  36     SCALE_FACTORS= []
  37     for t in txt:
  38         SCALE_FACTORS.append(float(t))
  39         
  40     txt =  lines[11].split()   
  41     MISSING_VALUES =[]
  42     for t in txt:
  43         MISSING_VALUES.append(float(t))
  44         
  45     SHORT_NAMES = lines[12:12+NUMBER_OF_VARS]
  46     
  47 NUMBER_OF_COMMENTS = long(lines[12+NUMBER_OF_VARS])
  48 COMMENTS = lines[11+NUMBER_OF_VARS+2:11+NUMBER_OF_VARS+2+NUMBER_OF_COMMENTS]
  49 NUMBER_SPECIAL_COMMENTS = long(lines[11+NUMBER_OF_VARS+2+NUMBER_OF_COMMENTS])
  50 SPECIAL_COMMENTS = lines[11+NUMBER_OF_VARS+2+NUMBER_OF_COMMENTS+1:11+NUMBER_OF_VARS+2+NUMBER_OF_COMMENTS+1+NUMBER_SPECIAL_COMMENTS]
  51 FIRST_DATA_LINE = lines[11+NUMBER_OF_VARS+2+NUMBER_OF_COMMENTS+1+NUMBER_SPECIAL_COMMENTS]
  52 
  53 print "FIRST CHECK"
  54 print "----------------------------------------------------"
  55 print "%s %s" % (NO_HEADER, FFI)
  56 print PI_NAME
  57 print PI_ORGANISATION
  58 print EXPERIMENT_NAME
  59 print CAMPAIGN
  60 print "%s %s" % (AVN, TNV)
  61 print "%s %s" % (DEPENDENT_TIME, FILE_MODIFICATION_TIME)
  62 print TIME_INCREMENT
  63 print TIME_BASE
  64 print NUMBER_OF_VARS
  65 print SCALE_FACTORS
  66 print MISSING_VALUES
  67 print SHORT_NAMES
  68 print NUMBER_OF_COMMENTS
  69 print COMMENTS
  70 print NUMBER_SPECIAL_COMMENTS
  71 print SPECIAL_COMMENTS
  72 print FIRST_DATA_LINE
  73 
  74 error = False
  75 print "LOGICAL CHECK"
  76 print "----------------------------------------------------"
  77 if FFI != 1001:
  78     print "%s is wrong used. it should be 1001 " %(str(FFI)) 
  79     error = True
  80    
  81 if lines[NO_HEADER] != FIRST_DATA_LINE:
  82     print "The following line should show the first data line of your file"
  83     print lines[NO_HEADER]
  84     print "%s may be is not the right number for header lines" %(str(NO_HEADER))
  85     error = True
  86 if TIME_BASE != 'Elapsed UT seconds from 0 hours on day line 7':
  87     print "please use: Elapsed UT seconds from 0 hours on day line 7"
  88     error = True
  89 record =  lines[NO_HEADER].split()
  90 if len(record)-1 != NUMBER_OF_VARS:
  91     print "number of columns does not dependent on number of vars of %s" % (str(NUMBER_OF_VARS))
  92     error = True
  93 if NUMBER_OF_VARS != len(SCALE_FACTORS):
  94     print "not right number of scale factor values used. you need %s" % (str(NUMBER_OF_VARS))
  95     error = True
  96 if NUMBER_OF_VARS != len(MISSING_VALUES):
  97     print "not right number of missing values used. you need %s" % (str(NUMBER_OF_VARS))
  98     error = True
  99 for name in SHORT_NAMES: 
 100    if '(' not in name:
 101        print "please add a unit to your var %s enclosed into '()'" % (name)
 102        error = True
 103    
 104 if error:
 105    print "----------------------------------"
 106    print "sorry this file '%s' can't be accepted" % (fn)
 107    
 108 else:
 109    print "the file '%s' seems to be right" % (fn)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-11-01 09:18:24, 3.7 KB) [[attachment:check_1001.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.