ARTS  2.0.49
check_input.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
2  Patrick Eriksson <patrick.eriksson@chalmers.se>
3  Stefan Buehler <sbuehler@ltu.se>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA. */
19 
20 
21 
22 /*===========================================================================
23  === File description
24  ===========================================================================*/
25 
36 /*===========================================================================
37  === External declarations
38  ===========================================================================*/
39 
40 #include <cmath>
41 #include <stdexcept>
42 #include "check_input.h"
43 #include "array.h"
44 #include "logic.h"
45 #include "gridded_fields.h"
46 
47 extern const Index GFIELD3_P_GRID;
48 extern const Index GFIELD3_LAT_GRID;
49 extern const Index GFIELD3_LON_GRID;
50 
51 /*===========================================================================
52  === Functions for Index
53  ===========================================================================*/
54 
56 
68  const String& x_name,
69  const Index& x )
70 {
71  if ( !is_bool(x) )
72  {
73  ostringstream os;
74  os << "The variable *" << x_name << "* must be a boolean (0 or 1).\n"
75  << "The present value of *"<< x_name << "* is " << x << ".";
76  throw runtime_error( os.str() );
77  }
78 }
79 
81 
96  const String& x_name,
97  const Index& x,
98  const Index& x_low,
99  const Index& x_high )
100 {
101  if ( (x<x_low) || (x>x_high) )
102  {
103  ostringstream os;
104  os << "The variable *" << x_name << "* must fulfill:\n"
105  << " " << x_low << " <= " << x_name << " <= " << x_high << "\n"
106  << "The present value of *"<< x_name << "* is " << x << ".";
107  throw runtime_error( os.str() );
108  }
109 }
110 
112 
127  const String& x_name,
128  const ArrayOfIndex& x )
129 {
130  if ( !is_increasing(x) )
131  {
132  ostringstream os;
133  os << "The ArrayOfIndex *" << x_name << "* must have strictly\n"
134  << "increasing values, but this is not the case.\n";
135  os << "x = " << x << "\n";
136  throw runtime_error( os.str() );
137  }
138 }
139 
140 
141 /*===========================================================================
142  === Functions for Numeric
143  ===========================================================================*/
144 
146 
158  const String& x_name,
159  const Numeric& x )
160 {
161  if ( x < 0 )
162  {
163  ostringstream os;
164  os << "The variable *" << x_name << "* must be >= 0.\n"
165  << "The present value of *"<< x_name << "* is " << x << ".";
166  throw runtime_error( os.str() );
167  }
168 }
169 
170 
171 
173 
188  const String& x_name,
189  const Numeric& x,
190  const Numeric& x_low,
191  const Numeric& x_high )
192 {
193  if ( (x<x_low) || (x>x_high) )
194  {
195  ostringstream os;
196  os << "The variable *" << x_name << "* must fulfill:\n"
197  << " " << x_low << " <= " << x_name << " <= " << x_high << "\n"
198  << "The present value of *"<< x_name << "* is " << x << ".";
199  throw runtime_error( os.str() );
200  }
201 }
202 
203 
204 
205 /*===========================================================================
206  === Functions for Vector
207  ===========================================================================*/
208 
210 
223  const String& x_name,
224  ConstVectorView x,
225  const Index& l )
226 {
227  if ( x.nelem() != l )
228  {
229  ostringstream os;
230  os << "The vector *" << x_name << "* must have the length " << l
231  << ".\n"
232  << "The present length of *"<< x_name << "* is " << x.nelem() << ".";
233  throw runtime_error( os.str() );
234  }
235 }
236 
237 
238 
240 
254  const String& x1_name,
255  const String& x2_name,
256  ConstVectorView x1,
257  ConstVectorView x2 )
258 {
259  if ( x1.nelem() != x2.nelem() )
260  {
261  ostringstream os;
262  os << "The vectors *" << x1_name << "* and *" << x2_name
263  << "* must have the same length.\n"
264  << "The length of *"<< x1_name << "* is " << x1.nelem() << ".\n"
265  << "The length of *"<< x2_name << "* is " << x2.nelem() << ".";
266  throw runtime_error( os.str() );
267  }
268 }
269 
270 
271 
273 
287  const String& x_name,
288  ConstVectorView x )
289 {
290  if ( !is_increasing(x) )
291  {
292  ostringstream os;
293  os << "The vector *" << x_name << "* must have strictly\n"
294  << "increasing values, but this is not the case.\n";
295  os << "x = " << x << "\n";
296  throw runtime_error( os.str() );
297  }
298 }
299 
300 
301 
303 
317  const String& x_name,
318  ConstVectorView x )
319 {
320  if ( !is_decreasing(x) )
321  {
322  ostringstream os;
323  os << "The vector *" << x_name << "* must have strictly\ndecreasing "
324  << "values, but this is not the case.\n";
325  throw runtime_error( os.str() );
326  }
327 }
328 
330 
344  const String& x1_name,
345  const String& x2_name,
346  ConstVectorView v1,
347  ConstVectorView v2,
348  Numeric margin
349  )
350 {
351  chk_vector_length(x1_name, x2_name, v1, v2);
352 
353  for (Index i = 0; i<v1.nelem(); i++)
354  {
355  if (abs(v1[i] - v2[i]) > margin)
356  {
357  ostringstream os;
358  os << "Vectors " << x1_name << " and " << x2_name
359  << " differ.\n"
360  << x1_name << "[" << i << "]" << " = " << v1[i] << "\n"
361  << x2_name << "[" << i << "]" << " = " << v2[i] << "\n"
362  << "Difference should not exceed " << margin << "\n";
363  throw runtime_error(os.str());
364  }
365  }
366 }
367 
368 /*===========================================================================
369  === Functions for interpolation grids
370  ===========================================================================*/
371 
373 
390 void chk_interpolation_grids(const String& which_interpolation,
391  ConstVectorView old_grid,
392  ConstVectorView new_grid,
393  const Index order,
394  const Numeric& extpolfac )
395 {
396  const Index n_old = old_grid.nelem();
397 
398  ostringstream os;
399  os << "There is a problem with the grids for the\n"
400  << "following interpolation: " << which_interpolation << ".\n";
401 
402  // Old grid must have at least order+1 elements:
403  if (n_old < order+1)
404  {
405  os << "The original grid must have at least " << order+1 << " elements.";
406  throw runtime_error( os.str() );
407  }
408 
409  // Decide whether we have an ascending or descending grid:
410  bool ascending = ( old_grid[0] <= old_grid[1] );
411 
412  // Minimum and maximum allowed value from old grid. (Will include
413  // extrapolation tolerance.)
414  Numeric og_min, og_max;
415 
416  if (ascending)
417  {
418  // Old grid must be strictly increasing (no duplicate values.)
419  if ( !is_increasing(old_grid) )
420  {
421  os << "The original grid must be strictly sorted\n"
422  << "(no duplicate values). Yours is:\n"
423  << old_grid << ".";
424  throw runtime_error( os.str() );
425  }
426 
427  // Limits of extrapolation.
428  og_min = old_grid[0] -
429  extpolfac * ( old_grid[1] - old_grid[0] );
430  og_max = old_grid[n_old-1] +
431  extpolfac * ( old_grid[n_old-1] - old_grid[n_old-2] );
432  }
433  else
434  {
435  // Old grid must be strictly decreasing (no duplicate values.)
436  if ( !is_decreasing(old_grid) )
437  {
438  os << "The original grid must be strictly sorted\n"
439  << "(no duplicate values). Yours is:\n"
440  << old_grid << ".";
441  throw runtime_error( os.str() );
442  }
443 
444  // The max is now the first point, the min the last point!
445  // I think the sign is right here...
446  og_max = old_grid[0] -
447  extpolfac * ( old_grid[1] - old_grid[0] );
448  og_min = old_grid[n_old-1] +
449  extpolfac * ( old_grid[n_old-1] - old_grid[n_old-2] );
450  }
451 
452  // Min and max of new grid:
453  const Numeric ng_min = min(new_grid);
454  const Numeric ng_max = max(new_grid);
455 
456  // New grid must be inside old grid (plus extpolfac).
457  // (Values right on the edge (ng_min==og_min) are still allowed.)
458 
459  if (ng_min < og_min)
460  {
461  os << "The minimum of the new grid must be inside\n"
462  << "the original grid. (We allow a bit of extrapolation,\n"
463  << "but not so much).\n"
464  << "Minimum of original grid: " << min(old_grid) << "\n"
465  << "Minimum allowed value for new grid: " << og_min << "\n"
466  << "Actual minimum of new grid: " << ng_min;
467  throw runtime_error( os.str() );
468  }
469 
470  if (ng_max > og_max)
471  {
472  os << "The maximum of the new grid must be inside\n"
473  << "the original grid. (We allow a bit of extrapolation,\n"
474  << "but not so much).\n"
475  << "Maximum of original grid: " << max(old_grid) << "\n"
476  << "Maximum allowed value for new grid: " << og_max << "\n"
477  << "Actual maximum of new grid: " << ng_max;
478  throw runtime_error( os.str() );
479  }
480 
481  // If we get here, than everything should be fine.
482 }
483 
484 
486 
508 void chk_interpolation_grids(const String& which_interpolation,
509  ConstVectorView old_grid,
510  const Numeric& new_grid,
511  const Index order,
512  const Numeric& extpolfac )
513 {
514  Vector v(1, new_grid);
515  chk_interpolation_grids(which_interpolation,
516  old_grid,
517  v,
518  order,
519  extpolfac );
520 }
521 
522 /*===========================================================================
523  === Functions for Matrix
524  ===========================================================================*/
525 
527 
540  const String& x_name,
541  ConstMatrixView x,
542  const Index& l )
543 {
544  if ( x.ncols() != l )
545  {
546  ostringstream os;
547  os << "The matrix *" << x_name << "* must have " << l << " columns,\n"
548  << "but the number of columns is " << x.ncols() << ".";
549  throw runtime_error( os.str() );
550  }
551 }
552 
553 
554 
556 
569  const String& x_name,
570  ConstMatrixView x,
571  const Index& l )
572 {
573  if ( x.nrows() != l )
574  {
575  ostringstream os;
576  os << "The matrix *" << x_name << "* must have " << l << " rows,\n"
577  << "but the number of rows is " << x.nrows() << ".";
578  throw runtime_error( os.str() );
579  }
580 }
581 
582 
583 
584 /*===========================================================================
585  === Functions related to atmospheric and surface grids and fields.
586  ===========================================================================*/
587 
589 
604  const Index& dim,
605  ConstVectorView p_grid,
606  ConstVectorView lat_grid,
607  ConstVectorView lon_grid )
608 {
609  // p_grid
610  if( p_grid.nelem() < 2 )
611  throw runtime_error( "The length of *p_grid* must be >= 2." );
612  chk_if_decreasing( "p_grid", p_grid );
613 
614  // lat_grid
615  if( dim == 1 )
616  {
617  if( lat_grid.nelem() > 1 )
618  throw runtime_error(
619  "For dim=1, the length of *lat_grid* must be 0 or 1." );
620  }
621  else
622  {
623  if( lat_grid.nelem() < 2 )
624  throw runtime_error(
625  "For dim>1, the length of *lat_grid* must be >= 2.");
626  chk_if_increasing( "lat_grid", lat_grid );
627  }
628 
629  // lon_grid
630  if( dim < 3 )
631  {
632  if( lon_grid.nelem() > 1 )
633  throw runtime_error(
634  "For dim<3, the length of *lon_grid* must be 0 or 1." );
635  }
636  else
637  {
638  if( lon_grid.nelem() < 2 )
639  throw runtime_error(
640  "For dim=3, the length of *lon_grid* must be >= 2.");
641  chk_if_increasing( "lon_grid", lon_grid );
642  }
643 
644  // Check that latitude and longitude grids are inside OK ranges for 3D
645  if( dim == 3 )
646  {
647  if( lat_grid[0] < -90 )
648  throw runtime_error(
649  "The latitude grid cannot extend below -90 degrees for 3D" );
650  if( lat_grid[lat_grid.nelem() - 1] > 90 )
651  throw runtime_error(
652  "The latitude grid cannot extend above 90 degrees for 3D" );
653  if( lon_grid[0] < -360 )
654  throw runtime_error(
655  "No longitude (in lon_grid) can be below -360 degrees." );
656  if( lon_grid[lon_grid.nelem() - 1] > 360 )
657  throw runtime_error(
658  "No longitude (in lon_grid) can be above 360 degrees." );
659  if( lon_grid[lon_grid.nelem() - 1]-lon_grid[0] > 360 )
660  throw runtime_error(
661  "The longitude grid is not allowed to cover more than 360 degrees." );
662  }
663 }
664 
665 
666 
668 
684  const String& x_name,
685  ConstTensor3View x,
686  const Index& dim,
687  ConstVectorView p_grid,
688  ConstVectorView lat_grid,
689  ConstVectorView lon_grid )
690 {
691  // It is assumed that grids OK-ed through chk_atm_grids
692  Index npages=p_grid.nelem(), nrows=1, ncols=1;
693  if( dim > 1 )
694  nrows = lat_grid.nelem();
695  if( dim > 2 )
696  ncols = lon_grid.nelem();
697  if( x.ncols()!=ncols || x.nrows()!=nrows || x.npages()!=npages )
698  {
699  ostringstream os;
700  os << "The atmospheric field *" << x_name << "* has wrong size.\n"
701  << "Expected size is " << npages << " x " << nrows << " x "
702  << ncols << ", while actual size is " << x.npages() << " x "
703  << x.nrows() << " x " << x.ncols() << ".";
704  throw runtime_error( os.str() );
705  }
706  // If all lons are covered, check if cyclic
707  if( dim == 3 && (lon_grid[ncols-1]-lon_grid[0]) == 360 )
708  {
709  const Index ic = ncols-1;
710  for( Index ip=0; ip<npages; ip++ )
711  {
712  for( Index ir=0; ir<nrows; ir++ )
713  {
714  if( fabs(x(ip,ir,ic)-x(ip,ir,0)) > 0 )
715  {
716  ostringstream os;
717  os << "The variable *" << x_name << "* covers 360 "
718  << "degrees in the longitude direction, but the field "
719  << "seems to deviate between first and last longitude "
720  << "point. The field must be \"cyclic\".";
721  throw runtime_error( os.str() );
722  }
723  }
724  }
725  }
726 }
727 
729 
748  const String& x_name,
749  ConstTensor4View x,
750  const Index& dim,
751  const Index& nspecies,
752  ConstVectorView p_grid,
753  ConstVectorView lat_grid,
754  ConstVectorView lon_grid )
755 {
756  Index npages=p_grid.nelem(), nrows=1, ncols=1;
757  if( dim > 1 )
758  nrows = lat_grid.nelem();
759  if( dim > 2 )
760  ncols = lon_grid.nelem();
761 
762  const Index nbooks=nspecies;
763 
764  if( x.ncols()!=ncols || x.nrows()!=nrows || x.npages()!=npages ||
765  x.nbooks()!=nbooks )
766  {
767  ostringstream os;
768  os << "The atmospheric field *" << x_name << "* has wrong size.\n"
769  << "Expected size is "
770  << nbooks << " x " << npages << " x "
771  << nrows << " x " << ncols << ",\n"
772  << "while actual size is "
773  << x.nbooks() << " x " << x.npages() << " x "
774  << x.nrows() << " x " << x.ncols() << ".";
775  throw runtime_error( os.str() );
776  }
777  // If all lons are covered, check if cyclic
778  if( dim == 3 && (lon_grid[ncols-1]-lon_grid[0]) == 360 )
779  {
780  const Index ic = ncols-1;
781  for( Index is=0; is<nspecies; is++ )
782  {
783  for( Index ip=0; ip<npages; ip++ )
784  {
785  for( Index ir=0; ir<nrows; ir++ )
786  {
787  if( fabs(x(is,ip,ir,ic)-x(is,ip,ir,0)) > 0 )
788  {
789  ostringstream os;
790  os << "The variable *" << x_name << "* covers 360 degrees"
791  << "in the longitude direction, but at least one field "
792  << "seems to deviate between first and last longitude "
793  << "point. The field must be \"cyclic\". This was found "
794  << "for field with index " << is <<" (0-based).";
795  throw runtime_error( os.str() );
796  }
797  }
798  }
799  }
800  }
801 }
802 
803 
805 
822  const String& x_name,
823  const Matrix& x,
824  const Index& dim,
825  ConstVectorView lat_grid,
826  ConstVectorView lon_grid )
827 {
828  Index ncols=1, nrows=1;
829  if( dim > 1 )
830  nrows = lat_grid.nelem();
831  if( dim > 2 )
832  ncols = lon_grid.nelem();
833  if( x.ncols()!=ncols || x.nrows()!=nrows )
834  {
835  ostringstream os;
836  os << "The surface variable *" << x_name << "* has wrong size.\n"
837  << "Expected size is " << nrows << " x " << ncols << ","
838  << " while actual size is " << x.nrows() << " x " << x.ncols() << ".";
839  throw runtime_error( os.str() );
840  }
841  // If all lons are covered, check if cyclic
842  if( dim == 3 && (lon_grid[ncols-1]-lon_grid[0]) == 360 )
843  {
844  const Index ic = ncols-1;
845  for( Index ir=0; ir<nrows; ir++ )
846  {
847  if( fabs(x(ir,ic)-x(ir,0)) > 0 )
848  {
849  ostringstream os;
850  os << "The variable *" << x_name << "* covers 360 "
851  << "degrees in the longitude direction, but the data "
852  << "seems to deviate between first and last longitude "
853  << "point. The surface must be \"cyclic\".";
854  throw runtime_error( os.str() );
855  }
856  }
857  }
858 }
859 
860 
861 
862 
863 
864 /*===========================================================================
865  === Functions for Agendas
866  ===========================================================================*/
867 
869 
881  const String& x_name,
882  const Agenda& x )
883 {
884  if( x.nelem() == 0 )
885  {
886  ostringstream os;
887  os << "The agenda *" << x_name << "* is empty.\nIt is not allowed \n"
888  << "that an agenda that is actually used to be empty.\n"
889  << "Empty agendas are only created of methods setting dummy values \n"
890  << "to variables.";
891  throw runtime_error( os.str() );
892  }
893 }
894 
895 /*===========================================================================
896  === Functions for Tensors
897  ===========================================================================*/
898 
900 
911 void chk_size( const String& x_name,
912  ConstVectorView x,
913  const Index& c )
914 {
915  if ( !is_size(x,c) )
916  {
917  ostringstream os;
918  os << "The object *" << x_name
919  << "* does not have the right size.\n"
920  << "Dimensions should be:"
921  << " " << c
922  << ",\nbut they are: "
923  << " " << x.nelem()
924  << ".";
925  throw runtime_error( os.str() );
926  }
927 }
928 
930 
942 void chk_size( const String& x_name,
943  ConstMatrixView x,
944  const Index& r,
945  const Index& c )
946 {
947  if ( !is_size(x,r,c) )
948  {
949  ostringstream os;
950  os << "The object *" << x_name
951  << "* does not have the right size.\n"
952  << "Dimensions should be:"
953  << " " << r
954  << " " << c
955  << ",\nbut they are: "
956  << " " << x.nrows()
957  << " " << x.ncols()
958  << ".";
959  throw runtime_error( os.str() );
960  }
961 }
962 
964 
977 void chk_size( const String& x_name,
979  const Index& p,
980  const Index& r,
981  const Index& c )
982 {
983  if ( !is_size(x,p,r,c) )
984  {
985  ostringstream os;
986  os << "The object *" << x_name
987  << "* does not have the right size.\n"
988  << "Dimensions should be:"
989  << " " << p
990  << " " << r
991  << " " << c
992  << ",\nbut they are: "
993  << " " << x.npages()
994  << " " << x.nrows()
995  << " " << x.ncols()
996  << ".";
997  throw runtime_error( os.str() );
998  }
999 }
1000 
1002 
1016 void chk_size( const String& x_name,
1017  ConstTensor4View x,
1018  const Index& b,
1019  const Index& p,
1020  const Index& r,
1021  const Index& c )
1022 {
1023  if ( !is_size(x,b,p,r,c) )
1024  {
1025  ostringstream os;
1026  os << "The object *" << x_name
1027  << "* does not have the right size.\n"
1028  << "Dimensions should be:"
1029  << " " << b
1030  << " " << p
1031  << " " << r
1032  << " " << c
1033  << ",\nbut they are: "
1034  << " " << x.nbooks()
1035  << " " << x.npages()
1036  << " " << x.nrows()
1037  << " " << x.ncols()
1038  << ".";
1039  throw runtime_error( os.str() );
1040  }
1041 }
1042 
1044 
1059 void chk_size( const String& x_name,
1060  ConstTensor5View x,
1061  const Index& s,
1062  const Index& b,
1063  const Index& p,
1064  const Index& r,
1065  const Index& c )
1066 {
1067  if ( !is_size(x,s,b,p,r,c) )
1068  {
1069  ostringstream os;
1070  os << "The object *" << x_name
1071  << "* does not have the right size.\n"
1072  << "Dimensions should be:"
1073  << " " << s
1074  << " " << b
1075  << " " << p
1076  << " " << r
1077  << " " << c
1078  << ",\nbut they are: "
1079  << " " << x.nshelves()
1080  << " " << x.nbooks()
1081  << " " << x.npages()
1082  << " " << x.nrows()
1083  << " " << x.ncols()
1084  << ".";
1085  throw runtime_error( os.str() );
1086  }
1087 }
1088 
1090 
1106 void chk_size( const String& x_name,
1107  ConstTensor6View x,
1108  const Index& v,
1109  const Index& s,
1110  const Index& b,
1111  const Index& p,
1112  const Index& r,
1113  const Index& c )
1114 {
1115  if ( !is_size(x,v,s,b,p,r,c) )
1116  {
1117  ostringstream os;
1118  os << "The object *" << x_name
1119  << "* does not have the right size.\n"
1120  << "Dimensions should be:"
1121  << " " << v
1122  << " " << s
1123  << " " << b
1124  << " " << p
1125  << " " << r
1126  << " " << c
1127  << ",\nbut they are: "
1128  << " " << x.nvitrines()
1129  << " " << x.nshelves()
1130  << " " << x.nbooks()
1131  << " " << x.npages()
1132  << " " << x.nrows()
1133  << " " << x.ncols()
1134  << ".";
1135  throw runtime_error( os.str() );
1136  }
1137 }
1138 
1140 
1157 void chk_size( const String& x_name,
1158  ConstTensor7View x,
1159  const Index& l,
1160  const Index& v,
1161  const Index& s,
1162  const Index& b,
1163  const Index& p,
1164  const Index& r,
1165  const Index& c )
1166 {
1167  if ( !is_size(x,l,v,s,b,p,r,c) )
1168  {
1169  ostringstream os;
1170  os << "The object *" << x_name
1171  << "* does not have the right size.\n"
1172  << "Dimensions should be:"
1173  << " " << l
1174  << " " << v
1175  << " " << s
1176  << " " << b
1177  << " " << p
1178  << " " << r
1179  << " " << c
1180  << ",\nbut they are: "
1181  << " " << x.nlibraries()
1182  << " " << x.nvitrines()
1183  << " " << x.nshelves()
1184  << " " << x.nbooks()
1185  << " " << x.npages()
1186  << " " << x.nrows()
1187  << " " << x.ncols()
1188  << ".";
1189  throw runtime_error( os.str() );
1190  }
1191 }
1192 
1194 
1212  const Index& dim,
1213  const ArrayOfGriddedField3& pnd_field_raw,
1214  ConstVectorView p_grid,
1215  ConstVectorView lat_grid,
1216  ConstVectorView lon_grid,
1217  const ArrayOfIndex& cloudbox_limits )
1218 {
1219  Numeric p, lat, lon, v;
1220  Index n, p_i, lat_i, lon_i;
1221  // For any non-zero point, verify we're outside the cloudbox
1222  for (n=0; n < pnd_field_raw.nelem(); n++) {
1223  for (p_i=0; p_i < pnd_field_raw[n].data.npages(); p_i++) {
1224  for (lat_i=0; lat_i < pnd_field_raw[n].data.nrows(); lat_i++) {
1225  for (lon_i=0; lon_i < pnd_field_raw[n].data.ncols(); lon_i++) {
1226  v = pnd_field_raw[n].data(p_i, lat_i, lon_i);
1227  if (v != 0) {
1228  // Verify pressure is between cloudbox limits
1229  p = pnd_field_raw[n].get_numeric_grid(GFIELD3_P_GRID)[p_i];
1230  if (!((p <= p_grid[cloudbox_limits[0]]) &
1231  (p >= p_grid[cloudbox_limits[1]]))) {
1232  ostringstream os;
1233  os << "Found non-zero pnd outside cloudbox. "
1234  << "Cloudbox extends from p="
1235  << p_grid[cloudbox_limits[0]]
1236  << " Pa to p="
1237  << p_grid[cloudbox_limits[1]]
1238  << " Pa, but found pnd=" << v
1239  << "/m³ at p=" << p << " Pa.";
1240  throw runtime_error(os.str());
1241  }
1242  // Verify latitude is too
1243  if (dim > 1) {
1244  lat = pnd_field_raw[n].get_numeric_grid(GFIELD3_LAT_GRID)[lat_i];
1245  if (!((lat >= lat_grid[cloudbox_limits[2]]) &
1246  (lat <= lat_grid[cloudbox_limits[3]]))) {
1247  ostringstream os;
1248  os << "Found non-zero pnd outside cloudbox. "
1249  << "Cloudbox extends from lat="
1250  << lat_grid[cloudbox_limits[2]]
1251  << "° to lat="
1252  << lat_grid[cloudbox_limits[3]]
1253  << "°, but found pnd=" << v
1254  << "/m³ at lat=" << lat << "°.";
1255  throw runtime_error(os.str());
1256  }
1257  }
1258  // Etc. for longitude
1259  if (dim > 2) {
1260  lon = pnd_field_raw[n].get_numeric_grid(GFIELD3_LON_GRID)[lon_i];
1261  if (!((lon >= lon_grid[cloudbox_limits[4]]) &
1262  (lon <= lon_grid[cloudbox_limits[5]]))) {
1263  ostringstream os;
1264  os << "Found non-zero pnd outside cloudbox. "
1265  << "Cloudbox extends from lon="
1266  << lon_grid[cloudbox_limits[4]]
1267  << "° to lat="
1268  << lon_grid[cloudbox_limits[5]]
1269  << "°, but found pnd=" << v
1270  << "/m³ at lon=" << lon << "°.";
1271  throw runtime_error(os.str());
1272  }
1273  }
1274  }
1275  }
1276  }
1277  }
1278  }
1279 }
Matrix
The Matrix class.
Definition: matpackI.h:767
gridded_fields.h
Implementation of gridded fields.
ConstTensor7View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVII.cc:43
ConstTensor6View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:37
ConstTensor5View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:38
chk_atm_surface
void chk_atm_surface(const String &x_name, const Matrix &x, const Index &dim, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_surface
Definition: check_input.cc:821
chk_if_increasing
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:126
chk_if_bool
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:67
ConstTensor5View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
ConstTensor6View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:49
ConstTensor7View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVII.cc:67
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:169
Agenda::nelem
Index nelem() const
Return the number of agenda elements.
Definition: agenda_class.h:243
GFIELD3_LON_GRID
const Index GFIELD3_LON_GRID
GFIELD3_P_GRID
const Index GFIELD3_P_GRID
chk_not_empty
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
Definition: check_input.cc:880
ConstTensor6View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:55
ConstMatrixView::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:796
is_bool
bool is_bool(const Index &x)
Checks if a variable equals 0 or 1.
Definition: logic.cc:53
array.h
This file contains the definition of Array.
is_size
bool is_size(ConstVectorView x, const Index &n)
Verifies that the size of x is l.
Definition: logic.cc:90
Agenda
The Agenda class.
Definition: agenda_class.h:44
ConstTensor5View::npages
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:44
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:151
ConstTensor7View::nlibraries
Index nlibraries() const
Returns the number of libraries.
Definition: matpackVII.cc:31
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:149
Array< Index >
chk_not_negative
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:157
is_decreasing
bool is_decreasing(ConstVectorView x)
Checks if a vector is sorted in reversed order and is strictly decreasing.
Definition: logic.cc:303
ConstTensor6View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:31
ConstMatrixView::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:802
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
chk_matrix_ncols
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:539
abs
#define abs(x)
Definition: continua.cc:13094
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:175
ConstTensor7View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVII.cc:37
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:78
ConstTensor7View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVII.cc:55
ConstTensor6View
A constant view of a Tensor6.
Definition: matpackVI.h:167
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:66
chk_atm_field
void chk_atm_field(const String &x_name, ConstTensor3View x, const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_field (simple fields)
Definition: check_input.cc:683
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:60
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:154
max
#define max(a, b)
Definition: continua.cc:13097
chk_if_equal
void chk_if_equal(const String &x1_name, const String &x2_name, ConstVectorView v1, ConstVectorView v2, Numeric margin)
chk_if_equal
Definition: check_input.cc:343
ConstTensor6View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:43
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
chk_matrix_nrows
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
Definition: check_input.cc:568
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:72
ConstTensor7View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVII.cc:49
ConstTensor5View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:50
is_increasing
bool is_increasing(ConstVectorView x)
Checks if a vector is sorted and strictly increasing.
Definition: logic.cc:258
logic.h
Header file for logic.cc.
chk_vector_length
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:222
ConstTensor5View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:32
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:157
chk_pnd_field_raw_only_in_cloudbox
void chk_pnd_field_raw_only_in_cloudbox(const Index &dim, const ArrayOfGriddedField3 &pnd_field_raw, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, const ArrayOfIndex &cloudbox_limits)
chk_pnd_field_raw_only_in_cloudbox
Definition: check_input.cc:1211
chk_atm_grids
void chk_atm_grids(const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_grids
Definition: check_input.cc:603
min
#define min(a, b)
Definition: continua.cc:13096
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:147
chk_size
void chk_size(const String &x_name, ConstVectorView x, const Index &c)
Runtime check for size of Vector.
Definition: check_input.cc:911
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
chk_if_in_range
void chk_if_in_range(const String &x_name, const Index &x, const Index &x_low, const Index &x_high)
chk_if_in_range
Definition: check_input.cc:95
ConstTensor7View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVII.cc:61
GFIELD3_LAT_GRID
const Index GFIELD3_LAT_GRID
check_input.h
Vector
The Vector class.
Definition: matpackI.h:555
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
ConstTensor6View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:61
chk_if_decreasing
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:316
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:160
chk_interpolation_grids
void chk_interpolation_grids(const String &which_interpolation, ConstVectorView old_grid, ConstVectorView new_grid, const Index order, const Numeric &extpolfac)
Check interpolation grids.
Definition: check_input.cc:390