From debasish.hazra5 at gmail.com Tue Feb 3 12:37:41 2026 From: debasish.hazra5 at gmail.com (Debasish Hazra) Date: Tue, 3 Feb 2026 14:37:41 -0500 Subject: [ncl-talk] reading station data Message-ID: Hi, I am trying to read station data with header and column of data, with COlumn lengths are not equal in files and have attached one example file in the attachment. Can someone help to point what ascii read command to be used to extract time and column information from these files. Thanks Debasish. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 20240401_20240430_CATUC_Bamenda.lev15 Type: application/octet-stream Size: 204390 bytes Desc: not available URL: From dave.allured at noaa.gov Tue Feb 3 15:50:16 2026 From: dave.allured at noaa.gov (Dave Allured - NOAA Affiliate) Date: Tue, 3 Feb 2026 15:50:16 -0700 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Debasish, that is a CSV file with header lines. Use *asciiread* to read the entire file as strings. Then use string parsing functions such as *str_split_csv* and/or *str_get_field* to get individual columns. Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. https://www.ncl.ucar.edu/Applications/read_csv.shtml On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < ncl-talk at mailman.ucar.edu> wrote: > Hi, > I am trying to read station data with header and column of data, with > COlumn lengths are not equal in files and have attached one example file in > the attachment. Can someone help to point what ascii read command to be > used to extract time and column information from these files. > Thanks > Debasish. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at ucar.edu Tue Feb 3 16:04:24 2026 From: shea at ucar.edu (Dennis Shea) Date: Tue, 3 Feb 2026 16:04:24 -0700 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Also at *https://www.ncl.ucar.edu/Applications */ Look under* File I/O* see: *Read ascii* On Tue, Feb 3, 2026 at 3:50?PM Dave Allured - NOAA Affiliate via ncl-talk < ncl-talk at mailman.ucar.edu> wrote: > Debasish, that is a CSV file with header lines. Use *asciiread* to read > the entire file as strings. Then use string parsing functions such as > *str_split_csv* and/or *str_get_field* to get individual columns. > Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. > > https://www.ncl.ucar.edu/Applications/read_csv.shtml > > > On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < > ncl-talk at mailman.ucar.edu> wrote: > >> Hi, >> I am trying to read station data with header and column of data, with >> COlumn lengths are not equal in files and have attached one example file in >> the attachment. Can someone help to point what ascii read command to be >> used to extract time and column information from these files. >> Thanks >> Debasish. >> > _______________________________________________ > ncl-talk mailing list > ncl-talk at mailman.ucar.edu > List instructions, subscriber options, unsubscribe: > https://mailman.ucar.edu/mailman/listinfo/ncl-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From geetag54 at yahoo.com Thu Feb 5 00:47:32 2026 From: geetag54 at yahoo.com (Geeta Geeta) Date: Thu, 5 Feb 2026 07:47:32 +0000 (UTC) Subject: [ncl-talk] how do I make understand the code that there are so many blank columns not 1 References: <1918374861.403742.1770277652217.ref@mail.yahoo.com> Message-ID: <1918374861.403742.1770277652217@mail.yahoo.com> Hi? My data file looks like this? how do I make understand the code that there are so many blank columns not 1 pfa the section of my code? do i =2771, 2900print(dstr(i)) ; split the stringssplit= str_split(dstr(i)," ")print(split) ; it is stringDateTime = split(0)+" "+split(1)+split(2) following error is comingfatal:Dimension sizes of left hand side and right hand side of assignment do not matchfatal:["Execute.c":8637]:Execute: Error occurred at or near line 35 in file c1.ncl Geeta. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 1770277579123blob.jpg Type: image/png Size: 41640 bytes Desc: not available URL: From dave.allured at noaa.gov Thu Feb 5 08:08:34 2026 From: dave.allured at noaa.gov (Dave Allured - NOAA Affiliate) Date: Thu, 5 Feb 2026 08:08:34 -0700 Subject: [ncl-talk] how do I make understand the code that there are so many blank columns not 1 In-Reply-To: <1918374861.403742.1770277652217@mail.yahoo.com> References: <1918374861.403742.1770277652217.ref@mail.yahoo.com> <1918374861.403742.1770277652217@mail.yahoo.com> Message-ID: Geeta, it looks like this is a "tab-separated" ASCII text file. The symbol "^I" is code for a single tab character, coming from your print program. Confirm this by printing a sample line with a low level dump tool, such as *"od"* (linux) or maybe *"hexdump"* or other such tools. Or you can read a sample line in binary with NCL, using *cbinread ("sample.txt", -1, "ubyte")*. This will read each character as a single 8-bit unsigned integer. Then use NCL *print()* to show the integers. In this mode, ASCII tab characters are the number 9 in decimal; spaces are 32; digits are 48-57; etc. End of line is 10, or maybe the 13/10 pair. Consult an ASCII code table. Once again, this method is only for confirming the file format. To split each line into separate data fields, use *str_split_csv* with the tab character as the delimiter, instead of the usual comma. Get a single tab character with *str_get_tab*. You can also use *str_split_csv* to split multiple lines, instead of looping over single lines. This is more efficient if you have large amounts of data. On Thu, Feb 5, 2026 at 12:47?AM Geeta Geeta via ncl-talk < ncl-talk at mailman.ucar.edu> wrote: > Hi My data file looks like this [image: Inline image] > how do I make understand the code that there are so many blank columns not > 1 > pfa the section of my code > > do i =2771, 2900 > print(dstr(i)) > ; split the strings > split= str_split(dstr(i)," ") > print(split) ; it is string > DateTime = split(0)+" "+split(1)+split(2) > > following error is coming > fatal:Dimension sizes of left hand side and right hand side of assignment > do not match > fatal:["Execute.c":8637]:Execute: Error occurred at or near line 35 in > file c1.ncl > > Geeta. > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 1770277579123blob.jpg Type: image/jpeg Size: 41640 bytes Desc: not available URL: From debasish.hazra5 at gmail.com Thu Feb 5 09:42:06 2026 From: debasish.hazra5 at gmail.com (Debasish Hazra) Date: Thu, 5 Feb 2026 11:42:06 -0500 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Thanks Dave and Dennis for your suggestions. I followed the examples and created a script to read the file I sent earlier, but it seems to be I am still getting some header information in the column I am trying to extract. Attached are output and script that was used, any suggestions to overcome this issue. Debasish. On Tue, Feb 3, 2026 at 5:50?PM Dave Allured - NOAA Affiliate < dave.allured at noaa.gov> wrote: > Debasish, that is a CSV file with header lines. Use *asciiread* to read > the entire file as strings. Then use string parsing functions such as > *str_split_csv* and/or *str_get_field* to get individual columns. > Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. > > https://www.ncl.ucar.edu/Applications/read_csv.shtml > > > On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < > ncl-talk at mailman.ucar.edu> wrote: > >> Hi, >> I am trying to read station data with header and column of data, with >> COlumn lengths are not equal in files and have attached one example file in >> the attachment. Can someone help to point what ascii read command to be >> used to extract time and column information from these files. >> Thanks >> Debasish. >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- Copyright (C) 1995-2019 - All Rights Reserved University Corporation for Atmospheric Research NCAR Command Language Version 6.6.2 The use of this software is governed by a License Agreement. See http://www.ncl.ucar.edu/ for more details. warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value Variable: mhs Type: string Total Size: 1536 bytes 192 values Number of Dimensions: 1 Dimensions and sizes: [192] Coordinates: (0) (1) (2) (3) (4) UNITS can be found at (5) Time(hh:mm:ss) (6) 06:20:28 (7) 07:10:29 (8) 07:13:29 (9) 07:18:29 (10) 07:22:18 (11) 07:55:39 (12) 08:05:08 (13) 08:08:30 (14) 08:13:30 (15) 08:23:30 (16) 08:58:30 (17) 09:43:31 (18) 10:13:31 (19) 10:43:31 (20) 08:52:53 (21) 08:57:53 (22) 09:02:53 (23) 09:07:53 (24) 09:17:54 (25) 09:22:54 (26) 09:32:54 (27) 09:42:54 (28) 09:52:54 (29) 10:12:54 (30) 09:15:09 (31) 10:04:54 (32) 10:09:54 (33) 10:14:54 (34) 10:59:55 (35) 11:04:55 (36) 11:09:55 (37) 11:14:55 (38) 11:54:55 (39) 12:34:54 (40) 13:09:54 (41) 13:29:54 (42) 14:04:53 (43) 16:15:12 (44) 16:28:39 (45) 09:29:13 (46) 09:49:13 (47) 09:59:13 (48) 10:04:13 (49) 10:09:13 (50) 10:14:13 (51) 10:24:13 (52) 11:54:14 (53) 11:59:13 (54) 12:04:13 (55) 12:34:13 (56) 13:19:13 (57) 06:53:03 (58) 07:38:47 (59) 07:41:14 (60) 07:50:19 (61) 07:59:47 (62) 08:03:47 (63) 08:08:47 (64) 08:13:47 (65) 08:18:47 (66) 08:27:54 (67) 08:37:26 (68) 08:43:47 (69) 08:48:47 (70) 08:53:47 (71) 08:58:47 (72) 09:03:47 (73) 09:08:48 (74) 09:13:48 (75) 09:18:48 (76) 09:28:48 (77) 09:33:48 (78) 10:03:48 (79) 10:13:48 (80) 10:18:48 (81) 10:38:48 (82) 10:58:49 (83) 12:18:48 (84) 12:53:48 (85) 13:58:47 (86) 14:03:47 (87) 14:08:47 (88) 14:48:47 (89) 08:36:30 (90) 08:42:53 (91) 08:47:53 (92) 08:57:53 (93) 09:07:54 (94) 09:32:54 (95) 09:42:54 (96) 09:47:54 (97) 09:52:54 (98) 09:57:54 (99) 10:07:54 (100) 10:12:54 (101) 10:17:54 (102) 10:32:54 (103) 10:47:55 (104) 11:17:55 (105) 06:02:43 (106) 06:04:57 (107) 06:21:05 (108) 06:23:04 (109) 06:32:16 (110) 06:41:19 (111) 06:52:43 (112) 06:54:44 (113) 07:02:43 (114) 07:07:43 (115) 07:58:57 (116) 08:26:48 (117) 10:17:45 (118) 10:32:45 (119) 10:42:45 (120) 10:52:46 (121) 11:02:46 (122) 08:02:35 (123) 08:12:35 (124) 08:42:35 (125) 10:57:37 (126) 11:42:37 (127) 11:47:37 (128) 11:52:36 (129) 12:07:36 (130) 12:12:36 (131) 12:17:36 (132) 12:32:36 (133) 12:37:36 (134) 13:02:36 (135) 13:17:36 (136) 13:27:36 (137) 13:42:35 (138) 13:57:35 (139) 14:17:35 (140) 06:11:18 (141) 07:02:26 (142) 07:04:35 (143) 07:07:26 (144) 07:12:26 (145) 07:24:24 (146) 09:12:28 (147) 09:17:28 (148) 09:27:28 (149) 09:32:28 (150) 09:47:28 (151) 09:52:28 (152) 09:57:28 (153) 10:02:28 (154) 10:07:28 (155) 10:17:28 (156) 10:47:28 (157) 10:52:29 (158) 11:02:29 (159) 11:12:29 (160) 11:37:29 (161) 13:47:27 (162) 14:02:27 (163) 06:31:45 (164) 06:40:48 (165) 06:52:11 (166) 06:54:11 (167) 06:57:18 (168) 07:02:18 (169) 07:04:18 (170) 07:07:18 (171) 07:12:18 (172) 07:15:16 (173) 07:24:17 (174) 07:37:19 (175) 07:40:13 (176) 07:49:18 (177) 07:58:44 (178) 08:02:19 (179) 08:07:19 (180) 08:12:19 (181) 08:17:19 (182) 08:26:25 (183) 08:35:55 (184) 08:42:19 (185) 08:47:19 (186) 08:52:19 (187) 09:02:19 (188) 09:07:20 (189) 09:12:20 (190) 09:17:20 (191) 09:32:20 Variable: time_s Type: string Total Size: 1536 bytes 192 values Number of Dimensions: 1 Dimensions and sizes: [192] Coordinates: (0) (1) (2) (3) (4) https://aeronet.gsfc.nasa.gov/new_web/units.html (5) Day_of_Year (6) 93 (7) 93 (8) 93 (9) 93 (10) 93 (11) 93 (12) 93 (13) 93 (14) 93 (15) 93 (16) 93 (17) 93 (18) 93 (19) 93 (20) 95 (21) 95 (22) 95 (23) 95 (24) 95 (25) 95 (26) 95 (27) 95 (28) 95 (29) 95 (30) 105 (31) 106 (32) 106 (33) 106 (34) 106 (35) 106 (36) 106 (37) 106 (38) 106 (39) 106 (40) 106 (41) 106 (42) 106 (43) 106 (44) 106 (45) 109 (46) 109 (47) 109 (48) 109 (49) 109 (50) 109 (51) 109 (52) 109 (53) 109 (54) 109 (55) 109 (56) 109 (57) 111 (58) 111 (59) 111 (60) 111 (61) 111 (62) 111 (63) 111 (64) 111 (65) 111 (66) 111 (67) 111 (68) 111 (69) 111 (70) 111 (71) 111 (72) 111 (73) 111 (74) 111 (75) 111 (76) 111 (77) 111 (78) 111 (79) 111 (80) 111 (81) 111 (82) 111 (83) 111 (84) 111 (85) 111 (86) 111 (87) 111 (88) 111 (89) 116 (90) 116 (91) 116 (92) 116 (93) 116 (94) 116 (95) 116 (96) 116 (97) 116 (98) 116 (99) 116 (100) 116 (101) 116 (102) 116 (103) 116 (104) 116 (105) 117 (106) 117 (107) 117 (108) 117 (109) 117 (110) 117 (111) 117 (112) 117 (113) 117 (114) 117 (115) 117 (116) 117 (117) 117 (118) 117 (119) 117 (120) 117 (121) 117 (122) 118 (123) 118 (124) 118 (125) 118 (126) 118 (127) 118 (128) 118 (129) 118 (130) 118 (131) 118 (132) 118 (133) 118 (134) 118 (135) 118 (136) 118 (137) 118 (138) 118 (139) 118 (140) 119 (141) 119 (142) 119 (143) 119 (144) 119 (145) 119 (146) 119 (147) 119 (148) 119 (149) 119 (150) 119 (151) 119 (152) 119 (153) 119 (154) 119 (155) 119 (156) 119 (157) 119 (158) 119 (159) 119 (160) 119 (161) 119 (162) 119 (163) 120 (164) 120 (165) 120 (166) 120 (167) 120 (168) 120 (169) 120 (170) 120 (171) 120 (172) 120 (173) 120 (174) 120 (175) 120 (176) 120 (177) 120 (178) 120 (179) 120 (180) 120 (181) 120 (182) 120 (183) 120 (184) 120 (185) 120 (186) 120 (187) 120 (188) 120 (189) 120 (190) 120 (191) 120 Variable: aot500 Type: float Total Size: 768 bytes 192 values Number of Dimensions: 1 Dimensions and sizes: [192] Coordinates: Number Of Attributes: 1 _FillValue : 9.96921e+36 (0) 9.96921e+36 (1) 9.96921e+36 (2) 9.96921e+36 (3) 9.96921e+36 (4) 9.96921e+36 (5) 9.96921e+36 (6) 0.516767 (7) 0.563869 (8) 0.537748 (9) 0.574594 (10) 0.562609 (11) 0.588072 (12) 0.536206 (13) 0.536685 (14) 0.529194 (15) 0.57317 (16) 0.754846 (17) 0.62998 (18) 0.660645 (19) 0.51136 (20) 0.609276 (21) 0.632476 (22) 0.6065 (23) 0.586432 (24) 0.594579 (25) 0.593671 (26) 0.631975 (27) 0.700727 (28) 0.615976 (29) 0.603309 (30) 0.423319 (31) 0.353742 (32) 0.387588 (33) 0.361109 (34) 0.310555 (35) 0.295444 (36) 0.325005 (37) 0.313745 (38) 0.306736 (39) 0.318272 (40) 0.302237 (41) 0.323514 (42) 0.338343 (43) 0.245366 (44) 0.252717 (45) 0.53154 (46) 0.379412 (47) 0.368456 (48) 0.368535 (49) 0.363831 (50) 0.372119 (51) 0.424137 (52) 0.343276 (53) 0.344318 (54) 0.350251 (55) 0.357187 (56) 0.390748 (57) 0.597628 (58) 0.436115 (59) 0.422942 (60) 0.398002 (61) 0.490957 (62) 0.517161 (63) 0.510731 (64) 0.492952 (65) 0.504228 (66) 0.476302 (67) 0.472615 (68) 0.451448 (69) 0.422576 (70) 0.423629 (71) 0.417787 (72) 0.399637 (73) 0.389453 (74) 0.401793 (75) 0.430106 (76) 0.416493 (77) 0.420504 (78) 0.433418 (79) 0.41608 (80) 0.407221 (81) 0.494894 (82) 0.517688 (83) 0.525834 (84) 0.592808 (85) 0.444845 (86) 0.449846 (87) 0.446284 (88) 0.52824 (89) 0.662019 (90) 0.618207 (91) 0.631149 (92) 0.691626 (93) 0.622629 (94) 0.564822 (95) 0.531724 (96) 0.543187 (97) 0.532673 (98) 0.526504 (99) 0.533057 (100) 0.526452 (101) 0.543464 (102) 0.56998 (103) 0.589392 (104) 0.58229 (105) 0.451834 (106) 0.450906 (107) 0.538151 (108) 0.545592 (109) 0.547781 (110) 0.571741 (111) 0.512242 (112) 0.514135 (113) 0.519098 (114) 0.488852 (115) 0.553493 (116) 0.540033 (117) 0.462402 (118) 0.483284 (119) 0.475912 (120) 0.45786 (121) 0.497982 (122) 0.640874 (123) 0.581643 (124) 0.505501 (125) 0.647867 (126) 0.555627 (127) 0.521737 (128) 0.516424 (129) 0.463021 (130) 0.437534 (131) 0.458264 (132) 0.451876 (133) 0.441651 (134) 0.415896 (135) 0.437695 (136) 0.424631 (137) 0.452342 (138) 0.477956 (139) 0.504925 (140) 1.405625 (141) 1.533373 (142) 1.519282 (143) 1.522146 (144) 1.559416 (145) 1.515716 (146) 0.718552 (147) 0.680828 (148) 0.656679 (149) 0.654457 (150) 0.639357 (151) 0.649904 (152) 0.604629 (153) 0.603419 (154) 0.600191 (155) 0.569188 (156) 0.585529 (157) 0.57319 (158) 0.519653 (159) 0.60797 (160) 0.525382 (161) 0.462203 (162) 0.426086 (163) 0.509711 (164) 0.531249 (165) 0.55479 (166) 0.557595 (167) 0.567539 (168) 0.580142 (169) 0.581008 (170) 0.570694 (171) 0.554121 (172) 0.532265 (173) 0.554709 (174) 0.568186 (175) 0.550102 (176) 0.505335 (177) 0.51263 (178) 0.505702 (179) 0.510411 (180) 0.503677 (181) 0.526063 (182) 0.534265 (183) 0.527774 (184) 0.530307 (185) 0.563132 (186) 0.523929 (187) 0.521151 (188) 0.516597 (189) 0.514424 (190) 0.507523 (191) 0.531182 -------------- next part -------------- A non-text attachment was scrubbed... Name: extract.ncl Type: application/octet-stream Size: 802 bytes Desc: not available URL: From dave.allured at noaa.gov Fri Feb 6 00:13:47 2026 From: dave.allured at noaa.gov (Dave Allured - NOAA Affiliate) Date: Fri, 6 Feb 2026 00:13:47 -0700 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Debasish, you have almost everything right, except for the position of field names, and start of data. You have: field_names = str_split(lines(0),delim) But the field names are on line 7, not line 1. Change this to get the field names from line 7. Since NCL uses zero-based indexing, the correct line index is 7 - 1 = 6. field_names = str_split(lines(6),delim) Likewise, data lines start on the next line after the field names, at line index 7. This should clear up the header errors: mhs = str_get_field(lines(7:),2,delim) ... etc. If you are processing a lot of data, then the start of data can change between files. Can you have start of data hard coded at 7, or do you need a way to detect the position automatically? On Thu, Feb 5, 2026 at 9:42?AM Debasish Hazra wrote: > Thanks Dave and Dennis for your suggestions. I followed the examples and > created a script to read the file I sent earlier, but it seems to be I am > still getting some header information in the column I am trying to extract. > Attached are output and script that was used, any suggestions to overcome > this issue. > > Debasish. > > On Tue, Feb 3, 2026 at 5:50?PM Dave Allured - NOAA Affiliate < > dave.allured at noaa.gov> wrote: > >> Debasish, that is a CSV file with header lines. Use *asciiread* to read >> the entire file as strings. Then use string parsing functions such as >> *str_split_csv* and/or *str_get_field* to get individual columns. >> Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. >> >> https://www.ncl.ucar.edu/Applications/read_csv.shtml >> >> >> On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < >> ncl-talk at mailman.ucar.edu> wrote: >> >>> Hi, >>> I am trying to read station data with header and column of data, with >>> COlumn lengths are not equal in files and have attached one example file in >>> the attachment. Can someone help to point what ascii read command to be >>> used to extract time and column information from these files. >>> Thanks >>> Debasish. >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From debasish.hazra5 at gmail.com Fri Feb 6 10:05:37 2026 From: debasish.hazra5 at gmail.com (Debasish Hazra) Date: Fri, 6 Feb 2026 12:05:37 -0500 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Many thanks Dave. It worked fine. I think I need a way to detect the position automatically as I found it does not always start at line 7, that will be helpful. Also, I am trying to write the columns that I read into a csv file, but not getting right for the middle column. Any suggestions? Attached the code and output csv file as well. Debasish. On Fri, Feb 6, 2026 at 2:14?AM Dave Allured - NOAA Affiliate < dave.allured at noaa.gov> wrote: > Debasish, you have almost everything right, except for the position of > field names, and start of data. You have: > > field_names = str_split(lines(0),delim) > > But the field names are on line 7, not line 1. Change this to get the > field names from line 7. Since NCL uses zero-based indexing, the correct > line index is 7 - 1 = 6. > > field_names = str_split(lines(6),delim) > > Likewise, data lines start on the next line after the field names, at line > index 7. This should clear up the header errors: > > mhs = str_get_field(lines(7:),2,delim) ... etc. > > If you are processing a lot of data, then the start of data can change > between files. Can you have start of data hard coded at 7, or do you need > a way to detect the position automatically? > > > On Thu, Feb 5, 2026 at 9:42?AM Debasish Hazra > wrote: > >> Thanks Dave and Dennis for your suggestions. I followed the examples and >> created a script to read the file I sent earlier, but it seems to be I am >> still getting some header information in the column I am trying to extract. >> Attached are output and script that was used, any suggestions to overcome >> this issue. >> >> Debasish. >> >> On Tue, Feb 3, 2026 at 5:50?PM Dave Allured - NOAA Affiliate < >> dave.allured at noaa.gov> wrote: >> >>> Debasish, that is a CSV file with header lines. Use *asciiread* to >>> read the entire file as strings. Then use string parsing functions such as >>> *str_split_csv* and/or *str_get_field* to get individual columns. >>> Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. >>> >>> https://www.ncl.ucar.edu/Applications/read_csv.shtml >>> >>> >>> On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < >>> ncl-talk at mailman.ucar.edu> wrote: >>> >>>> Hi, >>>> I am trying to read station data with header and column of data, with >>>> COlumn lengths are not equal in files and have attached one example file in >>>> the attachment. Can someone help to point what ascii read command to be >>>> used to extract time and column information from these files. >>>> Thanks >>>> Debasish. >>>> >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: BamendaTest_202404.csv Type: application/vnd.ms-excel Size: 5208 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: extract.ncl Type: application/octet-stream Size: 1432 bytes Desc: not available URL: From dave.allured at noaa.gov Fri Feb 6 11:35:38 2026 From: dave.allured at noaa.gov (Dave Allured - NOAA Affiliate) Date: Fri, 6 Feb 2026 11:35:38 -0700 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: To detect the position of the header line, choose a substring in that line that (1) will be included exactly in every file that you want to read, and (2) is very unlikely to be used anywhere else in any file. I like the third header, "Day_of_Year", but most other headers would also be fine. Then locate the line containing this substring. iheader = str_match_ind (line(:) .eq. "Day_of_Year") idata = iheader + 1 Then use these indices in place of the previous hard-coded line indices. field_names = str_split(lines(iheader),delim) mhs = str_get_field(lines(idata:),2,delim) ... etc. If you want to add quality control, you can use ismissing(iheader) to check for missing header line, or unexpected spelling. You might also want to verify that your selected field names are actually the ones that you expected. The problem with the middle column is that you are using an integer format code "%3.0i" to print, but you forgot to convert Day from string to integer. I think you need to use toint(). Printing string with a numeric format code is always good for chaos. On Fri, Feb 6, 2026 at 10:07?AM Debasish Hazra wrote: > Many thanks Dave. It worked fine. I think I need a way to detect the > position automatically as I found it does not always start at line 7, that > will be helpful. > Also, I am trying to write the columns that I read into a csv file, but > not getting right for the middle column. Any suggestions? Attached the code > and output csv file as well. > > Debasish. > > On Fri, Feb 6, 2026 at 2:14?AM Dave Allured - NOAA Affiliate < > dave.allured at noaa.gov> wrote: > >> Debasish, you have almost everything right, except for the position of >> field names, and start of data. You have: >> >> field_names = str_split(lines(0),delim) >> >> But the field names are on line 7, not line 1. Change this to get the >> field names from line 7. Since NCL uses zero-based indexing, the correct >> line index is 7 - 1 = 6. >> >> field_names = str_split(lines(6),delim) >> >> Likewise, data lines start on the next line after the field names, at >> line index 7. This should clear up the header errors: >> >> mhs = str_get_field(lines(7:),2,delim) ... etc. >> >> If you are processing a lot of data, then the start of data can change >> between files. Can you have start of data hard coded at 7, or do you need >> a way to detect the position automatically? >> >> >> On Thu, Feb 5, 2026 at 9:42?AM Debasish Hazra >> wrote: >> >>> Thanks Dave and Dennis for your suggestions. I followed the examples and >>> created a script to read the file I sent earlier, but it seems to be I am >>> still getting some header information in the column I am trying to extract. >>> Attached are output and script that was used, any suggestions to overcome >>> this issue. >>> >>> Debasish. >>> >>> On Tue, Feb 3, 2026 at 5:50?PM Dave Allured - NOAA Affiliate < >>> dave.allured at noaa.gov> wrote: >>> >>>> Debasish, that is a CSV file with header lines. Use *asciiread* to >>>> read the entire file as strings. Then use string parsing functions such as >>>> *str_split_csv* and/or *str_get_field* to get individual columns. >>>> Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. >>>> >>>> https://www.ncl.ucar.edu/Applications/read_csv.shtml >>>> >>>> >>>> On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < >>>> ncl-talk at mailman.ucar.edu> wrote: >>>> >>>>> Hi, >>>>> I am trying to read station data with header and column of data, with >>>>> COlumn lengths are not equal in files and have attached one example file in >>>>> the attachment. Can someone help to point what ascii read command to be >>>>> used to extract time and column information from these files. >>>>> Thanks >>>>> Debasish. >>>>> >>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From debasish.hazra5 at gmail.com Fri Feb 6 22:42:43 2026 From: debasish.hazra5 at gmail.com (Debasish Hazra) Date: Sat, 7 Feb 2026 00:42:43 -0500 Subject: [ncl-talk] reading station data In-Reply-To: References: Message-ID: Thanks Dave, very helpful information and it worked. Debasish On Fri, Feb 6, 2026 at 1:36?PM Dave Allured - NOAA Affiliate < dave.allured at noaa.gov> wrote: > To detect the position of the header line, choose a substring in that line > that (1) will be included exactly in every file that you want to read, and > (2) is very unlikely to be used anywhere else in any file. I like the > third header, "Day_of_Year", but most other headers would also be fine. > Then locate the line containing this substring. > > iheader = str_match_ind (line(:) .eq. "Day_of_Year") > idata = iheader + 1 > > Then use these indices in place of the previous hard-coded line indices. > > field_names = str_split(lines(iheader),delim) > mhs = str_get_field(lines(idata:),2,delim) ... etc. > > If you want to add quality control, you can use ismissing(iheader) to > check for missing header line, or unexpected spelling. You might also want > to verify that your selected field names are actually the ones that you > expected. > > The problem with the middle column is that you are using an integer format > code "%3.0i" to print, but you forgot to convert Day from string to > integer. I think you need to use toint(). Printing string with a numeric > format code is always good for chaos. > > > On Fri, Feb 6, 2026 at 10:07?AM Debasish Hazra > wrote: > >> Many thanks Dave. It worked fine. I think I need a way to detect the >> position automatically as I found it does not always start at line 7, that >> will be helpful. >> Also, I am trying to write the columns that I read into a csv file, but >> not getting right for the middle column. Any suggestions? Attached the code >> and output csv file as well. >> >> Debasish. >> >> On Fri, Feb 6, 2026 at 2:14?AM Dave Allured - NOAA Affiliate < >> dave.allured at noaa.gov> wrote: >> >>> Debasish, you have almost everything right, except for the position of >>> field names, and start of data. You have: >>> >>> field_names = str_split(lines(0),delim) >>> >>> But the field names are on line 7, not line 1. Change this to get the >>> field names from line 7. Since NCL uses zero-based indexing, the correct >>> line index is 7 - 1 = 6. >>> >>> field_names = str_split(lines(6),delim) >>> >>> Likewise, data lines start on the next line after the field names, at >>> line index 7. This should clear up the header errors: >>> >>> mhs = str_get_field(lines(7:),2,delim) ... etc. >>> >>> If you are processing a lot of data, then the start of data can change >>> between files. Can you have start of data hard coded at 7, or do you need >>> a way to detect the position automatically? >>> >>> >>> On Thu, Feb 5, 2026 at 9:42?AM Debasish Hazra >>> wrote: >>> >>>> Thanks Dave and Dennis for your suggestions. I followed the examples >>>> and created a script to read the file I sent earlier, but it seems to be I >>>> am still getting some header information in the column I am trying to >>>> extract. Attached are output and script that was used, any suggestions to >>>> overcome this issue. >>>> >>>> Debasish. >>>> >>>> On Tue, Feb 3, 2026 at 5:50?PM Dave Allured - NOAA Affiliate < >>>> dave.allured at noaa.gov> wrote: >>>> >>>>> Debasish, that is a CSV file with header lines. Use *asciiread* to >>>>> read the entire file as strings. Then use string parsing functions such as >>>>> *str_split_csv* and/or *str_get_field* to get individual columns. >>>>> Examples *csv_3.ncl* and *csv4_ncl* are close to what you want to do. >>>>> >>>>> https://www.ncl.ucar.edu/Applications/read_csv.shtml >>>>> >>>>> >>>>> On Tue, Feb 3, 2026 at 12:38?PM Debasish Hazra via ncl-talk < >>>>> ncl-talk at mailman.ucar.edu> wrote: >>>>> >>>>>> Hi, >>>>>> I am trying to read station data with header and column of data, with >>>>>> COlumn lengths are not equal in files and have attached one example file in >>>>>> the attachment. Can someone help to point what ascii read command to be >>>>>> used to extract time and column information from these files. >>>>>> Thanks >>>>>> Debasish. >>>>>> >>>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: